INTERNAL REWRITE! server configs

This commit is contained in:
2025-08-12 03:10:25 -04:00
parent 1c51b37a7c
commit 7fc0d6c5b0
23 changed files with 645 additions and 564 deletions

View File

@@ -1,30 +1,26 @@
using System.Reflection;
using HarmonyLib;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.Config;
namespace undead_universal_patch_il2cpp.Patches;
[HarmonyPatch]
public class AFKPatch
{
static readonly string TargetTypeName = "Player";
static readonly string TargetMethodName = "UpdateAFKStatus";
static readonly string Description = "Always present, never AFK";
static PatchTypesResult patchResult = Util.ConfigPreparePatchTypes(
PatchConfig.AFKPatch,
"Always present, never AFK",
"Player",
"UpdateAFKStatus"
);
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;
}
static bool Prepare() => patchResult.Success;
static MethodBase TargetMethod() => patchResult.Method;
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
static MethodBase TargetMethod() => AccessTools.Method(AccessTools.TypeByName(TargetTypeName), TargetMethodName);
static void Prefix(ref bool userIsPresent)
{
if (GenericConfig.AFKPatch.Value) userIsPresent = true;
if (PatchConfig.AFKPatch.Value) userIsPresent = true;
}
}

View File

@@ -1,152 +0,0 @@
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}'");
}
}
}
}

View File

