Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5KB

  1. using System.Reflection;
  2. using GameNetworkLayer.Shared;
  3. using HarmonyLib;
  4. namespace CLre.API.Tools
  5. {
  6. public class NetClientListener
  7. {
  8. internal static bool isEnabled = false;
  9. public static void Enable()
  10. {
  11. isEnabled = true;
  12. }
  13. public static void Disable()
  14. {
  15. isEnabled = false;
  16. }
  17. }
  18. [HarmonyPatch]
  19. class NetMessageClientListener_HandleAllMessages_Patch
  20. {
  21. [HarmonyPrefix]
  22. public static void BeforeMethodCall(object ____deserializer, int playerId, object value)
  23. {
  24. if (!NetClientListener.isEnabled) return;
  25. // TODO optimize this to not use Traverse
  26. Traverse result = Traverse.Create(____deserializer).Method("Deserialize", value);
  27. NetworkDispatcherCode code = result.Field<NetworkDispatcherCode>("dispatcherCode").Value;
  28. byte[] data = result.Field<byte[]>("bytes").Value;
  29. if (data == null)
  30. {
  31. Utility.Logging.LogWarning("Network message data was deserialized as null");
  32. return;
  33. }
  34. Utility.Logging.Log($"Received network message for player {playerId} (code: {code.ToString()}, len: {data.Length})");
  35. }
  36. [HarmonyTargetMethod]
  37. public static MethodBase Target()
  38. {
  39. return AccessTools.Method("GameNetworkLayer.Client.NetMessageClientListener:HandleAllMessages");
  40. }
  41. }
  42. }