Initial commit

This commit is contained in:
2024-11-22 21:13:17 -05:00
parent ae4cf9b7a1
commit 400bd791db
10 changed files with 179 additions and 88 deletions

View File

@@ -31,10 +31,7 @@ namespace undead_universal_patch_il2cpp.Patches
return true;
}
static MethodBase TargetMethod()
{
return targetMethod;
}
static MethodBase TargetMethod() => targetMethod;
[HarmonyPrefix]
static bool Prefix(ref object request)
@@ -46,7 +43,7 @@ namespace undead_universal_patch_il2cpp.Patches
return false;
}
var uriInstance = (Uri)uriProperty.GetValue(request, null);
var uriInstance = (Il2CppSystem.Uri)uriProperty.GetValue(request, null);
if (uriInstance == null)
{
Plugin.Log.LogFatal("BestHTTP_Unob failed: uriInstance was null.");
@@ -55,11 +52,11 @@ namespace undead_universal_patch_il2cpp.Patches
if (GenericConfig.LogAllRequests.Value) Plugin.Log.LogInfo($"BestHTTP_Unob request (Before) URL: {uriInstance.ToString()}");
Uri newUri = new(NameserverConfig.NewUrl.Value);
Il2CppSystem.Uri newUri = new(uriInstance.ToString().Contains("ns.rec.net") ? NameserverConfig.NewUrl.Value : uriInstance.ToString());
if (GenericConfig.LogAllRequests.Value) Plugin.Log.LogInfo($"BestHTTP_Unob request (After) URL: {newUri.ToString()}");
uriProperty.SetValue(request, NameserverConfig., null);
uriProperty.SetValue(request, NameserverConfig.Rewrite.Value ? newUri : uriInstance, null);
return true;
}
}

63
Patches/HilePatch.cs Normal file
View File

@@ -0,0 +1,63 @@
using HarmonyLib;
using System;
using System.Reflection;
using UnityEngine;
namespace undead_universal_patch_il2cpp.Patches
{
[HarmonyPatch]
public static class HilePatch
{
public static void Patch()
{
Plugin.Log.LogInfo("Attempting hile patch");
HileManager man = GameObject.Find("/GameRoot/Startup/Core Systems/[CheatManager]").GetComponent<HileManager>();
string[] asdf = [
"GameAssembly.dll",
"UnityPlayer.dll",
"WinPixEventRuntime.dll",
"steam_api64.dll",
"steam_api.dll",
"d3d11.dll",
"d3d9.dll",
"d3d8.dll",
"ddraw.dll",
"dxgi.dll",
"winhttp.dll"
];
man.KnownDlls = asdf;
Plugin.Log.LogInfo("Hile patch successful.");
}
static string TargetTypeName = "BootSequence";
static string TargetMethodName = "set_CurrentState";
static string Description = "Add BepInEx to allowed DLLs";
static Type targetType = AccessTools.TypeByName(TargetTypeName);
static MethodInfo targetMethod = AccessTools.Method(targetType, TargetMethodName);
static bool Prepare()
{
if (targetMethod == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
return false;
}
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
return true;
}
static MethodBase TargetMethod()
{
return targetMethod;
}
static void Prefix(ref BootSequence __instance)
{
if (GenericConfig.HilePatch.Value && __instance.CurrentState == BootSequence.BootSequenceState.RECNET_CONNECTION) Patch();
}
}
}

View File