@@ -1,62 +1,55 @@
using System;
using System.Reflection;
using BestHTTP;
using HarmonyLib;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.Config;
namespace undead_universal_patch_il2cpp.Patches
{
[HarmonyPatch]
public class BestHTTP_Unob
public class BestHTTPProxy
{
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 PatchTypesResult patchResult = Util.PreparePatchSpecificTypes(
"BestHTTP request URL rewrite patch",
"BestHTTP.HTTPManager",
"SendRequest",
[
"BestHTTP.HTTPRequest",
]
);
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;
}
static readonly MethodInfo getHeaderMethod = requestType?.GetMethod("GetFirstHeaderValue");
static readonly PropertyInfo methodTypeProp = requestType?.GetProperty("MethodType");
static readonly PropertyInfo uriProp = requestType?.GetProperty("Uri");
static readonly PropertyInfo customCertProp = requestType?.GetProperty("CustomCertificateVerifyer");
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
static MethodBase TargetMethod() => AccessTools.Method(targetType, TargetMethodName, [requestType]);
static bool Prepare() => Util.PostRequireTypes(patchResult, [
getHeaderMethod,
methodTypeProp,
uriProp,
customCertProp
]).Success;
static MethodBase TargetMethod() => patchResult.Method;
[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;
}
if (PatchConfig.CertificatePatch.Value) customCertProp.GetSetMethod().Invoke(request, [null]);
var uriInstance = (Il2CppSystem.Uri)uriProperty.GetValue(request, null);
string contentType = (string)getHeaderMethod.Invoke(request, ["Content-Type"]);
HTTPMethods method = (HTTPMethods)methodTypeProp.GetGetMethod().Invoke(request, []);
var uriInstance = (Il2CppSystem.Uri)uriProp.GetValue(request, null);
if (uriInstance == null)
{
Plugin.Log.LogFatal("BestHTTP_Unob failed: uriInstance was null.");
UniversalPatchPlugin.Log.LogFatal("BestHTTPProxy failed: uriInstance was null.");
return;
}
if (GenericConfig.LogAllRequests.Value) Plugin.Log.LogInfo($"BestHTTP_Unob request b-URL: {uriInstance.ToString()}");
if (!NameserverConfig.Rewrite.Value) return;
string beforeUrl = uriInstance.ToString();
Il2CppSystem.Uri newUri = new(uriInstance.ToString());
@@ -64,8 +57,22 @@ namespace undead_universal_patch_il2cpp.Patches
if (newUri.ToString().Contains("ns.rec.net")) newUri = new Il2CppSystem.Uri(NameserverConfig.NewUrl.Value);
if (GenericConfig.LogAllRequests.Value) Plugin.Log.LogInfo($"BestHTTP_Unob request a-URL: {newUri.ToString()}");
uriProperty.SetValue(request, NameserverConfig.Rewrite.Value ? newUri : uriInstance, null);
// Finish request changes
string afterUrl = newUri.ToString();
uriProp.SetValue(request, NameserverConfig.Rewrite.Value ? newUri : uriInstance, null);
if (GenericConfig.LogAllRequests.Value)
{
if (GenericConfig.VerboseRequestLogs.Value) UniversalPatchPlugin.Log.LogInfo("BestHTTP Request Log\n" +
$" URL Before : {beforeUrl}\n" +
$" URL After : {(beforeUrl == afterUrl ? "(unmodified)" : afterUrl)}\n" +
$" Method : {method}\n" +
$" Content-Type : {contentType ?? "(not set)"}");
else UniversalPatchPlugin.Log.LogInfo("BestHTTPProxy Request Log\n" +
$" Before : {beforeUrl}\n" +
$" After : {afterUrl}");
}
}
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.Config;
using undead_universal_patch_il2cpp.Core.UndeadGameManager;
namespace undead_universal_patch_il2cpp.Patches.UndeadGameManager;
@@ -12,44 +13,35 @@ 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);
static PatchTypesResult patchResult = Util.ConfigPreparePatchTypes(
GameManagerConfig.AnyGameFreeSpawn,
"FreeSpawns event patch",
"GamePlayerSpawnPoint",
"Awake"
);
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;
}
public static bool Prepare() => patchResult.Success;
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
public static MethodBase TargetMethod() => AccessTools.Method(targetType, TargetMethodName);
public static MethodBase TargetMethod() => patchResult.Method;
public static void Postfix(ref GamePlayerSpawnPoint __instance)
{
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("Attempting FreeSpawns patch");
Util.ConditionalDebug("Attempting FreeSpawns patch");
GameManager man = NetworkedSingletonMonoBehaviour<GameManager>.instance;
if (man.CurrentGameConfiguration == null)
{
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("CurrentGameConfiguration was null");
Util.ConditionalDebug("CurrentGameConfiguration was null");
return;
}
if (man.CurrentGameConfiguration.configurationData == null)
{
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("CurrentGameConfiguration.configurationData was null");
Util.ConditionalDebug("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");
Util.ConditionalDebug($"Game '{man.CurrentGameConfiguration.configurationData.Name}' is not specified by GameFreeSpawns");
return;
}

View File

@@ -4,7 +4,7 @@ using System.Reflection;
using HarmonyLib;
using Mapster;
using RecRoom.Core.GameManagement;
using RecRoom.Protobuf;
using undead_universal_patch_il2cpp.Core.Config;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.UndeadGameManager;
@@ -15,29 +15,16 @@ public class GameConfiguratorPatch
{
static Dictionary<string, GameConfigurationAssetDTO> gameConfig = GameConfigurator.config.Get();
static string TargetTypeName = "GameConfigurationTool";
static string TargetMethodName = "SetGameConfiguration";
static string Description = "GameConfigurator event patch";
static PatchTypesResult patchResult = Util.ConfigPreparePatchTypes(
GameManagerConfig.StaticGameConfig,
"GameConfigurator event patch",
"GameConfigurationTool",
"SetGameConfiguration"
);
static Type targetType = AccessTools.TypeByName(TargetTypeName);
static MethodInfo targetMethod = AccessTools.Method(targetType, TargetMethodName);
static bool Prepare() => patchResult.Success;
public static bool Prepare()
{
if (!GameManagerConfig.StaticGameConfig.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 GameConfigurationData res;
static MethodBase TargetMethod() => patchResult.Method;
public static void Prefix(ref GameConfigurationAsset config, ref bool showNotification)
{
@@ -47,14 +34,14 @@ public class GameConfiguratorPatch
var gameConf = gameConfig.GetValueOrDefault(conf.Name, null);
if (gameConf == null)
{
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Game '{conf.Name}' does not have external configuration");
if (GenericConfig.PatchDebug.Value) UniversalPatchPlugin.Log.LogDebug($"Game '{conf.Name}' does not have external configuration");
return;
}
gameConf.Adapt(conf);
config = conf;
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Applied external game configuration for '{config.Name}'");
if (GenericConfig.PatchDebug.Value) UniversalPatchPlugin.Log.LogDebug($"Applied external game configuration for '{config.Name}'");
}
}

View File

@@ -1,6 +1,7 @@
using System.Reflection;
using HarmonyLib;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.Config;
using UnityEngine;
namespace undead_universal_patch_il2cpp.Patches
@@ -8,27 +9,23 @@ 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 PatchTypesResult patchResult = Util.ConfigPreparePatchTypes(
PatchConfig.HilePatch,
"Hile Patch event method",
"RecNet.Core",
"ConnectToRecNet"
);
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;
}
static bool Prepare() => patchResult.Success;
static MethodBase TargetMethod() => patchResult.Method;
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();
if (PatchConfig.HilePatch.Value) HilePatch.Patch();
}
}
public static class HilePatch
{
public static void Patch()
@@ -51,7 +48,7 @@ namespace undead_universal_patch_il2cpp.Patches
"winhttp.dll"
]));
Plugin.Log.LogInfo("Hile patch succeeded.");
UniversalPatchPlugin.Log.LogInfo("Hile patch succeeded.");
}
}
}

