From 4447f3c96d1dcb302f14655c9c7ec14506db1bdb Mon Sep 17 00:00:00 2001 From: TuanAnh2901 Date: Wed, 20 Aug 2025 21:50:36 +0700 Subject: [PATCH] Update BIE to current ML branch --- .gitignore | 1 + BepInEx/Core.cs | 7 ++-- .../Patches/GameObjects/GardenPlant_Patch.cs | 36 ++++++++++--------- .../GameObjects/PlayerShootingMenu_Patch.cs | 15 ++++++++ .../Managers/AlmanacMgrZombie_Patch.cs | 31 +++++++++++----- .../Managers/AlmanacPlantBank_Patch.cs | 15 ++++++-- 6 files changed, 76 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 86935dc..f8d1c11 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,4 @@ MelonLoader/bin/x64/Debug/net6.0/UnityEngine.VRModule.dll MelonLoader/bin/x64/Debug/net6.0/UnityEngine.WindModule.dll MelonLoader/bin/x64/Debug/net6.0/UnityEngine.XRModule.dll MelonLoader/bin/x64/Debug/net6.0/WebSocketDotNet.dll +/BepInEx/bin/Debug/net6.0 diff --git a/BepInEx/Core.cs b/BepInEx/Core.cs index cd10d14..7583580 100644 --- a/BepInEx/Core.cs +++ b/BepInEx/Core.cs @@ -91,8 +91,11 @@ public class Core : BasePlugin { Utils.OpenTrello(); } - TowerManager_Patch.UpdateText(); - } + if (TowerManager.Instance != null) + { + TowerManager_Patch.UpdateText(); + } + } public void OnGUI() { diff --git a/BepInEx/Patches/GameObjects/GardenPlant_Patch.cs b/BepInEx/Patches/GameObjects/GardenPlant_Patch.cs index 8942ca6..5d8ea61 100644 --- a/BepInEx/Patches/GameObjects/GardenPlant_Patch.cs +++ b/BepInEx/Patches/GameObjects/GardenPlant_Patch.cs @@ -1,24 +1,28 @@ -using HarmonyLib; +using HarmonyLib; using System; +using System.Text.RegularExpressions; using PvZ_Fusion_Translator__BepInEx_.AssetStore; namespace PvZ_Fusion_Translator__BepInEx_.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/BepInEx/Patches/GameObjects/PlayerShootingMenu_Patch.cs b/BepInEx/Patches/GameObjects/PlayerShootingMenu_Patch.cs index 6d84cb0..b893898 100644 --- a/BepInEx/Patches/GameObjects/PlayerShootingMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/PlayerShootingMenu_Patch.cs @@ -21,5 +21,20 @@ namespace PvZ_Fusion_Translator__BepInEx_.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 diff --git a/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs b/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs index 0c96618..3ece64f 100644 --- a/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs +++ b/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs @@ -111,8 +111,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers } } } - - return; + DumpAlmanacModdedZombies(__instance); + return; } [HarmonyPatch(nameof(AlmanacMgrZombie.OnMouseDown))] @@ -129,6 +129,25 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers } } + + [HarmonyPatch(typeof(AlmanacMgrZombie))] + public static partial class AlmanacMgrZombie_Patch + { + [HarmonyPatch(nameof(AlmanacMgrZombie.OnMouseDown))] + [HarmonyPostfix] + public static void DumpAlmanacModdedZombies(AlmanacMgrZombie __instance) + { + // Dump the texts if needed using Ctrl key + if (Input.GetKey(KeyCode.LeftControl)) + { + FileLoader.DumpUntranslatedStrings(__instance.info.GetComponent().text); + Log.LogInfo($"Info: {__instance.info.GetComponent().text}"); + FileLoader.DumpUntranslatedStrings(__instance.zombieName.GetComponent().text); + Log.LogInfo($"Zombie Name: {__instance.zombieName.GetComponent().text}"); + } + } + } + // Patch to translate the modded almanac zombie names and info [HarmonyPatch(typeof(AlmanacMgrZombie))] public static partial class AlmanacMgrZombie_Patch @@ -141,13 +160,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers __instance.introduce.text = StringStore.TranslateText(__instance.introduce.text); __instance.introduce.font = FontStore.LoadTMPFont(currentLanguage); - // Dump the texts if needed - if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftControl)) - { - FileLoader.DumpUntranslatedStrings(__instance.info.GetComponent().text); - FileLoader.DumpUntranslatedStrings(__instance.zombieName.GetComponent().text); - } - + DumpAlmanacModdedZombies(__instance); // translate all TMP components in info foreach (TextMeshPro text in __instance.info.GetComponentsInChildren()) { diff --git a/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs b/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs index c3927b9..c488424 100644 --- a/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs +++ b/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using HarmonyLib; using Il2CppInterop.Runtime; using PvZ_Fusion_Translator__BepInEx_; @@ -159,6 +159,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers text.text = StringStore.TranslateText(text.text); } } + + TranslateTextAlmanac(__instance); return; } @@ -182,7 +184,16 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers [HarmonyPostfix] public static void TranslateTextAlmanac(AlmanacPlantBank __instance) { - + + // Dump the texts if needed + if (Input.GetKey(KeyCode.LeftControl)) + { + FileLoader.DumpUntranslatedStrings(__instance.introduce.GetComponent().text); + Log.LogInfo($"Info: {__instance.introduce.GetComponent().text}"); + FileLoader.DumpUntranslatedStrings(__instance.plantName.GetComponent().text); + Log.LogInfo($"PlantName Name: {__instance.plantName.GetComponent().text}"); + Log.LogInfo($"PlantShadow Name: {__instance.plantName.transform.GetChild(0).GetComponent().text}"); + } string currentLanguage = Utils.Language.ToString(); __instance.introduce.text = StringStore.TranslateText(__instance.introduce.text); __instance.introduce.font = FontStore.LoadTMPFont(currentLanguage);