Initial commit
This commit is contained in:
61
.gitignore
vendored
Normal file
61
.gitignore
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
## A streamlined .gitignore for modern .NET projects
|
||||
## including temporary files, build results, and
|
||||
## files generated by popular .NET tools. If you are
|
||||
## developing with Visual Studio, the VS .gitignore
|
||||
## https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||
## has more thorough IDE-specific entries.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/main/Dotnet.gitignore
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# Others
|
||||
~$*
|
||||
*~
|
||||
CodeCoverage/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Root
|
||||
.vs
|
||||
Managed
|
||||
0
Core/Dictionary.cs
Normal file
0
Core/Dictionary.cs
Normal file
18
Core/Message.cs
Normal file
18
Core/Message.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace PhotonLogger.Core;
|
||||
|
||||
public enum MessageType
|
||||
{
|
||||
Event,
|
||||
OperationRequest,
|
||||
OperationResponse
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Message
|
||||
{
|
||||
public long Time { get; set; }
|
||||
public MessageType Type { get; set; }
|
||||
public object Data { get; set; }
|
||||
}
|
||||
24
Core/Plugin.cs
Normal file
24
Core/Plugin.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using BepInEx.Logging;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace PhotonLogger.Core;
|
||||
|
||||
public static class LoggerPlugin
|
||||
{
|
||||
public static ManualLogSource Log = Logger.CreateLogSource("PhotonLogger");
|
||||
|
||||
public static Harmony harmony = new("dev.proxnet.photon.logger");
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
harmony.PatchAll();
|
||||
SocketProvider.Instance.Connect();
|
||||
}
|
||||
|
||||
public static void Unload()
|
||||
{
|
||||
harmony.UnpatchSelf();
|
||||
SocketProvider.Instance.Close();
|
||||
Log.LogInfo("Unloading");
|
||||
}
|
||||
}
|
||||
25
Core/Socket.cs
Normal file
25
Core/Socket.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using WebSocketSharp;
|
||||
|
||||
namespace PhotonLogger.Core;
|
||||
|
||||
public class SocketProvider
|
||||
{
|
||||
public static readonly SocketProvider Instance = new();
|
||||
|
||||
private readonly WebSocket socket = new("wss://photonlogger.proxnet.dev");
|
||||
|
||||
public void Write(string msg)
|
||||
{
|
||||
socket.Send(msg);
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
socket.Connect();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
socket.Close();
|
||||
}
|
||||
}
|
||||
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
|
||||
}));
|
||||
}
|
||||
}
|
||||
51
PhotonLogger.csproj
Normal file
51
PhotonLogger.csproj
Normal file
@@ -0,0 +1,51 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net46</TargetFramework>
|
||||
<AssemblyName>PhotonLogger</AssemblyName>
|
||||
<Version>1.0.0</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<RestoreAdditionalProjectSources>
|
||||
https://api.nuget.org/v3/index.json;
|
||||
https://nuget.bepinex.dev/v3/index.json;
|
||||
https://nuget.samboy.dev/v3/index.json
|
||||
</RestoreAdditionalProjectSources>
|
||||
<RootNamespace>PhotonLogger</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
|
||||
<PackageReference Include="BepInEx.Unity.Mono" Version="6.0.0-be.*" IncludeAssets="compile" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||
<PackageReference Include="UnityEngine.Modules" Version="2022.3.8" IncludeAssets="compile" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="netstandard">
|
||||
<HintPath>Managed\netstandard.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Photon3Unity3D">
|
||||
<HintPath>Managed\Photon3Unity3D.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PhotonChat">
|
||||
<HintPath>Managed\PhotonChat.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PhotonRealtime">
|
||||
<HintPath>Managed\PhotonRealtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PhotonUnityNetworking">
|
||||
<HintPath>Managed\PhotonUnityNetworking.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PhotonUnityNetworking.Utilities">
|
||||
<HintPath>Managed\PhotonUnityNetworking.Utilities.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="websocket-sharp">
|
||||
<HintPath>Managed\websocket-sharp.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
25
PhotonLogger.sln
Normal file
25
PhotonLogger.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 18
|
||||
VisualStudioVersion = 18.2.11430.68 d18.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhotonLogger", "PhotonLogger.csproj", "{E0AA83DA-CAD1-2C72-F6E6-EA3B0250E6C4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E0AA83DA-CAD1-2C72-F6E6-EA3B0250E6C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E0AA83DA-CAD1-2C72-F6E6-EA3B0250E6C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E0AA83DA-CAD1-2C72-F6E6-EA3B0250E6C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E0AA83DA-CAD1-2C72-F6E6-EA3B0250E6C4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {56915C5F-6396-4D63-B89C-0DD2C586C221}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
22
Plugin.cs
Normal file
22
Plugin.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using BepInEx;
|
||||
using BepInEx.Unity.Mono;
|
||||
using PhotonLogger.Core;
|
||||
|
||||
namespace PhotonLogger;
|
||||
|
||||
[BepInPlugin("dev.proxnet.photon.logger", "PhotonLogger", "0.1.0")]
|
||||
#pragma warning disable BepInEx002 // Classes with BepInPlugin attribute must inherit from BaseUnityPlugin
|
||||
public class MonoPlugin : BaseUnityPlugin
|
||||
#pragma warning restore BepInEx002 // Classes with BepInPlugin attribute must inherit from BaseUnityPlugin
|
||||
{
|
||||
public void Awake()
|
||||
{
|
||||
LoggerPlugin.Log.LogInfo($"Plugin Initialized");
|
||||
LoggerPlugin.Load();
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
LoggerPlugin.Unload();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user