Add project files.

This commit is contained in:
2024-07-06 17:14:02 -04:00
parent 9923b10bac
commit ae4cf9b7a1
6 changed files with 297 additions and 0 deletions

66
Patches/BestHTTP.cs Normal file
View File

@@ -0,0 +1,66 @@
using System;
using System.Reflection;
using HarmonyLib;
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 readonly MethodInfo targetMethod = AccessTools.Method(targetType, TargetMethodName, [requestType]);
static bool Prepare()
{
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()
{
return targetMethod;
}
[HarmonyPrefix]
static bool Prefix(ref object request)
{
PropertyInfo uriProperty = AccessTools.Property(requestType, "Uri");
if (uriProperty == null)
{
Plugin.Log.LogFatal("BestHTTP_Unob failed: uriProperty was null.");
return false;
}
var uriInstance = (Uri)uriProperty.GetValue(request, null);
if (uriInstance == null)
{
Plugin.Log.LogFatal("BestHTTP_Unob failed: uriInstance was null.");
return false;
}
if (GenericConfig.LogAllRequests.Value) Plugin.Log.LogInfo($"BestHTTP_Unob request (Before) URL: {uriInstance.ToString()}");
Uri newUri = new(NameserverConfig.NewUrl.Value);
if (GenericConfig.LogAllRequests.Value) Plugin.Log.LogInfo($"BestHTTP_Unob request (After) URL: {newUri.ToString()}");
uriProperty.SetValue(request, NameserverConfig., null);
return true;
}
}
}

94
Patches/Photon.cs Normal file
View File

@@ -0,0 +1,94 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace undead_universal_patch_il2cpp.Patches
{
public class PhotonPatchEvent
{
}
public class Photon
{
public static object Patch()
{
Plugin.Log.LogInfo("Attempting Photon patch.");
Type serverSettingsType = AccessTools.TypeByName("ServerSettings");
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;
}
}
}