Fix garbage network data being read by the game when reading LuaCs network messages

This commit is contained in:
Evil Factory
2026-04-10 13:37:01 -03:00
parent 9250e27953
commit 1adf76168d

View File

@@ -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<IEventServerRawNetMessageReceived>(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<IEventClientRawNetMessageReceived>(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]