From ce822a5d06910b2648951a38c352ec1a6490d596 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Wed, 19 Nov 2025 19:01:12 -0500 Subject: [PATCH] button fixes (back to index, almanac skin button logging an error) --- .../ButtonObjects/BackToIndex_Patch.cs | 19 +++++++++++++++ .../ButtonObjects/NormalBtn_Patch.cs | 11 +++++---- .../GameObjects/ButtonObjects/UIBtn_Patch.cs | 24 +++++++++++++++++++ ...PvZ Fusion Translator [MelonLoader].csproj | 3 +++ 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs new file mode 100644 index 0000000..d23cc59 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs @@ -0,0 +1,19 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects +{ + [HarmonyPatch(typeof(BackToIndex))] + public class BackToIndex_Patch + { + [HarmonyPostfix] + [HarmonyPatch(nameof(BackToIndex.Awake))] + public static void Awake(BackToIndex __instance) + { + StringStore.TranslateTextTransform(__instance.transform.GetChild(0)); + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs index 1e65872..8ccfcf0 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs @@ -13,11 +13,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects [HarmonyPatch(nameof(NormalBtn.OnMouseUpAsButton))] public static void OnMouseUpAsButton(NormalBtn __instance) { - Transform banTransform = __instance.transform.GetChild(0); - if (banTransform != null) + if(__instance.transform.childCount > 0) { - banTransform.GetComponent().text = StringStore.TranslateText(banTransform.GetComponent().text); - } + Transform banTransform = __instance.transform.GetChild(0); + if (banTransform != null) + { + banTransform.GetComponent().text = StringStore.TranslateText(banTransform.GetComponent().text); + } + } } } } \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs new file mode 100644 index 0000000..9c00324 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using UnityEngine.UI; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(UIBtn))] + public static class UIBtn_Patch + { + [HarmonyPatch(nameof(UIBtn.Awake))] + [HarmonyPostfix] + private static void Postfix_Awake(UIBtn __instance) + { + if(__instance.TryGetComponent(out BackToIndex component)) + { + Log.LogDebug("found BackToIndex class"); + Utils.ConvertButtonText(__instance.transform.parent, "BackToIndex"); + } + } + } +} diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index c9a13a6..eb8f074 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -403,6 +403,8 @@ + + @@ -521,5 +523,6 @@ + \ No newline at end of file