111 lines
3.8 KiB
C#
111 lines
3.8 KiB
C#
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.Generic;
|
|
using System.Reflection;
|
|
|
|
namespace PhotonLogger.Patches;
|
|
|
|
[Serializable]
|
|
internal class SerializableOperationResponse
|
|
{
|
|
public byte OperationCode { get; set; }
|
|
public short ReturnCode { get; set; }
|
|
public string DebugMessage { get; set; }
|
|
public Dictionary<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, 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 = OperationNormalizer.NormalizeDictionaryValues(
|
|
new Dictionary<byte, object>(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, ref PhotonPeer __instance)
|
|
{
|
|
var newMsg = new Message
|
|
{
|
|
Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
|
|
Type = MessageType.OperationRequest,
|
|
Server = __instance.ServerAddress,
|
|
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, ref PhotonPeer __instance)
|
|
{
|
|
var newMsg = new Message
|
|
{
|
|
Time = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
|
|
Type = MessageType.OperationRequest,
|
|
Server = __instance.ServerAddress,
|
|
Data = new SerializableOperationRequest
|
|
{
|
|
OperationCode = operationCode,
|
|
Parameters = OperationNormalizer.NormalizeDictionaryValues(
|
|
new Dictionary<byte, object>(operationParameters.paramDict)
|
|
)
|
|
}
|
|
};
|
|
|
|
SocketProvider.Instance.Write(JsonConvert.SerializeObject(newMsg, Formatting.Indented, new JsonSerializerSettings
|
|
{
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
|
}));
|
|
}
|
|
} |