From 6bbe5be5e6d613b82526b36037ba637a5e3b272b Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Tue, 10 Feb 2026 20:26:46 -0300 Subject: [PATCH] Fix networking being completely bamboozled --- .../BarotraumaClient/ClientSource/Networking/GameClient.cs | 2 -- .../BarotraumaServer/ServerSource/Networking/GameServer.cs | 2 -- .../LuaCs/_Services/HarmonyEventPatchesService.cs | 6 ++++-- .../SharedSource/LuaCs/_Services/NetworkingService.cs | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Barotrauma/BarotraumaClient/ClientSource/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/ClientSource/Networking/GameClient.cs index d5d195ce8..98d00c624 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Networking/GameClient.cs @@ -604,8 +604,6 @@ namespace Barotrauma.Networking { ServerPacketHeader header = (ServerPacketHeader)inc.ReadByte(); - GameMain.LuaCs.EventService.PublishEvent(p => p.OnReceivedServerNetMessage(inc, header)); - if (roundInitStatus == RoundInitStatus.WaitingForStartGameFinalize && header is not ( ServerPacketHeader.STARTGAMEFINALIZE diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs index a7b5dd02b..eb971f54b 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs @@ -838,8 +838,6 @@ namespace Barotrauma.Networking ClientPacketHeader header = (ClientPacketHeader)inc.ReadByte(); - GameMain.LuaCs.EventService.PublishEvent(p => p.OnReceivedClientNetMessage(inc, header, sender)); - switch (header) { case ClientPacketHeader.PING_RESPONSE: diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/HarmonyEventPatchesService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/HarmonyEventPatchesService.cs index c31ac49db..22186a47e 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/HarmonyEventPatchesService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/HarmonyEventPatchesService.cs @@ -69,8 +69,9 @@ internal class HarmonyEventPatchesService : IService [HarmonyPatch(typeof(GameClient), "ReadDataMessage"), HarmonyPrefix] public static void GameClient_ReadDataMessage_Pre(IReadMessage inc) { - ServerPacketHeader header = (ServerPacketHeader)inc.PeekByte(); // Read but don't advance the read pointer + ServerPacketHeader header = (ServerPacketHeader)inc.ReadByte(); _eventService.PublishEvent(x => x.OnReceivedServerNetMessage(inc, header)); + inc.BitPosition -= 8; // rewind so the game can read the message } [HarmonyPatch(typeof(SubEditorScreen), nameof(SubEditorScreen.Select), new Type[] { }), HarmonyPostfix] @@ -88,8 +89,9 @@ internal class HarmonyEventPatchesService : IService [HarmonyPatch(typeof(GameServer), "ReadDataMessage"), HarmonyPrefix] public static void GameServer_ReadDataMessage_Pre(NetworkConnection sender, IReadMessage inc) { - ClientPacketHeader header = (ClientPacketHeader)inc.PeekByte(); // Read but don't advance the read pointer + ClientPacketHeader header = (ClientPacketHeader)inc.ReadByte(); _eventService.PublishEvent(x => x.OnReceivedClientNetMessage(inc, header, sender)); + inc.BitPosition -= 8; // rewind so the game can read the message } #endif diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/NetworkingService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/NetworkingService.cs index 909e1f2c7..afa9c7e7c 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/NetworkingService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/NetworkingService.cs @@ -224,7 +224,7 @@ internal partial class NetworkingService : INetworkingService #if CLIENT SendToServer(message); #elif SERVER - SendToClient(message); + SendToClient(message, connection); #endif }