View File

@@ -2,40 +2,27 @@
using HarmonyLib;
using System.Reflection;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.Config;
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);
static PatchTypesResult patchResult = Util.ConfigPreparePatchTypes(
PatchConfig.ImageSignaturePatch,
"Image signature patch",
"RecNet.Images",
"VerifySignature"
);
public static bool Prepare()
static bool Prepare() => patchResult.Success;
static MethodBase TargetMethod() => patchResult.Method;
static bool Prefix(ref bool __result)
{
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");
Util.ConditionalDebug("Verified image signature");
__result = true;
return false;
}

View File

@@ -2,40 +2,27 @@
using System.Reflection;
using HarmonyLib;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.Config;
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 PatchTypesResult patchResult = Util.ConfigPreparePatchTypes(
PhotonConfig.PatchPhotonIds,
"Photon ConnectUsingSettings event path",
"PhotonNetwork",
"ConnectUsingSettings"
);
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;
}
static bool Prepare() => patchResult.Success;
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
static MethodInfo TargetMethod() => AccessTools.Method(targetType, TargetMethodName);
static MethodInfo TargetMethod() => patchResult.Method;
static void Prefix()
{
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("Attempting Photon patch");
Util.ConditionalDebug("Attempting Photon patch");
PhotonPatch.Patch();
}
}
@@ -43,36 +30,24 @@ namespace undead_universal_patch_il2cpp.Patches
[HarmonyPatch]
public class ForceSelfHostedPhoton
{
class HarmonyState
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 PatchTypesResult patchResult = Util.ConfigsPreparePatchTypes(
[
PhotonConfig.PatchPhotonIds,
PhotonConfig.SelfHosted
],
"Force JoinOrCreateRoom when connected to master",
"PUNNetworkManager",
"OnConnectedToMaster"
);
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;
}
static bool Prepare() => patchResult.Success;
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
static MethodBase TargetMethod() => targetMethod;
static MethodBase TargetMethod() => patchResult.Method;
static void Prefix(ref PUNNetworkManager __instance, ref HarmonyState __state)
{
@@ -80,25 +55,25 @@ namespace undead_universal_patch_il2cpp.Patches
PropertyInfo targetGameSessionProperty = __instance.GetType().GetRuntimeProperty("targetGameSession");
if (targetGameSessionProperty == null)
{
Plugin.Log.LogFatal("Cannot force masterserver: targetGameSessionProperty was null.");
UniversalPatchPlugin.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.");
UniversalPatchPlugin.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.");
UniversalPatchPlugin.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");
Util.ConditionalDebug("Forcing masterserver");
}
static void Postfix(ref PUNNetworkManager __instance, ref HarmonyState __state)
@@ -106,24 +81,24 @@ namespace undead_universal_patch_il2cpp.Patches
PropertyInfo targetGameSessionProperty = __instance.GetType().GetRuntimeProperty("targetGameSession");
if (targetGameSessionProperty == null)
{
Plugin.Log.LogFatal("Cannot force masterserver postfix: targetGameSessionProperty was null.");
UniversalPatchPlugin.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.");
UniversalPatchPlugin.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.");
UniversalPatchPlugin.Log.LogFatal("Cannot force masterserver: photonRegionIdProperty was null.");
return;
}
photonRegionIdProperty.SetValue(targetGameSession, __state.code);
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("Masterserver regionId roundtrip");
Util.ConditionalDebug("Masterserver regionId roundtrip");
}
}
@@ -139,7 +114,7 @@ namespace undead_universal_patch_il2cpp.Patches
if (photonNetworkType == null || serverSettingsType == null)
{
Plugin.Log.LogError("Cannot patch Photon: PhotonNetwork or ServerSettings types were not found. Is this build supported?");
UniversalPatchPlugin.Log.LogError("Cannot patch Photon: PhotonNetwork or ServerSettings types were not found. Is this build supported?");
return;
}
@@ -157,8 +132,8 @@ namespace undead_universal_patch_il2cpp.Patches
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}'");
Util.ConditionalDebug($"New Photon AppID: '{PhotonConfig.AppID.Value}'");
Util.ConditionalDebug($"New Photon AppID: '{PhotonConfig.VoiceAppID.Value}'");
appIdProperty.SetValue(serverSettings, PhotonConfig.AppID.Value);
voiceAppIdProperty.SetValue(serverSettings, PhotonConfig.VoiceAppID.Value);
@@ -178,28 +153,28 @@ namespace undead_universal_patch_il2cpp.Patches
PropertyInfo networkingPeerProperty = photonNetworkType.GetRuntimeProperty("networkingPeer");
if (networkingPeerProperty == null)
{
Plugin.Log.LogError("Cannot patch Photon: networkingPeerProperty was null. Is this build supported?");
UniversalPatchPlugin.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?");
UniversalPatchPlugin.Log.LogError("Cannot patch Photon: networkingPeerInstance was null. Is this build supported?");
return;
}
string id = Core.Util.LocalInstanceGuid;
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Instance GUID is {id}");
Util.ConditionalDebug($"Instance GUID is {id}");
PhotonNetwork.AuthValues = new AuthenticationValues
{
UserId = id
};
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Set the authValues userId to {id}");
Util.ConditionalDebug($"Set the authValues userId to {id}");
}
Plugin.Log.LogInfo($"Photon patch ({(PhotonConfig.SelfHosted.Value ? "self-hosted" : "cloud")}) succeeded.");
UniversalPatchPlugin.Log.LogInfo($"Photon patch ({(PhotonConfig.SelfHosted.Value ? "self-hosted" : "cloud")}) succeeded.");
}
}
}

