refactor: no more dynvalues or userdatas

This commit is contained in:
Evil Factory
2021-08-29 00:16:33 -03:00
parent fdb9ca1d30
commit e24797dd05
16 changed files with 161 additions and 149 deletions
@@ -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)
@@ -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)
@@ -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; }
}