From 9f80498520497de01405432d538bd873c9e22223 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Wed, 8 May 2024 13:48:03 -0700 Subject: [PATCH] Autofocus number in flea market offer --- Patches/DialogPatches.cs | 60 ++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/Patches/DialogPatches.cs b/Patches/DialogPatches.cs index 6d135e7..3e8234f 100644 --- a/Patches/DialogPatches.cs +++ b/Patches/DialogPatches.cs @@ -1,36 +1,66 @@ using Aki.Reflection.Patching; +using EFT.InventoryLogic; using EFT.UI; +using EFT.UI.Ragfair; using HarmonyLib; using System; +using System.Linq; using System.Reflection; +using TMPro; using UnityEngine; namespace UIFixes { - public class DialogPatch : ModulePatch + public class DialogPatches { - private static MethodInfo AcceptMethod; - - protected override MethodBase GetTargetMethod() + public static void Enable() { - Type dialogWindowType = typeof(MessageWindow).BaseType; - AcceptMethod = AccessTools.Method(dialogWindowType, "Accept"); - - return AccessTools.Method(dialogWindowType, "Update"); + new DialogWindowPatch().Enable(); + new FleaPurchaseDialogPatch().Enable(); } - [PatchPostfix] - private static void Postfix(object __instance, bool ___bool_0) + private class DialogWindowPatch : ModulePatch { - if (!___bool_0) + private static MethodInfo AcceptMethod; + + protected override MethodBase GetTargetMethod() { - return; + Type dialogWindowType = typeof(MessageWindow).BaseType; + AcceptMethod = AccessTools.Method(dialogWindowType, "Accept"); + + return AccessTools.Method(dialogWindowType, "Update"); } - if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) + [PatchPostfix] + private static void Postfix(object __instance, bool ___bool_0) { - AcceptMethod.Invoke(__instance, []); - return; + if (!___bool_0) + { + return; + } + + if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) + { + AcceptMethod.Invoke(__instance, []); + return; + } + } + } + + private class FleaPurchaseDialogPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + // The parent has a Show() so need to be specific + return typeof(HandoverRagfairMoneyWindow).GetMethods().First(m => m.Name == "Show" && m.GetParameters()[0].ParameterType == typeof(Inventory)); + } + + [PatchPostfix] + private static void Postfix(TMP_InputField ____inputField) + { + ____inputField.contentType = TMP_InputField.ContentType.IntegerNumber; + ____inputField.ActivateInputField(); + ____inputField.Select(); } } }