This commit is contained in:
2026-02-16 15:53:20 -05:00
parent 3b8f32c19b
commit acbefc568c
4 changed files with 51 additions and 16 deletions

View File

@@ -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<byte, object> NormalizeDictionaryValues(Dictionary<byte, object> inDict)
{
var dictionary = new Dictionary<byte, object>(inDict);
foreach (KeyValuePair<byte, object> 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<byte, object>) dictionary[key] = NormalizeDictionaryValues((Dictionary<byte, object>)value);
else if (value is ParameterDictionary) dictionary[key] = NormalizeDictionaryValues(new Dictionary<byte, object>((ParameterDictionary)value));
else if (value is StructWrapper<byte>) dictionary[key] = "a byte that must be unwrapped";
else if (value is StructWrapper<bool>) dictionary[key] = "a bool that must be unwrapped";
}
return dictionary;
}
}

View File

@@ -1,4 +1,5 @@
using System; using Photon.Realtime;
using System;
namespace PhotonLogger.Core; namespace PhotonLogger.Core;
@@ -14,5 +15,6 @@ public class Message
{ {
public long Time { get; set; } public long Time { get; set; }
public MessageType Type { get; set; } public MessageType Type { get; set; }
public string Server { get; set; }
public object Data { get; set; } public object Data { get; set; }
} }

View File

@@ -4,8 +4,7 @@ using Newtonsoft.Json;
using Photon.Realtime; using Photon.Realtime;
using PhotonLogger.Core; using PhotonLogger.Core;
using System; using System;
using System.Collections; using System.Collections.Generic;
using System.IO;
using System.Reflection; using System.Reflection;
[HarmonyPatch] [HarmonyPatch]
@@ -15,21 +14,24 @@ public class OnEventPatch
public class SerializableEventData public class SerializableEventData
{ {
public byte Code { get; set; } public byte Code { get; set; }
public NonAllocDictionary<byte, object> Parameters { get; set; } public Dictionary<byte, object> Parameters { get; set; }
} }
static MethodInfo TargetMethod() => typeof(LoadBalancingClient).GetRuntimeMethod("OnEvent", [ typeof(EventData) ]); 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 var newMsg = new Message
{ {
Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
Type = MessageType.Event, Type = MessageType.Event,
Server = __instance.CurrentServerAddress,
Data = new SerializableEventData Data = new SerializableEventData
{ {
Code = photonEvent.Code, Code = photonEvent.Code,
Parameters = photonEvent.Parameters.paramDict Parameters = OperationNormalizer.NormalizeDictionaryValues(
new Dictionary<byte, object>(photonEvent.Parameters.paramDict)
)
} }
}; };

View File

@@ -5,12 +5,8 @@ using Newtonsoft.Json;
using Photon.Realtime; using Photon.Realtime;
using PhotonLogger.Core; using PhotonLogger.Core;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection; using System.Reflection;
using static UnityEngine.UIElements.UIR.Implementation.UIRStylePainter;
namespace PhotonLogger.Patches; namespace PhotonLogger.Patches;
@@ -20,7 +16,7 @@ internal class SerializableOperationResponse
public byte OperationCode { get; set; } public byte OperationCode { get; set; }
public short ReturnCode { get; set; } public short ReturnCode { get; set; }
public string DebugMessage { get; set; } public string DebugMessage { get; set; }
public NonAllocDictionary<byte, object> Parameters { get; set; } public Dictionary<byte, object> Parameters { get; set; }
} }
[HarmonyPatch] [HarmonyPatch]
@@ -28,18 +24,21 @@ public class OperationResponsePatch
{ {
static MethodInfo TargetMethod() => AccessTools.Method(typeof(LoadBalancingClient), nameof(LoadBalancingClient.OnOperationResponse)); 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 var newMsg = new Message
{ {
Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
Type = MessageType.OperationResponse, Type = MessageType.OperationResponse,
Server = __instance.CurrentServerAddress,
Data = new SerializableOperationResponse Data = new SerializableOperationResponse
{ {
OperationCode = operationResponse.OperationCode, OperationCode = operationResponse.OperationCode,
ReturnCode = operationResponse.ReturnCode, ReturnCode = operationResponse.ReturnCode,
DebugMessage = operationResponse.DebugMessage, DebugMessage = operationResponse.DebugMessage,
Parameters = operationResponse.Parameters.paramDict Parameters = OperationNormalizer.NormalizeDictionaryValues(
new Dictionary<byte, object>(operationResponse.Parameters.paramDict)
)
} }
}; };
@@ -62,12 +61,13 @@ public class OperationRequestDictPatch
{ {
static MethodInfo TargetMethod() => typeof(PhotonPeer).GetRuntimeMethod("SendOperation", [ typeof(byte), typeof(Dictionary<byte, object>), typeof(SendOptions) ]); static MethodInfo TargetMethod() => typeof(PhotonPeer).GetRuntimeMethod("SendOperation", [ typeof(byte), typeof(Dictionary<byte, object>), typeof(SendOptions) ]);
static void Postfix(ref byte operationCode, ref Dictionary<byte, object> operationParameters) static void Postfix(ref byte operationCode, ref Dictionary<byte, object> operationParameters, ref PhotonPeer __instance)
{ {
var newMsg = new Message var newMsg = new Message
{ {
Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
Type = MessageType.OperationRequest, Type = MessageType.OperationRequest,
Server = __instance.ServerAddress,
Data = new SerializableOperationRequest Data = new SerializableOperationRequest
{ {
OperationCode = operationCode, OperationCode = operationCode,
@@ -87,16 +87,19 @@ public class OperationRequestParamDictPatch
{ {
static MethodInfo TargetMethod() => typeof(PhotonPeer).GetRuntimeMethod("SendOperation", [ typeof(byte), typeof(ParameterDictionary), typeof(SendOptions) ]); 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 var newMsg = new Message
{ {
Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
Type = MessageType.OperationRequest, Type = MessageType.OperationRequest,
Server = __instance.ServerAddress,
Data = new SerializableOperationRequest Data = new SerializableOperationRequest
{ {
OperationCode = operationCode, OperationCode = operationCode,
Parameters = new Dictionary<byte, object>(operationParameters.paramDict) Parameters = OperationNormalizer.NormalizeDictionaryValues(
new Dictionary<byte, object>(operationParameters.paramDict)
)
} }
}; };