From ce822a5d06910b2648951a38c352ec1a6490d596 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Wed, 19 Nov 2025 19:01:12 -0500 Subject: [PATCH 01/12] button fixes (back to index, almanac skin button logging an error) --- .../ButtonObjects/BackToIndex_Patch.cs | 19 +++++++++++++++ .../ButtonObjects/NormalBtn_Patch.cs | 11 +++++---- .../GameObjects/ButtonObjects/UIBtn_Patch.cs | 24 +++++++++++++++++++ ...PvZ Fusion Translator [MelonLoader].csproj | 3 +++ 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs new file mode 100644 index 0000000..d23cc59 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs @@ -0,0 +1,19 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects +{ + [HarmonyPatch(typeof(BackToIndex))] + public class BackToIndex_Patch + { + [HarmonyPostfix] + [HarmonyPatch(nameof(BackToIndex.Awake))] + public static void Awake(BackToIndex __instance) + { + StringStore.TranslateTextTransform(__instance.transform.GetChild(0)); + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs index 1e65872..8ccfcf0 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs @@ -13,11 +13,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects [HarmonyPatch(nameof(NormalBtn.OnMouseUpAsButton))] public static void OnMouseUpAsButton(NormalBtn __instance) { - Transform banTransform = __instance.transform.GetChild(0); - if (banTransform != null) + if(__instance.transform.childCount > 0) { - banTransform.GetComponent().text = StringStore.TranslateText(banTransform.GetComponent().text); - } + 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/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs new file mode 100644 index 0000000..9c00324 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using UnityEngine.UI; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(UIBtn))] + public static class UIBtn_Patch + { + [HarmonyPatch(nameof(UIBtn.Awake))] + [HarmonyPostfix] + private static void Postfix_Awake(UIBtn __instance) + { + if(__instance.TryGetComponent(out BackToIndex component)) + { + Log.LogDebug("found BackToIndex class"); + Utils.ConvertButtonText(__instance.transform.parent, "BackToIndex"); + } + } + } +} diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index c9a13a6..eb8f074 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -403,6 +403,8 @@ + + @@ -521,5 +523,6 @@ + \ No newline at end of file From 3c6fef1ce515a32725bc2a4cbb225fbbd57c6d7f Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Thu, 20 Nov 2025 22:04:54 -0500 Subject: [PATCH 02/12] gacha 2 menu fix + remove backtoindex patch --- .../ButtonObjects/BackToIndex_Patch.cs | 20 ++++---- .../GameObjects/ButtonObjects/UIBtn_Patch.cs | 1 - .../GameObjects/OppositeBuffManager_Patch.cs | 49 +++++++++++++++++++ ...PvZ Fusion Translator [MelonLoader].csproj | 1 + 4 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 MelonLoader/Patches/GameObjects/OppositeBuffManager_Patch.cs diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs index d23cc59..621e118 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/BackToIndex_Patch.cs @@ -6,14 +6,14 @@ using UnityEngine; namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects { - [HarmonyPatch(typeof(BackToIndex))] - public class BackToIndex_Patch - { - [HarmonyPostfix] - [HarmonyPatch(nameof(BackToIndex.Awake))] - public static void Awake(BackToIndex __instance) - { - StringStore.TranslateTextTransform(__instance.transform.GetChild(0)); - } - } + //[HarmonyPatch(typeof(BackToIndex))] + //public class BackToIndex_Patch + // { + // [HarmonyPostfix] + // [HarmonyPatch(nameof(BackToIndex.Awake))] + // public static void Awake(BackToIndex __instance) + // { + // StringStore.TranslateTextTransform(__instance.transform.GetChild(0)); + // } + //} } \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs index 9c00324..af10682 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs @@ -16,7 +16,6 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects { if(__instance.TryGetComponent(out BackToIndex component)) { - Log.LogDebug("found BackToIndex class"); Utils.ConvertButtonText(__instance.transform.parent, "BackToIndex"); } } diff --git a/MelonLoader/Patches/GameObjects/OppositeBuffManager_Patch.cs b/MelonLoader/Patches/GameObjects/OppositeBuffManager_Patch.cs new file mode 100644 index 0000000..6e9d088 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/OppositeBuffManager_Patch.cs @@ -0,0 +1,49 @@ +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/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index eb8f074..075d09d 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -401,6 +401,7 @@ + From 40215c68df479d8a1bc25103334bf1fe3fc46b3d Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Fri, 21 Nov 2025 21:32:15 -0500 Subject: [PATCH 03/12] proper backtoindex fix i promise --- .../Patches/GameObjects/BaseMenu_Patch.cs | 8 ++++ .../GameObjects/ButtonObjects/UIBtn_Patch.cs | 44 +++++++++---------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs b/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs index c16d0c2..013ae37 100644 --- a/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs @@ -114,6 +114,14 @@ namespace PvZ_Fusion_Translator.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()) { txt.text = StringStore.TranslateText(txt.text); diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs index af10682..4afc43c 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIBtn_Patch.cs @@ -1,23 +1,23 @@ -using HarmonyLib; -using Il2Cpp; -using Il2CppTMPro; -using PvZ_Fusion_Translator.AssetStore; -using UnityEngine; -using UnityEngine.UI; +//using HarmonyLib; +//using Il2Cpp; +//using Il2CppTMPro; +//using PvZ_Fusion_Translator.AssetStore; +//using UnityEngine; +//using UnityEngine.UI; -namespace PvZ_Fusion_Translator.Patches.GameObjects -{ - [HarmonyPatch(typeof(UIBtn))] - public static class UIBtn_Patch - { - [HarmonyPatch(nameof(UIBtn.Awake))] - [HarmonyPostfix] - private static void Postfix_Awake(UIBtn __instance) - { - if(__instance.TryGetComponent(out BackToIndex component)) - { - Utils.ConvertButtonText(__instance.transform.parent, "BackToIndex"); - } - } - } -} +//namespace PvZ_Fusion_Translator.Patches.GameObjects +//{ +// [HarmonyPatch(typeof(UIBtn))] +// public static class UIBtn_Patch +// { +// [HarmonyPatch(nameof(UIBtn.Awake))] +// [HarmonyPostfix] +// private static void Postfix_Awake(UIBtn __instance) +// { +// if(__instance.TryGetComponent(out BackToIndex component)) +// { +// Utils.ConvertButtonText(__instance.transform.parent, component.name); +// } +// } +// } +//} From 51f5c991e5f99a7fc0d73bc890e8f3d8a925977c Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Mon, 24 Nov 2025 11:47:54 -0500 Subject: [PATCH 04/12] travel buff fix #32409284031 --- .../Patches/GameObjects/TravelBuffMenu_Patch.cs | 5 ++++- .../GameObjects/TravelBuffOptionButton_Patch.cs | 13 +++++++------ .../Patches/GameObjects/TravelStore_Patch.cs | 12 ++++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/MelonLoader/Patches/GameObjects/TravelBuffMenu_Patch.cs b/MelonLoader/Patches/GameObjects/TravelBuffMenu_Patch.cs index c684917..ed5b9fd 100644 --- a/MelonLoader/Patches/GameObjects/TravelBuffMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TravelBuffMenu_Patch.cs @@ -4,6 +4,7 @@ using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using static PvZ_Fusion_Translator.Patches.Managers.TravelMgr_Patch; using UnityEngine; +using MelonLoader; namespace PvZ_Fusion_Translator.Patches.GameObjects { @@ -16,7 +17,9 @@ namespace PvZ_Fusion_Translator.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/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs b/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs index 49585e7..8769d29 100644 --- a/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs @@ -1,6 +1,7 @@ using HarmonyLib; using Il2Cpp; using Il2CppTMPro; +using MelonLoader; using PvZ_Fusion_Translator.AssetStore; using static PvZ_Fusion_Translator.Patches.Managers.TravelMgr_Patch; @@ -14,8 +15,8 @@ namespace PvZ_Fusion_Translator.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))] @@ -23,8 +24,8 @@ namespace PvZ_Fusion_Translator.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,8 +33,8 @@ namespace PvZ_Fusion_Translator.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/MelonLoader/Patches/GameObjects/TravelStore_Patch.cs b/MelonLoader/Patches/GameObjects/TravelStore_Patch.cs index 1f0305b..82b8c24 100644 --- a/MelonLoader/Patches/GameObjects/TravelStore_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TravelStore_Patch.cs @@ -19,7 +19,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects 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]; } @@ -50,7 +50,15 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects { 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) From 845dae37d568e711950ac68339c88866086f0bf5 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Wed, 26 Nov 2025 23:15:46 -0500 Subject: [PATCH 05/12] Merge branch 'cassidy' --- .../Patches/GameObjects/TravelBuffMenu_Patch.cs | 5 ++++- .../GameObjects/TravelBuffOptionButton_Patch.cs | 13 +++++++------ .../Patches/GameObjects/TravelStore_Patch.cs | 12 ++++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/MelonLoader/Patches/GameObjects/TravelBuffMenu_Patch.cs b/MelonLoader/Patches/GameObjects/TravelBuffMenu_Patch.cs index c684917..ed5b9fd 100644 --- a/MelonLoader/Patches/GameObjects/TravelBuffMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TravelBuffMenu_Patch.cs @@ -4,6 +4,7 @@ using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using static PvZ_Fusion_Translator.Patches.Managers.TravelMgr_Patch; using UnityEngine; +using MelonLoader; namespace PvZ_Fusion_Translator.Patches.GameObjects { @@ -16,7 +17,9 @@ namespace PvZ_Fusion_Translator.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/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs b/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs index 49585e7..8769d29 100644 --- a/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs @@ -1,6 +1,7 @@ using HarmonyLib; using Il2Cpp; using Il2CppTMPro; +using MelonLoader; using PvZ_Fusion_Translator.AssetStore; using static PvZ_Fusion_Translator.Patches.Managers.TravelMgr_Patch; @@ -14,8 +15,8 @@ namespace PvZ_Fusion_Translator.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))] @@ -23,8 +24,8 @@ namespace PvZ_Fusion_Translator.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,8 +33,8 @@ namespace PvZ_Fusion_Translator.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/MelonLoader/Patches/GameObjects/TravelStore_Patch.cs b/MelonLoader/Patches/GameObjects/TravelStore_Patch.cs index 1f0305b..82b8c24 100644 --- a/MelonLoader/Patches/GameObjects/TravelStore_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TravelStore_Patch.cs @@ -19,7 +19,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects 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]; } @@ -50,7 +50,15 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects { 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) From f743f9c49136bbeeff382058ae2a879ff45ea2f6 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Wed, 26 Nov 2025 23:22:49 -0500 Subject: [PATCH 06/12] idk what happened --- BepInEx/PvZ Fusion Translator [BepInEx].csproj | 6 +++--- MelonLoader/PvZ Fusion Translator [MelonLoader].csproj | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BepInEx/PvZ Fusion Translator [BepInEx].csproj b/BepInEx/PvZ Fusion Translator [BepInEx].csproj index 9fc2fa2..5efe955 100644 --- a/BepInEx/PvZ Fusion Translator [BepInEx].csproj +++ b/BepInEx/PvZ Fusion Translator [BepInEx].csproj @@ -13,7 +13,8 @@ https://nuget.samboy.dev/v3/index.json PvZ_Fusion_Translator__BepInEx_ - D:\PvZ Fusion\BepInEx Game Files + C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.1.1-BepInEx + C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.1.1 Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate;DebugMulti AnyCPU;x64 @@ -592,8 +593,7 @@ - - + diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 1145cf6..f9e7526 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -13,7 +13,7 @@ latest enable Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate - D:\PvZ Fusion\Game Files + C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.1.1 AnyCPU;ARM64;x64 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 07/12] 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 @@ - From 44f1d5aac36d9695fdcb843a6f08ac085bde958c Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Thu, 27 Nov 2025 12:43:28 -0500 Subject: [PATCH 08/12] almanac skin stuff --- .../Patches/Managers/AlmanacPlantBank_Patch.cs | 18 ++++++++++++++++++ .../Patches/Managers/AlmanacPlantBank_Patch.cs | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs b/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs index a99abb7..5d70093 100644 --- a/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs +++ b/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs @@ -204,5 +204,23 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers banText.text = StringStore.TranslateText(banText.text); } } + + [HarmonyPatch(nameof(AlmanacPlantBank.Start))] + [HarmonyPostfix] + public static void Post_Start(AlmanacPlantBank __instance) + { + GameObject skinTextObj = __instance.skinButton.transform.GetChild(0).gameObject; + GameObject skinShadowTextObj = UnityEngine.Object.Instantiate(skinTextObj, parent: __instance.skinButton.transform); + TextMeshPro skinShadowText = skinShadowTextObj.GetComponent(); + skinShadowText.text = StringStore.TranslateText("换肤_S"); + skinShadowText.sortingOrder -= 2; + skinShadowTextObj.transform.Translate(new Vector3(0.015f, -0.015f, 0)); + skinTextObj.transform.Translate(new Vector3(-0.022f, 0)); + skinShadowTextObj.transform.Translate(new Vector3(-0.022f, 0)); + __instance.skinButton.transform.localScale /= 1.75f; + __instance.skinButton.transform.Translate(new Vector3(-0.075f, -0.15f, 0)); + __instance.skinButton.transform.GetChild(1).Translate(new Vector3(0.35f, 0)); + __instance.skinButton.transform.GetChild(2).Translate(new Vector3(-0.35f, 0)); + } } } \ No newline at end of file diff --git a/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs b/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs index 3b17692..a2be15c 100644 --- a/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs +++ b/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs @@ -178,5 +178,23 @@ namespace PvZ_Fusion_Translator.Patches.Managers banTransform.GetComponent().text = StringStore.TranslateText(banTransform.GetComponent().text); } } + + [HarmonyPatch(nameof(AlmanacPlantBank.Start))] + [HarmonyPostfix] + public static void Post_Start(AlmanacPlantBank __instance) + { + GameObject skinTextObj = __instance.skinButton.transform.GetChild(0).gameObject; + GameObject skinShadowTextObj = UnityEngine.Object.Instantiate(skinTextObj, parent: __instance.skinButton.transform); + TextMeshPro skinShadowText = skinShadowTextObj.GetComponent(); + skinShadowText.text = StringStore.TranslateText("换肤_S"); + skinShadowText.sortingOrder -= 2; + skinShadowTextObj.transform.Translate(new Vector3(0.015f, -0.015f, 0)); + skinTextObj.transform.Translate(new Vector3(-0.022f, 0)); + skinShadowTextObj.transform.Translate(new Vector3(-0.022f, 0)); + __instance.skinButton.transform.localScale /= 1.75f; + __instance.skinButton.transform.Translate(new Vector3(-0.075f, -0.15f, 0)); + __instance.skinButton.transform.GetChild(1).Translate(new Vector3(0.35f, 0)); + __instance.skinButton.transform.GetChild(2).Translate(new Vector3(-0.35f, 0)); + } } } \ No newline at end of file From 4cad61403a6988e26c177f370be1f7e92224d8e2 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Mon, 22 Dec 2025 13:12:24 -0500 Subject: [PATCH 09/12] almanac coding --- .../BaseTextObjects/TMP_InputField_Patch.cs | 1 + .../GameObjects/AlmanacPlantMenu_Patch.cs | 71 +++++ .../GameObjects/AlmanacPlantWindow_Patch.cs | 66 +++++ .../GameObjects/AlmanacZombieMenu_Patch.cs | 34 +++ .../GameObjects/AlmanacZombieWindow_Patch.cs | 68 +++++ .../Patches/GameObjects/Almanac_Patch.cs | 52 ++++ .../Patches/GameObjects/BaseMenu_Patch.cs | 128 ++------- .../ExploreMakeZombieButton_Patch.cs | 4 +- .../ButtonObjects/UIButton_Patch.cs | 84 +----- .../GameObjects/NoticePauseMenu_Patch.cs | 2 +- .../Managers/AlmanacMgrZombie_Patch.cs | 26 +- .../Managers/AlmanacPlantBank_Patch.cs | 268 +++++++++--------- MelonLoader/Patches/Managers/GameAPP_Patch.cs | 28 ++ ...PvZ Fusion Translator [MelonLoader].csproj | 8 +- MelonLoader/Utils.cs | 72 +++-- 15 files changed, 552 insertions(+), 360 deletions(-) create mode 100644 MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/AlmanacZombieMenu_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/AlmanacZombieWindow_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/Almanac_Patch.cs create mode 100644 MelonLoader/Patches/Managers/GameAPP_Patch.cs diff --git a/MelonLoader/Patches/BaseTextObjects/TMP_InputField_Patch.cs b/MelonLoader/Patches/BaseTextObjects/TMP_InputField_Patch.cs index 00d9589..3d665d3 100644 --- a/MelonLoader/Patches/BaseTextObjects/TMP_InputField_Patch.cs +++ b/MelonLoader/Patches/BaseTextObjects/TMP_InputField_Patch.cs @@ -1,6 +1,7 @@ using HarmonyLib; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; namespace PvZ_Fusion_Translator.Patches.BaseTextObjects { diff --git a/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs new file mode 100644 index 0000000..b9aa2f0 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs @@ -0,0 +1,71 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using System.Text.RegularExpressions; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.UI; +using static PvZ_Fusion_Translator.FileLoader; +using static PvZ_Fusion_Translator.Utils; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(AlmanacPlantMenu))] + public static class AlmanacPlantMenu_Patch + { + [HarmonyPatch(nameof(AlmanacPlantMenu.Awake))] + [HarmonyPostfix] + private static void Awake(AlmanacPlantMenu __instance) + { + TMP_FontAsset font = FontStore.LoadTMPFont(Utils.Language.ToString()); + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren(true)) + { + bool isPlantName = text.gameObject.name.Contains("Name") && text.transform.parent.name != "Background"; + if (text.gameObject.name != "Description" && !isPlantName) + { + text.text = StringStore.TranslateText(text.text); + text.font = font; + text.autoSizeTextContainer = true; + } + } + } + + [HarmonyPatch(nameof(AlmanacPlantMenu.SearchChanged))] + [HarmonyPrefix] + public static bool SearchChanged(AlmanacPlantMenu __instance, ref TMP_InputField inputField) + { + string search = inputField.text; + if (search != StringStore.TranslateText("搜索")) + { + string currentLanguage = Utils.Language.ToString(); + string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); + string path = Path.Combine(almanacDir, "LawnStringsTranslate.json"); + string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json"); + + string json; + json = File.ReadAllText(path); + + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(currentLanguage); + + AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); + + Il2CppSystem.Collections.Generic.List searchedPlants = new(); + + foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants) + { + if (plantInfo.name.ToLower().Contains(search.ToLower())) + { + searchedPlants.Add((PlantType)plantInfo.seedType); + } + } + + __instance.ShowPlants(searchedPlants); + + return false; + } + + return true; + } + } +} diff --git a/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs new file mode 100644 index 0000000..1e7260a --- /dev/null +++ b/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs @@ -0,0 +1,66 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using System.Text.RegularExpressions; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.UI; +using static PvZ_Fusion_Translator.FileLoader; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(AlmanacPlantWindow))] + public static class AlmanacPlantWindow_Patch + { + [HarmonyPatch(nameof(AlmanacPlantWindow.UpdateText))] + [HarmonyPostfix] + private static void UpdateText(AlmanacPlantWindow __instance) + { + string currentLanguage = Utils.Language.ToString(); + string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); + string path = Path.Combine(almanacDir, "LawnStringsTranslate.json"); + string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json"); + + string json; + json = File.ReadAllText(path); + + bool hasAlmanacFont = false; + TMP_FontAsset almanacFontAsset = null; + if (FontStore.fontAssetDictSecondary.ContainsKey(currentLanguage + "_Almanac") || FontStore.fontAssetDictSecondary.ContainsKey(currentLanguage)) + { + almanacFontAsset = FontStore.LoadTMPFontAlmanac(currentLanguage); + hasAlmanacFont = true; + } + + TMP_FontAsset fontAsset = (hasAlmanacFont) ? FontStore.LoadTMPFontAlmanac(Utils.Language.ToString()) : FontStore.LoadTMPFont(Utils.Language.ToString()); + + AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); + + foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants) + { + if (plantInfo.seedType == (int)__instance.currentPlantType) + { + foreach (TextMeshProUGUI text in __instance.showedPlantName) + { + text.text = $"{Utils.RemoveSizeTags(plantInfo.name)} ({plantInfo.seedType})"; + text.font = fontAsset; + } + + __instance.showedPlantIntroduce.text = Utils.RemoveSizeTags(plantInfo.info) + "\n\n" + Utils.RemoveSizeTags(plantInfo.introduce) + "\n\n"; + __instance.showedPlantIntroduce.font = fontAsset; + __instance.showedPlantIntroduce.margin = new Vector4(6, 2, 12, 0); + + __instance.showedPlantIntroduce.enableWordWrapping = true; + __instance.showedPlantIntroduce.overflowMode = TextOverflowModes.ScrollRect; + + Canvas.ForceUpdateCanvases(); + __instance.showedPlantIntroduce.ForceMeshUpdate(); + + float textHeight = __instance.showedPlantIntroduce.preferredHeight; + __instance.plantTextContent.sizeDelta = new Vector2(__instance.plantTextContent.sizeDelta.x, textHeight); + } + } + } + } +} diff --git a/MelonLoader/Patches/GameObjects/AlmanacZombieMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacZombieMenu_Patch.cs new file mode 100644 index 0000000..09e0de0 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/AlmanacZombieMenu_Patch.cs @@ -0,0 +1,34 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using System.Text.RegularExpressions; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.UI; +using static PvZ_Fusion_Translator.FileLoader; +using static PvZ_Fusion_Translator.Utils; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(AlmanacZombieMenu))] + public static class AlmanacZombieMenu_Patch + { + [HarmonyPatch(nameof(AlmanacZombieMenu.Awake))] + [HarmonyPostfix] + private static void Awake(AlmanacZombieMenu __instance) + { + TMP_FontAsset font = FontStore.LoadTMPFont(Utils.Language.ToString()); + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren(true)) + { + bool isZombieName = text.gameObject.name.Contains("Name") && text.transform.parent.name != "Background"; + if (text.gameObject.name != "Description" && !isZombieName) + { + text.text = StringStore.TranslateText(text.text); + text.font = font; + text.autoSizeTextContainer = true; + } + } + } + } +} diff --git a/MelonLoader/Patches/GameObjects/AlmanacZombieWindow_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacZombieWindow_Patch.cs new file mode 100644 index 0000000..707f270 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/AlmanacZombieWindow_Patch.cs @@ -0,0 +1,68 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using System.Text.RegularExpressions; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.UI; +using static PvZ_Fusion_Translator.FileLoader; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(AlmanacZombieWindow))] + public static class AlmanacZombieWindow_Patch + { + [HarmonyPatch(nameof(AlmanacZombieWindow.UpdateText))] + [HarmonyPostfix] + private static void UpdateText(AlmanacZombieWindow __instance) + { + string currentLanguage = Utils.Language.ToString(); + string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); + string path = Path.Combine(almanacDir, "ZombieStringsTranslate.json"); + string moddedPath = Path.Combine(almanacDir, "ModdedZombiesTranslate.json"); + + string json; + json = File.ReadAllText(path); + + bool hasAlmanacFont = false; + TMP_FontAsset almanacFontAsset = null; + if (FontStore.fontAssetDictSecondary.ContainsKey(currentLanguage + "_Almanac") || FontStore.fontAssetDictSecondary.ContainsKey(currentLanguage)) + { + almanacFontAsset = FontStore.LoadTMPFontAlmanac(currentLanguage); + hasAlmanacFont = true; + } + + TMP_FontAsset fontAsset = (hasAlmanacFont) ? FontStore.LoadTMPFontAlmanac(Utils.Language.ToString()) : FontStore.LoadTMPFont(Utils.Language.ToString()); + + ZombieAlmanacData zombieData = JsonUtility.FromJson(json); + + foreach (ZombieInfo zombieInfo in zombieData.zombies) + { + if (zombieInfo.theZombieType == __instance.currentZombieType) + { + foreach (TextMeshProUGUI text in __instance.showedZombieName) + { + text.autoSizeTextContainer = false; + text.text = $"{Utils.RemoveSizeTags(zombieInfo.name)} ({(int)zombieInfo.theZombieType})"; + text.font = fontAsset; + text.fontSizeMax = 21; + } + + __instance.showedZombieIntroduce.text = Utils.RemoveSizeTags(zombieInfo.info) + "\n\n" + Utils.RemoveSizeTags(zombieInfo.introduce) + "\n\n"; + __instance.showedZombieIntroduce.font = fontAsset; + __instance.showedZombieIntroduce.margin = new Vector4(3, 2, 12, 0); + + __instance.showedZombieIntroduce.enableWordWrapping = true; + __instance.showedZombieIntroduce.overflowMode = TextOverflowModes.ScrollRect; + + Canvas.ForceUpdateCanvases(); + __instance.showedZombieIntroduce.ForceMeshUpdate(); + + float textHeight = __instance.showedZombieIntroduce.preferredHeight; + __instance.zombieTextContent.sizeDelta = new Vector2(__instance.zombieTextContent.sizeDelta.x, textHeight); + } + } + } + } +} diff --git a/MelonLoader/Patches/GameObjects/Almanac_Patch.cs b/MelonLoader/Patches/GameObjects/Almanac_Patch.cs new file mode 100644 index 0000000..5d2e2dd --- /dev/null +++ b/MelonLoader/Patches/GameObjects/Almanac_Patch.cs @@ -0,0 +1,52 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; +using Unity.VisualScripting; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(Almanac))] + public static class Almanac_Patch + { + [HarmonyPatch(nameof(Almanac.Awake))] + [HarmonyPostfix] + private static void Awake(Almanac __instance) + { + TranslateAlmanacMenu(__instance); + } + + [HarmonyPatch(nameof(Almanac.OldAlmanac))] + [HarmonyPostfix] + private static void OldAlmanac(Almanac __instance) + { + TranslateAlmanacMenu(__instance); + } + + [HarmonyPatch(nameof(Almanac.AnimSwitch))] + [HarmonyPostfix] + private static void AnimSwitch(Almanac __instance) + { + TranslateAlmanacMenu(__instance); + } + + public static void TranslateAlmanacMenu(Almanac __instance) + { + TMP_FontAsset font = FontStore.LoadTMPFont(Utils.Language.ToString()); + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + if(text.text == "关闭") + { + text.text = StringStore.TranslateText("合上"); + } + else + { + text.text = StringStore.TranslateText(text.text); + } + text.font = font; + } + } + } +} diff --git a/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs b/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs index 013ae37..e4e8d50 100644 --- a/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs @@ -3,6 +3,7 @@ using Il2Cpp; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using UnityEngine; +using static MelonLoader.MelonLogger; namespace PvZ_Fusion_Translator.Patches.GameObjects { @@ -13,120 +14,27 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects [HarmonyPostfix] private static void Awake(BaseMenu __instance) { - Transform mainTransform = __instance.transform; - if (mainTransform != null) + TranslateBaseMenu(__instance, "Level"); + TranslateBaseMenu(__instance, "Levels"); + TranslateBaseMenu(__instance, "CustomLevel"); + } + + public static void TranslateBaseMenu(BaseMenu __instance, string levelsName) + { + Transform levels = __instance.transform.Find(levelsName); + if (levels != null) { - StringStore.TranslateTextTransform(mainTransform.Find("Goback")); - StringStore.TranslateTextTransform(mainTransform.Find("Switich")); - - Transform levelTransform = mainTransform.Find("Level"); - if (levelTransform != null) + List children = levels.GetComponentsInChildren(true).ToList(); + foreach (Transform child in children) { - StringStore.TranslateTextTransform(levelTransform.Find("Nextpage")); - StringStore.TranslateTextTransform(levelTransform.Find("LastPage")); + if (child.name == "Nextpage" || child.name == "LastPage" || child.name == "BackToIndex") + { + StringStore.TranslateTextTransform(child); + } } - Transform customLevelTransform = mainTransform.Find("CustomLevel"); - if (customLevelTransform != null) - { - StringStore.TranslateTextTransform(customLevelTransform.Find("Nextpage")); - StringStore.TranslateTextTransform(customLevelTransform.Find("LastPage")); - } - - Transform levelsTransform = mainTransform.Find("Levels"); - if (levelsTransform != null) - { - - StringStore.TranslateTextTransform(levelsTransform.Find("Nextpage")); - StringStore.TranslateTextTransform(levelsTransform.Find("LastPage")); - - Transform pageMiniGamesTransform = levelsTransform.transform.Find("PageMiniGames"); - if (pageMiniGamesTransform != null) - { - StringStore.TranslateTextTransform(pageMiniGamesTransform.Find("BackToIndex")); - StringStore.TranslateTextTransform(pageMiniGamesTransform.Find("Nextpage")); - StringStore.TranslateTextTransform(pageMiniGamesTransform.Find("LastPage")); - } - - Transform pageUnlockChallengeTransform = levelsTransform.transform.Find("PageUnlockChallenge"); - if (pageUnlockChallengeTransform != null) - { - StringStore.TranslateTextTransform(pageUnlockChallengeTransform.Find("BackToIndex")); - } - - Transform pageFlagChallengeTransform = levelsTransform.transform.Find("PageFlagChallenge"); - if (pageFlagChallengeTransform != null) - { - StringStore.TranslateTextTransform(pageFlagChallengeTransform.Find("BackToIndex")); - } - - Transform pageTravelExperienceTransform = levelsTransform.transform.Find("PageTravelExperience"); - if (pageTravelExperienceTransform != null) - { - StringStore.TranslateTextTransform(pageTravelExperienceTransform.Find("BackToIndex")); - } - - Transform pageGardenProtectionTransform = levelsTransform.transform.Find("PageGardenProtection"); - if (pageGardenProtectionTransform != null) - { - StringStore.TranslateTextTransform(pageGardenProtectionTransform.Find("BackToIndex")); - } - - Transform pageNormalTravelTransform = levelsTransform.transform.Find("PageNormalTravel"); - if (pageNormalTravelTransform != null) - { - StringStore.TranslateTextTransform(pageNormalTravelTransform.Find("BackToIndex")); - } - - Transform pageRandomLevelTransform = levelsTransform.transform.Find("PageRandomLevel"); - if (pageRandomLevelTransform != null) - { - StringStore.TranslateTextTransform(pageRandomLevelTransform.Find("BackToIndex")); - } - - Transform pageUltimateExperienceTransform = levelsTransform.transform.Find("PageUltimateExprience"); - if (pageUltimateExperienceTransform != null) - { - StringStore.TranslateTextTransform(pageUltimateExperienceTransform.Find("BackToIndex")); - } - - Transform pageAdvantureLevelTransform = levelsTransform.transform.Find("PageAdvantureLevel"); - if (pageAdvantureLevelTransform != null) - { - StringStore.TranslateTextTransform(pageAdvantureLevelTransform.Find("BackToIndex")); - StringStore.TranslateTextTransform(pageAdvantureLevelTransform.Find("Nextpage")); - StringStore.TranslateTextTransform(pageAdvantureLevelTransform.Find("LastPage")); - } - - Transform pageScaryPotTransform = levelsTransform.transform.Find("PageScaryPot"); - if (pageScaryPotTransform != null) - { - StringStore.TranslateTextTransform(pageScaryPotTransform.Find("BackToIndex")); - StringStore.TranslateTextTransform(pageScaryPotTransform.Find("Nextpage")); - StringStore.TranslateTextTransform(pageScaryPotTransform.Find("LastPage")); - } - - Transform pageEndlessLevelTransform = levelsTransform.transform.Find("PageEndlessLevel"); - if (pageEndlessLevelTransform != null) - { - StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("BackToIndex")); - StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("Nextpage")); - 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()) - { - txt.text = StringStore.TranslateText(txt.text); - } - } + StringStore.TranslateTextTransform(__instance.transform.Find("Goback")); + StringStore.TranslateTextTransform(__instance.transform.Find("Switich")); } } } diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs index 91a0312..da7b212 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs @@ -13,8 +13,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects [HarmonyPatch(nameof(ExploreMakeZombieButton.Start))] public static void Start(ExploreMakeZombieButton __instance) { - __instance.sceneText.text = Utils.GetZombieNameFromAlmanac(__instance.theZombieType); - __instance.sceneText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + //__instance.sceneText.text = Utils.GetZombieNameFromAlmanac(__instance.theZombieType); + //__instance.sceneText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); } } } \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index 032f495..cc57702 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -4,96 +4,42 @@ using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using UnityEngine; using UnityEngine.UI; +using UnityEngine.UIElements; namespace PvZ_Fusion_Translator.Patches.GameObjects { [HarmonyPatch(typeof(UIButton))] public static class UIButton_Patch { - [HarmonyPatch(nameof(UIButton.Start))] + [HarmonyPatch(typeof(UIButton), nameof(UIButton.Start))] [HarmonyPostfix] - private static void Postfix_Start(UIButton __instance) + public static void Start(UIButton __instance) { - try + if(__instance.transform.childCount >= 2) { - // 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(); + TMP_FontAsset font = FontStore.LoadTMPFont(Utils.Language.ToString()); - 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()); - } - else + foreach (TextMeshProUGUI text in __instance.transform.GetComponentsInChildren()) { - // Convert and translate legacy Text components - Text[] textComponents = __instance.GetComponentsInChildren(true); - TextMeshProUGUI[] textMeshComponents = __instance.GetComponentsInChildren(true); - foreach (Text textComponent in textComponents) + if (__instance.transform.name == "Goback") { - 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; - } - } - } + text.text = "合上"; } + text.text = StringStore.TranslateText(text.text); + text.font = font; } - } - catch (Exception) { } - } - - [HarmonyPatch(nameof(UIButton.OnMouseUpAsButton))] - [HarmonyPostfix] - public static void Postfix_OnMouseUpAsButton(UIButton __instance) - { - try + else { - if (__instance.transform.childCount >= 2) + StringStore.TranslateTextTransform(__instance.transform); + if(__instance.transform.name == "Goback") { - if(__instance.name == "EditMode") + foreach(TextMeshProUGUI text in __instance.transform.GetComponentsInChildren()) { - TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - - TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); - TextMeshProUGUI[] extraTexts = __instance.transform.GetChild(1).GetComponentsInChildren(); - - text.text = StringStore.TranslateText(text.text, false); - text.font = fontAsset; - - foreach(TextMeshProUGUI extraText in extraTexts) - { - extraText.text = StringStore.TranslateText(extraText.text, false); - extraText.font = fontAsset; - } - } - else - { - TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); - TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent(); - - 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.text = StringStore.TranslateText("合上"); } } } - catch (Exception) { } } } } diff --git a/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs b/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs index 768eea8..2e73634 100644 --- a/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs @@ -14,7 +14,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects [HarmonyPatch(nameof(NoticeMenu.Awake))] private static void Pre_Awake(NoticeMenu __instance) { - GameObject contentObject = __instance.transform.FindChild("Scroll View").GetChild(0).GetChild(0).gameObject; //bc normal Find or FindChild didn't work + GameObject contentObject = __instance.transform.FindChild("Scroll View/Viewport/Content").gameObject; TextMeshProUGUI contentText = contentObject.GetComponent(); File.WriteAllText(Path.Combine(FileLoader.GetAssetDir(FileLoader.AssetType.Dumps), "changelog.txt"), contentText.text); diff --git a/MelonLoader/Patches/Managers/AlmanacMgrZombie_Patch.cs b/MelonLoader/Patches/Managers/AlmanacMgrZombie_Patch.cs index 097f84d..daf88bc 100644 --- a/MelonLoader/Patches/Managers/AlmanacMgrZombie_Patch.cs +++ b/MelonLoader/Patches/Managers/AlmanacMgrZombie_Patch.cs @@ -14,13 +14,13 @@ namespace PvZ_Fusion_Translator.Patches.Managers [HarmonyPostfix] private static void InitNameAndInfoFromJson(AlmanacMgrZombie __instance) { - #if MULTI_LANGUAGE +#if MULTI_LANGUAGE string currentLanguage = Utils.Language.ToString(); string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); - #else +#else string almanacDir = almanacDir = GetAssetDir(AssetType.Almanac); string currentLanguage = "English"; - #endif +#endif string path = Path.Combine(almanacDir, "ZombieStringsTranslate.json"); string moddedPath = Path.Combine(almanacDir, "ModdedZombiesTranslate.json"); @@ -30,13 +30,13 @@ namespace PvZ_Fusion_Translator.Patches.Managers return; } - #if OBFUSCATE +#if OBFUSCATE if (CheckSumStore.IsModified(path)) { Log.LogError("File {0} was modified!", path); return; } - #endif +#endif string json; json = File.ReadAllText(path); @@ -49,19 +49,19 @@ namespace PvZ_Fusion_Translator.Patches.Managers hasAlmanacFont = true; } - #if MULTI_LANGUAGE +#if MULTI_LANGUAGE TMP_FontAsset fontAsset = FontStore.LoadTMPFont(currentLanguage); - #else +#else TMP_FontAsset fontAsset = FontStore.LoadTMPFont(); - #endif +#endif TextMeshPro component = __instance.info.GetComponent(); TextMeshPro component2 = __instance.zombieName.GetComponent(); TextMeshPro component3 = __instance.zombieName.transform.GetChild(0).GetComponent(); - AlmanacMgrZombie.ZombieAlmanacData zombieData = JsonUtility.FromJson(json); + ZombieAlmanacData zombieData = JsonUtility.FromJson(json); - foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in zombieData.zombies) + foreach (ZombieInfo zombieInfo in zombieData.zombies) { if (zombieInfo.theZombieType == __instance.theZombieType) { @@ -86,9 +86,9 @@ namespace PvZ_Fusion_Translator.Patches.Managers string moddedJson; moddedJson = File.ReadAllText(moddedPath); - AlmanacMgrZombie.ZombieAlmanacData moddedZombieData = JsonUtility.FromJson(moddedJson); + ZombieAlmanacData moddedZombieData = JsonUtility.FromJson(moddedJson); - foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in moddedZombieData.zombies) + foreach (ZombieInfo zombieInfo in moddedZombieData.zombies) { if (zombieInfo.theZombieType == __instance.theZombieType) { @@ -125,4 +125,4 @@ namespace PvZ_Fusion_Translator.Patches.Managers return true; } } -} +} \ No newline at end of file diff --git a/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs b/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs index a2be15c..bf150c8 100644 --- a/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs +++ b/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs @@ -7,170 +7,170 @@ using static PvZ_Fusion_Translator.FileLoader; namespace PvZ_Fusion_Translator.Patches.Managers { - [HarmonyPatch(typeof(AlmanacPlantBank))] - public static partial class AlmanacPlantBank_Patch - { - [HarmonyPatch(nameof(AlmanacPlantBank.InitNameAndInfoFromJson))] - [HarmonyPostfix] - private static void InitNameAndInfoFromJson(Il2Cpp.AlmanacPlantBank __instance) - { - #if MULTI_LANGUAGE - string currentLanguage = Utils.Language.ToString(); - string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); - #else + [HarmonyPatch(typeof(AlmanacPlantBank))] + public static partial class AlmanacPlantBank_Patch + { + [HarmonyPatch(nameof(AlmanacPlantBank.InitNameAndInfoFromJson))] + [HarmonyPostfix] + private static void InitNameAndInfoFromJson(Il2Cpp.AlmanacPlantBank __instance) + { +#if MULTI_LANGUAGE + string currentLanguage = Utils.Language.ToString(); + string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); +#else string almanacDir = GetAssetDir(AssetType.Almanac); string currentLanguage = "English"; - #endif - string path = Path.Combine(almanacDir, "LawnStringsTranslate.json"); - string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json"); +#endif + string path = Path.Combine(almanacDir, "LawnStringsTranslate.json"); + string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json"); - if (!File.Exists(path)) - { - Log.LogError($"LawnStringsTranslate.json file not found at path: {path}"); - return; - } + if (!File.Exists(path)) + { + Log.LogError($"LawnStringsTranslate.json file not found at path: {path}"); + return; + } - #if OBFUSCATE +#if OBFUSCATE if (CheckSumStore.IsModified(path)) { Log.LogError("File {0} was modified!", path); return; } - #endif +#endif - string json; - json = File.ReadAllText(path); - - bool hasAlmanacFont = false; - TMP_FontAsset almanacFontAsset = null; - if (FontStore.fontAssetDictSecondary.ContainsKey(currentLanguage + "_Almanac") || FontStore.fontAssetDictSecondary.ContainsKey(currentLanguage)) - { - almanacFontAsset = FontStore.LoadTMPFontAlmanac(currentLanguage); - hasAlmanacFont = true; - } + string json; + json = File.ReadAllText(path); - #if MULTI_LANGUAGE - TMP_FontAsset fontAsset = FontStore.LoadTMPFont(currentLanguage); - #else + bool hasAlmanacFont = false; + TMP_FontAsset almanacFontAsset = null; + if (FontStore.fontAssetDictSecondary.ContainsKey(currentLanguage + "_Almanac") || FontStore.fontAssetDictSecondary.ContainsKey(currentLanguage)) + { + almanacFontAsset = FontStore.LoadTMPFontAlmanac(currentLanguage); + hasAlmanacFont = true; + } + +#if MULTI_LANGUAGE + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(currentLanguage); +#else TMP_FontAsset fontAsset = FontStore.LoadTMPFont(); - #endif +#endif - TextMeshPro component = __instance.introduce.GetComponent(); - TextMeshPro component2 = __instance.plantName.GetComponent(); - TextMeshPro component3 = __instance.plantName.transform.GetChild(0).GetComponent(); - TextMeshPro component4 = __instance.cost.GetComponent(); + TextMeshPro component = __instance.introduce.GetComponent(); + TextMeshPro component2 = __instance.plantName.GetComponent(); + TextMeshPro component3 = __instance.plantName.transform.GetChild(0).GetComponent(); + TextMeshPro component4 = __instance.cost.GetComponent(); - AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); + AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants) - { + { if (plantInfo.seedType == __instance.theSeedType && !string.IsNullOrEmpty(plantInfo.name)) - { - component.autoSizeTextContainer = false; - component.text = plantInfo.info + "\n\n" + plantInfo.introduce; - component.overflowMode = TextOverflowModes.Page; + { + component.autoSizeTextContainer = false; + component.text = plantInfo.info + "\n\n" + plantInfo.introduce; + component.overflowMode = TextOverflowModes.Page; - // fix dimensions for cost text - component.rectTransform.offsetMax = new Vector2(component.rectTransform.offsetMax.x, 27.3839f); - component.rectTransform.offsetMin = new Vector2(component.rectTransform.offsetMin.x, -29.3079f); - component.rectTransform.sizeDelta = new Vector2(component.rectTransform.sizeDelta.x, 50.917f); - component.transform.localPosition = new Vector3(component.transform.localPosition.x, component.transform.localPosition.y + 0.15f, component.transform.localPosition.z); - + // fix dimensions for cost text + component.rectTransform.offsetMax = new Vector2(component.rectTransform.offsetMax.x, 27.3839f); + component.rectTransform.offsetMin = new Vector2(component.rectTransform.offsetMin.x, -29.3079f); + component.rectTransform.sizeDelta = new Vector2(component.rectTransform.sizeDelta.x, 50.917f); + component.transform.localPosition = new Vector3(component.transform.localPosition.x, component.transform.localPosition.y + 0.15f, component.transform.localPosition.z); - component2.text = plantInfo.name; - component2.autoSizeTextContainer = true; + + component2.text = plantInfo.name; + component2.autoSizeTextContainer = true; component3.text = Utils.RemoveColorTags(plantInfo.name ?? string.Empty); - component3.autoSizeTextContainer = true; + component3.autoSizeTextContainer = true; - component4.text = plantInfo.cost; + component4.text = plantInfo.cost; - if (hasAlmanacFont) - { - component.font = almanacFontAsset; - component4.font = almanacFontAsset; - } - else - { - component.font = fontAsset; - component4.font = fontAsset; - } - component2.font = fontAsset; - component3.font = fontAsset; - } - } + if (hasAlmanacFont) + { + component.font = almanacFontAsset; + component4.font = almanacFontAsset; + } + else + { + component.font = fontAsset; + component4.font = fontAsset; + } + component2.font = fontAsset; + component3.font = fontAsset; + } + } - if (File.Exists(moddedPath)) - { - string moddedJson; - moddedJson = File.ReadAllText(moddedPath); + if (File.Exists(moddedPath)) + { + string moddedJson; + moddedJson = File.ReadAllText(moddedPath); - AlmanacPlantBank.PlantData moddedPlantData = JsonUtility.FromJson(moddedJson); + AlmanacPlantBank.PlantData moddedPlantData = JsonUtility.FromJson(moddedJson); foreach (AlmanacPlantBank.PlantInfo plantInfo in moddedPlantData.plants) - { + { if (plantInfo.seedType == __instance.theSeedType && !string.IsNullOrEmpty(plantInfo.name)) - { - component.autoSizeTextContainer = false; - component.text = plantInfo.info + "\n\n" + plantInfo.introduce; - component.overflowMode = TextOverflowModes.Page; + { + component.autoSizeTextContainer = false; + component.text = plantInfo.info + "\n\n" + plantInfo.introduce; + component.overflowMode = TextOverflowModes.Page; - // fix dimensions for cost text - component.rectTransform.offsetMax = new Vector2(component.rectTransform.offsetMax.x, 27.3839f); - component.rectTransform.offsetMin = new Vector2(component.rectTransform.offsetMin.x, -29.3079f); - component.rectTransform.sizeDelta = new Vector2(component.rectTransform.sizeDelta.x, 50.917f); - component.transform.localPosition = new Vector3(component.transform.localPosition.x, component.transform.localPosition.y + 0.15f, component.transform.localPosition.z); - + // fix dimensions for cost text + component.rectTransform.offsetMax = new Vector2(component.rectTransform.offsetMax.x, 27.3839f); + component.rectTransform.offsetMin = new Vector2(component.rectTransform.offsetMin.x, -29.3079f); + component.rectTransform.sizeDelta = new Vector2(component.rectTransform.sizeDelta.x, 50.917f); + component.transform.localPosition = new Vector3(component.transform.localPosition.x, component.transform.localPosition.y + 0.15f, component.transform.localPosition.z); - component2.text = plantInfo.name; - component2.autoSizeTextContainer = true; + + component2.text = plantInfo.name; + component2.autoSizeTextContainer = true; component3.text = Utils.RemoveColorTags(plantInfo.name ?? string.Empty); - component3.autoSizeTextContainer = true; + component3.autoSizeTextContainer = true; - component4.text = plantInfo.cost; + component4.text = plantInfo.cost; - if (hasAlmanacFont) - { - component.font = almanacFontAsset; - component4.font = almanacFontAsset; - } - else - { - component.font = fontAsset; - component4.font = fontAsset; - } - component2.font = fontAsset; - component3.font = fontAsset; - } - } - } + if (hasAlmanacFont) + { + component.font = almanacFontAsset; + component4.font = almanacFontAsset; + } + else + { + component.font = fontAsset; + component4.font = fontAsset; + } + component2.font = fontAsset; + component3.font = fontAsset; + } + } + } return; - } + } - [HarmonyPatch(nameof(AlmanacPlantBank.OnMouseDown))] - [HarmonyPrefix] - private static bool OnMouseDown(AlmanacPlantBank __instance) - { - TextMeshPro component = __instance.introduce.GetComponent(); - if (component != null) - { - component.pageToDisplay = component.pageToDisplay > component.m_pageNumber ? 1 : component.pageToDisplay + 1; - return false; - } - return true; - } + [HarmonyPatch(nameof(AlmanacPlantBank.OnMouseDown))] + [HarmonyPrefix] + private static bool OnMouseDown(AlmanacPlantBank __instance) + { + TextMeshPro component = __instance.introduce.GetComponent(); + if (component != null) + { + component.pageToDisplay = component.pageToDisplay > component.m_pageNumber ? 1 : component.pageToDisplay + 1; + return false; + } + return true; + } - [HarmonyPatch(nameof(AlmanacPlantBank.PVPInit))] - [HarmonyPostfix] - private static void PVPInit(Il2Cpp.AlmanacPlantBank __instance) - { - TextMeshPro component = __instance.introduce.GetComponent(); - if (component != null) - { - component.autoSizeTextContainer = false; - } + [HarmonyPatch(nameof(AlmanacPlantBank.PVPInit))] + [HarmonyPostfix] + private static void PVPInit(Il2Cpp.AlmanacPlantBank __instance) + { + TextMeshPro component = __instance.introduce.GetComponent(); + if (component != null) + { + component.autoSizeTextContainer = false; + } Transform banTransform = __instance.transform.FindChild("Ban").GetChild(0); if (banTransform != null) @@ -179,22 +179,22 @@ namespace PvZ_Fusion_Translator.Patches.Managers } } - [HarmonyPatch(nameof(AlmanacPlantBank.Start))] - [HarmonyPostfix] - public static void Post_Start(AlmanacPlantBank __instance) - { + [HarmonyPatch(nameof(AlmanacPlantBank.Start))] + [HarmonyPostfix] + public static void Post_Start(AlmanacPlantBank __instance) + { GameObject skinTextObj = __instance.skinButton.transform.GetChild(0).gameObject; GameObject skinShadowTextObj = UnityEngine.Object.Instantiate(skinTextObj, parent: __instance.skinButton.transform); TextMeshPro skinShadowText = skinShadowTextObj.GetComponent(); skinShadowText.text = StringStore.TranslateText("换肤_S"); skinShadowText.sortingOrder -= 2; skinShadowTextObj.transform.Translate(new Vector3(0.015f, -0.015f, 0)); - skinTextObj.transform.Translate(new Vector3(-0.022f, 0)); + skinTextObj.transform.Translate(new Vector3(-0.022f, 0)); skinShadowTextObj.transform.Translate(new Vector3(-0.022f, 0)); __instance.skinButton.transform.localScale /= 1.75f; __instance.skinButton.transform.Translate(new Vector3(-0.075f, -0.15f, 0)); - __instance.skinButton.transform.GetChild(1).Translate(new Vector3(0.35f, 0)); - __instance.skinButton.transform.GetChild(2).Translate(new Vector3(-0.35f, 0)); + __instance.skinButton.transform.GetChild(1).Translate(new Vector3(0.35f, 0)); + __instance.skinButton.transform.GetChild(2).Translate(new Vector3(-0.35f, 0)); } - } + } } \ No newline at end of file diff --git a/MelonLoader/Patches/Managers/GameAPP_Patch.cs b/MelonLoader/Patches/Managers/GameAPP_Patch.cs new file mode 100644 index 0000000..73943c3 --- /dev/null +++ b/MelonLoader/Patches/Managers/GameAPP_Patch.cs @@ -0,0 +1,28 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace PvZ_Fusion_Translator.Patches.Managers +{ + [HarmonyPatch(typeof(GameAPP))] + public static class GameAPP_Patch + { + [HarmonyPatch(nameof(GameAPP.Update))] + [HarmonyPrefix] + private static bool Update(GameAPP __instance) + { + if(EventSystem.current.currentSelectedGameObject != null) + { + if (EventSystem.current.currentSelectedGameObject.TryGetComponent(out TMP_InputField field)) + { + __instance.MusicUpdate(); + return false; + } + } + return true; + } + } +} diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index cedb4a6..251ff6a 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -13,7 +13,7 @@ latest enable Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate - C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.1.1 + C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.2 AnyCPU;ARM64;x64 @@ -401,6 +401,12 @@ + + + + + + diff --git a/MelonLoader/Utils.cs b/MelonLoader/Utils.cs index 91b2afe..e44fad9 100644 --- a/MelonLoader/Utils.cs +++ b/MelonLoader/Utils.cs @@ -80,15 +80,27 @@ namespace PvZ_Fusion_Translator Process.Start(new ProcessStartInfo(website) { UseShellExecute = true }); } - public static string RemoveColorTags(string text) + public static string RemoveColorTags(string text) { - if (string.IsNullOrEmpty(text)) + if (string.IsNullOrEmpty(text)) return text ?? string.Empty; // Remove opening color tags like string withoutOpenTags = Regex.Replace(text, @"]+>", string.Empty, RegexOptions.IgnoreCase); // Remove closing color tags like string withoutCloseTags = Regex.Replace(withoutOpenTags, @"", string.Empty, RegexOptions.IgnoreCase); + return withoutCloseTags; + } + + public static string RemoveSizeTags(string text) + { + if (string.IsNullOrEmpty(text)) + return text ?? string.Empty; + + // Remove opening color tags like + string withoutOpenTags = Regex.Replace(text, @"]+>", string.Empty, RegexOptions.IgnoreCase); + // Remove closing color tags like + string withoutCloseTags = Regex.Replace(withoutOpenTags, @"", string.Empty, RegexOptions.IgnoreCase); return withoutCloseTags; } @@ -203,39 +215,39 @@ namespace PvZ_Fusion_Translator return thePlantName; } - public static string GetZombieNameFromAlmanac(ZombieType theZombieType) - { - string json; - string theZombieName = ""; + public static string GetZombieNameFromAlmanac(ZombieType theZombieType) + { + string json; + string theZombieName = ""; - string currentLanguage = Utils.Language.ToString(); - string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); - string path = Path.Combine(almanacDir, "ZombieStringsTranslate.json"); + string currentLanguage = Utils.Language.ToString(); + string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); + string path = Path.Combine(almanacDir, "ZombieStringsTranslate.json"); - if (!File.Exists(path)) - { - Log.LogError($"ZombieStringsTranslate.json file not found at path: {path}"); - Log.LogError("Zombie name could not be found!"); - theZombieName = ""; - } - else - { - json = File.ReadAllText(path); - AlmanacMgrZombie.ZombieAlmanacData zombieData = JsonUtility.FromJson(json); + if (!File.Exists(path)) + { + Log.LogError($"ZombieStringsTranslate.json file not found at path: {path}"); + Log.LogError("Zombie name could not be found!"); + theZombieName = ""; + } + else + { + json = File.ReadAllText(path); + ZombieAlmanacData zombieData = JsonUtility.FromJson(json); - foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in zombieData.zombies) - { - if ((int)zombieInfo.theZombieType == (int)theZombieType) - { - theZombieName = zombieInfo.name; - } - } - } + foreach (ZombieInfo zombieInfo in zombieData.zombies) + { + if ((int)zombieInfo.theZombieType == (int)theZombieType) + { + theZombieName = zombieInfo.name; + } + } + } - return theZombieName; - } + return theZombieName; + } - public static Dictionary> plantIndices = new Dictionary>(); + public static Dictionary> plantIndices = new Dictionary>(); public static void RegisterPlantIndices() { From 42f5667d57b7b62136fcb9b081c7095715d275be Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Tue, 23 Dec 2025 02:56:28 -0500 Subject: [PATCH 10/12] skin button fixes --- .../GameObjects/AlmanacPlantMenu_Patch.cs | 92 +++++++++++++++++++ .../GameObjects/AlmanacPlantWindow_Patch.cs | 2 + ...PvZ Fusion Translator [MelonLoader].csproj | 4 +- 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs index b9aa2f0..3dbf239 100644 --- a/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs @@ -3,6 +3,7 @@ using Il2Cpp; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using System.Text.RegularExpressions; +using Unity.Collections; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; @@ -29,6 +30,19 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects text.autoSizeTextContainer = true; } } + + // skin button resize + + AlmanacPlantWindow window = __instance.window; + GameObject skinButton = window.skinButton; + GameObject skinTextObj = skinButton.transform.GetChild(0).gameObject; + GameObject skinShadowTextObj = skinTextObj.transform.GetChild(0).gameObject; + TextMeshProUGUI skinShadowText = skinShadowTextObj.GetComponent(); + skinShadowText.text = StringStore.TranslateText("换肤_S"); + skinButton.transform.localScale /= 1.75f; + skinButton.transform.localPosition = new Vector3(0.0f, 111.345f, 0.0f); + skinButton.transform.GetChild(1).Translate(new Vector3(-0.35f, 0)); + skinButton.transform.GetChild(2).Translate(new Vector3(0.35f, 0)); } [HarmonyPatch(nameof(AlmanacPlantMenu.SearchChanged))] @@ -54,6 +68,24 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants) { + //List uniqueIngredients = GetIngredients(plantInfo.seedType); + + //// ingredient-based search + + //foreach(int i in uniqueIngredients) + //{ + // string name = Utils.GetPlantNameFromAlmanac((PlantType)i); + + // if(name.ToLower().Contains(search.ToLower())) + // { + // searchedPlants.Add((PlantType)i); + // } + //} + + // keyword-based search + + // name-based search + if (plantInfo.name.ToLower().Contains(search.ToLower())) { searchedPlants.Add((PlantType)plantInfo.seedType); @@ -67,5 +99,65 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects return true; } + + private static List GetIngredients(int theSeedType) + { + List ingredientPairs = new(); + Il2CppSystem.Array mixData = MixData.data.Cast(); + int rows = mixData.GetLength(0); + int columns = mixData.GetLength(1); + + for(int i = 0; i < rows; i++) + { + for(int j = 0; j < columns; j++) + { + if(ContainsFormula(theSeedType)) + { + if (mixData.GetValue(i, j).Unbox() == theSeedType) + { + if (!ingredientPairs.Contains(i)) + { + ingredientPairs.Add(i); + } + + if (!ingredientPairs.Contains(j)) + { + ingredientPairs.Add(j); + } + } + } + else + { + return ingredientPairs; + } + + } + } + + return ingredientPairs; + } + + private static bool ContainsFormula(int theSeedType) + { + bool contains = false; + + Il2CppSystem.Array mixData = MixData.data.Cast(); + int rows = mixData.GetLength(0); + int columns = mixData.GetLength(1); + + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < columns; j++) + { + if (mixData.GetValue(i, j).Unbox() == theSeedType) + { + contains = true; + return contains; + } + } + } + + return contains; + } } } diff --git a/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs index 1e7260a..5b07557 100644 --- a/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs +++ b/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs @@ -43,8 +43,10 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects { foreach (TextMeshProUGUI text in __instance.showedPlantName) { + text.autoSizeTextContainer = false; text.text = $"{Utils.RemoveSizeTags(plantInfo.name)} ({plantInfo.seedType})"; text.font = fontAsset; + text.fontSizeMax = 21; } __instance.showedPlantIntroduce.text = Utils.RemoveSizeTags(plantInfo.info) + "\n\n" + Utils.RemoveSizeTags(plantInfo.introduce) + "\n\n"; diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 251ff6a..e2604aa 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -1,4 +1,4 @@ - + net6.0 enable @@ -13,7 +13,7 @@ latest enable Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate - C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.2 + C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.2.1 AnyCPU;ARM64;x64 From ade617e3e45f339c9427edbb9a67593db6b11443 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Thu, 25 Dec 2025 23:59:58 -0500 Subject: [PATCH 11/12] 3.2.1 version 1 code (no almanac keyword/formula search) --- MelonLoader/Core.cs | 2 +- .../GameObjects/AlmanacPlantMenu_Patch.cs | 85 +------------------ .../ExploreMakeZombieButton_Patch.cs | 6 +- .../ButtonObjects/UIButton_Patch.cs | 40 +++++++++ .../Patches/GameObjects/EveBuffMenu_Patch.cs | 38 +++++++++ .../GameObjects/EveOptionWindow_Patch.cs | 50 +++++++++++ .../GameObjects/NoticePauseMenu_Patch.cs | 2 +- .../GameObjects/PlantDamageMenu_Patch.cs | 37 ++++++++ .../Patches/Managers/IZBottomMenu_Patch.cs | 36 +++----- ...PvZ Fusion Translator [MelonLoader].csproj | 3 + MelonLoader/Utils.cs | 44 ++++++++++ 11 files changed, 234 insertions(+), 109 deletions(-) create mode 100644 MelonLoader/Patches/GameObjects/EveBuffMenu_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/EveOptionWindow_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs diff --git a/MelonLoader/Core.cs b/MelonLoader/Core.cs index 54cddc8..c9eb3b3 100644 --- a/MelonLoader/Core.cs +++ b/MelonLoader/Core.cs @@ -35,7 +35,7 @@ namespace PvZ_Fusion_Translator AudioStore.Init(); FontStore.Init(); Utils.RegisterPlantIndices(); - + //Utils.RegisterRecipeLinks(); } public override void OnLateInitializeMelon() diff --git a/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs index 3dbf239..80ab13e 100644 --- a/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs @@ -7,6 +7,7 @@ using Unity.Collections; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; +using static Il2Cpp.AlmanacPlantBank; using static PvZ_Fusion_Translator.FileLoader; using static PvZ_Fusion_Translator.Utils; @@ -50,7 +51,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects public static bool SearchChanged(AlmanacPlantMenu __instance, ref TMP_InputField inputField) { string search = inputField.text; - if (search != StringStore.TranslateText("搜索")) + if (search != StringStore.TranslateText("搜索") && search != "") { string currentLanguage = Utils.Language.ToString(); string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); @@ -62,30 +63,12 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects TMP_FontAsset fontAsset = FontStore.LoadTMPFont(currentLanguage); - AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); + PlantData plantData = JsonUtility.FromJson(json); Il2CppSystem.Collections.Generic.List searchedPlants = new(); - foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants) + foreach (PlantInfo plantInfo in plantData.plants) { - //List uniqueIngredients = GetIngredients(plantInfo.seedType); - - //// ingredient-based search - - //foreach(int i in uniqueIngredients) - //{ - // string name = Utils.GetPlantNameFromAlmanac((PlantType)i); - - // if(name.ToLower().Contains(search.ToLower())) - // { - // searchedPlants.Add((PlantType)i); - // } - //} - - // keyword-based search - - // name-based search - if (plantInfo.name.ToLower().Contains(search.ToLower())) { searchedPlants.Add((PlantType)plantInfo.seedType); @@ -99,65 +82,5 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects return true; } - - private static List GetIngredients(int theSeedType) - { - List ingredientPairs = new(); - Il2CppSystem.Array mixData = MixData.data.Cast(); - int rows = mixData.GetLength(0); - int columns = mixData.GetLength(1); - - for(int i = 0; i < rows; i++) - { - for(int j = 0; j < columns; j++) - { - if(ContainsFormula(theSeedType)) - { - if (mixData.GetValue(i, j).Unbox() == theSeedType) - { - if (!ingredientPairs.Contains(i)) - { - ingredientPairs.Add(i); - } - - if (!ingredientPairs.Contains(j)) - { - ingredientPairs.Add(j); - } - } - } - else - { - return ingredientPairs; - } - - } - } - - return ingredientPairs; - } - - private static bool ContainsFormula(int theSeedType) - { - bool contains = false; - - Il2CppSystem.Array mixData = MixData.data.Cast(); - int rows = mixData.GetLength(0); - int columns = mixData.GetLength(1); - - for (int i = 0; i < rows; i++) - { - for (int j = 0; j < columns; j++) - { - if (mixData.GetValue(i, j).Unbox() == theSeedType) - { - contains = true; - return contains; - } - } - } - - return contains; - } } } diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs index da7b212..49d638f 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs @@ -13,8 +13,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects [HarmonyPatch(nameof(ExploreMakeZombieButton.Start))] public static void Start(ExploreMakeZombieButton __instance) { - //__instance.sceneText.text = Utils.GetZombieNameFromAlmanac(__instance.theZombieType); - //__instance.sceneText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - } + __instance.sceneText.text = Utils.GetZombieNameFromAlmanac(__instance.theZombieType); + __instance.sceneText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } } } \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index cc57702..22dbe7a 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -41,5 +41,45 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects } } } + + [HarmonyPatch(nameof(UIButton.OnMouseUpAsButton))] + [HarmonyPostfix] + public static void Postfix_OnMouseUpAsButton(UIButton __instance) + { + try + { + if (__instance.transform.childCount >= 2) + { + if (__instance.name == "EditMode") + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); + TextMeshProUGUI[] extraTexts = __instance.transform.GetChild(1).GetComponentsInChildren(); + + text.text = StringStore.TranslateText(text.text, false); + text.font = fontAsset; + + foreach (TextMeshProUGUI extraText in extraTexts) + { + extraText.text = StringStore.TranslateText(extraText.text, false); + extraText.font = fontAsset; + } + } + else + { + TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); + TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent(); + + 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()); + } + } + } + catch (Exception) { } + } } } diff --git a/MelonLoader/Patches/GameObjects/EveBuffMenu_Patch.cs b/MelonLoader/Patches/GameObjects/EveBuffMenu_Patch.cs new file mode 100644 index 0000000..51725ab --- /dev/null +++ b/MelonLoader/Patches/GameObjects/EveBuffMenu_Patch.cs @@ -0,0 +1,38 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(EveBuffMenu))] + public static class EveBuffMenu_Patch + { + [HarmonyPatch(nameof(EveBuffMenu.Start))] + [HarmonyPostfix] + private static void Start(EveBuffMenu __instance) + { + foreach (EveOptionWindow window in __instance.windows) + { + EveOptionWindow_Patch.TranslateEveOptionWindow(window); + } + + foreach (TextMeshProUGUI text in __instance.quitButton.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText("合上"); + } + } + + [HarmonyPatch(nameof(EveBuffMenu.InitWindows))] + [HarmonyPostfix] + private static void InitWindows(EveBuffMenu __instance) + { + foreach(EveOptionWindow window in __instance.windows) + { + EveOptionWindow_Patch.TranslateEveOptionWindow(window); + } + } + } +} diff --git a/MelonLoader/Patches/GameObjects/EveOptionWindow_Patch.cs b/MelonLoader/Patches/GameObjects/EveOptionWindow_Patch.cs new file mode 100644 index 0000000..3d0a4c0 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/EveOptionWindow_Patch.cs @@ -0,0 +1,50 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(EveOptionWindow))] + public static class EveOptionWindow_Patch + { + [HarmonyPatch(nameof(EveOptionWindow.SetType))] + [HarmonyPostfix] + private static void SetType(EveOptionWindow __instance) + { + TranslateEveOptionWindow(__instance); + } + + [HarmonyPatch(nameof(EveOptionWindow.OnAnimOver))] + [HarmonyPostfix] + private static void OnAnimOver(EveOptionWindow __instance) + { + TranslateEveOptionWindow(__instance); + } + + [HarmonyPatch(nameof(EveOptionWindow.SelectedByRow))] + [HarmonyPostfix] + private static void SelectedByRow(EveOptionWindow __instance) + { + TranslateEveOptionWindow(__instance); + } + + public static void TranslateEveOptionWindow(EveOptionWindow __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; + + foreach (TextMeshProUGUI text in __instance.buttonText) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + } + } + } +} diff --git a/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs b/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs index 2e73634..cdfd61e 100644 --- a/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs @@ -38,7 +38,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects string changelogText = File.ReadAllText(changelogDir); - GameObject contentObject = __instance.transform.FindChild("Scroll View").GetChild(0).GetChild(0).gameObject; //bc normal Find or FindChild didn't work + GameObject contentObject = __instance.transform.FindChild("Scroll View/Viewport/Content").gameObject; TextMeshProUGUI contentText = contentObject.GetComponent(); contentText.text = changelogText; diff --git a/MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs b/MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs new file mode 100644 index 0000000..c5e3bb1 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs @@ -0,0 +1,37 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(PlantDamageMenu))] + public static class PlantDamageMenu_Patch + { + [HarmonyPatch(nameof(PlantDamageMenu.Awake))] + [HarmonyPostfix] + private static void Awake(PlantDamageMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + } + } + + [HarmonyPatch(nameof(PlantDamageMenu.InitCards))] + [HarmonyPostfix] + private static void InitCards(PlantDamageMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + } + } + } +} diff --git a/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs b/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs index 976806b..8630912 100644 --- a/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs +++ b/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs @@ -14,24 +14,19 @@ namespace PvZ_Fusion_Translator.Patches.Managers [HarmonyPostfix] public static void ChangeStringz(IZBottomMenu __instance) { - TextMeshProUGUI[] array = - [ - __instance.transform.GetChild(0).GetComponent(), - __instance.transform.GetChild(0).GetChild(0).GetComponent(), - ]; - for (int i = 0; i < array.Length; i++) + foreach(TextMeshProUGUI text in __instance.levelName) { string fStr = StringStore.translationStringRegex["([^\\s]+),推荐难度:(\\d+)"]; - string[] parts = array[i].text.Split(",推荐难度:"); + string[] parts = text.text.Split(",推荐难度:"); - if(new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text)) + if(new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(text.text)) { string customName = (StringStore.translationString.ContainsKey(parts[0] + "_IZ")) ? parts[0] + "_IZ" : parts[0]; - array[i].text = string.Format(fStr, StringStore.TranslateText(customName), parts[1]); + text.text = string.Format(fStr, StringStore.TranslateText(customName), parts[1]); } - - array[i] = StringStore.TranslateText(array[i]); - array[i].text = array[i].text.Replace("\n", " "); + + text.text = StringStore.TranslateText(text.text); + text.text = text.text.Replace("\n", " "); } } @@ -39,23 +34,18 @@ namespace PvZ_Fusion_Translator.Patches.Managers [HarmonyPostfix] public static void SetLevelName(IZBottomMenu __instance) { - TextMeshProUGUI[] array = - [ - __instance.transform.GetChild(0).GetComponent(), - __instance.transform.GetChild(0).GetChild(0).GetComponent(), - ]; - for (int i = 0; i < array.Length; i++) + foreach(TextMeshProUGUI text in __instance.levelName) { string fStr = StringStore.translationStringRegex["([^\\s]+),推荐难度:(\\d+)"]; - string[] parts = array[i].text.Split(",推荐难度:"); + string[] parts = text.text.Split(",推荐难度:"); - if (new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text)) + if (new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(text.text)) { - array[i].text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]); + text.text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]); } - array[i] = StringStore.TranslateText(array[i]); - array[i].text = array[i].text.Replace("\n", " "); + text.text = StringStore.TranslateText(text.text); + text.text = text.text.Replace("\n", " "); } } } diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index e2604aa..02a6774 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -406,6 +406,9 @@ + + + diff --git a/MelonLoader/Utils.cs b/MelonLoader/Utils.cs index e44fad9..6bb2e79 100644 --- a/MelonLoader/Utils.cs +++ b/MelonLoader/Utils.cs @@ -7,6 +7,7 @@ using PvZ_Fusion_Translator.AssetStore; using PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects; using System.Diagnostics; using System.Text.RegularExpressions; +using Unity.Burst.Intrinsics; using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.UI; @@ -299,6 +300,49 @@ namespace PvZ_Fusion_Translator } } + public static Dictionary> recipeLinks = new Dictionary>(); + + public static void RegisterRecipeLinks() + { + recipeLinks.Clear(); + + Il2CppSystem.Array mixData = MixData.data.Cast(); + int rows = mixData.GetLength(0); + int columns = mixData.GetLength(1); + + foreach (PlantType plantType in Enum.GetValues(typeof(PlantType))) + { + int seedType = (int)plantType; + + recipeLinks.Add(seedType, new()); + + if(seedType > 0) + { + foreach (PlantType checkType in Enum.GetValues(typeof(PlantType))) + { + if(checkType > 0) + { + int[] checks = [mixData.GetValue(seedType, (int)checkType).Unbox(), mixData.GetValue((int)checkType, seedType).Unbox()]; + + if (checks[0] != 0) + { + recipeLinks[seedType].Add(checks[0]); + } + + if (checks[1] != 0) + { + recipeLinks[seedType].Add(checks[1]); + } + } + } + } + if (recipeLinks[seedType].Count > 0) + { + Log.LogDebug($"Found {recipeLinks[seedType].Count} fusions for {seedType}!"); + } + } + } + public static bool CheckForUntranslatedText(string text) { Regex regex = new("\\p{IsCJKUnifiedIdeographs}+"); From c566c95bd5cc5ee720e6e9a1280f4814cbf51e49 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Fri, 26 Dec 2025 00:45:58 -0500 Subject: [PATCH 12/12] lane arena points fix --- .../GameObjects/MinorObjects/Brain_Patch.cs | 57 +++++++++++++++++++ ...PvZ Fusion Translator [MelonLoader].csproj | 1 + 2 files changed, 58 insertions(+) create mode 100644 MelonLoader/Patches/GameObjects/MinorObjects/Brain_Patch.cs diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/Brain_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/Brain_Patch.cs new file mode 100644 index 0000000..58a09e7 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/MinorObjects/Brain_Patch.cs @@ -0,0 +1,57 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using System.Text.RegularExpressions; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects +{ + [HarmonyPatch(typeof(Brain))] + public static class Brain_Patch + { + [HarmonyPostfix] + [HarmonyPatch(nameof(Brain.Awake))] + private static void Awake(Brain __instance) + { + // reposition original points + Transform pointsTransform = __instance.points.transform; + GameObject pointsObject = __instance.points.gameObject; + pointsTransform.position = new Vector3(-6.5f, pointsTransform.position.y, pointsTransform.position.z); + + // instantiate and move new shadow + GameObject pointsShadowObject = UnityEngine.Object.Instantiate(pointsObject, parent: pointsTransform); + pointsShadowObject.SetActive(true); + Transform pointsShadowTransform = pointsShadowObject.transform; + pointsShadowTransform.position = new Vector3(-6.485f, pointsTransform.position.y - 0.015f, pointsTransform.position.z); + + // set points text + TextMeshPro pointsShadowText = pointsShadowObject.GetComponent(); + pointsShadowText.text = __instance.points.text; + pointsShadowText.sortingOrder -= 2; + pointsShadowText.color = Color.black; + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(Brain.Update))] + private static void Update(Brain __instance) + { + if(__instance.transform.Find("Points").GetChild(0) != null) + { + TextMeshPro shadowText = __instance.transform.Find("Points").GetChild(0).GetComponent(); + shadowText.text = __instance.points.text; + } + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(Brain.WinAction))] + private static void WinAction(Brain __instance) + { + if (__instance.transform.Find("Points").GetChild(0) != null) + { + TextMeshPro shadowText = __instance.transform.Find("Points").GetChild(0).GetComponent(); + shadowText.text = __instance.points.text; + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 02a6774..9d1f60d 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -406,6 +406,7 @@ +