From 3eab4a94393e0bcc5893f4806abc6712de5f7fb6 Mon Sep 17 00:00:00 2001 From: TuanAnh2901 Date: Wed, 20 Aug 2025 22:02:01 +0700 Subject: [PATCH] Sync MelonLoader from origin/main (keep BepInEx local changes) --- MelonLoader/Core.cs | 8 +++-- .../Patches/GameObjects/GardenPlant_Patch.cs | 34 +++++++++++-------- .../GameObjects/PlayerShootingMenu_Patch.cs | 15 ++++++++ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/MelonLoader/Core.cs b/MelonLoader/Core.cs index dbcc538..bf447c9 100644 --- a/MelonLoader/Core.cs +++ b/MelonLoader/Core.cs @@ -4,6 +4,7 @@ using MelonLoader.Utils; using PvZ_Fusion_Translator.AssetStore; using PvZ_Fusion_Translator.Patches.Managers; using UnityEngine; +using Il2Cpp; [assembly: MelonInfo(typeof(PvZ_Fusion_Translator.Core), "PvZ Fusion Translator", "231.0.0", "dynaslash / arifrios1st / lancerx0 / JustNull / Dakosha / Mamoru-kun / cassidy / Teyliu", null)] [assembly: MelonGame("LanPiaoPiao", "PlantsVsZombiesRH")] @@ -74,8 +75,11 @@ namespace PvZ_Fusion_Translator Utils.OpenTrello(); } - TowerManager_Patch.UpdateText(); - } + if(TowerManager.Instance != null) + { + TowerManager_Patch.UpdateText(); + } + } public override void OnGUI() { diff --git a/MelonLoader/Patches/GameObjects/GardenPlant_Patch.cs b/MelonLoader/Patches/GameObjects/GardenPlant_Patch.cs index 679627a..ead08fa 100644 --- a/MelonLoader/Patches/GameObjects/GardenPlant_Patch.cs +++ b/MelonLoader/Patches/GameObjects/GardenPlant_Patch.cs @@ -1,24 +1,28 @@ using HarmonyLib; using Il2Cpp; using PvZ_Fusion_Translator.AssetStore; +using System.Text.RegularExpressions; namespace PvZ_Fusion_Translator.Patches.GameObjects { [HarmonyPatch(typeof(GardenPlant))] - public static class GardenPlant_Patch - { - [HarmonyPatch(nameof(GardenPlant.Update))] - [HarmonyPostfix] - private static void Update(GardenPlant __instance) - { - __instance.infoText = StringStore.TranslateText(__instance.infoText); - } + public static class GardenPlant_Patch + { + [HarmonyPatch(nameof(GardenPlant.Start))] + [HarmonyPostfix] + private static void Start(GardenPlant __instance) + { + __instance.infoText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + __instance.infoText.text = StringStore.TranslateText(__instance.infoText.text); + } - [HarmonyPatch(nameof(GardenPlant.UpdateInfo))] - [HarmonyPostfix] - private static void UpdateInfo(GardenPlant __instance) - { - __instance.infoText = StringStore.TranslateText(__instance.infoText); - } - } + [HarmonyPatch(nameof(GardenPlant.UpdateInfo))] + [HarmonyPostfix] + private static void UpdateInfo(GardenPlant __instance) + { + + __instance.infoText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + __instance.infoText.text = StringStore.TranslateText(__instance.infoText.text); + } + } } \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/PlayerShootingMenu_Patch.cs b/MelonLoader/Patches/GameObjects/PlayerShootingMenu_Patch.cs index db4c48a..3e47e10 100644 --- a/MelonLoader/Patches/GameObjects/PlayerShootingMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/PlayerShootingMenu_Patch.cs @@ -21,5 +21,20 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects txt.font = fontAsset; } } + + [HarmonyPatch(nameof(PlayerShootingMenu.Refresh))] + [HarmonyPostfix] + private static void Refresh(PlayerShootingMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + Transform refreshTransform = __instance.transform.FindChild("Button"); + foreach (TextMeshProUGUI text in refreshTransform.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + text.autoSizeTextContainer = false; + } + } } } \ No newline at end of file