Refactor and fix #56

This commit is contained in:
Evil Factory
2022-04-15 19:05:24 -03:00
parent 6eb575ea81
commit 42df433d3e
35 changed files with 144 additions and 97 deletions
@@ -27,7 +27,17 @@ namespace Barotrauma
string[] filesToUpdate = new string[] string[] filesToUpdate = new string[]
{ {
"Barotrauma.dll", "Barotrauma.deps.json", "Barotrauma.dll", "Barotrauma.deps.json",
"0harmony.dll", "MoonSharp.Interpreter.dll", "0harmony.dll", "Mono.Cecil.dll",
"Mono.Cecil.Mdb.dll", "Mono.Cecil.Pdb.dll",
"Mono.Cecil.Rocks.dll", "MonoMod.Common.dll",
"MoonSharp.Interpreter.dll",
"mscordaccore_amd64_amd64_4.700.22.11601.dll",
"Microsoft.CodeAnalysis.dll", "Microsoft.CodeAnalysis.CSharp.dll",
"Microsoft.CodeAnalysis.CSharp.Scripting.dll", "Microsoft.CodeAnalysis.Scripting.dll",
"System.Reflection.Metadata.dll", "System.Collections.Immutable.dll",
"System.Runtime.CompilerServices.Unsafe.dll"
}; };
@@ -690,7 +690,7 @@ namespace Barotrauma.Networking
{ {
ServerPacketHeader header = (ServerPacketHeader)inc.ReadByte(); ServerPacketHeader header = (ServerPacketHeader)inc.ReadByte();
GameMain.LuaCs.networking.NetMessageReceived(inc, header); GameMain.LuaCs.Networking.NetMessageReceived(inc, header);
if (roundInitStatus != RoundInitStatus.Started && if (roundInitStatus != RoundInitStatus.Started &&
roundInitStatus != RoundInitStatus.NotStarted && roundInitStatus != RoundInitStatus.NotStarted &&
@@ -413,17 +413,23 @@ namespace Barotrauma
{ {
msg.Close(); msg.Close();
string[] filesToRemove = new string[]
{
"Barotrauma.dll", "Barotrauma.deps.json",
"System.Reflection.Metadata.dll", "System.Collections.Immutable.dll",
"System.Runtime.CompilerServices.Unsafe.dll"
};
try try
{ {
System.IO.File.Move("Barotrauma.dll", "Barotrauma.dll.todelete", true); foreach (string file in filesToRemove)
System.IO.File.Move("Barotrauma.deps.json", "Barotrauma.deps.json.todelete", true); {
System.IO.File.Move(file, file + ".todelete", true);
System.IO.File.Move("Barotrauma.dll.old", "Barotrauma.dll", true); System.IO.File.Move(file + ".old", file, true);
System.IO.File.Move("Barotrauma.deps.json.old", "Barotrauma.deps.json", true); }
}
}catch(Exception e) catch(Exception e)
{ {
new GUIMessageBox("Error", "Error: " + e.ToString()); new GUIMessageBox("Error", $"{e} {e.InnerException}");
return false; return false;
} }
@@ -13,6 +13,7 @@
<ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon> <ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon>
<Configurations>Debug;Release;Unstable</Configurations> <Configurations>Debug;Release;Unstable</Configurations>
<WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors> <WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup> </PropertyGroup>
<!-- <!--
@@ -133,7 +134,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" />
<PackageReference Include="MonoMod.Common" Version="22.1.20.1" /> <PackageReference Include="MonoMod.Common" Version="22.3.24.1" />
<PackageReference Include="NVorbis" Version="0.8.6" /> <PackageReference Include="NVorbis" Version="0.8.6" />
<PackageReference Include="RestSharp" Version="106.13.0" /> <PackageReference Include="RestSharp" Version="106.13.0" />
</ItemGroup> </ItemGroup>
@@ -13,6 +13,7 @@
<ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon> <ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon>
<Configurations>Debug;Release;Unstable</Configurations> <Configurations>Debug;Release;Unstable</Configurations>
<WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors> <WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -127,6 +128,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" />
<PackageReference Include="MonoMod.Common" Version="22.1.20.1" /> <PackageReference Include="MonoMod.Common" Version="22.1.20.1" />
<PackageReference Include="NVorbis" Version="0.8.6" /> <PackageReference Include="NVorbis" Version="0.8.6" />
<PackageReference Include="RestSharp" Version="106.13.0" /> <PackageReference Include="RestSharp" Version="106.13.0" />
@@ -14,6 +14,7 @@
<Configurations>Debug;Release;Unstable</Configurations> <Configurations>Debug;Release;Unstable</Configurations>
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
<WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors> <WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -138,7 +139,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" />
<PackageReference Include="MonoMod.Common" Version="22.1.20.1" /> <PackageReference Include="MonoMod.Common" Version="22.3.24.1" />
<PackageReference Include="NVorbis" Version="0.8.6" /> <PackageReference Include="NVorbis" Version="0.8.6" />
<PackageReference Include="RestSharp" Version="106.13.0" /> <PackageReference Include="RestSharp" Version="106.13.0" />
</ItemGroup> </ItemGroup>
+11 -1
View File
@@ -13,6 +13,7 @@
<ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon> <ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon>
<Configurations>Debug;Release;Unstable</Configurations> <Configurations>Debug;Release;Unstable</Configurations>
<WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors> <WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup> </PropertyGroup>
<!-- <!--
@@ -87,9 +88,18 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" />
<PackageReference Include="MonoMod.Common" Version="22.1.20.1" /> <PackageReference Include="MonoMod.Common" Version="22.3.24.1" />
<PackageReference Include="RestSharp" Version="106.13.0" /> <PackageReference Include="RestSharp" Version="106.13.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\..\Libraries\0Harmony.dll</HintPath>
</Reference>
<Reference Include="MoonSharp.Interpreter">
<HintPath>..\..\Libraries\MoonSharp.Interpreter.dll</HintPath>
</Reference>
</ItemGroup>
<!-- Sourced from https://stackoverflow.com/a/45248069 --> <!-- Sourced from https://stackoverflow.com/a/45248069 -->
<Target Name="GetGitRevision" BeforeTargets="WriteGitRevision" Condition="'$(BuildHash)' == ''"> <Target Name="GetGitRevision" BeforeTargets="WriteGitRevision" Condition="'$(BuildHash)' == ''">
@@ -13,6 +13,7 @@
<ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon> <ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon>
<Configurations>Debug;Release;Unstable</Configurations> <Configurations>Debug;Release;Unstable</Configurations>
<WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors> <WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -81,6 +82,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" />
<PackageReference Include="RestSharp" Version="106.13.0" /> <PackageReference Include="RestSharp" Version="106.13.0" />
</ItemGroup> </ItemGroup>
@@ -91,6 +93,14 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\..\Libraries\0Harmony.dll</HintPath>
</Reference>
<Reference Include="MoonSharp.Interpreter">
<HintPath>..\..\Libraries\MoonSharp.Interpreter.dll</HintPath>
</Reference>
</ItemGroup>
<Target Name="GetGitRevision" BeforeTargets="WriteGitRevision" Condition="'$(BuildHash)' == ''"> <Target Name="GetGitRevision" BeforeTargets="WriteGitRevision" Condition="'$(BuildHash)' == ''">
<PropertyGroup> <PropertyGroup>
<!-- temp file for the git version (lives in "obj" folder)--> <!-- temp file for the git version (lives in "obj" folder)-->
@@ -43,7 +43,7 @@ namespace Barotrauma
var owner = GameMain.Server.ConnectedClients.Find(c => c.Character == this); var owner = GameMain.Server.ConnectedClients.Find(c => c.Character == this);
if (owner != null) if (owner != null)
{ {
if (!GameMain.LuaCs.game.overrideTraitors) if (!GameMain.LuaCs.Game.overrideTraitors)
{ {
GameMain.Server.SendDirectChatMessage(TextManager.FormatServerMessage("KilledByTraitorNotification"), owner, ChatMessageType.ServerMessageBoxInGame); GameMain.Server.SendDirectChatMessage(TextManager.FormatServerMessage("KilledByTraitorNotification"), owner, ChatMessageType.ServerMessageBoxInGame);
} }
@@ -700,7 +700,7 @@ namespace Barotrauma
var tempBuffer = new ReadWriteMessage(); var tempBuffer = new ReadWriteMessage();
WriteStatus(tempBuffer); WriteStatus(tempBuffer);
if (msgLengthBeforeStatus + tempBuffer.LengthBytes >= 255 && restrictMessageSize && GameMain.LuaCs.networking.restrictMessageSize) if (msgLengthBeforeStatus + tempBuffer.LengthBytes >= 255 && restrictMessageSize && GameMain.LuaCs.Networking.restrictMessageSize)
{ {
msg.Write(false); msg.Write(false);
if (msgLengthBeforeStatus < 255) if (msgLengthBeforeStatus < 255)
@@ -1273,11 +1273,21 @@ namespace Barotrauma
"Mono.Cecil.Rocks.dll", "MonoMod.Common.dll", "Mono.Cecil.Rocks.dll", "MonoMod.Common.dll",
"MoonSharp.Interpreter.dll", "MoonSharp.Interpreter.dll",
"mscordaccore_amd64_amd64_4.700.22.11601.dll", "mscordaccore_amd64_amd64_4.700.22.11601.dll",
"Microsoft.CodeAnalysis.dll", "Microsoft.CodeAnalysis.CSharp.dll",
"Microsoft.CodeAnalysis.CSharp.Scripting.dll", "Microsoft.CodeAnalysis.Scripting.dll",
"System.Reflection.Metadata.dll", "System.Collections.Immutable.dll",
"System.Runtime.CompilerServices.Unsafe.dll"
}; };
File.Move("Barotrauma.dll", "Barotrauma.dll.old", true); File.Move("Barotrauma.dll", "Barotrauma.dll.old", true);
File.Move("Barotrauma.deps.json", "Barotrauma.deps.json.old", true); File.Move("Barotrauma.deps.json", "Barotrauma.deps.json.old", true);
File.Move("System.Reflection.Metadata.dll", "System.Reflection.Metadata.dll.old", true);
File.Move("System.Collections.Immutable.dll", "System.Collections.Immutable.dll.old", true);
File.Move("System.Runtime.CompilerServices.Unsafe.dll", "System.Runtime.CompilerServices.Unsafe.dll.old", true);
foreach (string file in filesToCopy) foreach (string file in filesToCopy)
{ {
File.Copy(Path.Combine(path, "Binary", file), file, true); File.Copy(Path.Combine(path, "Binary", file), file, true);
@@ -104,7 +104,7 @@ namespace Barotrauma.Networking
bool isOwner = GameMain.Server.OwnerConnection != null && c.Connection == GameMain.Server.OwnerConnection; bool isOwner = GameMain.Server.OwnerConnection != null && c.Connection == GameMain.Server.OwnerConnection;
if (similarity + c.ChatSpamSpeed > 5.0f && !isOwner && !GameMain.LuaCs.game.disableSpamFilter) if (similarity + c.ChatSpamSpeed > 5.0f && !isOwner && !GameMain.LuaCs.Game.disableSpamFilter)
{ {
GameMain.Server.KarmaManager.OnSpamFilterTriggered(c); GameMain.Server.KarmaManager.OnSpamFilterTriggered(c);
@@ -125,7 +125,7 @@ namespace Barotrauma.Networking
c.ChatSpamSpeed += similarity + 0.5f; c.ChatSpamSpeed += similarity + 0.5f;
if (c.ChatSpamTimer > 0.0f && !isOwner && !GameMain.LuaCs.game.disableSpamFilter) if (c.ChatSpamTimer > 0.0f && !isOwner && !GameMain.LuaCs.Game.disableSpamFilter)
{ {
ChatMessage denyMsg = Create("", TextManager.Get("SpamFilterBlocked").Value, ChatMessageType.Server, null); ChatMessage denyMsg = Create("", TextManager.Get("SpamFilterBlocked").Value, ChatMessageType.Server, null);
c.ChatSpamTimer = 10.0f; c.ChatSpamTimer = 10.0f;
@@ -378,7 +378,7 @@ namespace Barotrauma.Networking
Character character = Character.CharacterList[i]; Character character = Character.CharacterList[i];
if (character.IsDead || !character.ClientDisconnected) { continue; } if (character.IsDead || !character.ClientDisconnected) { continue; }
if (!GameMain.LuaCs.game.disableDisconnectCharacter) if (!GameMain.LuaCs.Game.disableDisconnectCharacter)
{ {
character.KillDisconnectedTimer += deltaTime; character.KillDisconnectedTimer += deltaTime;
character.SetStun(1.0f); character.SetStun(1.0f);
@@ -700,7 +700,7 @@ namespace Barotrauma.Networking
ClientPacketHeader header = (ClientPacketHeader)inc.ReadByte(); ClientPacketHeader header = (ClientPacketHeader)inc.ReadByte();
GameMain.LuaCs.networking.NetMessageReceived(inc, header, connectedClient); GameMain.LuaCs.Networking.NetMessageReceived(inc, header, connectedClient);
switch (header) switch (header)
{ {
@@ -2429,7 +2429,7 @@ namespace Barotrauma.Networking
{ {
if (!(GameMain.GameSession?.GameMode is CampaignMode)) if (!(GameMain.GameSession?.GameMode is CampaignMode))
{ {
if (!GameMain.LuaCs.game.overrideTraitors) if (!GameMain.LuaCs.Game.overrideTraitors)
{ {
TraitorManager = new TraitorManager(); TraitorManager = new TraitorManager();
TraitorManager.Start(this); TraitorManager.Start(this);
@@ -3133,7 +3133,7 @@ namespace Barotrauma.Networking
senderName = null; senderName = null;
senderCharacter = null; senderCharacter = null;
} }
else if (type == ChatMessageType.Radio && !GameMain.LuaCs.game.overrideSignalRadio) else if (type == ChatMessageType.Radio && !GameMain.LuaCs.Game.overrideSignalRadio)
{ {
//send to chat-linked wifi components //send to chat-linked wifi components
Signal s = new Signal(message, sender: senderCharacter, source: senderRadio.Item); Signal s = new Signal(message, sender: senderCharacter, source: senderRadio.Item);
@@ -25,7 +25,7 @@ namespace Barotrauma.Networking
MultiPlayerCampaign campaign = GameMain.GameSession.GameMode as MultiPlayerCampaign; MultiPlayerCampaign campaign = GameMain.GameSession.GameMode as MultiPlayerCampaign;
foreach (Client c in networkMember.ConnectedClients) foreach (Client c in networkMember.ConnectedClients)
{ {
if (GameMain.LuaCs.game.overrideRespawnSub) if (GameMain.LuaCs.Game.overrideRespawnSub)
continue; continue;
if (!c.InGame) { continue; } if (!c.InGame) { continue; }
@@ -125,7 +125,7 @@ namespace Barotrauma.Networking
private bool ShouldStartRespawnCountdown(int characterToRespawnCount) private bool ShouldStartRespawnCountdown(int characterToRespawnCount)
{ {
if (GameMain.LuaCs.game.overrideRespawnSub) if (GameMain.LuaCs.Game.overrideRespawnSub)
{ {
characterToRespawnCount = 0; characterToRespawnCount = 0;
} }
@@ -136,7 +136,7 @@ namespace Barotrauma.Networking
{ {
if (RespawnShuttle != null) if (RespawnShuttle != null)
{ {
if (!GameMain.LuaCs.game.overrideRespawnSub) if (!GameMain.LuaCs.Game.overrideRespawnSub)
{ {
RespawnShuttle.Velocity = Vector2.Zero; RespawnShuttle.Velocity = Vector2.Zero;
} }
@@ -185,7 +185,7 @@ namespace Barotrauma.Networking
{ {
if (RespawnShuttle != null) if (RespawnShuttle != null)
{ {
if (GameMain.LuaCs.game.overrideRespawnSub) if (GameMain.LuaCs.Game.overrideRespawnSub)
{ {
CurrentState = State.Waiting; CurrentState = State.Waiting;
} }
@@ -206,7 +206,7 @@ namespace Barotrauma.Networking
Vector2 spawnPos = FindSpawnPos(); Vector2 spawnPos = FindSpawnPos();
if (!GameMain.LuaCs.game.overrideRespawnSub) if (!GameMain.LuaCs.Game.overrideRespawnSub)
{ {
RespawnCharacters(spawnPos); RespawnCharacters(spawnPos);
} }
@@ -13,6 +13,7 @@
<ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon> <ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon>
<Configurations>Debug;Release;Unstable</Configurations> <Configurations>Debug;Release;Unstable</Configurations>
<WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors> <WarningsAsErrors>;NU1605;CS0114;CS0108CS8597;CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8606;CS8607;CS8608;CS8609;CS8610;CS8611;CS8612;CS8613;CS8614;CS8615;CS8616;CS8617;CS8618;CS8619;CS8620;CS8621;CS8622;CS8624;CS8625;CS8626;CS8629;CS8631;CS8632;CS8633;CS8634;CS8638;CS8643;CS8644;CS8645;CS8653;CS8654;CS8655;CS8667;CS8669;CS8670;CS8714;CS8717;CS8765</WarningsAsErrors>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -84,9 +85,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.1.0" />
<PackageReference Include="MonoMod.Common" Version="22.1.20.1" /> <PackageReference Include="MonoMod.Common" Version="22.3.24.1" />
<PackageReference Include="RestSharp" Version="106.13.0" /> <PackageReference Include="RestSharp" Version="106.13.0" />
</ItemGroup> </ItemGroup>
@@ -2723,13 +2723,13 @@ namespace Barotrauma
{ {
for (int i = 0; i < CharacterList.Count; i++) for (int i = 0; i < CharacterList.Count; i++)
{ {
if (GameMain.LuaCs.game.updatePriorityCharacters.Contains(CharacterList[i])) continue; if (GameMain.LuaCs.Game.updatePriorityCharacters.Contains(CharacterList[i])) continue;
CharacterList[i].Update(deltaTime * CharacterUpdateInterval, cam); CharacterList[i].Update(deltaTime * CharacterUpdateInterval, cam);
} }
} }
foreach (Character character in GameMain.LuaCs.game.updatePriorityCharacters) foreach (Character character in GameMain.LuaCs.Game.updatePriorityCharacters)
{ {
if (character.Removed) continue; if (character.Removed) continue;
@@ -302,7 +302,7 @@ namespace Barotrauma
if (Prefab is AfflictionPrefabHusk huskPrefab) if (Prefab is AfflictionPrefabHusk huskPrefab)
{ {
if (huskPrefab.ControlHusk || GameMain.LuaCs.game.enableControlHusk) if (huskPrefab.ControlHusk || GameMain.LuaCs.Game.enableControlHusk)
{ {
#if SERVER #if SERVER
if (client != null) if (client != null)
@@ -74,7 +74,7 @@ namespace Barotrauma.Items.Components
#if SERVER #if SERVER
get get
{ {
if(GameMain.LuaCs.game.allowWifiChat) return true; if(GameMain.LuaCs.Game.allowWifiChat) return true;
return linkToChat; return linkToChat;
} }
@@ -47,6 +47,8 @@ namespace Barotrauma
} }
} }
private Harmony harmony;
private Dictionary<string, Dictionary<string, (LuaCsHookCallback, ACsMod)>> hookFunctions; private Dictionary<string, Dictionary<string, (LuaCsHookCallback, ACsMod)>> hookFunctions;
private Dictionary<long, HashSet<(string, CsPatch, ACsMod)>> hookPrefixMethods; private Dictionary<long, HashSet<(string, CsPatch, ACsMod)>> hookPrefixMethods;
@@ -54,7 +56,11 @@ namespace Barotrauma
private Queue<(float, CsAction, object[])> queuedFunctionCalls; private Queue<(float, CsAction, object[])> queuedFunctionCalls;
private LuaCsHook() { private static LuaCsHook instance;
public LuaCsHook() {
instance = this;
hookFunctions = new Dictionary<string, Dictionary<string, (LuaCsHookCallback, ACsMod)>>(); hookFunctions = new Dictionary<string, Dictionary<string, (LuaCsHookCallback, ACsMod)>>();
hookPrefixMethods = new Dictionary<long, HashSet<(string, CsPatch, ACsMod)>>(); hookPrefixMethods = new Dictionary<long, HashSet<(string, CsPatch, ACsMod)>>();
@@ -63,10 +69,12 @@ namespace Barotrauma
queuedFunctionCalls = new Queue<(float, CsAction, object[])>(); queuedFunctionCalls = new Queue<(float, CsAction, object[])>();
} }
private static LuaCsHook _inst; public void Initialize()
static LuaCsHook() => _inst = new LuaCsHook(); {
public static LuaCsHook Instance { get => _inst; } harmony = new Harmony("LuaCsForBarotrauma");
}
private static void _hookLuaCsPatch(MethodBase __originalMethod, object[] __args, object __instance, out object result, HookMethodType hookMethodType) private static void _hookLuaCsPatch(MethodBase __originalMethod, object[] __args, object __instance, out object result, HookMethodType hookMethodType)
{ {
result = null; result = null;
@@ -81,10 +89,10 @@ namespace Barotrauma
switch (hookMethodType) switch (hookMethodType)
{ {
case HookMethodType.Before: case HookMethodType.Before:
_inst.hookPrefixMethods.TryGetValue(funcAddr, out methodSet); instance.hookPrefixMethods.TryGetValue(funcAddr, out methodSet);
break; break;
case HookMethodType.After: case HookMethodType.After:
_inst.hookPostfixMethods.TryGetValue(funcAddr, out methodSet); instance.hookPostfixMethods.TryGetValue(funcAddr, out methodSet);
break; break;
default: default:
break; break;
@@ -196,7 +204,6 @@ namespace Barotrauma
public void HookMethod(string identifier, MethodInfo method, CsPatch patch, HookMethodType hookType = HookMethodType.Before, ACsMod owner = null) public void HookMethod(string identifier, MethodInfo method, CsPatch patch, HookMethodType hookType = HookMethodType.Before, ACsMod owner = null)
{ {
Console.WriteLine($" --== '{identifier}' {method.ReflectedType.Name}.{method.Name} -> {method.ReturnType.Name} | {hookType.ToString("G")}");
if (identifier == null || method == null || patch == null) throw new ArgumentNullException("Identifier, Method and Patch arguments must not be null."); if (identifier == null || method == null || patch == null) throw new ArgumentNullException("Identifier, Method and Patch arguments must not be null.");
var funcAddr = ((long)method.MethodHandle.GetFunctionPointer()); var funcAddr = ((long)method.MethodHandle.GetFunctionPointer());
@@ -208,14 +215,14 @@ namespace Barotrauma
{ {
if (patches == null || patches.Prefixes == null || patches.Prefixes.Find(patch => patch.PatchMethod == _miHookLuaCsPatchRetPrefix) == null) if (patches == null || patches.Prefixes == null || patches.Prefixes.Find(patch => patch.PatchMethod == _miHookLuaCsPatchRetPrefix) == null)
{ {
GameMain.LuaCs.harmony.Patch(method, prefix: new HarmonyMethod(_miHookLuaCsPatchRetPrefix)); harmony.Patch(method, prefix: new HarmonyMethod(_miHookLuaCsPatchRetPrefix));
} }
} }
else else
{ {
if (patches == null || patches.Prefixes == null || patches.Prefixes.Find(patch => patch.PatchMethod == _miHookLuaCsPatchPrefix) == null) if (patches == null || patches.Prefixes == null || patches.Prefixes.Find(patch => patch.PatchMethod == _miHookLuaCsPatchPrefix) == null)
{ {
GameMain.LuaCs.harmony.Patch(method, prefix: new HarmonyMethod(_miHookLuaCsPatchPrefix)); harmony.Patch(method, prefix: new HarmonyMethod(_miHookLuaCsPatchPrefix));
} }
} }
@@ -236,14 +243,14 @@ namespace Barotrauma
{ {
if (patches == null || patches.Postfixes == null || patches.Postfixes.Find(patch => patch.PatchMethod == _miHookLuaCsPatchRetPostfix) == null) if (patches == null || patches.Postfixes == null || patches.Postfixes.Find(patch => patch.PatchMethod == _miHookLuaCsPatchRetPostfix) == null)
{ {
GameMain.LuaCs.harmony.Patch(method, postfix: new HarmonyMethod(_miHookLuaCsPatchRetPostfix)); harmony.Patch(method, postfix: new HarmonyMethod(_miHookLuaCsPatchRetPostfix));
} }
} }
else else
{ {
if (patches == null || patches.Postfixes == null || patches.Postfixes.Find(patch => patch.PatchMethod == _miHookLuaCsPatchPostfix) == null) if (patches == null || patches.Postfixes == null || patches.Postfixes.Find(patch => patch.PatchMethod == _miHookLuaCsPatchPostfix) == null)
{ {
GameMain.LuaCs.harmony.Patch(method, postfix: new HarmonyMethod(_miHookLuaCsPatchPostfix)); harmony.Patch(method, postfix: new HarmonyMethod(_miHookLuaCsPatchPostfix));
} }
} }
@@ -312,7 +319,6 @@ namespace Barotrauma
{ {
name = name.ToLower(); name = name.ToLower();
LuaCsSetup.PrintLogMessage($"'{name}' | '{hookName}'");
if (name == null || hookName == null || hook == null) throw new ArgumentNullException("Names and Hook must not be null"); if (name == null || hookName == null || hook == null) throw new ArgumentNullException("Names and Hook must not be null");
if (!hookFunctions.ContainsKey(name)) if (!hookFunctions.ContainsKey(name))
@@ -340,7 +346,7 @@ namespace Barotrauma
queuedFunctionCalls.Clear(); queuedFunctionCalls.Clear();
GameMain.LuaCs.harmony?.UnpatchAll(); harmony?.UnpatchAll();
} }
@@ -24,19 +24,18 @@ namespace Barotrauma
internal LuaCsHook Hook { get; private set; } internal LuaCsHook Hook { get; private set; }
public LuaGame game; public LuaGame Game;
public LuaCsNetworking networking; public LuaCsNetworking Networking;
public Harmony harmony;
public LuaScriptLoader luaScriptLoader; public LuaScriptLoader LuaScriptLoader;
public CsScriptLoader netScriptLoader; public CsScriptLoader NetScriptLoader;
public LuaCsSetup() public LuaCsSetup()
{ {
Hook = LuaCsHook.Instance; Hook = new LuaCsHook();
game = new LuaGame(); Game = new LuaGame();
networking = new LuaCsNetworking(); Networking = new LuaCsNetworking();
} }
@@ -265,7 +264,7 @@ namespace Barotrauma
public void SetModulePaths(string[] str) public void SetModulePaths(string[] str)
{ {
luaScriptLoader.ModulePaths = str; LuaScriptLoader.ModulePaths = str;
} }
public void Update() public void Update()
@@ -279,31 +278,12 @@ namespace Barotrauma
ACsMod.LoadedMods.Clear(); ACsMod.LoadedMods.Clear();
Hook?.Call("stop"); Hook?.Call("stop");
game?.Stop(); Game?.Stop();
//harmony?.UnpatchAll();
//Hook = new LuaCsHook();
Hook.Clear(); Hook.Clear();
game = new LuaGame(); Game = new LuaGame();
networking = new LuaCsNetworking(); Networking = new LuaCsNetworking();
luaScriptLoader = null; LuaScriptLoader = null;
}
private void InitCs()
{
netScriptLoader = new CsScriptLoader(this);
netScriptLoader.SearchFolders();
if (netScriptLoader == null) throw new Exception("LuaCsSetup was not properly initialized.");
try
{
var modTypes = netScriptLoader.Compile();
//modTypes.ForEach(t => ACsMod.CreateInstance(t));
modTypes.ForEach(t => t.GetConstructor(new Type[] { })?.Invoke(null));
}
catch (Exception ex)
{
PrintMessage(ex);
}
} }
public void Initialize() public void Initialize()
@@ -312,32 +292,27 @@ namespace Barotrauma
PrintMessage("LuaCs! Version " + AssemblyInfo.GitRevision); PrintMessage("LuaCs! Version " + AssemblyInfo.GitRevision);
luaScriptLoader = new LuaScriptLoader(); LuaScriptLoader = new LuaScriptLoader();
luaScriptLoader.ModulePaths = new string[] { }; LuaScriptLoader.ModulePaths = new string[] { };
InitCs();
NetScriptLoader = new CsScriptLoader(this);
LuaCustomConverters.RegisterAll(); LuaCustomConverters.RegisterAll();
lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.Debug); lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.Debug);
lua.Options.DebugPrint = PrintMessage; lua.Options.DebugPrint = PrintMessage;
lua.Options.ScriptLoader = luaScriptLoader; lua.Options.ScriptLoader = LuaScriptLoader;
harmony = new Harmony("com.LuaForBarotrauma"); Hook.Initialize();
harmony.UnpatchAll(); Game = new LuaGame();
Networking = new LuaCsNetworking();
//Hook = new LuaCsHook();
game = new LuaGame();
networking = new LuaCsNetworking();
//UserData.RegisterType<LuaCsHook>();
UserData.RegisterType<LuaGame>(); UserData.RegisterType<LuaGame>();
UserData.RegisterType<LuaCsTimer>(); UserData.RegisterType<LuaCsTimer>();
UserData.RegisterType<LuaCsFile>(); UserData.RegisterType<LuaCsFile>();
UserData.RegisterType<LuaCsNetworking>(); UserData.RegisterType<LuaCsNetworking>();
UserData.RegisterType<LuaUserData>(); UserData.RegisterType<LuaUserData>();
UserData.RegisterType<IUserDataDescriptor>(); UserData.RegisterType<IUserDataDescriptor>();
lua.Globals["printerror"] = (Action<object>)PrintError;
var hookType = UserData.RegisterType<LuaCsHook>(); var hookType = UserData.RegisterType<LuaCsHook>();
var hookDesc = (StandardUserDataDescriptor)hookType; var hookDesc = (StandardUserDataDescriptor)hookType;
@@ -353,6 +328,8 @@ namespace Barotrauma
} }
}); });
lua.Globals["printerror"] = (Action<object>)PrintError;
lua.Globals["setmodulepaths"] = (Action<string[]>)SetModulePaths; lua.Globals["setmodulepaths"] = (Action<string[]>)SetModulePaths;
lua.Globals["dofile"] = (Func<string, Table, string, DynValue>)DoFile; lua.Globals["dofile"] = (Func<string, Table, string, DynValue>)DoFile;
@@ -363,11 +340,11 @@ namespace Barotrauma
lua.Globals["load"] = (Func<string, Table, string, DynValue>)LoadString; lua.Globals["load"] = (Func<string, Table, string, DynValue>)LoadString;
lua.Globals["LuaUserData"] = UserData.CreateStatic<LuaUserData>(); lua.Globals["LuaUserData"] = UserData.CreateStatic<LuaUserData>();
lua.Globals["Game"] = game; lua.Globals["Game"] = Game;
lua.Globals["Hook"] = Hook; lua.Globals["Hook"] = Hook;
lua.Globals["Timer"] = new LuaCsTimer(); lua.Globals["Timer"] = new LuaCsTimer();
lua.Globals["File"] = UserData.CreateStatic<LuaCsFile>(); lua.Globals["File"] = UserData.CreateStatic<LuaCsFile>();
lua.Globals["Networking"] = networking; lua.Globals["Networking"] = Networking;
bool isServer; bool isServer;
@@ -382,6 +359,20 @@ namespace Barotrauma
// LuaDocs.GenerateDocsAll(); // LuaDocs.GenerateDocsAll();
NetScriptLoader.SearchFolders();
if (NetScriptLoader == null) throw new Exception("LuaCsSetup was not properly initialized.");
try
{
var modTypes = NetScriptLoader.Compile();
modTypes.ForEach(t => t.GetConstructor(new Type[] { })?.Invoke(null));
}
catch (Exception ex)
{
PrintMessage(ex);
}
ContentPackage luaPackage = GetPackage(); ContentPackage luaPackage = GetPackage();
if (File.Exists(LUASETUP_FILE)) if (File.Exists(LUASETUP_FILE))
@@ -411,7 +402,7 @@ namespace Barotrauma
} }
else else
{ {
PrintError("LuaCs loader not found! Lua/LuaSetup.lua, no Lua scripts will be executed or work."); PrintError("LuaSetup.lua not found! Lua/LuaSetup.lua, no Lua scripts will be executed or work.");
} }
} }
@@ -596,12 +596,12 @@ namespace Barotrauma
Powered.UpdatePower(deltaTime * MapEntityUpdateInterval); Powered.UpdatePower(deltaTime * MapEntityUpdateInterval);
foreach (Item item in Item.ItemList) foreach (Item item in Item.ItemList)
{ {
if (GameMain.LuaCs.game.updatePriorityItems.Contains(item)) continue; if (GameMain.LuaCs.Game.updatePriorityItems.Contains(item)) continue;
item.Update(deltaTime * MapEntityUpdateInterval, cam); item.Update(deltaTime * MapEntityUpdateInterval, cam);
} }
} }
foreach (var item in GameMain.LuaCs.game.updatePriorityItems) foreach (var item in GameMain.LuaCs.Game.updatePriorityItems)
{ {
if (item.Removed) continue; if (item.Removed) continue;
@@ -117,7 +117,7 @@ namespace Barotrauma.Networking
foreach (Wire wire in connection.Wires) foreach (Wire wire in connection.Wires)
{ {
#if SERVER #if SERVER
if (GameMain.LuaCs.game.overrideRespawnSub == false) if (GameMain.LuaCs.Game.overrideRespawnSub == false)
{ {
if (wire != null) wire.Locked = true; if (wire != null) wire.Locked = true;
} }
@@ -205,7 +205,7 @@ namespace Barotrauma.Networking
{ {
#if SERVER #if SERVER
if (GameMain.LuaCs.game.overrideRespawnSub) if (GameMain.LuaCs.Game.overrideRespawnSub)
{ {
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
} }