@@ -1,4 +1,5 @@
using HarmonyLib;
using Il2CppInterop.Runtime;
using System;
using System.Collections.Generic;
using System.Reflection;
@@ -6,89 +7,44 @@ using UnityEngine;
namespace undead_universal_patch_il2cpp.Patches
{
[HarmonyPatch]
public class PhotonPatchEvent
{
static readonly string TargetTypeName = "RecNet.Core";
static readonly string TargetMethodName = "ConnectToRecNet";
static readonly string Description = "Photon Patch event method";
static readonly MethodInfo connectMethod = AccessTools.Method(AccessTools.TypeByName(TargetTypeName), TargetMethodName);
static bool Prepare()
{
if (connectMethod == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The type 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) Photon.Patch();
}
}
public class Photon
{
public static object Patch()
public static void Patch()
{
Plugin.Log.LogInfo("Attempting Photon patch.");
Type serverSettingsType = AccessTools.TypeByName("ServerSettings");
/*
Normally, I would be using reflection and AccessTools to create a new instance of ServerSettings and set the value of PhotonNetwork.PhotonServerSettings,
but since it was difficult and confusing with IL2CPP, I ended up just using explicit references.. every targeted game build *should* have these types anyway.
Now I'm wondering if the patch runs faster when using explicit references rather than reflection
*/
Type hostingOptionType = AccessTools.Inner(serverSettingsType, "HostingOption");
if (serverSettingsType == null)
{
Plugin.Log.LogFatal("Photon patch failed early, this Photon client is unsupported!");
return null;
}
ScriptableObject settingsInstance = ScriptableObject.CreateInstance(serverSettingsType);
object realPhotonServerSettings = Resources.Load("PhotonServerSettings", serverSettingsType);
try
{
var rpcListField = AccessTools.Field(serverSettingsType, "RpcList");
if (rpcListField == null)
{
Plugin.Log.LogFatal("Photon patch failed (serverSettingsType did not have an RpcList), this Photon client is unsupported!");
return null;
}
if (realPhotonServerSettings == null)
{
Plugin.Log.LogFatal("Photon patch failed (existing photon settings was null, is the patch event set to 'Awake'?), this Photon client is unsupported!");
return null;
}
var existingRpcList = (List<string>)rpcListField.GetValue(realPhotonServerSettings);
rpcListField.SetValue(settingsInstance, existingRpcList);
}
catch (Exception e)
{
Plugin.Log.LogFatal("Photon patch failed (RpcList), this Photon client is unsupported!");
Plugin.Log.LogDebug(e);
return null;
}
var appIdField = AccessTools.Field(serverSettingsType, "AppID");
appIdField.SetValue(settingsInstance, PhotonConfig.AppID.Value);
var voiceAppIdField = AccessTools.Field(serverSettingsType, "VoiceAppID");
voiceAppIdField.SetValue(settingsInstance, PhotonConfig.VoiceAppID.Value);
var hostTypeField = AccessTools.Field(serverSettingsType, "HostType");
if (hostTypeField != null && hostingOptionType != null && hostingOptionType.IsEnum)
{
try
{
object enumValue = Enum.Parse(hostingOptionType, "PhotonCloud");
hostTypeField.SetValue(settingsInstance, enumValue);
}
catch (ArgumentException ex)
{
Plugin.Log.LogFatal($"Photon patch failed, cannot set HostingOption: {ex.Message}");
return null;
}
}
// Save to property
Type photonNetworkType = AccessTools.TypeByName("PhotonNetwork");
if (photonNetworkType == null)
{
Plugin.Log.LogFatal("Photon patch will not work (class not found). Is this build supported?");
return null;
}
FieldInfo photonServerSettingsField = photonNetworkType.GetField("PhotonServerSettings");
if (photonServerSettingsField == null)
{
Plugin.Log.LogFatal("Photon patch will not work (property not found). Is this build supported?");
return null;
}
photonServerSettingsField.SetValue(serverSettingsType, settingsInstance);
Plugin.Log.LogInfo("Photon patch was successful.");
return settingsInstance;
PhotonNetwork.PhotonServerSettings.AppID = PhotonConfig.AppID.Value;
PhotonNetwork.PhotonServerSettings.VoiceAppID = PhotonConfig.VoiceAppID.Value;
}
}
}

View File

@@ -0,0 +1,15 @@
using ExitGames.Client.Photon;
using HarmonyLib;
using System;
namespace undead_universal_patch_il2cpp.Patches
{
[HarmonyPatch(typeof(PhotonNetwork), nameof(PhotonNetwork.ConnectUsingSettings))]
public class RealPhotonPatchEvent
{
public static void Prefix()
{
Photon.Patch();
}
}
}

41
Patches/TLS.cs Normal file
View File

@@ -0,0 +1,41 @@
using System;
using System.Reflection;
using HarmonyLib;
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 MethodInfo targetMethod = AccessTools.Method(targetType, TargetMethodName);
static bool Prepare()
{
if (targetMethod == 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 bool Prefix()
{
return !(GenericConfig.CertificatePatch.Value);
}
}
}