From e24797dd056943bb35900307932ec01c1820f9cb Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Sun, 29 Aug 2021 00:16:33 -0300 Subject: [PATCH] refactor: no more dynvalues or userdatas --- .../BarotraumaServer/ServerSource/GameMain.cs | 2 +- .../ServerSource/Lua/LuaClasses.cs | 44 +++--------- .../ServerSource/Lua/LuaCustomConverters.cs | 40 ----------- .../ServerSource/Lua/LuaSetup.cs | 14 +--- .../ServerSource/Networking/ChatMessage.cs | 17 +++-- .../ServerSource/Networking/GameServer.cs | 22 ++++-- .../Networking/Voip/VoipServer.cs | 9 ++- .../BarotraumaServer/WindowsServer.csproj | 1 + .../Characters/Animation/Ragdoll.cs | 7 +- .../SharedSource/Characters/Character.cs | 2 +- .../Characters/Health/CharacterHealth.cs | 48 +++++++++---- .../GameSession/GameModes/GameMode.cs | 2 +- .../Items/Components/ItemComponent.cs | 2 +- .../Items/Components/Signal/WifiComponent.cs | 14 +++- .../SharedSource/Items/Item.cs | 72 ++++++++++++++----- .../BarotraumaShared/SharedSource/Map/Gap.cs | 14 +++- 16 files changed, 161 insertions(+), 149 deletions(-) diff --git a/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs b/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs index d4a804ab4..38f8886c7 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/GameMain.cs @@ -366,7 +366,7 @@ namespace Barotrauma TaskPool.Update(); CoroutineManager.Update((float)Timing.Step, (float)Timing.Step); - GameMain.Lua.hook.Call("think", new DynValue[] { DynValue.NewNumber(elapsedTime), DynValue.NewNumber(Timing.TotalTime) }); + GameMain.Lua.hook.Call("think", new object[] { elapsedTime, Timing.TotalTime }); Timing.Accumulator -= Timing.Step; } diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs index 7af9c01d8..b41983e5d 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs @@ -31,28 +31,15 @@ namespace Barotrauma private class LuaPlayer { - public static List GetAllCharacters() + public static List GetAllCharacters() { - List values = new List(); - - foreach (Character ch in Character.CharacterList) - { - values.Add(UserData.Create(ch)); - } - - return values; + return Character.CharacterList; } - public static List GetAllClients() + public static List GetAllClients() { - List values = new List(); - foreach (Client ch in GameMain.Server.ConnectedClients) - { - values.Add(UserData.Create(ch)); - } - - return values; + return GameMain.Server.ConnectedClients; } public static CharacterInfo CreateCharacterInfo(string speciesName, string name = "", JobPrefab jobPrefab = null, string ragdollFileName = null, int variant = 0, Rand.RandSync randSync = Rand.RandSync.Unsynced) @@ -364,12 +351,6 @@ namespace Barotrauma env = e; } - public void Simple(int time, DynValue function) - { - - Task.Delay(time).ContinueWith(o => { env.RunFunction(function); }); - } - public static double GetTime() { return Timing.TotalTime; @@ -469,15 +450,6 @@ namespace Barotrauma } } - // hooks: - // chatMessage - // think - // update - // clientConnected - // clientDisconnected - // roundStart - // roundEnd - public class LuaHook { public LuaSetup env; @@ -491,9 +463,9 @@ namespace Barotrauma { public string name; public string hookName; - public DynValue function; + public object function; - public HookFunction(string n, string hn, DynValue func) + public HookFunction(string n, string hn, object func) { name = n; hookName = hn; @@ -503,7 +475,7 @@ namespace Barotrauma public List hookFunctions = new List(); - public void Add(string name, string hookName, DynValue function) + public void Add(string name, string hookName, object function) { foreach (HookFunction hf in hookFunctions) { @@ -518,7 +490,7 @@ namespace Barotrauma hookFunctions.Add(new HookFunction(name, hookName, function)); } - public DynValue Call(string name, DynValue[] args) + public object Call(string name, object[] args) { foreach (HookFunction hf in hookFunctions) { diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaCustomConverters.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaCustomConverters.cs index 8e8db28c3..e8b281153 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaCustomConverters.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaCustomConverters.cs @@ -13,46 +13,6 @@ namespace Barotrauma public static void RegisterAll() { -/* // Vector 2 - - Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Table, typeof(Vector2), - dynVal => { - Table table = dynVal.Table; - float x = (float)((Double)table[1]); - float y = (float)((Double)table[2]); - return new Vector2(x, y); - } - ); - Script.GlobalOptions.CustomConverters.SetClrToScriptCustomConversion( - (script, vector) => { - DynValue x = DynValue.NewNumber((double)vector.X); - DynValue y = DynValue.NewNumber((double)vector.Y); - DynValue dynVal = DynValue.NewTable(script, new DynValue[] { x, y }); - return dynVal; - } - ); - - // Vector3 - - Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Table, typeof(Vector3), - dynVal => { - Table table = dynVal.Table; - float x = (float)((Double)table[1]); - float y = (float)((Double)table[2]); - float z = (float)((Double)table[3]); - return new Vector3(x, y, z); - } - ); - Script.GlobalOptions.CustomConverters.SetClrToScriptCustomConversion( - (script, vector) => { - DynValue x = DynValue.NewNumber((double)vector.X); - DynValue y = DynValue.NewNumber((double)vector.Y); - DynValue z = DynValue.NewNumber((double)vector.Z); - DynValue dynVal = DynValue.NewTable(script, new DynValue[] { x, y, z }); - return dynVal; - } - );*/ - } } diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs index 2ab8b23ef..ad8459edf 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs @@ -8,6 +8,7 @@ using Microsoft.Xna.Framework; using System.Threading.Tasks; using Barotrauma.Items.Components; using System.Diagnostics; +using NLua; namespace Barotrauma { @@ -56,19 +57,6 @@ namespace Barotrauma } } - - public void RunFunction(DynValue func) - { - try - { - lua.Call(func); - } - catch (Exception e) - { - HandleLuaException(e); - } - } - public DynValue DoFile(string file) { try diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs index 938881052..db93b88dd 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs @@ -117,19 +117,18 @@ namespace Barotrauma.Networking return; } - var should = GameMain.Lua.hook.Call("chatMessage", new DynValue[] { DynValue.NewString(txt), UserData.Create(c), UserData.Create(type) }); + var should = GameMain.Lua.hook.Call("chatMessage", new object[] { txt, c, type }); if(should != null) { - if (should.CastToBool()) - { - return; - } - else - { - - } + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } if (type == ChatMessageType.Order) diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs index 4381a4e52..e086b9d8c 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs @@ -310,7 +310,7 @@ namespace Barotrauma.Networking SendConsoleMessage("Granted all permissions to " + newClient.Name + ".", newClient); } - GameMain.Lua.hook.Call("clientConnected", new MoonSharp.Interpreter.DynValue[] { MoonSharp.Interpreter.UserData.Create(newClient) }); + GameMain.Lua.hook.Call("clientConnected", new object[] { newClient }); SendChatMessage($"ServerMessage.JoinedServer~[client]={clName}", ChatMessageType.Server, null, changeType: PlayerConnectionChangeType.Joined); @@ -2439,7 +2439,7 @@ namespace Barotrauma.Networking roundStartTime = DateTime.Now; - GameMain.Lua.hook.Call("roundStart", new MoonSharp.Interpreter.DynValue[] { }); + GameMain.Lua.hook.Call("roundStart", new object[] { }); yield return CoroutineStatus.Success; @@ -2561,7 +2561,7 @@ namespace Barotrauma.Networking Log("Ending the round...", ServerLog.MessageType.ServerMessage); } - GameMain.Lua.hook.Call("roundEnd", new MoonSharp.Interpreter.DynValue[] { }); + GameMain.Lua.hook.Call("roundEnd", new object[] { }); string endMessage = TextManager.FormatServerMessage("RoundSummaryRoundHasEnded"); @@ -2857,7 +2857,7 @@ namespace Barotrauma.Networking { if (client == null) return; - GameMain.Lua.hook.Call("clientDisconnected", new MoonSharp.Interpreter.DynValue[] { MoonSharp.Interpreter.UserData.Create(client) }); + GameMain.Lua.hook.Call("clientDisconnected", new object[] { client }); if (gameStarted && client.Character != null) { @@ -3107,10 +3107,18 @@ namespace Barotrauma.Networking var hookChatMsg = ChatMessage.Create(senderName, message, (ChatMessageType)type, senderCharacter, senderClient, changeType); - var should = GameMain.Lua.hook.Call("modifyChatMessage", new DynValue[] { UserData.Create(hookChatMsg), LuaSetup.CreateUserDataSafe(senderRadio) }); + var should = GameMain.Lua.hook.Call("modifyChatMessage", new object[] { hookChatMsg, senderRadio }); - if (should != null && should.CastToBool()) - return; + if (should != null) + { + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } + } //check which clients can receive the message and apply distance effects foreach (Client client in ConnectedClients) diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/Voip/VoipServer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/Voip/VoipServer.cs index 39547a704..c94e8cb1c 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/Voip/VoipServer.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/Voip/VoipServer.cs @@ -94,10 +94,15 @@ namespace Barotrauma.Networking ChatMessage.CanUseRadio(sender.Character, out WifiComponent senderRadio) && ChatMessage.CanUseRadio(recipient.Character, out WifiComponent recipientRadio)) { - var should = GameMain.Lua.hook.Call("canUseVoiceRadio", new DynValue[] { UserData.Create(sender), LuaSetup.CreateUserDataSafe(recipient) }); + var should = GameMain.Lua.hook.Call("canUseVoiceRadio", new object[] { sender, recipient }); if (should != null) - return should.CastToBool(); + { + if (should is DynValue dyn) + { + return dyn.CastToBool(); + } + } if (recipientRadio.CanReceive(senderRadio)) { return true; } } diff --git a/Barotrauma/BarotraumaServer/WindowsServer.csproj b/Barotrauma/BarotraumaServer/WindowsServer.csproj index e037ff77e..434d3b553 100644 --- a/Barotrauma/BarotraumaServer/WindowsServer.csproj +++ b/Barotrauma/BarotraumaServer/WindowsServer.csproj @@ -83,6 +83,7 @@ + diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/Animation/Ragdoll.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/Animation/Ragdoll.cs index ce3ba073b..56805d478 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/Animation/Ragdoll.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/Animation/Ragdoll.cs @@ -714,11 +714,14 @@ namespace Barotrauma #if SERVER - var should = GameMain.Lua.hook.Call("changeFallDamage", new DynValue[] { DynValue.NewNumber(impactDamage), LuaSetup.CreateUserDataSafe(character), LuaSetup.CreateUserDataSafe(impactPos), LuaSetup.CreateUserDataSafe(velocity) }); + var should = GameMain.Lua.hook.Call("changeFallDamage", new object[] { impactDamage, character, impactPos, velocity }); if (should != null) { - impactDamage = (float)should.CastToNumber(); + if (should is DynValue dyn) + { + impactDamage = (float)dyn.CastToNumber(); + } } #endif diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs index 63bbb8261..78c479787 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs @@ -3810,7 +3810,7 @@ namespace Barotrauma #if SERVER - GameMain.Lua.hook.Call("characterDeath", new MoonSharp.Interpreter.DynValue[] { MoonSharp.Interpreter.UserData.Create(this) }); + GameMain.Lua.hook.Call("characterDeath", new object[] { this }); #endif } partial void KillProjSpecific(CauseOfDeathType causeOfDeath, Affliction causeOfDeathAffliction, bool log); diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/Health/CharacterHealth.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/Health/CharacterHealth.cs index 6cef4619a..cf84816b9 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/Health/CharacterHealth.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/Health/CharacterHealth.cs @@ -410,11 +410,17 @@ namespace Barotrauma if (targetLimb == null) { #if SERVER - var should = GameMain.Lua.hook.Call("afflictionApplied", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(affliction) }); + var should = GameMain.Lua.hook.Call("afflictionApplied", new object[] { this, affliction }); - if (should != null && should.CastToBool()) + if (should != null) { - return; + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } #endif @@ -428,11 +434,17 @@ namespace Barotrauma else { #if SERVER - var should = GameMain.Lua.hook.Call("afflictionApplied", new DynValue[] { UserData.Create(this), UserData.Create(affliction), UserData.Create(targetLimb) }); + var should = GameMain.Lua.hook.Call("afflictionApplied", new object[] { this, affliction, targetLimb }); - if (should != null && should.CastToBool()) + if (should != null) { - return; + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } #endif @@ -442,11 +454,17 @@ namespace Barotrauma else { #if SERVER - var should = GameMain.Lua.hook.Call("afflictionApplied", new DynValue[] { UserData.Create(this), UserData.Create(affliction)}); + var should = GameMain.Lua.hook.Call("afflictionApplied", new object[] { this, affliction }); - if (should != null && should.CastToBool()) + if (should != null) { - return; + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } #endif @@ -527,11 +545,17 @@ namespace Barotrauma } #if SERVER - var should = GameMain.Lua.hook.Call("afflictionApplied", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(attackResult), LuaSetup.CreateUserDataSafe(hitLimb) }); + var should = GameMain.Lua.hook.Call("afflictionApplied", new object[] { this, attackResult, hitLimb }); - if (should != null && should.CastToBool()) + if (should != null) { - return; + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } #endif diff --git a/Barotrauma/BarotraumaShared/SharedSource/GameSession/GameModes/GameMode.cs b/Barotrauma/BarotraumaShared/SharedSource/GameSession/GameModes/GameMode.cs index 7d935f587..435fb195b 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/GameSession/GameModes/GameMode.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/GameSession/GameModes/GameMode.cs @@ -73,7 +73,7 @@ namespace Barotrauma CrewManager?.Update(deltaTime); #if SERVER - GameMain.Lua.hook.Call("update", new DynValue[] { DynValue.NewNumber(deltaTime) }); + GameMain.Lua.hook.Call("update", new object[] { deltaTime }); #endif } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs index 4558d1cf1..fff2793cd 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs @@ -441,7 +441,7 @@ namespace Barotrauma.Items.Components #if SERVER if (!lastSignal.ContainsValue(connection.Name) || lastSignal[connection.Name] != signal.value) { - GameMain.Lua.hook.Call("signalReceived", new DynValue[] { UserData.Create(signal), UserData.Create(connection) }); + GameMain.Lua.hook.Call("signalReceived", new object[] { signal, connection }); lastSignal[connection.Name] = signal.value; } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/WifiComponent.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/WifiComponent.cs index 945155786..2ffa431bf 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/WifiComponent.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/WifiComponent.cs @@ -187,10 +187,18 @@ namespace Barotrauma.Items.Components if (senderComponent != null && !CanReceive(senderComponent)) { return; } #if SERVER - var should = GameMain.Lua.hook.Call("wifiSignalTransmitted", new DynValue[] { UserData.Create(this), UserData.Create(signal), DynValue.NewBoolean(sentFromChat) }); + var should = GameMain.Lua.hook.Call("wifiSignalTransmitted", new object[] { this, signal, sentFromChat }); - if (should != null && should.CastToBool()) - return; + if (should != null) + { + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } + } #endif bool chatMsgSent = false; diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs index 0e05aa5f4..dd901bc0a 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Item.cs @@ -2226,11 +2226,17 @@ namespace Barotrauma if (condition == 0.0f) { return; } #if SERVER - var should = GameMain.Lua.hook.Call("itemUse", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(character), LuaSetup.CreateUserDataSafe(targetLimb) }); + var should = GameMain.Lua.hook.Call("itemUse", new object[] { this, character, targetLimb }); - if (should != null && should.CastToBool()) + if (should != null) { - return; + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } #endif @@ -2268,11 +2274,17 @@ namespace Barotrauma if (condition == 0.0f) { return; } #if SERVER - var should = GameMain.Lua.hook.Call("itemSecondaryUse", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(character)}); + var should = GameMain.Lua.hook.Call("itemSecondaryUse", new object[] { this, character}); - if (should != null && should.CastToBool()) + if (should != null) { - return; + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } #endif @@ -2308,11 +2320,17 @@ namespace Barotrauma public void ApplyTreatment(Character user, Character character, Limb targetLimb) { #if SERVER - var should = GameMain.Lua.hook.Call("itemApplyTreatment", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(user), LuaSetup.CreateUserDataSafe(character), LuaSetup.CreateUserDataSafe(targetLimb) }); + var should = GameMain.Lua.hook.Call("itemApplyTreatment", new object[] { this, user, character, targetLimb }); - if (should != null && should.CastToBool()) + if (should != null) { - return; + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } #endif @@ -2373,11 +2391,17 @@ namespace Barotrauma public void Drop(Character dropper, bool createNetworkEvent = true) { #if SERVER - var should = GameMain.Lua.hook.Call("itemDrop", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(dropper)}); + var should = GameMain.Lua.hook.Call("itemDrop", new object[] { this, dropper}); - if (should != null && should.CastToBool()) + if (should != null) { - return; + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } #endif @@ -2432,11 +2456,17 @@ namespace Barotrauma public void Equip(Character character) { #if SERVER - var should = GameMain.Lua.hook.Call("itemEquip", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(character)}); + var should = GameMain.Lua.hook.Call("itemEquip", new object[] { this, character}); - if (should != null && should.CastToBool()) + if (should != null) { - return; + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } #endif @@ -2452,11 +2482,17 @@ namespace Barotrauma public void Unequip(Character character) { #if SERVER - var should = GameMain.Lua.hook.Call("itemUnequip", new DynValue[] { LuaSetup.CreateUserDataSafe(this), LuaSetup.CreateUserDataSafe(character)}); + var should = GameMain.Lua.hook.Call("itemUnequip", new object[] { this, character }); - if (should != null && should.CastToBool()) + if (should != null) { - return; + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } } #endif diff --git a/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs b/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs index 304a0980c..5ae3be0df 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs @@ -651,10 +651,18 @@ namespace Barotrauma } #if SERVER - var should = GameMain.Lua.hook.Call("gapOxygenUpdate", new DynValue[] { UserData.Create(this), UserData.Create(hull1), UserData.Create(hull2) }); + var should = GameMain.Lua.hook.Call("gapOxygenUpdate", new object[] { this, hull1, hull2 }); - if (should != null && should.CastToBool()) - return; + if (should != null) + { + if (should is DynValue dyn) + { + if (dyn.CastToBool()) + { + return; + } + } + } #endif float totalOxygen = hull1.Oxygen + hull2.Oxygen;