From f2f5a87813e1718873b59005e1b1672b61adf038 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Sat, 27 Sep 2025 20:11:02 -0400 Subject: [PATCH] 3.0 part 1 --- .../BaseTextObjects/TextMeshPro_Patch.cs | 2 +- .../ButtonObjects/Advanture_Btn_Patch.cs | 7 +++- .../ButtonObjects/OptLanguageBtn_Patch.cs | 2 +- .../GameObjects/GardenBagMenu_Patch.cs | 40 +++++++++++++++++++ .../Patches/GameObjects/GardenCard_Patch.cs | 24 +++++++++++ .../Patches/Managers/DifficultyMgr_Patch.cs | 21 +++++----- MelonLoader/Patches/Managers/Garden_Patch.cs | 22 ++++++++++ ...PvZ Fusion Translator [MelonLoader].csproj | 5 ++- 8 files changed, 108 insertions(+), 15 deletions(-) create mode 100644 MelonLoader/Patches/GameObjects/GardenBagMenu_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/GardenCard_Patch.cs create mode 100644 MelonLoader/Patches/Managers/Garden_Patch.cs diff --git a/MelonLoader/Patches/BaseTextObjects/TextMeshPro_Patch.cs b/MelonLoader/Patches/BaseTextObjects/TextMeshPro_Patch.cs index baf393f..8008f53 100644 --- a/MelonLoader/Patches/BaseTextObjects/TextMeshPro_Patch.cs +++ b/MelonLoader/Patches/BaseTextObjects/TextMeshPro_Patch.cs @@ -18,7 +18,7 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects __instance = StringStore.TranslateText(__instance); __instance.autoSizeTextContainer = false; return; - } else if (!(__instance.transform.name.Contains("AlmanacZombie") || __instance.transform.name.Contains("AlmanacPlant"))) + } else if (!(__instance.transform.name.Contains("AlmanacZombie") || __instance.transform.name.Contains("AlmanacPlant") || __instance.transform.name.Contains("Name") || __instance.transform.name.Contains("Tips") || __instance.transform.parent.name.Contains("Signboard") || __instance.transform.parent.name.Contains("text"))) { __instance = StringStore.TranslateText(__instance); __instance.autoSizeTextContainer = true; diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs index c7dfb52..08e6209 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs @@ -18,8 +18,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects if (__instance.name == "Goback") { Transform backgroundTransform = parentTransform.Find("Background"); - backgroundTransform.Find("Name").GetComponent().autoSizeTextContainer = true; - backgroundTransform.Find("Shadow").GetComponent().autoSizeTextContainer = true; + if(backgroundTransform != null) + { + backgroundTransform.Find("Name").GetComponent().autoSizeTextContainer = true; + backgroundTransform.Find("Shadow").GetComponent().autoSizeTextContainer = true; + } } Transform levelTransform = parentTransform.Find("Levels"); diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs index d117b45..5fffd82 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs @@ -224,7 +224,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects } child.gameObject.SetActive(true); - Task.Delay(1000).ContinueWith(_ => + System.Threading.Tasks.Task.Delay(1000).ContinueWith(_ => { if (button != null && child != null && child.gameObject.activeSelf) { diff --git a/MelonLoader/Patches/GameObjects/GardenBagMenu_Patch.cs b/MelonLoader/Patches/GameObjects/GardenBagMenu_Patch.cs new file mode 100644 index 0000000..da1ea0f --- /dev/null +++ b/MelonLoader/Patches/GameObjects/GardenBagMenu_Patch.cs @@ -0,0 +1,40 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(GardenBagMenu))] + public static class GardenBagMenu_Patch + { + [HarmonyPatch(nameof(GardenBagMenu.SetTreasureCards))] + [HarmonyPostfix] + private static void SetTreasureCards(GardenBagMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + FileLoader.DumpUntranslatedStrings(txt.text); + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(GardenBagMenu.SetTreasureCard))] + [HarmonyPostfix] + private static void SetTreasureCard(GardenBagMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + FileLoader.DumpUntranslatedStrings(txt.text); + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/GardenCard_Patch.cs b/MelonLoader/Patches/GameObjects/GardenCard_Patch.cs new file mode 100644 index 0000000..cb4e23d --- /dev/null +++ b/MelonLoader/Patches/GameObjects/GardenCard_Patch.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using Il2Cpp; +using PvZ_Fusion_Translator.AssetStore; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(GardenCard))] + public static class GardenCard_Patch + { + [HarmonyPatch(nameof(GardenCard.Start))] + [HarmonyPostfix] + private static void Start(GardenCard __instance) + { + __instance.text.text = StringStore.TranslateText(__instance.text.text).Replace("26", "16"); + } + + [HarmonyPatch(nameof(GardenCard.ChangeCardSprite))] + [HarmonyPostfix] + private static void ChangeCardSprite(GardenCard __instance) + { + __instance.text.text = StringStore.TranslateText(__instance.text.text).Replace("26", "16"); + } + } +} diff --git a/MelonLoader/Patches/Managers/DifficultyMgr_Patch.cs b/MelonLoader/Patches/Managers/DifficultyMgr_Patch.cs index e494473..3d05ff1 100644 --- a/MelonLoader/Patches/Managers/DifficultyMgr_Patch.cs +++ b/MelonLoader/Patches/Managers/DifficultyMgr_Patch.cs @@ -1,18 +1,19 @@ using HarmonyLib; using Il2Cpp; +using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; namespace PvZ_Fusion_Translator.Patches.Managers { [HarmonyPatch(typeof(DifficultyMgr))] - public static class DifficultyMgr_Patch - { - [HarmonyPatch(nameof(DifficultyMgr.Update))] - [HarmonyPostfix] - private static void DifficultyMgr_Update(DifficultyMgr __instance) - { - __instance.t = StringStore.TranslateText(__instance.t); - __instance.t.autoSizeTextContainer = false; - } - } + public static class DifficultyMgr_Patch + { + [HarmonyPatch(nameof(DifficultyMgr.Update))] + [HarmonyPostfix] + private static void DifficultyMgr_Update(DifficultyMgr __instance) + { + __instance.t = StringStore.TranslateText(__instance.t); + __instance.t.autoSizeTextContainer = false; + } + } } diff --git a/MelonLoader/Patches/Managers/Garden_Patch.cs b/MelonLoader/Patches/Managers/Garden_Patch.cs new file mode 100644 index 0000000..698e2a5 --- /dev/null +++ b/MelonLoader/Patches/Managers/Garden_Patch.cs @@ -0,0 +1,22 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; + +namespace PvZ_Fusion_Translator.Patches.Managers +{ + [HarmonyPatch(typeof(Garden))] + public static class Garden_Patch + { + [HarmonyPatch(nameof(Garden.Awake))] + [HarmonyPostfix] + private static void Awake(Garden __instance) + { + foreach (TextMeshPro text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + } +} diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 86bba9f..1b47970 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_2.8.2 + C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.0 AnyCPU;ARM64;x64 @@ -401,10 +401,12 @@ + + @@ -443,6 +445,7 @@ +