using System;
using System.Reflection;
using HarmonyLib;
namespace undead_universal_patch.Patches
{
[HarmonyPatch]
class BestHTTP_MonoOne_Patch
{
static string TargetTypeName = "BestHTTP.EDGFEAGFEKH";
static string TargetMethodName = "MMOHCNJHBLK";
static string Description = "2018 BestHTTP request (early) rewrite patch";
static readonly Type targetType = AccessTools.TypeByName(TargetTypeName);
static readonly Type requestType = AccessTools.TypeByName("BestHTTP.KGBBPEDECCO");
// TODO: Reduce boilerplate
static bool Prepare()
{
if (targetType == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
return false;
}
MethodInfo requestMethod = AccessTools.Method(targetType, TargetMethodName, [ requestType ]);
if (requestMethod == 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 AccessTools.Method(targetType, TargetMethodName, [ requestType ]);
}
[HarmonyPrefix]
static bool Prefix(ref object OCJJLJHMMGH)
{
PropertyInfo uriProperty = AccessTools.Property(requestType, "NJCAFJDHMHI");
if (uriProperty == null)
{
Plugin.Log.LogFatal("BestHTTP_MonoOne failed: NJCAFJDHMHI was null.");
return false;
}
var uriInstance = (Uri)uriProperty.GetValue(OCJJLJHMMGH, null);
if (uriInstance == null)
{
Plugin.Log.LogFatal("BestHTTP_MonoOne failed: uriInstance was null.");
return false;
}
if (uriInstance.Host.Contains("api.amplitude.com") && GenericConfig.DisableAmplitude.Value) return false;
Plugin.Log.LogInfo($"BestHTTP_MonoOne request (Before) URL: {uriInstance.ToString()}");
Uri newUri;
if (GenericConfig.IsNameserver.Value) newUri = PatchUtils.RewriteUrlForNameserver(uriInstance);
else newUri = PatchUtils.RewriteUrlForGameserver(uriInstance);
Plugin.Log.LogInfo($"BestHTTP_MonoOne request (After) URL: {newUri.ToString()}");
uriProperty.SetValue(OCJJLJHMMGH, newUri, null);
return true;
}
}
[HarmonyPatch]
class BestHTTP_MonoTwo_Patch
{
static string TargetTypeName = "BestHTTP.IGMACIPKKLJ";
static string TargetMethodName = "LIADPGACMDN";
static string Description = "2018 BestHTTP request (late) rewrite patch";
static readonly Type targetType = AccessTools.TypeByName(TargetTypeName);
static readonly Type requestType = AccessTools.TypeByName("BestHTTP.CLFJEGPBDII");
static bool Prepare()
{
if (targetType == null)
{
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
return false;
}
MethodInfo requestMethod = AccessTools.Method(targetType, TargetMethodName, [requestType]);
if (requestMethod == 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 AccessTools.Method(targetType, TargetMethodName, [requestType]);
}
[HarmonyPrefix]
static bool Prefix(ref object GFKPFLABKMA)
{
PropertyInfo uriProperty = AccessTools.Property(requestType, "ECJJELCCIJA");
if (uriProperty == null)
{
Plugin.Log.LogFatal("BestHTTP_MonoTwo failed: ECJJELCCIJA was null.");
return false;
}
var uriInstance = (Uri)uriProperty.GetValue(GFKPFLABKMA, null);
if (uriInstance == null)
{
Plugin.Log.LogFatal("BestHTTP_MonoTwo failed: uriInstance was null.");
return false;
}
// TODO: Not the most elegant way to patch out amplitude - find a better way
if (uriInstance.Host.Contains("api.amplitude.com") && GenericConfig.DisableAmplitude.Value) return false;
Plugin.Log.LogInfo($"BestHTTP_MonoTwo request (Before) URL: {uriInstance.ToString()}");
Uri newUri;
if (GenericConfig.IsNameserver.Value) newUri = PatchUtils.RewriteUrlForNameserver(uriInstance);
else newUri = PatchUtils.RewriteUrlForGameserver(uriInstance);
Plugin.Log.LogInfo($"BestHTTP_MonoTwo request (After) URL: {newUri.ToString()}");
uriProperty.SetValue(GFKPFLABKMA, newUri, null);
return true;
}
}
}