From 2260a8f5d1eba1a694319013af30fe68cd468e9f Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Wed, 26 Nov 2025 23:34:59 -0500 Subject: [PATCH] bepinex port + misc changes --- BepInEx/Patches/GameObjects/BaseMenu_Patch.cs | 8 ++ .../ButtonObjects/NormalBtn_Patch.cs | 19 +-- .../GameObjects/TravelBuffMenu_Patch.cs | 4 + .../TravelBuffOptionButton_Patch.cs | 9 +- .../Patches/GameObjects/TravelStore_Patch.cs | 23 ++-- .../Managers/OppositeBuffManager_Patch.cs | 117 ++++++------------ .../GameObjects/OppositeBuffManager_Patch.cs | 49 -------- .../Managers/OppositeBuffManager_Patch.cs | 113 ++++++----------- ...PvZ Fusion Translator [MelonLoader].csproj | 3 +- 9 files changed, 119 insertions(+), 226 deletions(-) delete mode 100644 MelonLoader/Patches/GameObjects/OppositeBuffManager_Patch.cs diff --git a/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs b/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs index fa05462..a5b96c8 100644 --- a/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs @@ -114,6 +114,14 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("LastPage")); } + Transform pageNewAdvantureLevelTransform = levelsTransform.transform.Find("PageNewAdvantureLevel"); + if (pageNewAdvantureLevelTransform != null) + { + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("BackToIndex")); + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("Nextpage")); + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("LastPage")); + } + foreach (TextMeshProUGUI txt in mainTransform.GetComponentsInChildren()) { // Still dump untranslated strings for modded plants and zombies diff --git a/BepInEx/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs index 674fbc7..79ad47d 100644 --- a/BepInEx/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs +++ b/BepInEx/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs @@ -11,13 +11,16 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects { [HarmonyPostfix] [HarmonyPatch(nameof(NormalBtn.OnMouseUpAsButton))] - public static void OnMouseUpAsButton(NormalBtn __instance) - { - Transform banTransform = __instance.transform.GetChild(0); - if (banTransform != null) - { - banTransform.GetComponent().text = StringStore.TranslateText(banTransform.GetComponent().text); - } + public static void OnMouseUpAsButton(NormalBtn __instance) + { + if (__instance.transform.childCount > 0) + { + 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/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs b/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs index 3d49ad1..2532e0c 100644 --- a/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs @@ -3,6 +3,7 @@ using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; using static PvZ_Fusion_Translator__BepInEx_.Patches.Managers.TravelMgr_Patch; using UnityEngine; +using System.Collections.Generic; namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { @@ -16,6 +17,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects foreach (TravelBuffOptionButton button in __instance.options) { button.introduce.text = translatedTravelBuffs[buffLinks[button.buffType]][button.buffIndex]; + List buffSet = translatedTravelBuffs[buffLinks[button.buffType]]; + string buffText = (button.buffIndex < buffSet.Count && button.show != null) ? buffSet[button.buffIndex] : StringStore.TranslateText(button.introduce.text); + button.introduce.text = buffText; } } } diff --git a/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs b/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs index 2b07a77..9c67c46 100644 --- a/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs +++ b/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs @@ -16,7 +16,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects private static void SetBuff(TravelBuffOptionButton __instance) { List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; - string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + string buffText = (__instance.buffIndex < buffSet.Count && __instance.show != null) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + __instance.introduce.text = buffText; } [HarmonyPatch(nameof(TravelBuffOptionButton.Awake))] @@ -24,7 +25,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects private static void Awake(TravelBuffOptionButton __instance) { List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; - string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + string buffText = (__instance.buffIndex < buffSet.Count && __instance.show != null) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + __instance.introduce.text = buffText; } [HarmonyPatch(nameof(TravelBuffOptionButton.OnAnimOver))] @@ -32,7 +34,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects private static void OnAnimOver(TravelBuffOptionButton __instance) { List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; - string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + string buffText = (__instance.buffIndex < buffSet.Count && __instance.show != null) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + __instance.introduce.text = buffText; } } } diff --git a/BepInEx/Patches/GameObjects/TravelStore_Patch.cs b/BepInEx/Patches/GameObjects/TravelStore_Patch.cs index a8c54a5..5635ef8 100644 --- a/BepInEx/Patches/GameObjects/TravelStore_Patch.cs +++ b/BepInEx/Patches/GameObjects/TravelStore_Patch.cs @@ -8,19 +8,18 @@ using System.Linq; namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { - [HarmonyPatch(typeof(TravelStore))] public static class TravelStore_Patch { [HarmonyPatch(nameof(TravelStore.Update))] [HarmonyPostfix] private static void Update(TravelStore __instance) { - foreach(TextMeshProUGUI text in __instance.introduces) + foreach (TextMeshProUGUI text in __instance.introduces) { - if(__instance.currentSelect != null) + if (__instance.currentSelect != null) { var buffList = translatedTravelBuffs[buffLinks[(BuffType)__instance.currentSelect.theBuffType]]; - if(__instance.currentSelect.theBuffNumber < buffList.Count) + if (__instance.currentSelect.theBuffNumber < buffList.Count && __instance.currentSelect.theBuffNumber > -1) { text.text = buffList[__instance.currentSelect.theBuffNumber]; } @@ -45,18 +44,26 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects TextMeshProUGUI cost = buff.transform.GetChild(1).GetComponent(); cost.text = StringStore.TranslateText(cost.text); cost.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - //FileLoader.DumpUntranslatedStrings(cost.text); } + foreach (TextMeshProUGUI text in __instance.introduces) { if (__instance.currentSelect != null) { - text.text = translatedTravelBuffs[buffLinks[(BuffType)__instance.currentSelect.theBuffType]][__instance.currentSelect.theBuffNumber]; + var buffList = translatedTravelBuffs[buffLinks[(BuffType)__instance.currentSelect.theBuffType]]; + if (__instance.currentSelect.theBuffNumber < buffList.Count && __instance.currentSelect.theBuffNumber > -1) + { + text.text = buffList[__instance.currentSelect.theBuffNumber]; + } + else + { + text.text = StringStore.TranslateText(text.text); + } } } foreach (var textMesh in __instance.points) - { - textMesh.text = StringStore.TranslateText(textMesh.text); + { + textMesh.text = StringStore.TranslateText(textMesh.text); } } } diff --git a/BepInEx/Patches/Managers/OppositeBuffManager_Patch.cs b/BepInEx/Patches/Managers/OppositeBuffManager_Patch.cs index 8111a9c..b35fa41 100644 --- a/BepInEx/Patches/Managers/OppositeBuffManager_Patch.cs +++ b/BepInEx/Patches/Managers/OppositeBuffManager_Patch.cs @@ -1,89 +1,48 @@ using HarmonyLib; -using System; -using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using TMPro; +using UnityEngine; namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers { - [HarmonyPatch(typeof(OppositeBuffManager))] - public static class OppositeBuffManager_Patch - { -#if TESTING - [HarmonyPatch(nameof(OppositeBuffManager.InitBuffPool))] - [HarmonyPostfix] - private static void InitBuffPool(OppositeBuffManager __instance) - { - foreach(TextMeshProUGUI text in __instance.textA_bad) - { - string stripText = text.text.Replace("但", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textA_good) - { - text.text = StringStore.TranslateText(text.text); - } + [HarmonyPatch(typeof(OppositeBuffManager))] + public static class OppositeBuffManager_Patch + { + public static Dictionary buffLinks = TravelMgr_Patch.buffLinks; + public static Dictionary> translatedTravelBuffs = TravelMgr_Patch.translatedTravelBuffs; + public static string badPattern = @"^但(.*)"; + public static string badFormat = StringStore.translationStringRegex.ContainsKey(badPattern) ? StringStore.translationStringRegex[badPattern] : "But, {0}"; + public static TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - foreach(TextMeshProUGUI text in __instance.textB_bad) - { - string stripText = text.text.Replace("但", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textB_good) - { - text.text = StringStore.TranslateText(text.text); - } - } + [HarmonyPatch(nameof(OppositeBuffManager.Awake))] + [HarmonyPostfix] + private static void Awake(OppositeBuffManager __instance) + { + TranslateOppositeText(__instance.textA_bad, BuffType.Debuff, __instance.buffA.theDebuffID, true); + TranslateOppositeText(__instance.textA_good, __instance.buffA.theOptionType, __instance.buffA.theOptionID); + TranslateOppositeText(__instance.textB_bad, BuffType.Debuff, __instance.buffB.theDebuffID, true); + TranslateOppositeText(__instance.textB_good, __instance.buffB.theOptionType, __instance.buffB.theOptionID); + } - [HarmonyPatch(nameof(OppositeBuffManager.SetText), new Type[] { typeof(TextMeshProUGUI), typeof(BuffType), typeof(int)})] - [HarmonyPostfix] - private static void SetText(OppositeBuffManager __instance) - { - foreach(TextMeshProUGUI text in __instance.textA_bad) - { - string stripText = text.text.Replace("?", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textA_good) - { - text.text = StringStore.TranslateText(text.text); - } + public static void TranslateOppositeText(Il2CppSystem.Collections.Generic.List textList, BuffType buffType, int buffIndex, bool isBad = false) + { + string buff = translatedTravelBuffs[buffLinks[buffType]][buffIndex]; - foreach(TextMeshProUGUI text in __instance.textB_bad) - { - string stripText = text.text.Replace("但", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textB_good) - { - text.text = StringStore.TranslateText(text.text); - } - } -#endif + foreach (var text in textList) + { + if (isBad) + { + text.text = string.Format(badFormat, buff); + } + else + { + text.text = buff; + } - [HarmonyPatch(nameof(OppositeBuffManager.SetText), new Type[] { typeof(TextMeshProUGUI), typeof(BuffType), typeof(int)})] - [HarmonyPostfix] - private static void SetText(OppositeBuffManager __instance, ref TextMeshProUGUI text) - { - StringStore.TranslateTextUI(text); - } - - [HarmonyPatch(nameof(OppositeBuffManager.Awake))] - [HarmonyPostfix] - private static void Awake(OppositeBuffManager __instance) - { - StringStore.TranslateTextUI(__instance.textA_bad[0]); - StringStore.TranslateTextUI(__instance.textA_bad[1]); - StringStore.TranslateTextUI(__instance.textB_bad[0]); - StringStore.TranslateTextUI(__instance.textB_bad[1]); - } - - } + text.font = fontAsset; + } + } + } } diff --git a/MelonLoader/Patches/GameObjects/OppositeBuffManager_Patch.cs b/MelonLoader/Patches/GameObjects/OppositeBuffManager_Patch.cs deleted file mode 100644 index 6e9d088..0000000 --- a/MelonLoader/Patches/GameObjects/OppositeBuffManager_Patch.cs +++ /dev/null @@ -1,49 +0,0 @@ -using HarmonyLib; -using Il2Cpp; -using Il2CppTMPro; -using PvZ_Fusion_Translator.AssetStore; -using PvZ_Fusion_Translator.Patches.Managers; -using System.Text.RegularExpressions; -using UnityEngine; - -namespace PvZ_Fusion_Translator.Patches.GameObjects -{ - [HarmonyPatch(typeof(OppositeBuffManager))] - public static class OppositeBuffManager_Patch - { - public static Dictionary buffLinks = TravelMgr_Patch.buffLinks; - public static Dictionary> translatedTravelBuffs = TravelMgr_Patch.translatedTravelBuffs; - public static string badPattern = @"^但(.*)"; - public static string badFormat = StringStore.translationStringRegex.ContainsKey(badPattern) ? StringStore.translationStringRegex[badPattern] : "But, {0}"; - public static TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - - [HarmonyPatch(nameof(OppositeBuffManager.Awake))] - [HarmonyPostfix] - private static void Awake(OppositeBuffManager __instance) - { - TranslateOppositeText(__instance.textA_bad, BuffType.Debuff, __instance.buffA.theDebuffID, true); - TranslateOppositeText(__instance.textA_good, __instance.buffA.theOptionType, __instance.buffA.theOptionID); - TranslateOppositeText(__instance.textB_bad, BuffType.Debuff, __instance.buffB.theDebuffID, true); - TranslateOppositeText(__instance.textB_good, __instance.buffB.theOptionType, __instance.buffB.theOptionID); - } - - public static void TranslateOppositeText(Il2CppSystem.Collections.Generic.List textList, BuffType buffType, int buffIndex, bool isBad = false) - { - string buff = translatedTravelBuffs[buffLinks[buffType]][buffIndex]; - - foreach(var text in textList) - { - if(isBad) - { - text.text = string.Format(badFormat, buff); - } - else - { - text.text = buff; - } - - text.font = fontAsset; - } - } - } -} diff --git a/MelonLoader/Patches/Managers/OppositeBuffManager_Patch.cs b/MelonLoader/Patches/Managers/OppositeBuffManager_Patch.cs index 5c254d9..11a18af 100644 --- a/MelonLoader/Patches/Managers/OppositeBuffManager_Patch.cs +++ b/MelonLoader/Patches/Managers/OppositeBuffManager_Patch.cs @@ -2,88 +2,47 @@ using Il2Cpp; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; +using System.Text.RegularExpressions; +using UnityEngine; namespace PvZ_Fusion_Translator.Patches.Managers { - [HarmonyPatch(typeof(OppositeBuffManager))] - public static class OppositeBuffManager_Patch - { - #if TESTING - [HarmonyPatch(nameof(OppositeBuffManager.InitBuffPool))] - [HarmonyPostfix] - private static void InitBuffPool(OppositeBuffManager __instance) - { - foreach(TextMeshProUGUI text in __instance.textA_bad) - { - string stripText = text.text.Replace("但", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textA_good) - { - text.text = StringStore.TranslateText(text.text); - } + [HarmonyPatch(typeof(OppositeBuffManager))] + public static class OppositeBuffManager_Patch + { + public static Dictionary buffLinks = TravelMgr_Patch.buffLinks; + public static Dictionary> translatedTravelBuffs = TravelMgr_Patch.translatedTravelBuffs; + public static string badPattern = @"^但(.*)"; + public static string badFormat = StringStore.translationStringRegex.ContainsKey(badPattern) ? StringStore.translationStringRegex[badPattern] : "But, {0}"; + public static TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - foreach(TextMeshProUGUI text in __instance.textB_bad) - { - string stripText = text.text.Replace("但", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textB_good) - { - text.text = StringStore.TranslateText(text.text); - } - } + [HarmonyPatch(nameof(OppositeBuffManager.Awake))] + [HarmonyPostfix] + private static void Awake(OppositeBuffManager __instance) + { + TranslateOppositeText(__instance.textA_bad, BuffType.Debuff, __instance.buffA.theDebuffID, true); + TranslateOppositeText(__instance.textA_good, __instance.buffA.theOptionType, __instance.buffA.theOptionID); + TranslateOppositeText(__instance.textB_bad, BuffType.Debuff, __instance.buffB.theDebuffID, true); + TranslateOppositeText(__instance.textB_good, __instance.buffB.theOptionType, __instance.buffB.theOptionID); + } - [HarmonyPatch(nameof(OppositeBuffManager.SetText), new Type[] { typeof(TextMeshProUGUI), typeof(BuffType), typeof(int)})] - [HarmonyPostfix] - private static void SetText(OppositeBuffManager __instance) - { - foreach(TextMeshProUGUI text in __instance.textA_bad) - { - string stripText = text.text.Replace("但", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textA_good) - { - text.text = StringStore.TranslateText(text.text); - } + public static void TranslateOppositeText(Il2CppSystem.Collections.Generic.List textList, BuffType buffType, int buffIndex, bool isBad = false) + { + string buff = translatedTravelBuffs[buffLinks[buffType]][buffIndex]; - foreach(TextMeshProUGUI text in __instance.textB_bad) - { - string stripText = text.text.Replace("但", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textB_good) - { - text.text = StringStore.TranslateText(text.text); - } - } - #endif + foreach(var text in textList) + { + if(isBad) + { + text.text = string.Format(badFormat, buff); + } + else + { + text.text = buff; + } - [HarmonyPatch(nameof(OppositeBuffManager.SetText), new Type[] { typeof(TextMeshProUGUI), typeof(BuffType), typeof(int)})] - [HarmonyPostfix] - private static void SetText(OppositeBuffManager __instance, ref TextMeshProUGUI text) - { - StringStore.TranslateTextUI(text); - } - - [HarmonyPatch(nameof(OppositeBuffManager.Awake))] - [HarmonyPostfix] - private static void Awake(OppositeBuffManager __instance) - { - StringStore.TranslateTextUI(__instance.textA_bad[0]); - StringStore.TranslateTextUI(__instance.textA_bad[1]); - StringStore.TranslateTextUI(__instance.textB_bad[0]); - StringStore.TranslateTextUI(__instance.textB_bad[1]); - } - - } + text.font = fontAsset; + } + } + } } diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index f9e7526..cedb4a6 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -401,7 +401,7 @@ - + @@ -494,7 +494,6 @@ -