From 0e9debc5b8f75631b57d228416db91b7b3bdd049 Mon Sep 17 00:00:00 2001 From: TuanAnh2901 Date: Wed, 13 Aug 2025 12:35:24 +0700 Subject: [PATCH 1/4] Update to the current progress. Patch to translate mod (LibraHp's) using translation_strings --- BepInEx/Core.cs | 5 +- .../BaseTextObjects/TextMeshProUGUI_Patch.cs | 8 ++- .../Patches/GameObjects/AbyssMenu2_Patch.cs | 9 ++- .../Patches/GameObjects/AbyssMenu_Patch.cs | 6 +- BepInEx/Patches/GameObjects/BaseMenu_Patch.cs | 13 +++- .../ButtonObjects/UIButton_Patch.cs | 60 +++++++++++-------- .../MinorObjects/UIProgress2_Patch.cs | 17 ++++++ .../GameObjects/PlayerShootingMenu_Patch.cs | 25 ++++++++ .../GameObjects/PlayerShootingWindow_Patch.cs | 36 +++++++++++ .../Patches/GameObjects/TowerOption_Patch.cs | 40 ++++++------- .../GameObjects/TowerUpgradeMenu_Patch.cs | 39 ++++++++++++ .../GameObjects/TravelBuffMenu_Patch.cs | 21 +++++++ .../TravelBuffOptionButton_Patch.cs | 4 +- .../Managers/AlmanacMgrZombie_Patch.cs | 54 ++++++++++++++++- .../Patches/Managers/TowerManager_Patch.cs | 33 ++++++++++ .../PvZ Fusion Translator [BepInEx].csproj | 6 ++ 16 files changed, 319 insertions(+), 57 deletions(-) create mode 100644 BepInEx/Patches/GameObjects/MinorObjects/UIProgress2_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/PlayerShootingMenu_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/PlayerShootingWindow_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/TowerUpgradeMenu_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs create mode 100644 BepInEx/Patches/Managers/TowerManager_Patch.cs diff --git a/BepInEx/Core.cs b/BepInEx/Core.cs index 6df672c..cd10d14 100644 --- a/BepInEx/Core.cs +++ b/BepInEx/Core.cs @@ -3,15 +3,17 @@ using BepInEx.Configuration; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using BepInEx.Unity.IL2CPP.Utils; +using TMPro; using HarmonyLib; using PvZ_Fusion_Translator__BepInEx_; using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using PvZ_Fusion_Translator__BepInEx_.Patches.Managers; using System; using System.IO; using System.Reflection; using UnityEngine; -[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] +[BepInPlugin("PVZFusionTranslator_BepInEx", "PvZ Fusion Translator", "2.8.1")] [BepInProcess("PlantsVsZombiesRH.exe")] public class Core : BasePlugin { @@ -89,6 +91,7 @@ public class Core : BasePlugin { Utils.OpenTrello(); } + TowerManager_Patch.UpdateText(); } public void OnGUI() diff --git a/BepInEx/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs b/BepInEx/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs index 4ef8e8e..4046f6a 100644 --- a/BepInEx/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs +++ b/BepInEx/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs @@ -2,7 +2,9 @@ using System; using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using PvZ_Fusion_Translator__BepInEx_.Patches.Managers; using UnityEngine.UI; +using UnityEngine; namespace PvZ_Fusion_Translator__BepInEx_.Patches.BaseTextObjects { @@ -21,7 +23,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.BaseTextObjects if (__instance.name.StartsWith("LevelName")) { __instance.text = __instance.text.Replace("\n", " "); - } + if (__instance.name == "LevelName2" || __instance.name == "LevelName3") + { + TowerManager_Patch.updatedText.Add(__instance.transform); + } + } if (__instance.transform.parent != null && __instance.transform.parent.name.StartsWith("Window")) { __instance.fontSizeMin = 10; diff --git a/BepInEx/Patches/GameObjects/AbyssMenu2_Patch.cs b/BepInEx/Patches/GameObjects/AbyssMenu2_Patch.cs index 47089f5..2a0763e 100644 --- a/BepInEx/Patches/GameObjects/AbyssMenu2_Patch.cs +++ b/BepInEx/Patches/GameObjects/AbyssMenu2_Patch.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using System; using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; @@ -48,6 +48,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects textMesh.text = StringStore.TranslateText(textMesh.text); } } + + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + } } [HarmonyPatch(nameof(AbyssMenu2.Start))] @@ -56,7 +62,6 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { UpdateAbyss2Text(__instance); - Utils.ConvertButtonText(__instance.transform, "Goback"); Utils.ConvertButtonText(__instance.transform, "Help"); Utils.ConvertButtonText(__instance.transform, "Bag"); } diff --git a/BepInEx/Patches/GameObjects/AbyssMenu_Patch.cs b/BepInEx/Patches/GameObjects/AbyssMenu_Patch.cs index f67b7cc..2dea6d3 100644 --- a/BepInEx/Patches/GameObjects/AbyssMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/AbyssMenu_Patch.cs @@ -26,7 +26,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects txt.font = fontAsset; } - Utils.ConvertButtonText(__instance.transform, "Goback"); + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + } } [HarmonyPatch(nameof(AbyssMenu.UpdateLevelInfo))] diff --git a/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs b/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs index ca50e34..fa05462 100644 --- a/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using System; using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; @@ -106,8 +106,17 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects StringStore.TranslateTextTransform(pageScaryPotTransform.Find("LastPage")); } - foreach(TextMeshProUGUI txt in mainTransform.GetComponentsInChildren()) + Transform pageEndlessLevelTransform = levelsTransform.transform.Find("PageEndlessLevel"); + if (pageEndlessLevelTransform != null) { + StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("BackToIndex")); + StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("Nextpage")); + StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("LastPage")); + } + + foreach (TextMeshProUGUI txt in mainTransform.GetComponentsInChildren()) + { + // Still dump untranslated strings for modded plants and zombies FileLoader.DumpUntranslatedStrings(txt.text); txt.text = StringStore.TranslateText(txt.text); } diff --git a/BepInEx/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index ef94655..56839ff 100644 --- a/BepInEx/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs +++ b/BepInEx/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using System; using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; @@ -16,37 +16,42 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { try { - // Convert and translate legacy Text components - Text[] textComponents = __instance.GetComponentsInChildren(true); - TextMeshProUGUI[] textMeshComponents = __instance.GetComponentsInChildren(true); - foreach (Text textComponent in textComponents) - { - if (textComponent != null && !string.IsNullOrEmpty(textComponent.text)) - { - string translatedText = StringStore.TranslateText(textComponent.text); - if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text) - { - TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true); - - if (newTMP != null) - { - newTMP.text = translatedText; - } - } - } - } - // Also handle TMP components directly under the button if (__instance.transform.childCount >= 2) { TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent(); - StringStore.TranslateTextUI(text, false); - StringStore.TranslateTextUI(textShadow, false); + text.text = StringStore.TranslateText(text.text, false); + textShadow.text = StringStore.TranslateText(textShadow.text, false); + + text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + textShadow.font = FontStore.LoadTMPFont(Utils.Language.ToString()); text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true; } + else + { + // Convert and translate legacy Text components + Text[] textComponents = __instance.GetComponentsInChildren(true); + TextMeshProUGUI[] textMeshComponents = __instance.GetComponentsInChildren(true); + foreach (Text textComponent in textComponents) + { + if (textComponent != null && !string.IsNullOrEmpty(textComponent.text)) + { + string translatedText = StringStore.TranslateText(textComponent.text); + if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true); + + if (newTMP != null) + { + newTMP.text = translatedText; + } + } + } + } + } } catch (Exception) { } } @@ -62,8 +67,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent(); - StringStore.TranslateTextUI(text, false); - StringStore.TranslateTextUI(textShadow, false); + text.text = StringStore.TranslateText(text.text, false); + textShadow.text = StringStore.TranslateText(textShadow.text, false); + + text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + textShadow.font = FontStore.LoadTMPFont(Utils.Language.ToString()); text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true; } } diff --git a/BepInEx/Patches/GameObjects/MinorObjects/UIProgress2_Patch.cs b/BepInEx/Patches/GameObjects/MinorObjects/UIProgress2_Patch.cs new file mode 100644 index 0000000..8c8ccf0 --- /dev/null +++ b/BepInEx/Patches/GameObjects/MinorObjects/UIProgress2_Patch.cs @@ -0,0 +1,17 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(UIProgress2))] + public static class UIProgress2_Patch + { + [HarmonyPatch(nameof(UIProgress2.Update))] + [HarmonyPostfix] + private static void Update(UIProgress2 __instance) + { + __instance.t.text = StringStore.TranslateText(__instance.t.text); + } + } +} \ No newline at end of file diff --git a/BepInEx/Patches/GameObjects/PlayerShootingMenu_Patch.cs b/BepInEx/Patches/GameObjects/PlayerShootingMenu_Patch.cs new file mode 100644 index 0000000..6d84cb0 --- /dev/null +++ b/BepInEx/Patches/GameObjects/PlayerShootingMenu_Patch.cs @@ -0,0 +1,25 @@ +using HarmonyLib; +using TMPro; +using BepInEx.Unity.IL2CPP; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(PlayerShootingMenu))] + public static class PlayerShootingMenu_Patch + { + [HarmonyPatch(nameof(PlayerShootingMenu.Update))] + [HarmonyPostfix] + private static void Update(PlayerShootingMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} \ No newline at end of file diff --git a/BepInEx/Patches/GameObjects/PlayerShootingWindow_Patch.cs b/BepInEx/Patches/GameObjects/PlayerShootingWindow_Patch.cs new file mode 100644 index 0000000..2c228af --- /dev/null +++ b/BepInEx/Patches/GameObjects/PlayerShootingWindow_Patch.cs @@ -0,0 +1,36 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(PlayerShootingWindow))] + public static class PlayerShootingWindow_Patch + { + [HarmonyPatch(nameof(PlayerShootingWindow.SetType))] + [HarmonyPostfix] + private static void SetType(PlayerShootingWindow __instance) + { + Transform introduceTransform = __instance.transform.FindChild("Images").FindChild("Introduce"); + TextMeshProUGUI introduceText = introduceTransform.GetComponent(); + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + introduceText.text = StringStore.TranslateText(introduceText.text); + introduceText.font = fontAsset; + } + + [HarmonyPatch(nameof(PlayerShootingWindow.OnAnimOver))] + [HarmonyPostfix] + private static void OnAnimOver(PlayerShootingWindow __instance) + { + Transform introduceTransform = __instance.transform.FindChild("Images").FindChild("Introduce"); + TextMeshProUGUI introduceText = introduceTransform.GetComponent(); + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + introduceText.text = StringStore.TranslateText(introduceText.text); + introduceText.font = fontAsset; + } + } +} diff --git a/BepInEx/Patches/GameObjects/TowerOption_Patch.cs b/BepInEx/Patches/GameObjects/TowerOption_Patch.cs index 2095824..a8784d1 100644 --- a/BepInEx/Patches/GameObjects/TowerOption_Patch.cs +++ b/BepInEx/Patches/GameObjects/TowerOption_Patch.cs @@ -1,21 +1,21 @@ -using HarmonyLib; -using System; -using TMPro; -using PvZ_Fusion_Translator__BepInEx_.AssetStore; -using UnityEngine; +//using HarmonyLib; +//using System; +//using TMPro; +//using PvZ_Fusion_Translator__BepInEx_.AssetStore; +//using UnityEngine; -namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects -{ - [HarmonyPatch(typeof(TowerOption))] - public static class TowerOption_Patch - { - [HarmonyPatch(nameof(TowerOption.Start))] - [HarmonyPostfix] - private static void Postfix_Start(TowerOption __instance) - { - //TextMeshProUGUI[] allTexts = __instance.GetComponentsInChildren(true); - __instance.introduce.text = StringStore.TranslateText(__instance.introduce.text); - __instance.introduce.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - } - } -} \ No newline at end of file +//namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +//{ +// [HarmonyPatch(typeof(TowerOption))] +// public static class TowerOption_Patch +// { +// [HarmonyPatch(nameof(TowerOption.Start))] +// [HarmonyPostfix] +// private static void Postfix_Start(TowerOption __instance) +// { +// //TextMeshProUGUI[] allTexts = __instance.GetComponentsInChildren(true); +// __instance.introduce.text = StringStore.TranslateText(__instance.introduce.text); +// __instance.introduce.font = FontStore.LoadTMPFont(Utils.Language.ToString()); +// } +// } +//} \ No newline at end of file diff --git a/BepInEx/Patches/GameObjects/TowerUpgradeMenu_Patch.cs b/BepInEx/Patches/GameObjects/TowerUpgradeMenu_Patch.cs new file mode 100644 index 0000000..fee9af4 --- /dev/null +++ b/BepInEx/Patches/GameObjects/TowerUpgradeMenu_Patch.cs @@ -0,0 +1,39 @@ +using HarmonyLib; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using TMPro; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(TowerUpgradeMenu))] + public static class TowerUpgradeMenu_Patch + { + [HarmonyPatch(nameof(TowerUpgradeMenu.Awake))] + [HarmonyPostfix] + private static void Awake(TowerUpgradeMenu __instance) + { + __instance.des.text = StringStore.TranslateText(__instance.des.text); + __instance.des2.text = StringStore.TranslateText(__instance.des2.text); + + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + + [HarmonyPatch(nameof(TowerUpgradeMenu.SetText))] + [HarmonyPostfix] + private static void SetText(TowerUpgradeMenu __instance) + { + __instance.des.text = StringStore.TranslateText(__instance.des.text); + __instance.des2.text = StringStore.TranslateText(__instance.des2.text); + + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + } +} \ No newline at end of file diff --git a/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs b/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs new file mode 100644 index 0000000..665a420 --- /dev/null +++ b/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs @@ -0,0 +1,21 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(TravelBuffMenu))] + public static class TravelBuffMenu_Patch + { + [HarmonyPatch(nameof(TravelBuffMenu.RefeshOptions))] + [HarmonyPostfix] + private static void RefeshOptions(TravelBuffMenu __instance) + { + foreach (TravelBuffOptionButton button in __instance.options) + { + button.introduce.text = StringStore.TranslateText(button.introduce.text); + } + } + } +} \ No newline at end of file diff --git a/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs b/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs index 4e17523..d03dd0a 100644 --- a/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs +++ b/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using System; using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; @@ -10,7 +10,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { [HarmonyPatch(nameof(TravelBuffOptionButton.SetBuff))] [HarmonyPostfix] - private static void Start(TravelBuffOptionButton __instance) + private static void SetBuff(TravelBuffOptionButton __instance) { __instance.introduce.text = StringStore.TranslateText(__instance.introduce.text); } diff --git a/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs b/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs index 945f940..0c96618 100644 --- a/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs +++ b/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using System; using System.IO; using System.Linq; @@ -119,7 +119,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers [HarmonyPrefix] private static bool OnMouseDown(AlmanacMgrZombie __instance) { - TextMeshPro component = __instance.info.GetComponent(); + TextMeshPro component = __instance.info.GetComponent(); if (component != null) { component.pageToDisplay = component.pageToDisplay > component.m_pageNumber ? 1 : component.pageToDisplay + 1; @@ -128,4 +128,54 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers return true; } } + + // Patch to translate the modded almanac zombie names and info + [HarmonyPatch(typeof(AlmanacMgrZombie))] + public static partial class AlmanacMgrZombie_Patch + { + [HarmonyPatch(nameof(AlmanacMgrZombie.Start))] + [HarmonyPostfix] + public static void TranslateTextAlmanac(AlmanacMgrZombie __instance) + { + string currentLanguage = Utils.Language.ToString(); + __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); + } + + // translate all TMP components in info + foreach (TextMeshPro text in __instance.info.GetComponentsInChildren()) + { + if (text != null) + { + text.text = StringStore.TranslateText(text.text); + text.name = StringStore.TranslateText(text.name); + text.font = FontStore.LoadTMPFont(currentLanguage); + } + } + foreach (TextMeshPro text in __instance.zombieName.GetComponentsInChildren()) + { + if (text != null) + { + text.text = StringStore.TranslateText(text.text); + text.name = StringStore.TranslateText(text.name); + text.font = FontStore.LoadTMPFont(currentLanguage); + } + } + + // Translate zombieName and its child + __instance.zombieName.name = StringStore.TranslateText(__instance.zombieName.name); + __instance.zombieName.GetComponent().font = FontStore.LoadTMPFont(currentLanguage); + __instance.zombieName.transform.GetChild(0).name = StringStore.TranslateText(__instance.zombieName.transform.GetChild(0).name); + // Get both for less testing + __instance.zombieName.GetComponent().text = StringStore.TranslateText(__instance.zombieName.GetComponent().text); + __instance.zombieName.transform.GetChild(0).GetComponent().text = StringStore.TranslateText(__instance.zombieName.transform.GetChild(0).GetComponent().text); + __instance.zombieName.transform.GetChild(0).GetComponent().font = FontStore.LoadTMPFont(currentLanguage); + } + } } diff --git a/BepInEx/Patches/Managers/TowerManager_Patch.cs b/BepInEx/Patches/Managers/TowerManager_Patch.cs new file mode 100644 index 0000000..71d3656 --- /dev/null +++ b/BepInEx/Patches/Managers/TowerManager_Patch.cs @@ -0,0 +1,33 @@ +using HarmonyLib; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using TMPro; +using BepInEx.Unity.IL2CPP; +using System.Collections.Generic; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers +{ + [HarmonyPatch(typeof(TowerManager))] + public static class TowerManager_Patch + { + public static List updatedText = []; + + public static void UpdateText() + { + foreach (Transform transform in updatedText) + { + if (transform != null) + { + transform.GetComponent().text = StringStore.TranslateText(transform.GetComponent().text); + } + } + } + + [HarmonyPatch(nameof(TowerManager.Update))] + [HarmonyPostfix] + public static void Update(TowerManager __instance) + { + + } + } +} \ No newline at end of file diff --git a/BepInEx/PvZ Fusion Translator [BepInEx].csproj b/BepInEx/PvZ Fusion Translator [BepInEx].csproj index 4139e85..2510057 100644 --- a/BepInEx/PvZ Fusion Translator [BepInEx].csproj +++ b/BepInEx/PvZ Fusion Translator [BepInEx].csproj @@ -120,6 +120,9 @@ + + + @@ -151,6 +154,8 @@ + + @@ -159,6 +164,7 @@ + From 497170aa2cbc687bfc9d51dae6da780da405722c Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Sat, 16 Aug 2025 17:34:00 -0400 Subject: [PATCH 2/4] Merge branch 'cassidy' --- 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 From 4447f3c96d1dcb302f14655c9c7ec14506db1bdb Mon Sep 17 00:00:00 2001 From: TuanAnh2901 Date: Wed, 20 Aug 2025 21:50:36 +0700 Subject: [PATCH 3/4] 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); From 3eab4a94393e0bcc5893f4806abc6712de5f7fb6 Mon Sep 17 00:00:00 2001 From: TuanAnh2901 Date: Wed, 20 Aug 2025 22:02:01 +0700 Subject: [PATCH 4/4] 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