using System.Reflection; using GameNetworkLayer.Shared; using HarmonyLib; namespace CLre.API.Tools { public class NetClientListener { internal static bool isEnabled = false; public static void Enable() { isEnabled = true; } public static void Disable() { isEnabled = false; } } [HarmonyPatch] class NetMessageClientListener_HandleAllMessages_Patch { [HarmonyPrefix] public static void BeforeMethodCall(object ____deserializer, int playerId, object value) { if (!NetClientListener.isEnabled) return; // TODO optimize this to not use Traverse Traverse result = Traverse.Create(____deserializer).Method("Deserialize", value); NetworkDispatcherCode code = result.Field("dispatcherCode").Value; byte[] data = result.Field("bytes").Value; if (data == null) { Utility.Logging.LogWarning("Network message data was deserialized as null"); return; } Utility.Logging.Log($"Received network message for player {playerId} (code: {code.ToString()}, len: {data.Length})"); } [HarmonyTargetMethod] public static MethodBase Target() { return AccessTools.Method("GameNetworkLayer.Client.NetMessageClientListener:HandleAllMessages"); } } }