diff --git a/Core/Dictionary.cs b/Core/Dictionary.cs index e69de29..12e3b07 100644 --- a/Core/Dictionary.cs +++ b/Core/Dictionary.cs @@ -0,0 +1,28 @@ +using ExitGames.Client.Photon; +using ExitGames.Client.Photon.StructWrapping; +using System.Collections.Generic; +using UnityEngine; + +namespace PhotonLogger.Core; + +public class OperationNormalizer +{ + public static Dictionary NormalizeDictionaryValues(Dictionary inDict) + { + var dictionary = new Dictionary(inDict); + + foreach (KeyValuePair entry in inDict) + { + var key = entry.Key; + var value = entry.Value; + if (value.GetType() == typeof(Vector2)) dictionary[key] = "StubVector2"; + else if (value.GetType() == typeof(Vector3)) dictionary[key] = "StubVector3"; + else if (value is Dictionary) dictionary[key] = NormalizeDictionaryValues((Dictionary)value); + else if (value is ParameterDictionary) dictionary[key] = NormalizeDictionaryValues(new Dictionary((ParameterDictionary)value)); + else if (value is StructWrapper) dictionary[key] = "a byte that must be unwrapped"; + else if (value is StructWrapper) dictionary[key] = "a bool that must be unwrapped"; + } + + return dictionary; + } +} \ No newline at end of file diff --git a/Core/Message.cs b/Core/Message.cs index f3c0ae4..eaac937 100644 --- a/Core/Message.cs +++ b/Core/Message.cs @@ -1,4 +1,5 @@ -using System; +using Photon.Realtime; +using System; namespace PhotonLogger.Core; @@ -14,5 +15,6 @@ public class Message { public long Time { get; set; } public MessageType Type { get; set; } + public string Server { get; set; } public object Data { get; set; } } \ No newline at end of file diff --git a/Patches/EventPatch.cs b/Patches/EventPatch.cs index 5311c1c..857c7ac 100644 --- a/Patches/EventPatch.cs +++ b/Patches/EventPatch.cs @@ -4,8 +4,7 @@ using Newtonsoft.Json; using Photon.Realtime; using PhotonLogger.Core; using System; -using System.Collections; -using System.IO; +using System.Collections.Generic; using System.Reflection; [HarmonyPatch] @@ -15,21 +14,24 @@ public class OnEventPatch public class SerializableEventData { public byte Code { get; set; } - public NonAllocDictionary Parameters { get; set; } + public Dictionary Parameters { get; set; } } static MethodInfo TargetMethod() => typeof(LoadBalancingClient).GetRuntimeMethod("OnEvent", [ typeof(EventData) ]); - static void Postfix(ref EventData photonEvent) + static void Postfix(ref EventData photonEvent, ref LoadBalancingClient __instance) { var newMsg = new Message { Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Type = MessageType.Event, + Server = __instance.CurrentServerAddress, Data = new SerializableEventData { Code = photonEvent.Code, - Parameters = photonEvent.Parameters.paramDict + Parameters = OperationNormalizer.NormalizeDictionaryValues( + new Dictionary(photonEvent.Parameters.paramDict) + ) } }; diff --git a/Patches/OperationPatch.cs b/Patches/OperationPatch.cs index fde8b3b..14d4f8f 100644 --- a/Patches/OperationPatch.cs +++ b/Patches/OperationPatch.cs @@ -5,12 +5,8 @@ using Newtonsoft.Json; using Photon.Realtime; using PhotonLogger.Core; using System; -using System.Collections; using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Reflection; -using static UnityEngine.UIElements.UIR.Implementation.UIRStylePainter; namespace PhotonLogger.Patches; @@ -20,7 +16,7 @@ internal class SerializableOperationResponse public byte OperationCode { get; set; } public short ReturnCode { get; set; } public string DebugMessage { get; set; } - public NonAllocDictionary Parameters { get; set; } + public Dictionary Parameters { get; set; } } [HarmonyPatch] @@ -28,18 +24,21 @@ public class OperationResponsePatch { static MethodInfo TargetMethod() => AccessTools.Method(typeof(LoadBalancingClient), nameof(LoadBalancingClient.OnOperationResponse)); - static void Postfix(ref OperationResponse operationResponse) + static void Postfix(ref OperationResponse operationResponse, ref LoadBalancingClient __instance) { var newMsg = new Message { Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Type = MessageType.OperationResponse, + Server = __instance.CurrentServerAddress, Data = new SerializableOperationResponse { OperationCode = operationResponse.OperationCode, ReturnCode = operationResponse.ReturnCode, DebugMessage = operationResponse.DebugMessage, - Parameters = operationResponse.Parameters.paramDict + Parameters = OperationNormalizer.NormalizeDictionaryValues( + new Dictionary(operationResponse.Parameters.paramDict) + ) } }; @@ -62,12 +61,13 @@ public class OperationRequestDictPatch { static MethodInfo TargetMethod() => typeof(PhotonPeer).GetRuntimeMethod("SendOperation", [ typeof(byte), typeof(Dictionary), typeof(SendOptions) ]); - static void Postfix(ref byte operationCode, ref Dictionary operationParameters) + static void Postfix(ref byte operationCode, ref Dictionary operationParameters, ref PhotonPeer __instance) { var newMsg = new Message { Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Type = MessageType.OperationRequest, + Server = __instance.ServerAddress, Data = new SerializableOperationRequest { OperationCode = operationCode, @@ -87,16 +87,19 @@ public class OperationRequestParamDictPatch { static MethodInfo TargetMethod() => typeof(PhotonPeer).GetRuntimeMethod("SendOperation", [ typeof(byte), typeof(ParameterDictionary), typeof(SendOptions) ]); - static void Postfix(ref byte operationCode, ref ParameterDictionary operationParameters) + static void Postfix(ref byte operationCode, ref ParameterDictionary operationParameters, ref PhotonPeer __instance) { var newMsg = new Message { Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Type = MessageType.OperationRequest, + Server = __instance.ServerAddress, Data = new SerializableOperationRequest { OperationCode = operationCode, - Parameters = new Dictionary(operationParameters.paramDict) + Parameters = OperationNormalizer.NormalizeDictionaryValues( + new Dictionary(operationParameters.paramDict) + ) } };