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 @@ +