From 1adf76168dc8cd4cb7446b09aa7b0344a65b7ead Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Fri, 10 Apr 2026 13:37:01 -0300 Subject: [PATCH] Fix garbage network data being read by the game when reading LuaCs network messages --- .../LuaCs/_Services/HarmonyEventPatchesService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/HarmonyEventPatchesService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/HarmonyEventPatchesService.cs index 00e3536fa..114b6aa9e 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/HarmonyEventPatchesService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/HarmonyEventPatchesService.cs @@ -124,9 +124,10 @@ internal class HarmonyEventPatchesService : ISystem [HarmonyPatch(typeof(GameClient), "ReadDataMessage"), HarmonyPrefix] public static void GameClient_ReadDataMessage_Pre(IReadMessage inc) { + int prevBitPosition = inc.BitPosition; ServerPacketHeader header = (ServerPacketHeader)inc.ReadByte(); _eventService.PublishEvent(x => x.OnReceivedServerNetMessage(inc, header)); - inc.BitPosition -= 8; // rewind so the game can read the message + inc.BitPosition = prevBitPosition; // rewind so the game can read the message } [HarmonyPatch(typeof(SubEditorScreen), nameof(SubEditorScreen.Select), new Type[] { }), HarmonyPostfix] @@ -160,9 +161,10 @@ internal class HarmonyEventPatchesService : ISystem [HarmonyPatch(typeof(GameServer), "ReadDataMessage"), HarmonyPrefix] public static void GameServer_ReadDataMessage_Pre(NetworkConnection sender, IReadMessage inc) { + int prevBitPosition = inc.BitPosition; ClientPacketHeader header = (ClientPacketHeader)inc.ReadByte(); _eventService.PublishEvent(x => x.OnReceivedClientNetMessage(inc, header, sender)); - inc.BitPosition -= 8; // rewind so the game can read the message + inc.BitPosition = prevBitPosition; // rewind so the game can read the message } [HarmonyPatch(typeof(GameServer), "OnInitializationComplete"), HarmonyPostfix]