new hook call method + function to delegate conversion

This commit is contained in:
Oiltanker
2022-04-15 17:15:45 +03:00
parent 891efb4c4f
commit 3eba20ecb7
39 changed files with 470 additions and 676 deletions
@@ -25,7 +25,7 @@ namespace Barotrauma
GameServer.Log(GameServer.CharacterLogName(this) + " has died (Cause of death: " + causeOfDeath + ")", ServerLog.MessageType.Attack);
}
}
GameMain.LuaCs.HookBase.Call("characterDeath", this,causeOfDeathAffliction);
GameMain.LuaCs.Hook.Call("characterDeath", this,causeOfDeathAffliction);
if (HasAbilityFlag(AbilityFlags.RetainExperienceForNewCharacter))
{
@@ -348,9 +348,9 @@ namespace Barotrauma
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
GameMain.LuaCs.Update();
GameMain.LuaCs.HookBase.Call("think", new object[] { });
GameMain.LuaCs.Hook.Call("think", new object[] { });
performanceCounterTimer.Stop();
LuaTimer.LastUpdateTime = performanceCounterTimer.ElapsedMilliseconds;
LuaCsTimer.LastUpdateTime = performanceCounterTimer.ElapsedMilliseconds;
performanceCounterTimer.Reset();
Timing.Accumulator -= Timing.Step;
@@ -133,9 +133,9 @@ namespace Barotrauma.Networking
return;
}
var should = new LuaResult(GameMain.LuaCs.HookBase.Call("chatMessage", txt, c, type));
var should = GameMain.LuaCs.Hook.Call<bool?>("chatMessage", txt, c, type);
if (should.Bool())
if (should != null && should.Value)
{
return;
}
@@ -290,7 +290,7 @@ namespace Barotrauma.Networking
SendConsoleMessage("Granted all permissions to " + newClient.Name + ".", newClient);
}
GameMain.LuaCs.HookBase.Call("clientConnected", newClient);
GameMain.LuaCs.Hook.Call("clientConnected", newClient);
SendChatMessage($"ServerMessage.JoinedServer~[client]={clName}", ChatMessageType.Server, null, changeType: PlayerConnectionChangeType.Joined);
@@ -1804,7 +1804,7 @@ namespace Barotrauma.Networking
outmsg.Write((byte)ServerNetObject.CLIENT_LIST);
outmsg.Write(LastClientListUpdateID);
GameMain.LuaCs.HookBase.Call("writeClientList", c, outmsg);
GameMain.LuaCs.Hook.Call("writeClientList", c, outmsg);
outmsg.Write((byte)connectedClients.Count);
foreach (Client client in connectedClients)
@@ -2251,7 +2251,7 @@ namespace Barotrauma.Networking
AssignJobs(teamClients);
var result = new LuaResult(GameMain.LuaCs.HookBase.Call("jobsAssigned"));
GameMain.LuaCs.Hook.Call("jobsAssigned");
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
foreach (Client client in teamClients)
@@ -2455,7 +2455,7 @@ namespace Barotrauma.Networking
roundStartTime = DateTime.Now;
GameMain.LuaCs.HookBase.Call("roundStart");
GameMain.LuaCs.Hook.Call("roundStart");
startGameCoroutine = null;
yield return CoroutineStatus.Success;
@@ -2586,7 +2586,7 @@ namespace Barotrauma.Networking
Log("Ending the round...", ServerLog.MessageType.ServerMessage);
}
GameMain.LuaCs.HookBase.Call("roundEnd");
GameMain.LuaCs.Hook.Call("roundEnd");
string endMessage = TextManager.FormatServerMessage("RoundSummaryRoundHasEnded");
@@ -2697,12 +2697,12 @@ namespace Barotrauma.Networking
newName = Client.SanitizeName(newName);
if (newName == c.Name && newJob == c.PreferredJob && newTeam == c.PreferredTeam) { return false; }
var result = new LuaResult(GameMain.LuaCs.HookBase.Call("tryChangeClientName", c, newName, newJob, newTeam));
var result = GameMain.LuaCs.Hook.Call<bool?>("tryChangeClientName", c, newName, newJob, newTeam);
if (!result.IsNull())
if (result != null)
{
LastClientListUpdateID++;
return result.Bool();
return result.Value;
}
c.PreferredJob = newJob;
@@ -2892,7 +2892,7 @@ namespace Barotrauma.Networking
{
if (client == null) return;
GameMain.LuaCs.HookBase.Call("clientDisconnected", client);
GameMain.LuaCs.Hook.Call("clientDisconnected", client);
if (gameStarted && client.Character != null)
{
@@ -3142,9 +3142,9 @@ namespace Barotrauma.Networking
var hookChatMsg = ChatMessage.Create(senderName, message, (ChatMessageType)type, senderCharacter, senderClient, changeType);
var should = new LuaResult(GameMain.LuaCs.HookBase.Call("modifyChatMessage", hookChatMsg, senderRadio));
var should = GameMain.LuaCs.Hook.Call<bool?>("modifyChatMessage", hookChatMsg, senderRadio);
if (should.Bool())
if (should != null && should.Value)
return;
@@ -3874,7 +3874,7 @@ namespace Barotrauma.Networking
{
if (GameMain.Server == null || !GameMain.Server.ServerSettings.SaveServerLogs) { return; }
GameMain.LuaCs?.HookBase?.Call("serverLog", line, messageType);
GameMain.LuaCs?.Hook?.Call("serverLog", line, messageType);
GameMain.Server.ServerSettings.ServerLog.WriteLine(line, messageType);
@@ -184,9 +184,9 @@ namespace Barotrauma.Networking
var skipDeny = false;
{
var result = new LuaResult(GameMain.LuaCs.HookBase.Call("lidgren.handleConnection", inc));
if (!result.IsNull()) {
if (result.Bool()) skipDeny = true;
var result = GameMain.LuaCs.Hook.Call<bool?>("lidgren.handleConnection", inc);
if (result != null) {
if (result.Value) skipDeny = true;
else return;
}
}
@@ -206,18 +206,16 @@ namespace Barotrauma.Networking
protected void UpdatePendingClient(PendingClient pendingClient)
{
var result = new LuaResult(GameMain.LuaCs.HookBase.Call("handlePendingClient", pendingClient));
var skipRemove = false;
var result = GameMain.LuaCs.Hook.Call<bool?>("handlePendingClient", pendingClient);
if (result.Bool())
goto ignore;
if (result != null) skipRemove = result.Value;
if (connectedClients.Count >= serverSettings.MaxPlayers)
if (!skipRemove && connectedClients.Count >= serverSettings.MaxPlayers)
{
RemovePendingClient(pendingClient, DisconnectReason.ServerFull, "");
}
ignore:
if (IsPendingClientBanned(pendingClient, out string banReason))
{
RemovePendingClient(pendingClient, DisconnectReason.Banned, banReason);
@@ -94,19 +94,19 @@ namespace Barotrauma.Networking
ChatMessage.CanUseRadio(sender.Character, out WifiComponent senderRadio) &&
ChatMessage.CanUseRadio(recipient.Character, out WifiComponent recipientRadio))
{
var should = new LuaResult(GameMain.LuaCs.HookBase.Call("canUseVoiceRadio", new object[] { sender, recipient }));
var should = GameMain.LuaCs.Hook.Call<bool?>("canUseVoiceRadio", new object[] { sender, recipient });
if (!should.IsNull())
return should.Bool();
if (should != null)
return should.Value;
if (recipientRadio.CanReceive(senderRadio)) { return true; }
}
var should2 = new LuaResult(GameMain.LuaCs.HookBase.Call("changeLocalVoiceRange", new object[] { sender, recipient }));
var should2 = GameMain.LuaCs.Hook.Call<float?>("changeLocalVoiceRange", sender, recipient);
float range = 1.0f;
if (!should2.IsNull())
range = should2.Float();
if (should2 != null)
range = should2.Value;
//otherwise do a distance check
@@ -92,8 +92,8 @@ namespace Barotrauma
var traitorCandidates = new List<Tuple<Client, Character>>();
foreach (Client c in server.ConnectedClients)
{
var result = new LuaResult(GameMain.LuaCs.HookBase.Call("traitor.findTraitorCandidate", new object[] { c, team }));
if (result.Bool())
var result = GameMain.LuaCs.Hook.Call<bool?>("traitor.findTraitorCandidate", c, team);
if (result != null && result.Value)
{
traitorCandidates.Add(Tuple.Create(c, c.Character));
continue;
@@ -234,7 +234,7 @@ namespace Barotrauma
foreach (var traitor in Traitors.Values)
{
traitor.Greet(server, CodeWords, CodeResponse, message => pendingMessages[traitor].Add(message));
GameMain.LuaCs.HookBase.Call("traitor.traitorAssigned", new object[] { traitor });
GameMain.LuaCs.Hook.Call("traitor.traitorAssigned", new object[] { traitor });
}
pendingMessages.ForEach(traitor => traitor.Value.ForEach(message => traitor.Key.SendChatMessage(message, Identifier)));
pendingMessages.ForEach(traitor => traitor.Value.ForEach(message => traitor.Key.SendChatMessageBox(message, Identifier)));
@@ -64,6 +64,8 @@
<Content Remove="..\BarotraumaShared\**\*.cs" />
<Content Remove="..\BarotraumaShared\**\*.props" />
<Compile Include="..\BarotraumaShared\**\*.cs" />
<Compile Remove="..\BarotraumaShared\SharedSource\Cs\CsHook.cs" />
<Compile Remove="..\BarotraumaShared\SharedSource\Lua\LuaClasses\LuaHook.cs" />
<Content Remove="DedicatedServer.exe" />
</ItemGroup>