View File

@@ -0,0 +1,44 @@
using System.Reflection;
using HarmonyLib;
using Il2CppInterop.Runtime;
using RecRoom.Async;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.CustomRecNet;
namespace undead_universal_patch_il2cpp.Patches;
[HarmonyPatch]
public class AuthenticationEventPatch
{
static PatchTypesResult patchResult = Util.PreparePatchTypes(
"RecNet AccessToken event patch",
"RecNet.Login",
"SetAccessToken"
);
static readonly PropertyInfo hasAccessTokenProperty = patchResult.Type?.GetProperty("HasAccessToken");
static bool Prepare() => Util.PostRequireTypes(patchResult, [
hasAccessTokenProperty
]).Success;
static MethodBase TargetMethod() => patchResult.Method;
private static bool RanPostActions { get; set; } = false;
static void Postfix(ref string accessToken)
{
UniversalPatchPlugin.Log.LogInfo("Intercepted AccessToken");
RecNetInteractions.AccessToken = accessToken;
if (!RanPostActions)
{
bool value = (bool)hasAccessTokenProperty.GetValue(patchResult.Type);
if (value) UniversalPatchPlugin.Log.LogInfo("Running post-authentication actions");
foreach (var action in RecNetInteractions.postAuthenticationActions)
action();
}
else RanPostActions = true;
}
}

