Initial commit
This commit is contained in:
41
Patches/EventPatch.cs
Normal file
41
Patches/EventPatch.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}));
|
||||
}
|
||||
}
|
||||
108
Patches/OperationPatch.cs
Normal file
108
Patches/OperationPatch.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using ExitGames.Client.Photon;
|
||||
using ExitGames.Client.Photon.StructWrapping;
|
||||
using HarmonyLib;
|
||||
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;
|
||||
|
||||
[Serializable]
|
||||
internal class SerializableOperationResponse
|
||||
{
|
||||
public byte OperationCode { get; set; }
|
||||
public short ReturnCode { get; set; }
|
||||
public string DebugMessage { get; set; }
|
||||
public NonAllocDictionary<byte, object> Parameters { get; set; }
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public class OperationResponsePatch
|
||||
{
|
||||
static MethodInfo TargetMethod() => AccessTools.Method(typeof(LoadBalancingClient), nameof(LoadBalancingClient.OnOperationResponse));
|
||||
|
||||
static void Postfix(ref OperationResponse operationResponse)
|
||||
{
|
||||
var newMsg = new Message
|
||||
{
|
||||
Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
|
||||
Type = MessageType.OperationResponse,
|
||||
Data = new SerializableOperationResponse
|
||||
{
|
||||
OperationCode = operationResponse.OperationCode,
|
||||
ReturnCode = operationResponse.ReturnCode,
|
||||
DebugMessage = operationResponse.DebugMessage,
|
||||
Parameters = operationResponse.Parameters.paramDict
|
||||
}
|
||||
};
|
||||
|
||||
SocketProvider.Instance.Write(JsonConvert.SerializeObject(newMsg, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class SerializableOperationRequest
|
||||
{
|
||||
public byte OperationCode { get; set; }
|
||||
public Dictionary<byte, object> Parameters { get; set; }
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public class OperationRequestDictPatch
|
||||
{
|
||||
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)
|
||||
{
|
||||
var newMsg = new Message
|
||||
{
|
||||
Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
|
||||
Type = MessageType.OperationRequest,
|
||||
Data = new SerializableOperationRequest
|
||||
{
|
||||
OperationCode = operationCode,
|
||||
Parameters = operationParameters
|
||||
}
|
||||
};
|
||||
|
||||
SocketProvider.Instance.Write(JsonConvert.SerializeObject(newMsg, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
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)
|
||||
{
|
||||
var newMsg = new Message
|
||||
{
|
||||
Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
|
||||
Type = MessageType.OperationRequest,
|
||||
Data = new SerializableOperationRequest
|
||||
{
|
||||
OperationCode = operationCode,
|
||||
Parameters = new Dictionary<byte, object>(operationParameters.paramDict)
|
||||
}
|
||||
};
|
||||
|
||||
SocketProvider.Instance.Write(JsonConvert.SerializeObject(newMsg, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user