- SignalR handshake fix

- Self-hosted PhotonSocketServer support
- Split photon and hile event patch
- Deprecated amplitude redirect patch
This commit is contained in:
2025-04-13 02:11:08 -04:00
parent 155dda33b9
commit 8d1bac8201
13 changed files with 304 additions and 99 deletions

View File

@@ -59,26 +59,19 @@ namespace undead_universal_patch_il2cpp.Patches
if (newUri.ToString().Contains("ns.rec.net")) newUri = new Il2CppSystem.Uri(NameserverConfig.NewUrl.Value);
if (newUri.ToString().Contains("api.amplitude"))
{
Il2CppSystem.UriBuilder replaceUri = new(new Il2CppSystem.Uri(NameserverConfig.NewUrl.Value));
replaceUri.Path = "/amplitude";
newUri = replaceUri.Uri;
}
if (GalvanicConfig.Enabled.Value)
{
string[] applyHeader = [
"authservice/cachedlogin/forplatformid",
"accountservice/account/create",
"authservice/connect/token"
"/cachedlogin/forplatformid",
"/account/create",
"/connect/token"
];
foreach (string header in applyHeader)
{
if (newUri.PathAndQuery.Contains(header))
{
// refresh the token if it expired
// this is somewhat inefficient, but we don't hook into many requests (see below) so it should be fine
// this is somewhat inefficient, but we don't hook into many requests (see above) so it should be fine
Galvanic.GalvanicWebAuth.TokenExpiry();
Type httpRequestType = request.GetType();

View File

@@ -1,11 +1,34 @@
using System.Collections.Generic;
using System.Reflection;
using System.Reflection;
using HarmonyLib;
using Il2CppSystem;
using UnityEngine;
namespace undead_universal_patch_il2cpp.Patches
{
[HarmonyPatch]
public class ConnectToRecNetPatchEvent
{
static readonly string TargetTypeName = "RecNet.Core";
static readonly string TargetMethodName = "ConnectToRecNet";
static readonly string Description = "Hile Patch event method"; // It's convenient. Could patch at a different time. But this part was easy.
static readonly MethodInfo connectMethod = AccessTools.Method(AccessTools.TypeByName(TargetTypeName), TargetMethodName);
static bool Prepare()
{
if (connectMethod == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
return false;
}
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
static MethodBase TargetMethod() => connectMethod;
static void Prefix()
{
if (GenericConfig.HilePatch.Value) HilePatch.Patch();
}
}
public static class HilePatch
{
public static void Patch()

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using System.Reflection;

207
BasePatches/PhotonPatch.cs Normal file
View File

@@ -0,0 +1,207 @@
using System;
using System.Reflection;
using BepInEx.Configuration;
using HarmonyLib;
using Il2CppSystem.Security.Cryptography;
using RecNet;
using UnityEngine;
namespace undead_universal_patch_il2cpp.Patches
{
[HarmonyPatch]
public class PhotonPatchEvent
{
static readonly string TargetTypeName = "PhotonNetwork";
static readonly string TargetMethodName = "ConnectUsingSettings";
static readonly string Description = "Photon ConnectUsingSettings patch event";
static readonly Type targetType = AccessTools.TypeByName(TargetTypeName);
static readonly MethodInfo targetMethod = AccessTools.Method(targetType, TargetMethodName);
static bool Prepare()
{
if (!PhotonConfig.PatchPhotonIds.Value) return false;
if (targetType == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
return false;
}
if (targetMethod == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
return false;
}
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
static MethodInfo TargetMethod() => targetMethod;
static void Prefix()
{
PhotonPatch.Patch();
}
}
[HarmonyPatch]
public class ForceSelfHostedPhoton
{
class HarmonyState
{
public object code;
}
static readonly string TargetTypeName = "PUNNetworkManager";
static readonly string TargetMethodName = "OnConnectedToMaster";
static readonly string Description = "Force JoinOrCreateRoom when connected to master";
static readonly Type targetType = AccessTools.TypeByName(TargetTypeName);
static readonly MethodInfo targetMethod = AccessTools.Method(targetType, TargetMethodName);
static bool Prepare()
{
if (!(PhotonConfig.PatchPhotonIds.Value && PhotonConfig.SelfHosted.Value)) return false;
if (targetType == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
return false;
}
if (targetMethod == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
return false;
}
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
static MethodBase TargetMethod() => targetMethod;
static void Prefix(ref PUNNetworkManager __instance, ref HarmonyState __state)
{
__state = new HarmonyState();
PropertyInfo targetGameSessionProperty = __instance.GetType().GetRuntimeProperty("targetGameSession");
if (targetGameSessionProperty == null)
{
Plugin.Log.LogFatal("Cannot force masterserver: targetGameSessionProperty was null.");
return;
}
var targetGameSession = targetGameSessionProperty.GetValue(__instance);
if (targetGameSession == null)
{
Plugin.Log.LogFatal("Cannot force masterserver: targetGameSession was null.");
return;
}
PropertyInfo photonRegionIdProperty = targetGameSession.GetType().GetRuntimeProperty("PhotonRegionId");
if (photonRegionIdProperty == null)
{
Plugin.Log.LogFatal("Cannot force masterserver: photonRegionIdProperty was null.");
return;
}
__state.code = photonRegionIdProperty.GetValue(targetGameSession);
photonRegionIdProperty.SetValue(targetGameSession, 4);
Plugin.Log.LogDebug("Forcing masterserver");
}
static void Postfix(ref PUNNetworkManager __instance, ref HarmonyState __state)
{
PropertyInfo targetGameSessionProperty = __instance.GetType().GetRuntimeProperty("targetGameSession");
if (targetGameSessionProperty == null)
{
Plugin.Log.LogFatal("Cannot force masterserver postfix: targetGameSessionProperty was null.");
return;
}
var targetGameSession = targetGameSessionProperty.GetValue(__instance);
if (targetGameSession == null)
{
Plugin.Log.LogFatal("Cannot force masterserver postfix: targetGameSession was null.");
return;
}
PropertyInfo photonRegionIdProperty = targetGameSession.GetType().GetRuntimeProperty("PhotonRegionId");
if (photonRegionIdProperty == null)
{
Plugin.Log.LogFatal("Cannot force masterserver: photonRegionIdProperty was null.");
return;
}
photonRegionIdProperty.SetValue(targetGameSession, __state.code);
Plugin.Log.LogDebug("Masterserver regionId roundtrip");
}
}
public class PhotonPatch
{
public static void Patch()
{
// It's fine to reference enums after we're pretty sure the relevant types exist
// i think
Type photonNetworkType = AccessTools.TypeByName("PhotonNetwork");
Type serverSettingsType = AccessTools.TypeByName("ServerSettings");
if (photonNetworkType == null || serverSettingsType == null)
{
Plugin.Log.LogError("Cannot patch Photon: PhotonNetwork or ServerSettings types were not found. Is this build supported?");
return;
// safe to reference enums proceeding this
}
PropertyInfo photonServerSettingsProperty = photonNetworkType.GetRuntimeProperty("PhotonServerSettings");
object serverSettings = photonServerSettingsProperty.GetValue(serverSettingsType);
if (PhotonConfig.PunLogging.Value)
{
PropertyInfo loggingProperty = serverSettingsType.GetRuntimeProperty("PunLogging");
loggingProperty.SetValue(serverSettings, PhotonLogLevel.Full);
PropertyInfo networkLoggingProperty = serverSettingsType.GetRuntimeProperty("NetworkLogging");
networkLoggingProperty.SetValue(serverSettings, ExitGames.Client.Photon.DebugLevel.ALL);
}
PropertyInfo appIdProperty = serverSettingsType.GetRuntimeProperty("AppID");
PropertyInfo voiceAppIdProperty = serverSettingsType.GetRuntimeProperty("VoiceAppID");
appIdProperty.SetValue(serverSettings, PhotonConfig.AppID.Value);
voiceAppIdProperty.SetValue(serverSettings, PhotonConfig.VoiceAppID.Value);
if (PhotonConfig.SelfHosted.Value)
{
MethodInfo useMyServerMethod = serverSettingsType.GetMethod("UseMyServer");
useMyServerMethod.Invoke(serverSettings, [
PhotonConfig.ServerAddress.Value,
PhotonConfig.ServerPort.Value,
PhotonConfig.AppID.Value,
]);
}
Type authValuesType = AccessTools.TypeByName("AuthenticationValues");
if (authValuesType != null)
{
PropertyInfo userIdProperty = authValuesType.GetRuntimeProperty("UserId");
PropertyInfo networkingPeerProperty = photonNetworkType.GetRuntimeProperty("networkingPeer");
if (networkingPeerProperty == null)
{
Plugin.Log.LogError("Cannot patch Photon: networkingPeerProperty was null. Is this build supported?");
return;
}
if (networkingPeerProperty.GetValue(null) == null)
{
Plugin.Log.LogError("Cannot patch Photon: networkingPeerInstance was null. Is this build supported?");
return;
}
string id = Util.LocalInstanceGuid;
Plugin.Log.LogDebug($"Instance GUID is {id}");
PhotonNetwork.AuthValues = new AuthenticationValues();
PhotonNetwork.AuthValues.UserId = id;
Plugin.Log.LogDebug($"Set the authValues userId to {id}");
}
Plugin.Log.LogInfo($"Photon patch ({(PhotonConfig.SelfHosted.Value ? "self-hosted" : "cloud")}) succeeded.");
}
}
}

View File

@@ -1,60 +0,0 @@
using HarmonyLib;
using System;
using System.Reflection;
namespace undead_universal_patch_il2cpp.Patches
{
[HarmonyPatch]
public class ConnectToRecNetPatchEvent
{
static readonly string TargetTypeName = "RecNet.Core";
static readonly string TargetMethodName = "ConnectToRecNet";
static readonly string Description = "Photon/Hile Patch event method"; // It's convenient. Could patch at a different time. But this part was easy.
static readonly MethodInfo connectMethod = AccessTools.Method(AccessTools.TypeByName(TargetTypeName), TargetMethodName);
static bool Prepare()
{
if (connectMethod == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
return false;
}
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
static MethodBase TargetMethod() => connectMethod;
static void Prefix()
{
if (PhotonConfig.PatchPhotonIds.Value) PhotonPatch.Patch();
if (GenericConfig.HilePatch.Value) HilePatch.Patch();
}
}
public class PhotonPatch
{
public static void Patch()
{
Type photonNetworkType = AccessTools.TypeByName("PhotonNetwork");
Type serverSettingsType = AccessTools.TypeByName("ServerSettings");
if (photonNetworkType == null || serverSettingsType == null)
{
Plugin.Log.LogError("Cannot patch Photon: PhotonNetwork or ServerSettings types were not found. Is this build supported?");
return;
}
// The property PhotonServerSettings (which should be a field) didn't appear when I didn't specify `Runtime`. Not sure why. But this works.
PropertyInfo photonServerSettingsProperty = photonNetworkType.GetRuntimeProperty("PhotonServerSettings");
object serverSettings = photonServerSettingsProperty.GetValue(serverSettingsType);
PropertyInfo appIdField = serverSettingsType.GetRuntimeProperty("AppID");
PropertyInfo voiceAppIdField = serverSettingsType.GetRuntimeProperty("VoiceAppID");
appIdField.SetValue(serverSettings, PhotonConfig.AppID.Value);
voiceAppIdField.SetValue(serverSettings, PhotonConfig.VoiceAppID.Value);
Plugin.Log.LogInfo("Photon patch succeeded.");
}
}
}

View File

@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
namespace undead_universal_patch_il2cpp.Patches

View File

@@ -15,6 +15,7 @@ namespace undead_universal_patch_il2cpp.Patches
static bool Prepare()
{
if (!GenericConfig.CertificatePatch.Value) return false;
if (targetMethod == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
@@ -34,7 +35,7 @@ namespace undead_universal_patch_il2cpp.Patches
static bool Prefix()
{
return !(GenericConfig.CertificatePatch.Value);
return false;
}
}