Files
PhotonLogger/Patches/EventPatch.cs
2026-02-16 15:53:20 -05:00

43 lines
1.3 KiB
C#

using ExitGames.Client.Photon;
using HarmonyLib;
using Newtonsoft.Json;
using Photon.Realtime;
using PhotonLogger.Core;
using System;
using System.Collections.Generic;
using System.Reflection;
[HarmonyPatch]
public class OnEventPatch
{
[Serializable]
public class SerializableEventData
{
public byte Code { get; set; }
public Dictionary<byte, object> Parameters { get; set; }
}
static MethodInfo TargetMethod() => typeof(LoadBalancingClient).GetRuntimeMethod("OnEvent", [ typeof(EventData) ]);
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 = OperationNormalizer.NormalizeDictionaryValues(
new Dictionary<byte, object>(photonEvent.Parameters.paramDict)
)
}
};
SocketProvider.Instance.Write(JsonConvert.SerializeObject(newMsg, Formatting.Indented, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
}));
}
}