From 68b428f9f4a600102c72610246666be6130f8a54 Mon Sep 17 00:00:00 2001 From: TuanAnh2901 Date: Sun, 28 Sep 2025 18:22:43 +0700 Subject: [PATCH] Port the patches to BepInEx --- .gitignore | 3 +- BepInEx/AssetStore/AudioStore.cs | 4 + BepInEx/AssetStore/FontStore.cs | 31 +++++- .../BaseTextObjects/TextMeshPro_Patch.cs | 2 +- .../ButtonObjects/Advanture_Btn_Patch.cs | 10 +- .../ButtonObjects/OptLanguageBtn_Patch.cs | 8 +- .../GameObjects/ExploreEnterWindow_Patch.cs | 40 ++++++++ .../Patches/GameObjects/ExploreMenu_Patch.cs | 48 +++++++++ .../GameObjects/GardenBagMenu_Patch.cs | 51 ++++++++++ .../Patches/GameObjects/GardenCard_Patch.cs | 24 +++++ .../MinorObjects/TreasureMoney_Patch.cs | 16 +++ .../GameObjects/PlantInfoWindow_Patch.cs | 51 ++++++++++ .../GameObjects/TreasureConfirmMenu_Patch.cs | 24 +++++ .../TreasureEquipmentMenu_Patch.cs | 37 +++++++ .../GameObjects/TreasureMainMenu_Patch.cs | 24 +++++ .../GameObjects/TreasureStoreMenu_Patch.cs | 24 +++++ .../GameObjects/TreasureUpgradeMenu_Patch.cs | 51 ++++++++++ .../TreasureWarehouseMenu_Patch.cs | 63 ++++++++++++ .../Managers/AlmanacMgrZombie_Patch.cs | 98 +++++++++++-------- BepInEx/Patches/Managers/Garden_Patch.cs | 21 ++++ BepInEx/Patches/Managers/InGameUI_Patch.cs | 60 ++++++------ .../PvZ Fusion Translator [BepInEx].csproj | 15 ++- BepInEx/Utils.cs | 46 +++++++++ .../Patches/GameObjects/ExploreMenu_Patch.cs | 14 ++- ...PvZ Fusion Translator [MelonLoader].csproj | 2 +- 25 files changed, 677 insertions(+), 90 deletions(-) create mode 100644 BepInEx/Patches/GameObjects/ExploreEnterWindow_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/ExploreMenu_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/GardenBagMenu_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/GardenCard_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/MinorObjects/TreasureMoney_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/PlantInfoWindow_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/TreasureConfirmMenu_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/TreasureEquipmentMenu_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/TreasureMainMenu_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/TreasureStoreMenu_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/TreasureWarehouseMenu_Patch.cs create mode 100644 BepInEx/Patches/Managers/Garden_Patch.cs diff --git a/.gitignore b/.gitignore index bad0472..8c7d99d 100644 --- a/.gitignore +++ b/.gitignore @@ -131,4 +131,5 @@ MelonLoader/bin/x64/Debug/net6.0/UnityEngine.WindModule.dll MelonLoader/bin/x64/Debug/net6.0/UnityEngine.XRModule.dll MelonLoader/bin/x64/Debug/net6.0/WebSocketDotNet.dll /BepInEx/bin/Debug/net6.0 -.HOWTO-sync-MelonLoader-from-origin-main.txt \ No newline at end of file +.HOWTO-sync-MelonLoader-from-origin-main.txt +/MelonLoader/bin/ReleaseMulti/net6.0 diff --git a/BepInEx/AssetStore/AudioStore.cs b/BepInEx/AssetStore/AudioStore.cs index 46ff120..93bc1c0 100644 --- a/BepInEx/AssetStore/AudioStore.cs +++ b/BepInEx/AssetStore/AudioStore.cs @@ -42,6 +42,10 @@ namespace PvZ_Fusion_Translator__BepInEx_ { try { + // Clear existing dictionaries to prevent duplicate key errors + AudioClips.Clear(); + AudioClipNames.Clear(); + if (!Directory.Exists(customAudioPath)) Directory.CreateDirectory(customAudioPath); diff --git a/BepInEx/AssetStore/FontStore.cs b/BepInEx/AssetStore/FontStore.cs index 9fb8409..5be4dd3 100644 --- a/BepInEx/AssetStore/FontStore.cs +++ b/BepInEx/AssetStore/FontStore.cs @@ -11,6 +11,10 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore internal static void Init() { + // Clear existing dictionaries to prevent duplicate key errors + fontAssetDict.Clear(); + fontAssetDictSecondary.Clear(); + string fontsDir = Path.Combine(Core.Instance.modsDirectory, "[Custom Fonts]"); #if MULTI_LANGUAGE @@ -27,7 +31,10 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore TMP_FontAsset fontAsset = FontHandler.LoadTMPFont(fontPath, true); fontAsset.name = fileName; - fontAssetDict.Add(fileName, fontAsset); + if (!fontAssetDict.ContainsKey(fileName)) + { + fontAssetDict.Add(fileName, fontAsset); + } Log.LogInfo($"Font for language '{fileName}' loaded"); } @@ -65,18 +72,32 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore { if (fileName.EndsWith("_Fallback")) { - fontAssetDictSecondary.Add(fileNameLanguage + "_Almanac", fontAssetDictSecondary[fileNameLanguage]); + if (!fontAssetDictSecondary.ContainsKey(fileNameLanguage + "_Almanac")) + { + fontAssetDictSecondary.Add(fileNameLanguage + "_Almanac", fontAssetDictSecondary[fileNameLanguage]); + } fontAssetDictSecondary.Remove(fileNameLanguage); } else { - fontAssetDictSecondary.Add(fileNameLanguage + "_Fallback", fontAssetDictSecondary[fileNameLanguage]); + if (!fontAssetDictSecondary.ContainsKey(fileNameLanguage + "_Fallback")) + { + fontAssetDictSecondary.Add(fileNameLanguage + "_Fallback", fontAssetDictSecondary[fileNameLanguage]); + } fontAssetDictSecondary.Remove(fileNameLanguage); } - fontAssetDictSecondary.Add(fileName, fallbackFont); + if (!fontAssetDictSecondary.ContainsKey(fileName)) + { + fontAssetDictSecondary.Add(fileName, fallbackFont); + } } else - fontAssetDictSecondary.Add(fileNameLanguage, fallbackFont); + { + if (!fontAssetDictSecondary.ContainsKey(fileNameLanguage)) + { + fontAssetDictSecondary.Add(fileNameLanguage, fallbackFont); + } + } // Log.LogInfo($"Fallback font for language '{fileNameLanguage}' loaded"); } diff --git a/BepInEx/Patches/BaseTextObjects/TextMeshPro_Patch.cs b/BepInEx/Patches/BaseTextObjects/TextMeshPro_Patch.cs index 5012841..0497378 100644 --- a/BepInEx/Patches/BaseTextObjects/TextMeshPro_Patch.cs +++ b/BepInEx/Patches/BaseTextObjects/TextMeshPro_Patch.cs @@ -19,7 +19,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.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/BepInEx/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs index cae0669..702e156 100644 --- a/BepInEx/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs +++ b/BepInEx/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs @@ -1,5 +1,4 @@ using HarmonyLib; -using System; using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; using UnityEngine; @@ -18,8 +17,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.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"); @@ -108,4 +110,4 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects StringStore.TranslateTextTransform(parentTransform.Find("CanvasSize")); } } -} +} \ No newline at end of file diff --git a/BepInEx/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs index efb52c8..f1df91e 100644 --- a/BepInEx/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs +++ b/BepInEx/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs @@ -232,7 +232,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.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) { @@ -242,9 +242,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects } } - private static void ToggleCustomAssets(string type) - { - if (type != "Textures" && type != "Audio") return; + private static void ToggleCustomAssets(string type) + { + if (type != "Textures" && type != "Audio") return; if (type == "Textures") { diff --git a/BepInEx/Patches/GameObjects/ExploreEnterWindow_Patch.cs b/BepInEx/Patches/GameObjects/ExploreEnterWindow_Patch.cs new file mode 100644 index 0000000..b7d3953 --- /dev/null +++ b/BepInEx/Patches/GameObjects/ExploreEnterWindow_Patch.cs @@ -0,0 +1,40 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(ExploreEnterWindow))] + public static class ExploreEnterWindow_Patch + { + [HarmonyPatch(nameof(ExploreEnterWindow.Awake))] + [HarmonyPostfix] + private static void Awake(ExploreEnterWindow __instance) + { + PlantType thePlantType = (PlantType)__instance.selfType; + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + StringStore.TranslateText(txt); + } + + __instance.nameText.text = Utils.GetPlantNameFromAlmanac(thePlantType); + } + + [HarmonyPatch(nameof(ExploreEnterWindow.SetInfo))] + [HarmonyPostfix] + private static void SetInfo(ExploreEnterWindow __instance) + { + PlantType thePlantType = (PlantType)__instance.selfType; + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + StringStore.TranslateText(txt); + } + + __instance.nameText.text = Utils.GetPlantNameFromAlmanac(thePlantType); + } + } +} diff --git a/BepInEx/Patches/GameObjects/ExploreMenu_Patch.cs b/BepInEx/Patches/GameObjects/ExploreMenu_Patch.cs new file mode 100644 index 0000000..3af0080 --- /dev/null +++ b/BepInEx/Patches/GameObjects/ExploreMenu_Patch.cs @@ -0,0 +1,48 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(ExploreMenu))] + public static class ExploreMenu_Patch + { + [HarmonyPatch(nameof(ExploreMenu.Awake))] + [HarmonyPostfix] + private static void Awake(ExploreMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + } + + Transform randomLevelTextTransform = __instance.transform.FindChild("RandomLevel"); + foreach (TextMeshProUGUI txt in randomLevelTextTransform.GetComponentsInChildren()) + { + if (txt.name.Contains("Text (TMP)")) + { + txt.autoSizeTextContainer = true; + if (txt.name == "Text (TMP)") + { + txt.transform.localPosition = new Vector3(94.4225f, -45.1565f, 0f); + } + } + } + } + + [HarmonyPatch(nameof(ExploreMenu.UpdateWindows))] + [HarmonyPostfix] + private static void UpdateWindows(ExploreMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/GardenBagMenu_Patch.cs b/BepInEx/Patches/GameObjects/GardenBagMenu_Patch.cs new file mode 100644 index 0000000..5c555a1 --- /dev/null +++ b/BepInEx/Patches/GameObjects/GardenBagMenu_Patch.cs @@ -0,0 +1,51 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.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()) + { + if(txt.transform.parent.name.Contains("Close")) + { + txt.text = StringStore.TranslateText("合上"); + } + else + { + 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()) + { + if (txt.transform.parent.name.Contains("Close")) + { + txt.text = StringStore.TranslateText("合上"); + } + else + { + txt.text = StringStore.TranslateText(txt.text); + } + txt.font = fontAsset; + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/GardenCard_Patch.cs b/BepInEx/Patches/GameObjects/GardenCard_Patch.cs new file mode 100644 index 0000000..ed7de7d --- /dev/null +++ b/BepInEx/Patches/GameObjects/GardenCard_Patch.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.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/BepInEx/Patches/GameObjects/MinorObjects/TreasureMoney_Patch.cs b/BepInEx/Patches/GameObjects/MinorObjects/TreasureMoney_Patch.cs new file mode 100644 index 0000000..3c4543d --- /dev/null +++ b/BepInEx/Patches/GameObjects/MinorObjects/TreasureMoney_Patch.cs @@ -0,0 +1,16 @@ +using HarmonyLib; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects +{ + [HarmonyPatch(typeof(TreasureMoney))] + public static class TreasureMoney_Patch + { + [HarmonyPostfix] + [HarmonyPatch(nameof(TreasureMoney.Update))] + private static void Update(TreasureMoney __instance) + { + __instance.text = StringStore.TranslateText(__instance.text); + } + } +} diff --git a/BepInEx/Patches/GameObjects/PlantInfoWindow_Patch.cs b/BepInEx/Patches/GameObjects/PlantInfoWindow_Patch.cs new file mode 100644 index 0000000..a57fe8f --- /dev/null +++ b/BepInEx/Patches/GameObjects/PlantInfoWindow_Patch.cs @@ -0,0 +1,51 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; +using UnityEngine.UIElements; +using static PvZ_Fusion_Translator__BepInEx_.FileLoader; +using System; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(PlantInfoWindow))] + public static class PlantInfoWindow_Patch + { + [HarmonyPatch(nameof(PlantInfoWindow.InitText))] + [HarmonyPostfix] + private static void InitText(PlantInfoWindow __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + PlantType thePlantType = __instance.plant.thePlantType; + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + if(txt.name.Contains("Introduce")) + { + string text = txt.text; + string[] lines = text.Split("\n"); + + lines[0] = Utils.GetPlantNameFromAlmanac(thePlantType); + string updatedText = String.Join("\n", lines); + + txt.text = StringStore.TranslateText(updatedText); + } + else + { + txt.text = StringStore.TranslateText(txt.text); + } + + txt.font = fontAsset; + } + + Transform parentWindowTransform = __instance.transform.parent; + Transform returnPlantTransform = parentWindowTransform.FindChild("Close"); + + foreach(TextMeshProUGUI txt in returnPlantTransform.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText("合上"); + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/TreasureConfirmMenu_Patch.cs b/BepInEx/Patches/GameObjects/TreasureConfirmMenu_Patch.cs new file mode 100644 index 0000000..5c7df14 --- /dev/null +++ b/BepInEx/Patches/GameObjects/TreasureConfirmMenu_Patch.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureConfirmMenu))] + public static class TreasureConfirmMenu_Patch + { + [HarmonyPatch(nameof(TreasureConfirmMenu.SetText))] + [HarmonyPostfix] + private static void SetText(TreasureConfirmMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/TreasureEquipmentMenu_Patch.cs b/BepInEx/Patches/GameObjects/TreasureEquipmentMenu_Patch.cs new file mode 100644 index 0000000..729ab03 --- /dev/null +++ b/BepInEx/Patches/GameObjects/TreasureEquipmentMenu_Patch.cs @@ -0,0 +1,37 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureEquipmentMenu))] + public static class TreasureEquipmentMenu_Patch + { + [HarmonyPatch(nameof(TreasureEquipmentMenu.Awake))] + [HarmonyPostfix] + private static void Awake(TreasureEquipmentMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureEquipmentMenu.UpdateCards))] + [HarmonyPostfix] + private static void UpdateCards(TreasureEquipmentMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/TreasureMainMenu_Patch.cs b/BepInEx/Patches/GameObjects/TreasureMainMenu_Patch.cs new file mode 100644 index 0000000..649af54 --- /dev/null +++ b/BepInEx/Patches/GameObjects/TreasureMainMenu_Patch.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureMainMenu))] + public static class TreasureMainMenu_Patch + { + [HarmonyPatch(nameof(TreasureMainMenu.Update))] + [HarmonyPostfix] + private static void Update(TreasureMainMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/TreasureStoreMenu_Patch.cs b/BepInEx/Patches/GameObjects/TreasureStoreMenu_Patch.cs new file mode 100644 index 0000000..7d11fe7 --- /dev/null +++ b/BepInEx/Patches/GameObjects/TreasureStoreMenu_Patch.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureStoreMenu))] + public static class TreasureStoreMenu_Patch + { + [HarmonyPatch(nameof(TreasureStoreMenu.InitCards))] + [HarmonyPostfix] + private static void InitCards(TreasureStoreMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs b/BepInEx/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs new file mode 100644 index 0000000..7f320d9 --- /dev/null +++ b/BepInEx/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs @@ -0,0 +1,51 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using System.Text.RegularExpressions; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureUpgradeMenu))] + public static class TreasureUpgradeMenu_Patch + { + [HarmonyPatch(nameof(TreasureUpgradeMenu.Start))] + [HarmonyPostfix] + private static void Start(TreasureUpgradeMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureUpgradeMenu.UpgradeWareHouse))] + [HarmonyPostfix] + private static void UpgradeWareHouse(TreasureUpgradeMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureUpgradeMenu.InitWareHouseUpgrade))] + [HarmonyPostfix] + private static void InitWareHouseUpgrade(TreasureUpgradeMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/TreasureWarehouseMenu_Patch.cs b/BepInEx/Patches/GameObjects/TreasureWarehouseMenu_Patch.cs new file mode 100644 index 0000000..235daba --- /dev/null +++ b/BepInEx/Patches/GameObjects/TreasureWarehouseMenu_Patch.cs @@ -0,0 +1,63 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureWarehouseMenu))] + public static class TreasureWarehouseMenu_Patch + { + [HarmonyPatch(nameof(TreasureWarehouseMenu.InitCards))] + [HarmonyPostfix] + private static void InitCards(TreasureWarehouseMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureWarehouseMenu.QuickSell))] + [HarmonyPostfix] + private static void QuickSell(TreasureWarehouseMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureWarehouseMenu.FastSell))] + [HarmonyPostfix] + private static void FastSell(TreasureWarehouseMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureWarehouseMenu.EnterStore))] + [HarmonyPostfix] + private static void EnterStore(TreasureWarehouseMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} diff --git a/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs b/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs index 3ece64f..4efcf36 100644 --- a/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs +++ b/BepInEx/Patches/Managers/AlmanacMgrZombie_Patch.cs @@ -62,54 +62,74 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers TextMeshPro component2 = __instance.zombieName.GetComponent(); TextMeshPro component3 = __instance.zombieName.transform.GetChild(0).GetComponent(); - AlmanacMgrZombie.ZombieAlmanacData zombieData = JsonUtility.FromJson(json); - - foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in zombieData.zombies) + try { - if (zombieInfo.theZombieType == __instance.theZombieType) - { - component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce; - component.overflowMode = TextOverflowModes.Page; - component2.text = zombieInfo.name; - component2.autoSizeTextContainer = true; - component3.text = Utils.RemoveColorTags(zombieInfo.name); - component3.autoSizeTextContainer = true; + AlmanacMgrZombie.ZombieAlmanacData zombieData = JsonUtility.FromJson(json); - if (hasAlmanacFont) - component.font = almanacFontAsset; - else - component.font = fontAsset; - component2.font = fontAsset; - component3.font = fontAsset; + if (zombieData != null && zombieData.zombies != null) + { + foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in zombieData.zombies) + { + if (zombieInfo.theZombieType == __instance.theZombieType) + { + component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce; + component.overflowMode = TextOverflowModes.Page; + component2.text = zombieInfo.name; + component2.autoSizeTextContainer = true; + component3.text = Utils.RemoveColorTags(zombieInfo.name); + component3.autoSizeTextContainer = true; + + if (hasAlmanacFont) + component.font = almanacFontAsset; + else + component.font = fontAsset; + component2.font = fontAsset; + component3.font = fontAsset; + } + } } } + catch (System.Exception ex) + { + Log.LogError($"Error parsing JSON in AlmanacMgrZombie_Patch: {ex.Message}"); + } if (File.Exists(moddedPath)) { - string moddedJson; - moddedJson = File.ReadAllText(moddedPath); - - AlmanacMgrZombie.ZombieAlmanacData moddedZombieData = JsonUtility.FromJson(moddedJson); - - foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in moddedZombieData.zombies) + try { - if (zombieInfo.theZombieType == __instance.theZombieType) - { - component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce; - component.overflowMode = TextOverflowModes.Page; - component2.text = zombieInfo.name; - component2.autoSizeTextContainer = true; - component3.text = Utils.RemoveColorTags(zombieInfo.name); - component3.autoSizeTextContainer = true; + string moddedJson; + moddedJson = File.ReadAllText(moddedPath); - if (hasAlmanacFont) - component.font = almanacFontAsset; - else - component.font = fontAsset; - component2.font = fontAsset; - component3.font = fontAsset; + AlmanacMgrZombie.ZombieAlmanacData moddedZombieData = JsonUtility.FromJson(moddedJson); + + if (moddedZombieData != null && moddedZombieData.zombies != null) + { + foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in moddedZombieData.zombies) + { + if (zombieInfo.theZombieType == __instance.theZombieType) + { + component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce; + component.overflowMode = TextOverflowModes.Page; + component2.text = zombieInfo.name; + component2.autoSizeTextContainer = true; + component3.text = Utils.RemoveColorTags(zombieInfo.name); + component3.autoSizeTextContainer = true; + + if (hasAlmanacFont) + component.font = almanacFontAsset; + else + component.font = fontAsset; + component2.font = fontAsset; + component3.font = fontAsset; + } + } } } + catch (System.Exception ex) + { + Log.LogError($"Error parsing modded JSON in AlmanacMgrZombie_Patch: {ex.Message}"); + } } DumpAlmanacModdedZombies(__instance); return; @@ -141,9 +161,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers if (Input.GetKey(KeyCode.LeftControl)) { FileLoader.DumpUntranslatedStrings(__instance.info.GetComponent().text); - Log.LogInfo($"Info: {__instance.info.GetComponent().text}"); + //Log.LogInfo($"Info: {__instance.info.GetComponent().text}"); FileLoader.DumpUntranslatedStrings(__instance.zombieName.GetComponent().text); - Log.LogInfo($"Zombie Name: {__instance.zombieName.GetComponent().text}"); + //Log.LogInfo($"Zombie Name: {__instance.zombieName.GetComponent().text}"); } } } diff --git a/BepInEx/Patches/Managers/Garden_Patch.cs b/BepInEx/Patches/Managers/Garden_Patch.cs new file mode 100644 index 0000000..6548f63 --- /dev/null +++ b/BepInEx/Patches/Managers/Garden_Patch.cs @@ -0,0 +1,21 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.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/BepInEx/Patches/Managers/InGameUI_Patch.cs b/BepInEx/Patches/Managers/InGameUI_Patch.cs index f1c4d88..72d2f39 100644 --- a/BepInEx/Patches/Managers/InGameUI_Patch.cs +++ b/BepInEx/Patches/Managers/InGameUI_Patch.cs @@ -90,40 +90,40 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers } } - [HarmonyPatch(nameof(InGameUI_IZ.Update))] - [HarmonyPostfix] - private static void Update(InGameUI_IZ __instance) - { - ApplyShovelBankTranslations(__instance.transform); - } + // [HarmonyPatch(nameof(InGameUI_IZ.Update))] + // [HarmonyPostfix] + // private static void Update(InGameUI_IZ __instance) + // { + // ApplyShovelBankTranslations(__instance.transform); + // } - private static void ApplyShovelBankTranslations(Transform root) - { - var shovelBank = root.Find("ShovelBank"); - if (!shovelBank) return; + // private static void ApplyShovelBankTranslations(Transform root) + // { + // var shovelBank = root.Find("ShovelBank"); + // if (!shovelBank) return; - string currentLanguage = Utils.Language.ToString(); - var fontAsset = FontStore.LoadTMPFont(currentLanguage); + // string currentLanguage = Utils.Language.ToString(); + // var fontAsset = FontStore.LoadTMPFont(currentLanguage); - for (int i = 0; i < shovelBank.childCount; i++) - { - var child = shovelBank.GetChild(i); - var tmp = child.GetComponent(); - if (tmp == null) continue; + // for (int i = 0; i < shovelBank.childCount; i++) + // { + // var child = shovelBank.GetChild(i); + // var tmp = child.GetComponent(); + // if (tmp == null) continue; - string orig = tmp.text; - string translated = StringStore.TranslateText(orig, false); - if (translated != orig) - { - tmp.text = translated; - if (fontAsset != null) tmp.font = fontAsset; - } - else - { - if (fontAsset != null) tmp.font = fontAsset; - } - } - } + // string orig = tmp.text; + // string translated = StringStore.TranslateText(orig, false); + // if (translated != orig) + // { + // tmp.text = translated; + // if (fontAsset != null) tmp.font = fontAsset; + // } + // else + // { + // if (fontAsset != null) tmp.font = fontAsset; + // } + // } + // } } } diff --git a/BepInEx/PvZ Fusion Translator [BepInEx].csproj b/BepInEx/PvZ Fusion Translator [BepInEx].csproj index 30886ec..c82c6f6 100644 --- a/BepInEx/PvZ Fusion Translator [BepInEx].csproj +++ b/BepInEx/PvZ Fusion Translator [BepInEx].csproj @@ -13,7 +13,7 @@ https://nuget.samboy.dev/v3/index.json PvZ_Fusion_Translator__BepInEx_ - C:\Users\rainb\Desktop\PC_PVZ-Fusion_2.8.2-BepInEx + D:\PvZ Fusion\BepInEx Game Files Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate;DebugMulti AnyCPU;x64 @@ -203,6 +203,19 @@ + + + + + + + + + + + + + diff --git a/BepInEx/Utils.cs b/BepInEx/Utils.cs index a5eb015..c46d525 100644 --- a/BepInEx/Utils.cs +++ b/BepInEx/Utils.cs @@ -112,6 +112,51 @@ namespace PvZ_Fusion_Translator__BepInEx_ newGoBackText.color = color; } + public static string GetPlantNameFromAlmanac(PlantType thePlantType) + { + string json; + string thePlantName = ""; + + string currentLanguage = Utils.Language.ToString(); + string almanacDir = FileLoader.GetAssetDir(FileLoader.AssetType.Almanac, Utils.Language); + 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}"); + Log.LogError("Plant name could not be found! (Big Garden)"); + thePlantName = ""; + } + else + { + try + { + json = File.ReadAllText(path); + AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); + if (plantData != null && plantData.plants != null) + { + foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants) + { + if (plantInfo.seedType == (int)thePlantType) + { + // Remove any ID numbers from the name (e.g., "Peashooter (0)" -> "Peashooter", "Peashooter26" -> "Peashooter") + thePlantName = System.Text.RegularExpressions.Regex.Replace(plantInfo.name, @"\s*\(\d+\)$|\d+$", ""); + break; + } + } + } + } + catch (System.Exception ex) + { + Log.LogError($"Error parsing JSON in GetPlantNameFromAlmanac: {ex.Message}"); + thePlantName = ""; + } + } + + return thePlantName; + } + #if MULTI_LANGUAGE internal static void ChangeLanguage(string language) { @@ -181,4 +226,5 @@ namespace PvZ_Fusion_Translator__BepInEx_ TOGGLE_END } } + } \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs b/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs index 0a3dc9b..faab9fe 100644 --- a/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs @@ -1,4 +1,5 @@ -using HarmonyLib; +using System.Numerics; +using HarmonyLib; using Il2Cpp; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; @@ -18,12 +19,17 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) { txt.text = StringStore.TranslateText(txt.text); - if(txt.name.Contains("Text (TMP)")) + } + + Transform randomLevelTextTransform = __instance.transform.FindChild("RandomLevel"); + foreach (TextMeshProUGUI txt in randomLevelTextTransform.GetComponentsInChildren()) + { + if (txt.name.Contains("Text (TMP)")) { txt.autoSizeTextContainer = true; - if(txt.name == "Text (TMP)") + if (txt.name == "Text (TMP)") { - txt.transform.localPosition = new Vector3(94.4225f, -45.1565f, 0f); + txt.transform.localPosition = new UnityEngine.Vector3(94.4225f, -45.1565f, 0f); } } } diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index c6c57b0..078fbbc 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.0 + D:\PvZ Fusion\Game Files AnyCPU;ARM64;x64