41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using ExitGames.Client.Photon;
|
|
using HarmonyLib;
|
|
using Newtonsoft.Json;
|
|
using Photon.Realtime;
|
|
using PhotonLogger.Core;
|
|
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
[HarmonyPatch]
|
|
public class OnEventPatch
|
|
{
|
|
[Serializable]
|
|
public class SerializableEventData
|
|
{
|
|
public byte Code { get; set; }
|
|
public NonAllocDictionary<byte, object> Parameters { get; set; }
|
|
}
|
|
|
|
static MethodInfo TargetMethod() => typeof(LoadBalancingClient).GetRuntimeMethod("OnEvent", [ typeof(EventData) ]);
|
|
|
|
static void Postfix(ref EventData photonEvent)
|
|
{
|
|
var newMsg = new Message
|
|
{
|
|
Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
|
|
Type = MessageType.Event,
|
|
Data = new SerializableEventData
|
|
{
|
|
Code = photonEvent.Code,
|
|
Parameters = photonEvent.Parameters.paramDict
|
|
}
|
|
};
|
|
|
|
SocketProvider.Instance.Write(JsonConvert.SerializeObject(newMsg, Formatting.Indented, new JsonSerializerSettings
|
|
{
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
|
}));
|
|
}
|
|
} |