33
Patches/PostNameserver.cs Normal file
View File

@@ -0,0 +1,33 @@
using System.Reflection;
using Il2CppInterop.Runtime;
using RecRoom.Async;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.CustomRecNet;
namespace undead_universal_patch_il2cpp.Patches;
public class NameserverConnectEventPatch
{
static PatchTypesResult patchResult = Util.PreparePatchTypes(
"Nameserver connect event patch",
"RecNet.Core",
"ConnectToRecNet"
);
static bool Prepare() => patchResult.Success;
static MethodBase TargetMethod() => patchResult.Method;
static void Postfix(ref IPromise __result)
{
__result.Finally(DelegateSupport.ConvertDelegate<Il2CppSystem.Action>(() =>
{
if (RecNetInteractions.HasNameserverConnected())
{
UniversalPatchPlugin.Log.LogInfo("Running post-nameserver actions");
foreach (var action in RecNetInteractions.postAuthenticationActions) action();
}
else Util.ConditionalDebug("The nameserver request did not resolve successfully, skipping post-nameserver actions.");
}));
}
}

View File

@@ -1,36 +1,31 @@
using System;
using System.Reflection;
using System.Reflection;
using HarmonyLib;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.Config;
namespace undead_universal_patch_il2cpp.Patches
{
[HarmonyPatch]
public class RegistrationPatch
{
static bool Prepare()
{
if (!GenericConfig.RegistrationPatch.Value) return false;
static PatchTypesResult patchResult = Util.ConfigPreparePatchTypes(
PatchConfig.RegistrationPatch,
"Registration patch (to be vetted, might not work)",
"UnityEngine.PlayerPrefs",
"GetInt"
);
Type unityEngineType = AccessTools.TypeByName("UnityEngine.PlayerPrefs");
MethodInfo getMethod = unityEngineType.GetMethod("GetInt", [typeof(string), typeof(int)]);
static bool Prepare() => patchResult.Success;
return unityEngineType != null && getMethod != null;
}
static MethodInfo TargetMethod()
{
Type tutorialManagerType = AccessTools.TypeByName("UnityEngine.PlayerPrefs");
return tutorialManagerType.GetMethod("GetInt", [ typeof(string), typeof(int) ]);
}
static MethodInfo TargetMethod() => patchResult.Method;
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");
UniversalPatchPlugin.Log.LogInfo("Detour'd IncompleteRegistration pref key");
}
}
}
}
}

View File

@@ -1,37 +1,25 @@
using System;
using System.Reflection;
using System.Reflection;
using HarmonyLib;
using undead_universal_patch_il2cpp.Core;
using undead_universal_patch_il2cpp.Core.Config;
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);
static PatchTypesResult patchResult = Util.ConfigPreparePatchTypes(
PatchConfig.SignalRHandshakeFix,
"SignalR Handshake Fix (quotes vs apostrophes)",
"JsonProtocol",
"WithSeparator"
);
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;
}
static bool Prepare() => patchResult.Success;
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
public static MethodBase TargetMethod() => AccessTools.Method(targetType, TargetMethodName);
public static void Prefix(ref string str)
static MethodBase TargetMethod() => patchResult.Method;
static void Prefix(ref string str)
{
if (str.Contains("protocol':"))
{

View File

@@ -1,42 +0,0 @@
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;
}
}
}