diff --git a/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix.csproj b/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix.csproj new file mode 100644 index 0000000..6379915 --- /dev/null +++ b/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix.csproj @@ -0,0 +1,37 @@ + + + + net35 + BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix + PuppetShopMenuFix + 1.0.0 + true + 9.0 + + + + + + + + + + + + + + + + ..\lib\SteamRelease\Assembly-CSharp.dll + false + + + ..\lib\UnityEngine\UnityEngine.UI.dll + false + + + + + + + diff --git a/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/HarmonyPatches/Interaction_CloseShopMenu.cs b/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/HarmonyPatches/Interaction_CloseShopMenu.cs new file mode 100644 index 0000000..4eb9920 --- /dev/null +++ b/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/HarmonyPatches/Interaction_CloseShopMenu.cs @@ -0,0 +1,19 @@ +using HarmonyLib; + +namespace BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix.HarmonyPatches +{ + [HarmonyPatch(typeof(Interaction), "CloseShopMenu")] + public class Interaction_CloseShopMenu + { + // Disable button selection auto fix. + public static void Prefix(Interaction __instance + //, ref EquipmentMenu ___equipmentMenuScript + ) + { + //if (!___equipmentMenuScript.buttonLock) + { + PuppetShopMenu_Update.checkPending = false; + } + } + } +} diff --git a/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/HarmonyPatches/PuppetShopMenu_Update.cs b/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/HarmonyPatches/PuppetShopMenu_Update.cs new file mode 100644 index 0000000..a20aa6b --- /dev/null +++ b/BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix/HarmonyPatches/PuppetShopMenu_Update.cs @@ -0,0 +1,143 @@ +using HarmonyLib; +using System; +using System.Reflection; +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; +using Object = UnityEngine.Object; + +namespace BepInEx5Plugins.Ash.Alisa.PuppetShopMenuFix.HarmonyPatches +{ + [HarmonyPatch(typeof(PuppetShopMenu), "Update")] + public class PuppetShopMenu_Update + { + public static float checkDelay = 1f; + + public static bool checkPending; + + public static float timer; + + private static FieldInfo ShopCancelButton_selected; + + public static bool Prepare(MethodBase original) + { + if (original is null) + { + try + { + ShopCancelButton_selected = typeof(ShopCancelButton).GetField("selected", BindingFlags.NonPublic | BindingFlags.Instance); + } + catch (Exception exception) + { + Console.WriteLine(exception); + return false; + } + } + + return true; + } + + // Auto fix button selection if necessary. + public static void Postfix(PuppetShopMenu __instance) + { + if (!checkPending) + { + return; + } + + if (timer >= checkDelay) + { + timer -= checkDelay; + + if (!HasSelection()) + { + SelectionFix(__instance); + } + } + + timer += Time.deltaTime; + } + + public static bool HasSelection() + { + foreach (var button in Object.FindObjectsOfType()) + { + if ((bool)ShopCancelButton_selected.GetValue(button)) + { + return true; + } + } + + return false; + } + + public static void SelectionFix(PuppetShopMenu shop) + { + checkPending = false; + + if (!EventSystem.current) + { + return; + } + + var selectedObject = EventSystem.current.currentSelectedGameObject; + + if (!selectedObject) + { + return; + } + + Console.WriteLine("PuppetShopMenu_Update.SelectionFix: Forcibly resetting shop selection to game object " + selectedObject); + + if (shop.weaponsScreen.activeSelf) + { + Console.WriteLine("Selecting first weapons slot"); + + shop.firstWeaponsSlot?.GetComponent