fixed reloadlua breaking __call metamethods, fixed singleplayer crash, added fun things to client-side lua :)

This commit is contained in:
Evil Factory
2021-09-23 21:29:18 -03:00
parent 8d52f2d664
commit d81684cd19
7 changed files with 65 additions and 8 deletions

View File

@@ -998,6 +998,8 @@ namespace Barotrauma
SoundManager?.Update();
GameMain.Lua.hook.Call("think", new object[] { });
Timing.Accumulator -= Timing.Step;
sw.Stop();

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
using Barotrauma.Networking;
namespace Barotrauma
{
partial class LuaSetup
{
public class LuaGUI
{
LuaSetup env;
public LuaGUI(LuaSetup _env)
{
env = _env;
}
public ChatBox ChatBox
{
get
{
return GameMain.Client.ChatBox;
}
}
}
}
}

View File

@@ -2805,6 +2805,10 @@ namespace Barotrauma.Networking
public override void AddChatMessage(ChatMessage message)
{
var should = new LuaResult(GameMain.Lua.hook.Call("chatMessage", new object[] { message.Text, message.SenderClient, message.Type, message }));
if (should.Bool()) return;
base.AddChatMessage(message);
if (string.IsNullOrEmpty(message.Text)) { return; }

View File

@@ -365,7 +365,7 @@ namespace Barotrauma
TaskPool.Update();
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
GameMain.Lua.hook.Call("think", new object[] { elapsedTime, Timing.TotalTime });
GameMain.Lua.hook.Call("think", new object[] { });
Timing.Accumulator -= Timing.Step;
}

View File

@@ -554,8 +554,9 @@ namespace Barotrauma
public object Call(string name, object[] args)
{
if (env == null) return null;
if (name == null) return null;
if(args == null) { args = new object[] { }; }
if (args == null) { args = new object[] { }; }
if (!hookFunctions.ContainsKey(name))
return null;

View File

@@ -204,15 +204,15 @@ namespace Barotrauma
private void AddCallMetaMember(IUserDataDescriptor IUDD)
{
var descriptor = (StandardUserDataDescriptor)IUDD;
descriptor.RemoveMetaMember("__call");
descriptor.AddMetaMember("__call", new ObjectCallbackMemberDescriptor("__call", HandleCall));
}
public void Stop()
{
lua = null;
hook = null;
game = null;
hook = new LuaHook(null);
game = new LuaGame(null);
networking = new LuaNetworking(null);
luaScriptLoader = null;
luaSetup = null;
@@ -321,8 +321,14 @@ namespace Barotrauma
AddCallMetaMember(UserData.RegisterType<Vector4>());
AddCallMetaMember(UserData.RegisterType<CharacterInfo>());
AddCallMetaMember(UserData.RegisterType<Signal>());
AddCallMetaMember(UserData.RegisterType<Color>());
#if SERVER
#elif CLIENT
UserData.RegisterType<LuaGUI>();
UserData.RegisterType<ChatBox>();
#endif
lua = new Script(CoreModules.Preset_SoftSandbox);
lua.Options.DebugPrint = PrintMessage;
@@ -373,6 +379,7 @@ namespace Barotrauma
lua.Globals["Vector2"] = UserData.CreateStatic<Vector2>();
lua.Globals["Vector3"] = UserData.CreateStatic<Vector3>();
lua.Globals["Vector4"] = UserData.CreateStatic<Vector4>();
lua.Globals["Color"] = UserData.CreateStatic<Color>();
lua.Globals["ChatMessage"] = UserData.CreateStatic<ChatMessage>();
lua.Globals["Hull"] = UserData.CreateStatic<Hull>();
lua.Globals["InvSlotType"] = UserData.CreateStatic<InvSlotType>();
@@ -384,6 +391,13 @@ namespace Barotrauma
lua.Globals["ClientPacketHeader"] = UserData.CreateStatic<ClientPacketHeader>();
lua.Globals["ServerPacketHeader"] = UserData.CreateStatic<ServerPacketHeader>();
#if SERVER
#elif CLIENT
lua.Globals["GUI"] = new LuaGUI(this);
#endif
// obsolete
lua.Globals["CreateVector2"] = (Func<float, float, Vector2>)CreateVector2;
lua.Globals["CreateVector3"] = (Func<float, float, float, Vector3>)CreateVector3;
@@ -424,7 +438,9 @@ namespace Barotrauma
public LuaSetup()
{
hook = new LuaHook(null);
game = new LuaGame(null);
networking = new LuaNetworking(null);
}
}

View File

@@ -79,9 +79,16 @@ namespace Barotrauma.Networking
public readonly string SenderName;
private Color? customColor = null;
public Color Color
{
get { return MessageColor[(int)Type]; }
get
{
if(customColor == null) return MessageColor[(int)Type];
return (Color)customColor;
}
set { customColor = value; }
}
public static string GetTimeStamp()