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,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}");
}
}
}
}