From 5e7a71769e2f1b82565e6d96fb0b7244963698e9 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Sat, 20 Apr 2024 01:52:48 -0700 Subject: [PATCH] Removing references to generated class ids, sometimes painfully --- Patches/EditBuildScreenPatch.cs | 7 ++++--- Patches/WeaponBindingPatch.cs | 17 +++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Patches/EditBuildScreenPatch.cs b/Patches/EditBuildScreenPatch.cs index edaeaac..13b4079 100644 --- a/Patches/EditBuildScreenPatch.cs +++ b/Patches/EditBuildScreenPatch.cs @@ -1,6 +1,7 @@ using Aki.Reflection.Patching; using EFT.UI; using System; +using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -22,8 +23,8 @@ namespace UIFixes { protected override MethodBase GetTargetMethod() { - Type type = typeof(EditBuildScreen.GClass3126); - return type.GetMethod("CloseScreenInterruption", BindingFlags.Public | BindingFlags.Instance); + Type type = typeof(EditBuildScreen).GetNestedTypes().Single(x => x.GetMethod("CloseScreenInterruption") != null); // EditBuildScreen.GClass3126 + return type.GetMethod("CloseScreenInterruption"); } [PatchPrefix] @@ -38,7 +39,7 @@ namespace UIFixes protected override MethodBase GetTargetMethod() { Type type = typeof(EditBuildScreen); - return type.GetMethod("method_35", BindingFlags.Public | BindingFlags.Instance); + return type.GetMethod("method_35"); } [PatchPrefix] diff --git a/Patches/WeaponBindingPatch.cs b/Patches/WeaponBindingPatch.cs index 2117648..7646cb9 100644 --- a/Patches/WeaponBindingPatch.cs +++ b/Patches/WeaponBindingPatch.cs @@ -8,30 +8,35 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using EFT.InputSystem; +using Aki.Reflection.Utils; namespace UIFixes { public class WeaponBindingPatch : ModulePatch { + private static Type ControlSettingsClass; + private static MethodInfo GetKeyNameMethod; + protected override MethodBase GetTargetMethod() { - Type type = typeof(GClass960); - return type.GetMethod("GetBoundItemNames", BindingFlags.Public | BindingFlags.Instance); + ControlSettingsClass = PatchConstants.EftTypes.Single(x => x.GetMethod("GetBoundItemNames") != null); // GClass960 + GetKeyNameMethod = ControlSettingsClass.GetMethod("GetKeyName"); + return ControlSettingsClass.GetMethod("GetBoundItemNames", BindingFlags.Public | BindingFlags.Instance); } [PatchPostfix] - private static void Postfix(GClass960 __instance, EBoundItem boundItem, ref string __result) + private static void Postfix(object __instance, EBoundItem boundItem, ref string __result) { switch(boundItem) { case EBoundItem.Item1: - __result = __instance.GetKeyName(EGameKey.SecondaryWeapon); + __result = GetKeyNameMethod.Invoke(__instance, [EGameKey.SecondaryWeapon]) as string; //__instance.GetKeyName(EGameKey.SecondaryWeapon); break; case EBoundItem.Item2: - __result = __instance.GetKeyName(EGameKey.PrimaryWeaponFirst); + __result = GetKeyNameMethod.Invoke(__instance, [EGameKey.PrimaryWeaponFirst]) as string; //__instance.GetKeyName(EGameKey.PrimaryWeaponFirst); break; case EBoundItem.Item3: - __result = __instance.GetKeyName(EGameKey.PrimaryWeaponSecond); + __result = GetKeyNameMethod.Invoke(__instance, [EGameKey.PrimaryWeaponSecond]) as string; //__instance.GetKeyName(EGameKey.PrimaryWeaponSecond); break; } }