forked from zombieb/undead-universal-patch-il2cpp
backend refactor yay!!! 1.4.0
This commit is contained in:
152
Patches/AssetManager/AGConfigEntryPatches.cs
Normal file
152
Patches/AssetManager/AGConfigEntryPatches.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using HarmonyLib;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
using undead_universal_patch_il2cpp.Core.AssetChanges;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches.AssetManager
|
||||
{
|
||||
public static class AGConfigEntryPatch_Common
|
||||
{
|
||||
public static Dictionary<string, List<RecChange>> Config = AGRoomChanges.config.Get();
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public class AGConfigEntryPatch_RoomScene
|
||||
{
|
||||
static readonly string TargetTypeName = "AGRoomSettings";
|
||||
static readonly string TargetMethodName = "TryGetRoomSceneConfigById";
|
||||
static readonly string Description = "AGRoomSettings data patch";
|
||||
static readonly Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
|
||||
public static bool Prepare()
|
||||
{
|
||||
if (!AssetChangesConfig.AGRoomChanges.Value) return false;
|
||||
if (targetType == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
if (AccessTools.Method(targetType, TargetMethodName) == 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() => AccessTools.Method(targetType, TargetMethodName);
|
||||
static void Postfix(ref string replicationId, ref AGRoomRuntimeConfig.Room roomConfig, ref AGRoomRuntimeConfig.RoomScene roomSceneConfig)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"RoomScene patch for repid '{replicationId}'");
|
||||
if (!AGConfigEntryPatch_Common.Config.ContainsKey(replicationId)) return;
|
||||
|
||||
var changes = AGConfigEntryPatch_Common.Config[replicationId];
|
||||
foreach (var change in changes)
|
||||
{
|
||||
PropertyInfo prop = AccessTools.Property(roomSceneConfig.GetType(), change.RecKey);
|
||||
if (prop == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"Key '{change.RecKey}' does not exist on the room scene for replication ID '{replicationId}'!");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (change.RecValue is JsonElement element)
|
||||
{
|
||||
object value;
|
||||
if (prop.PropertyType.IsEnum) value = Enum.Parse(prop.PropertyType, element.GetRawText());
|
||||
else value = JsonSerializer.Deserialize(element.GetRawText(), prop.PropertyType);
|
||||
|
||||
prop.SetValue(roomSceneConfig, value);
|
||||
}
|
||||
else prop.SetValue(roomSceneConfig, change.RecValue);
|
||||
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"'{change.RecKey}' on repId '{replicationId}' is now '{change.RecValue}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public class AGConfigEntryPatch_Location
|
||||
{
|
||||
static readonly string TargetTypeName = "AGRoomSettings";
|
||||
static readonly string TargetMethodName = "TryGetLocationConfigById";
|
||||
static readonly MethodInfo connectMethod = AccessTools.Method(AccessTools.TypeByName(TargetTypeName), TargetMethodName);
|
||||
|
||||
static bool Prepare() => AGConfigEntryPatch_RoomScene.Prepare();
|
||||
|
||||
static MethodBase TargetMethod() => connectMethod;
|
||||
static void Postfix(ref string replicationId, ref AGRoomRuntimeConfig.Location locationConfig)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Location patch for repid '{replicationId}'");
|
||||
if (!AGConfigEntryPatch_Common.Config.ContainsKey(replicationId)) return;
|
||||
|
||||
var changes = AGConfigEntryPatch_Common.Config[replicationId];
|
||||
foreach (var change in changes)
|
||||
{
|
||||
PropertyInfo prop = AccessTools.Property(locationConfig.GetType(), change.RecKey);
|
||||
if (prop == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"Key '{change.RecKey}' does not exist on the room scene for replication ID '{replicationId}'!");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (change.RecValue is JsonElement element)
|
||||
{
|
||||
object value;
|
||||
if (prop.PropertyType.IsEnum) value = Enum.Parse(prop.PropertyType, element.GetRawText());
|
||||
else value = JsonSerializer.Deserialize(element.GetRawText(), prop.PropertyType);
|
||||
|
||||
prop.SetValue(locationConfig, value);
|
||||
}
|
||||
else prop.SetValue(locationConfig, change.RecValue);
|
||||
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"'{change.RecKey}' on repId '{replicationId}' is now '{change.RecValue}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
public class AGConfigEntryPatch_Room
|
||||
{
|
||||
static readonly string TargetTypeName = "AGRoomSettings";
|
||||
static readonly string TargetMethodName = "TryGetRoomConfigById";
|
||||
static readonly MethodInfo connectMethod = AccessTools.Method(AccessTools.TypeByName(TargetTypeName), TargetMethodName);
|
||||
|
||||
static bool Prepare() => AGConfigEntryPatch_RoomScene.Prepare();
|
||||
|
||||
static MethodBase TargetMethod() => connectMethod;
|
||||
static void Postfix(ref string replicationId, ref AGRoomRuntimeConfig.Room roomConfig)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Roomconfig patch for repid '{replicationId}'");
|
||||
if (!AGConfigEntryPatch_Common.Config.ContainsKey(replicationId)) return;
|
||||
|
||||
var changes = AGConfigEntryPatch_Common.Config[replicationId];
|
||||
foreach (var change in changes)
|
||||
{
|
||||
PropertyInfo prop = AccessTools.Property(roomConfig.GetType(), change.RecKey);
|
||||
if (prop == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"Key '{change.RecKey}' does not exist on the room scene for replication ID '{replicationId}'!");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (change.RecValue is JsonElement element)
|
||||
{
|
||||
object value;
|
||||
if (prop.PropertyType.IsEnum) value = Enum.Parse(prop.PropertyType, element.GetRawText());
|
||||
else value = JsonSerializer.Deserialize(element.GetRawText(), prop.PropertyType);
|
||||
|
||||
prop.SetValue(roomConfig, value);
|
||||
}
|
||||
else prop.SetValue(roomConfig, change.RecValue);
|
||||
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"'{change.RecKey}' on repId '{replicationId}' is now '{change.RecValue}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
95
Patches/BestHTTP.cs
Normal file
95
Patches/BestHTTP.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public class BestHTTP_Unob
|
||||
{
|
||||
static string TargetTypeName = "BestHTTP.HTTPManager";
|
||||
static string TargetMethodName = "SendRequest";
|
||||
static string Description = "Unobfuscated BestHTTP request URL rewrite patch";
|
||||
static readonly Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
static readonly Type requestType = AccessTools.TypeByName("BestHTTP.HTTPRequest");
|
||||
|
||||
static bool Prepare()
|
||||
{
|
||||
if (targetType == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
if (requestType == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The request type for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
if (AccessTools.Method(targetType, TargetMethodName, [requestType]) == 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() => AccessTools.Method(targetType, TargetMethodName, [requestType]);
|
||||
|
||||
[HarmonyPrefix]
|
||||
static void Prefix(ref object request)
|
||||
{
|
||||
PropertyInfo uriProperty = AccessTools.Property(requestType, "Uri");
|
||||
if (uriProperty == null)
|
||||
{
|
||||
Plugin.Log.LogFatal("BestHTTP_Unob failed: uriProperty was null.");
|
||||
return;
|
||||
}
|
||||
|
||||
var uriInstance = (Il2CppSystem.Uri)uriProperty.GetValue(request, null);
|
||||
if (uriInstance == null)
|
||||
{
|
||||
Plugin.Log.LogFatal("BestHTTP_Unob failed: uriInstance was null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GenericConfig.LogAllRequests.Value) Plugin.Log.LogInfo($"BestHTTP_Unob request b-URL: {uriInstance.ToString()}");
|
||||
if (!NameserverConfig.Rewrite.Value) return;
|
||||
|
||||
Il2CppSystem.Uri newUri = new(uriInstance.ToString());
|
||||
|
||||
// Request changes below
|
||||
|
||||
if (newUri.ToString().Contains("ns.rec.net")) newUri = new Il2CppSystem.Uri(NameserverConfig.NewUrl.Value);
|
||||
|
||||
if (GalvanicConfig.Enabled.Value)
|
||||
{
|
||||
string[] applyHeader = [
|
||||
"/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 above) so it should be fine
|
||||
GalvanicWebAuth.TokenExpiry();
|
||||
|
||||
Type httpRequestType = request.GetType();
|
||||
MethodInfo addHeaderMethod = httpRequestType.GetMethod("AddHeader");
|
||||
addHeaderMethod.Invoke(request, ["GalvanicAuth", GalvanicWebAuth.Token]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GenericConfig.LogAllRequests.Value) Plugin.Log.LogInfo($"BestHTTP_Unob request a-URL: {newUri.ToString()}");
|
||||
uriProperty.SetValue(request, NameserverConfig.Rewrite.Value ? newUri : uriInstance, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
Patches/GameManager/FreeSpawns.cs
Normal file
58
Patches/GameManager/FreeSpawns.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
using undead_universal_patch_il2cpp.Core.UndeadGameManager;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches.UndeadGameManager;
|
||||
|
||||
[HarmonyPatch]
|
||||
public class FreeSpawnsPatch_Array
|
||||
{
|
||||
public static List<string> config = GameFreeSpawns.config.Get();
|
||||
|
||||
public static string TargetTypeName = "GamePlayerSpawnPoint";
|
||||
public static string TargetMethodName = "Awake";
|
||||
public static string Description = "FreeSpawns event patch";
|
||||
public static Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
|
||||
public static bool Prepare()
|
||||
{
|
||||
if (!GameManagerConfig.AnyGameFreeSpawn.Value) return false;
|
||||
if (AccessTools.Method(targetType, TargetMethodName) == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static MethodBase TargetMethod() => AccessTools.Method(targetType, TargetMethodName);
|
||||
|
||||
public static void Postfix(ref GamePlayerSpawnPoint __instance)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("Attempting FreeSpawns patch");
|
||||
GameManager man = NetworkedSingletonMonoBehaviour<GameManager>.instance;
|
||||
|
||||
if (man.CurrentGameConfiguration == null)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("CurrentGameConfiguration was null");
|
||||
return;
|
||||
}
|
||||
if (man.CurrentGameConfiguration.configurationData == null)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("CurrentGameConfiguration.configurationData was null");
|
||||
return;
|
||||
}
|
||||
if (!config.Contains(man.CurrentGameConfiguration.configurationData.Name))
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Game '{man.CurrentGameConfiguration.configurationData.Name}' is not specified by GameFreeSpawns");
|
||||
return;
|
||||
}
|
||||
|
||||
__instance.GameTeamPlayerIndex = GameTeamPlayerIndex.ANY_INDEX;
|
||||
}
|
||||
}
|
||||
58
Patches/GameManager/TeamConfigurator.cs
Normal file
58
Patches/GameManager/TeamConfigurator.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using RecRoom.Core.GameManagement;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
using undead_universal_patch_il2cpp.Core.UndeadGameManager;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches.UndeadGameManager;
|
||||
|
||||
[HarmonyPatch]
|
||||
public class TeamConfiguratorPatch
|
||||
{
|
||||
static List<GameConfiguration> gameConfig = TeamConfigurator.config.Get();
|
||||
|
||||
static string TargetTypeName = "GameConfigurationTool";
|
||||
static string TargetMethodName = "SetGameConfiguration";
|
||||
static string Description = "TeamConfigurator event patch";
|
||||
|
||||
static Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
static MethodInfo targetMethod = AccessTools.Method(targetType, TargetMethodName);
|
||||
|
||||
public static bool Prepare()
|
||||
{
|
||||
if (!GameManagerConfig.StaticGameTeamConfig.Value) 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;
|
||||
}
|
||||
|
||||
public static MethodBase TargetMethod() => targetMethod;
|
||||
|
||||
public static void Prefix(ref GameConfigurationAsset config, ref bool showNotification)
|
||||
{
|
||||
var conf = config;
|
||||
showNotification = GenericConfig.PatchDebug.Value;
|
||||
|
||||
var teamConf = gameConfig.Find(match => match.GameName == conf.Name);
|
||||
if (teamConf == null)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"'{config.Name}' does not have explicit team configurations");
|
||||
return;
|
||||
}
|
||||
|
||||
var arr = new Il2CppStructArray<TeamConfiguration>(teamConf.TeamConfigurations.Count);
|
||||
for (int i = 0; i < arr.Length; i++) arr[i] = new TeamConfiguration { MaxTeamSize = teamConf.TeamConfigurations[i].Size };
|
||||
config.TeamConfigurations = arr;
|
||||
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"New team configuration length for '{config.Name}': {arr.Length}");
|
||||
}
|
||||
}
|
||||
57
Patches/HilePatch.cs
Normal file
57
Patches/HilePatch.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
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 bool Prepare()
|
||||
{
|
||||
if (AccessTools.Method(AccessTools.TypeByName(TargetTypeName), TargetMethodName) == 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() => AccessTools.Method(AccessTools.TypeByName(TargetTypeName), TargetMethodName);
|
||||
static void Prefix()
|
||||
{
|
||||
if (GenericConfig.HilePatch.Value) HilePatch.Patch();
|
||||
}
|
||||
}
|
||||
public static class HilePatch
|
||||
{
|
||||
public static void Patch()
|
||||
{
|
||||
GameObject cheatManagerObject = GameObject.Find("[CheatManager]");
|
||||
HileManager hileManager = cheatManagerObject.GetComponent<HileManager>();
|
||||
|
||||
PropertyInfo knownDllsProperty = AccessTools.Property(typeof(HileManager), "KnownDlls");
|
||||
knownDllsProperty.SetValue(hileManager, new Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppStringArray([
|
||||
"GameAssembly.dll",
|
||||
"UnityPlayer.dll",
|
||||
"WinPixEventRuntime.dll",
|
||||
"steam_api64.dll",
|
||||
"steam_api.dll",
|
||||
"d3d11.dll",
|
||||
"d3d9.dll",
|
||||
"d3d8.dll",
|
||||
"ddraw.dll",
|
||||
"dxgi.dll",
|
||||
"winhttp.dll"
|
||||
]));
|
||||
|
||||
Plugin.Log.LogInfo("Hile patch succeeded.");
|
||||
}
|
||||
}
|
||||
}
|
||||
43
Patches/ImageSignature.cs
Normal file
43
Patches/ImageSignature.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using HarmonyLib;
|
||||
using System.Reflection;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public class ImageSignaturePatch
|
||||
{
|
||||
public static string TargetTypeName = "Images";
|
||||
public static string TargetMethodName = "VerifySignature";
|
||||
public static string Description = "Image signature patch";
|
||||
public static Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
|
||||
public static bool Prepare()
|
||||
{
|
||||
if (!GenericConfig.ImageSignaturePatch.Value) return false;
|
||||
if (targetType == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
if (targetType.GetMethod(TargetMethodName) == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static MethodBase TargetMethod() => targetType.GetMethod(TargetMethodName);
|
||||
|
||||
public static bool Prefix(ref bool __result)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("Verified image signature");
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
205
Patches/PhotonPatch.cs
Normal file
205
Patches/PhotonPatch.cs
Normal file
@@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
|
||||
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 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 (AccessTools.Method(targetType, TargetMethodName) == 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() => AccessTools.Method(targetType, TargetMethodName);
|
||||
|
||||
static void Prefix()
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("Attempting Photon patch");
|
||||
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);
|
||||
if (GenericConfig.PatchDebug.Value) 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);
|
||||
if (GenericConfig.PatchDebug.Value) 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;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"New Photon AppID: '{PhotonConfig.AppID.Value}'");
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"New Photon AppID: '{PhotonConfig.VoiceAppID.Value}'");
|
||||
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 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;
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Instance GUID is {id}");
|
||||
|
||||
PhotonNetwork.AuthValues = new AuthenticationValues
|
||||
{
|
||||
UserId = id
|
||||
};
|
||||
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Set the authValues userId to {id}");
|
||||
}
|
||||
|
||||
Plugin.Log.LogInfo($"Photon patch ({(PhotonConfig.SelfHosted.Value ? "self-hosted" : "cloud")}) succeeded.");
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Patches/Registration.cs
Normal file
36
Patches/Registration.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public class RegistrationPatch
|
||||
{
|
||||
static bool Prepare()
|
||||
{
|
||||
if (!GenericConfig.RegistrationPatch.Value) return false;
|
||||
|
||||
Type unityEngineType = AccessTools.TypeByName("UnityEngine.PlayerPrefs");
|
||||
MethodInfo getMethod = unityEngineType.GetMethod("GetInt", [typeof(string), typeof(int)]);
|
||||
|
||||
return unityEngineType != null && getMethod != null;
|
||||
}
|
||||
|
||||
static MethodInfo TargetMethod()
|
||||
{
|
||||
Type tutorialManagerType = AccessTools.TypeByName("UnityEngine.PlayerPrefs");
|
||||
return tutorialManagerType.GetMethod("GetInt", [ typeof(string), typeof(int) ]);
|
||||
}
|
||||
|
||||
static void Postfix(ref string key, ref int defaultValue, ref int __result)
|
||||
{
|
||||
if (key.StartsWith("IncompleteRegistration-"))
|
||||
{
|
||||
__result = 0;
|
||||
Plugin.Log.LogInfo("Detour'd IncompleteRegistration pref key");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Patches/SignalRHandshakeFix.cs
Normal file
42
Patches/SignalRHandshakeFix.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public class SignalRHandshakeFix
|
||||
{
|
||||
public static string TargetTypeName = "JsonProtocol";
|
||||
public static string TargetMethodName = "WithSeparator";
|
||||
public static string Description = "SignalR Handshake Fix (quotes vs apostrophes)";
|
||||
public static Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
|
||||
public static bool Prepare()
|
||||
{
|
||||
if (!GenericConfig.SignalRHandshakeFix.Value) return false;
|
||||
if (targetType == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
if (AccessTools.Method(targetType, TargetMethodName) == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
|
||||
return true;
|
||||
}
|
||||
public static MethodBase TargetMethod() => AccessTools.Method(targetType, TargetMethodName);
|
||||
public static void Prefix(ref string str)
|
||||
{
|
||||
if (str.Contains("protocol':"))
|
||||
{
|
||||
str = str.Replace("'", "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Patches/TLS.cs
Normal file
42
Patches/TLS.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public class TLSPatch
|
||||
{
|
||||
static string TargetTypeName = "Org.BouncyCastle.Crypto.Tls.LegacyTlsAuthentication";
|
||||
static string TargetMethodName = "NotifyServerCertificate";
|
||||
static string Description = "Certificate patch";
|
||||
static Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
|
||||
static bool Prepare()
|
||||
{
|
||||
if (!GenericConfig.CertificatePatch.Value) return false;
|
||||
if (targetType == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
if (AccessTools.Method(targetType, TargetMethodName) == 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() => AccessTools.Method(targetType, TargetMethodName);
|
||||
|
||||
static bool Prefix()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user