From 8930591cc57b1cb4d6057d2d56536d1881f642c5 Mon Sep 17 00:00:00 2001 From: TuanAnh2901 Date: Tue, 30 Sep 2025 03:55:51 +0700 Subject: [PATCH] Update BIE branch --- BepInEx/Core.cs | 7 + .../BaseTextObjects/TextMeshProUGUI_Patch.cs | 10 +- .../ButtonObjects/MainMenu_Btn_Patch.cs | 32 ++++ .../ButtonObjects/UIButton_Patch.cs | 5 +- .../GameObjects/ExploreEnterWindow_Patch.cs | 40 ++++- .../MinorObjects/TrainingDummy_Patch.cs | 4 +- .../GameObjects/MinorObjects/Zombie_Patch.cs | 50 +++++- .../GameObjects/PlantInfoWindow_Patch.cs | 4 +- .../Patches/GameObjects/SeedLibrary_Patch.cs | 36 +++++ .../GameObjects/TravelLookMenu_Patch.cs | 36 +++-- .../GameObjects/TreasureEvacuateMenu_Patch.cs | 30 ++++ .../GameObjects/TreasureUpgradeMenu_Patch.cs | 12 +- .../Managers/AlmanacPlantBank_Patch.cs | 2 +- BepInEx/Patches/Managers/InGameUI_Patch.cs | 29 +++- .../Patches/Managers/TreasureManager_Patch.cs | 31 ++++ .../PvZ Fusion Translator [BepInEx].csproj | 147 +++++++++--------- BepInEx/Utils.cs | 93 +++++++++++ 17 files changed, 455 insertions(+), 113 deletions(-) create mode 100644 BepInEx/Patches/GameObjects/ButtonObjects/MainMenu_Btn_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/SeedLibrary_Patch.cs create mode 100644 BepInEx/Patches/GameObjects/TreasureEvacuateMenu_Patch.cs create mode 100644 BepInEx/Patches/Managers/TreasureManager_Patch.cs diff --git a/BepInEx/Core.cs b/BepInEx/Core.cs index 5c9c98d..88de7d5 100644 --- a/BepInEx/Core.cs +++ b/BepInEx/Core.cs @@ -48,6 +48,9 @@ public class Core : BasePlugin TextureStore.Init(); StringStore.Init(); FontStore.Init(); + // Register plant indices for fast lookups and load HP regexes + Utils.RegisterPlantIndices(); + PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects.Zombie_Patch.LoadHPStrings(); InitCoroutine(); } @@ -92,6 +95,10 @@ public class Core : BasePlugin Log.LogInfo("del del"); Utils.OpenTrello(); } + if (Input.GetKeyDown(KeyCode.P)) + { + Time.timeScale = 0; + } if (TowerManager.Instance != null) { TowerManager_Patch.UpdateText(); diff --git a/BepInEx/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs b/BepInEx/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs index 4046f6a..94fa8fc 100644 --- a/BepInEx/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs +++ b/BepInEx/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs @@ -47,17 +47,17 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.BaseTextObjects __instance = StringStore.TranslateText(__instance); __instance.autoSizeTextContainer = false; - if (__instance.name.StartsWith("LevelName")) - { - __instance.text = __instance.text.Replace("\n", " "); - } + if (__instance.name.StartsWith("LevelName")) + { + __instance.text = __instance.text.Replace("\n", " "); + } if (__instance.transform.parent != null && __instance.transform.parent.name.StartsWith("Window")) { __instance.fontSizeMin = 10; __instance.fontSize = 12; } - if (__instance.text == "Полный Хаосs" && __instance.transform.parent.parent.Find("Image").GetComponent().activeSprite.name == "Present") + if (__instance.text == "Полный Хаос" && __instance.transform.parent.parent.Find("Image").GetComponent().activeSprite.name == "Present") { __instance.text += "\nБесконечно"; } diff --git a/BepInEx/Patches/GameObjects/ButtonObjects/MainMenu_Btn_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/MainMenu_Btn_Patch.cs new file mode 100644 index 0000000..de4cfd2 --- /dev/null +++ b/BepInEx/Patches/GameObjects/ButtonObjects/MainMenu_Btn_Patch.cs @@ -0,0 +1,32 @@ +using HarmonyLib; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects +{ + [HarmonyPatch(typeof(MainMenu_Btn))] + public static class MainMenu_Btn_Patch + { + [HarmonyPatch(nameof(MainMenu_Btn.OnMouseEnter))] + [HarmonyPostfix] + private static void OnMouseEnter(MainMenu_Btn __instance) + { + string textToShow = null; + + if (__instance.transform.parent.name == "recipe") + { + textToShow = "探索模式"; + } + else if (__instance.name == "mysterious") + { + textToShow = "神秘模式"; + } + + if (textToShow != null) + { + InGameText.Instance.ShowText(textToShow, 2.0f); + } + } + } +} + + diff --git a/BepInEx/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index 56839ff..de58356 100644 --- a/BepInEx/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs +++ b/BepInEx/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -27,7 +27,10 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); textShadow.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true; + if(!text.name.Contains("_EVACUATE")) + { + text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true; + } } else { diff --git a/BepInEx/Patches/GameObjects/ExploreEnterWindow_Patch.cs b/BepInEx/Patches/GameObjects/ExploreEnterWindow_Patch.cs index b7d3953..f0d6b94 100644 --- a/BepInEx/Patches/GameObjects/ExploreEnterWindow_Patch.cs +++ b/BepInEx/Patches/GameObjects/ExploreEnterWindow_Patch.cs @@ -15,12 +15,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { PlantType thePlantType = (PlantType)__instance.selfType; - foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) - { - StringStore.TranslateText(txt); - } - __instance.nameText.text = Utils.GetPlantNameFromAlmanac(thePlantType); + if (__instance.nameText.text == "") + { + __instance.nameText.text = StringStore.TranslateText(__instance.nameText.text); + } + __instance.nameText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); } [HarmonyPatch(nameof(ExploreEnterWindow.SetInfo))] @@ -29,12 +29,38 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { PlantType thePlantType = (PlantType)__instance.selfType; - foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + __instance.nameText.text = Utils.GetPlantNameFromAlmanac(thePlantType); + if (__instance.nameText.text == "") { - StringStore.TranslateText(txt); + __instance.nameText.text = StringStore.TranslateText(__instance.nameText.text); } + __instance.nameText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + + [HarmonyPatch(nameof(ExploreEnterWindow.SetIcon))] + [HarmonyPostfix] + private static void SetIcon(ExploreEnterWindow __instance) + { + PlantType thePlantType = (PlantType)__instance.selfType; __instance.nameText.text = Utils.GetPlantNameFromAlmanac(thePlantType); + if (__instance.nameText.text == "") + { + __instance.nameText.text = StringStore.TranslateText(__instance.nameText.text); + } + __instance.nameText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + + [HarmonyPatch(nameof(ExploreEnterWindow.SetDisable))] + [HarmonyPostfix] + private static void SetDisable(ExploreEnterWindow __instance) + { + if (__instance.disabled) + { + __instance.nameText.text = StringStore.TranslateText("敬请期待"); + } + + __instance.nameText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); } } } diff --git a/BepInEx/Patches/GameObjects/MinorObjects/TrainingDummy_Patch.cs b/BepInEx/Patches/GameObjects/MinorObjects/TrainingDummy_Patch.cs index fd98134..a28a6d5 100644 --- a/BepInEx/Patches/GameObjects/MinorObjects/TrainingDummy_Patch.cs +++ b/BepInEx/Patches/GameObjects/MinorObjects/TrainingDummy_Patch.cs @@ -9,8 +9,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects [HarmonyPostfix] public static void UpdateHealthText(TrainingDummy __instance) { - Zombie_Patch.TranslateHpUI(__instance.healthText); - Zombie_Patch.TranslateHpUI(__instance.healthTextShadow); + Zombie_Patch.TranslateHpUI(__instance.healthText, null); + Zombie_Patch.TranslateHpUI(__instance.healthTextShadow, null); } } } \ No newline at end of file diff --git a/BepInEx/Patches/GameObjects/MinorObjects/Zombie_Patch.cs b/BepInEx/Patches/GameObjects/MinorObjects/Zombie_Patch.cs index 4ee5f32..48289f2 100644 --- a/BepInEx/Patches/GameObjects/MinorObjects/Zombie_Patch.cs +++ b/BepInEx/Patches/GameObjects/MinorObjects/Zombie_Patch.cs @@ -14,9 +14,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects { private static Dictionary HPStrings = new Dictionary() { - { "最后一击:(\\d+)\nDPS:(.+)$", "Last damage: {0}\nDPS: {1}" }, - { "^HP:(\\d+)/(\\d+)\n\\D+(\\d+)/(\\d+)\n\\D+(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 1 armor: {2}/{3}\nType 2 armor: {4}/{5}" }, - { "^HP:(\\d+)/(\\d+)\n\\D+(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 1 armor: {2}/{3}" }, + { "最后一击:(\\d+)\nDPS:([^\\s]+)\n总伤害:(\\d+)", "Last Damage: {0}\nDPS: {1}\nTotal: {2}" }, + { "^HP:(\\d+)/(\\d+)\n一类:(\\d+)/(\\d+)\n二类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 1 armor: {2}/{3}\nType 2 armor: {4}/{5}" }, + { "^HP:(\\d+)/(\\d+)\n一类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 1 armor: {2}/{3}" }, { "^HP:(\\d+)/(\\d+)$", "HP: {0}/{1}" }, }; @@ -59,12 +59,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects __instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f); } - public static void TranslateHpUI(TextMeshPro textTMP) + public static void TranslateHpUI(TextMeshPro textTMP, Zombie __instance = null) { if (textTMP) { string origText = textTMP.text; - string translatedText = TranslateHPText(origText); + string translatedText = __instance == null ? TranslateHPText(origText) : TranslateHPText(origText, __instance); textTMP.text = translatedText == origText ? origText : translatedText; textTMP.autoSizeTextContainer = false; if (translatedText != origText) @@ -97,5 +97,45 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects } return originalText; } + + public static string TranslateHPText(string originalText, Zombie __instance) + { + string finalText = __instance.healthText.text; + int fIndex = -1; + bool found = false; + + for (int i = 0; i < HPStrings.Count; i++) + { + var hp = HPStrings.ElementAt(i); + Regex regex = new Regex(hp.Key); + if (regex.IsMatch(originalText)) + { + fIndex = i; + found = true; + } + } + + if (fIndex > -1 && found) + { + string fStr = HPStrings.ElementAt(fIndex).Value; + + switch (fIndex) + { + case 1: + finalText = string.Format(fStr, __instance.theHealth, __instance.theMaxHealth, __instance.theFirstArmorHealth, __instance.theFirstArmorMaxHealth, __instance.theSecondArmorHealth, __instance.theSecondArmorMaxHealth); + break; + case 2: + finalText = string.Format(fStr, __instance.theHealth, __instance.theMaxHealth, __instance.theFirstArmorHealth, __instance.theFirstArmorMaxHealth); + break; + case 3: + finalText = string.Format(fStr, __instance.theHealth, __instance.theMaxHealth); + break; + default: + break; + } + } + + return finalText; + } } } \ No newline at end of file diff --git a/BepInEx/Patches/GameObjects/PlantInfoWindow_Patch.cs b/BepInEx/Patches/GameObjects/PlantInfoWindow_Patch.cs index a57fe8f..13ceea3 100644 --- a/BepInEx/Patches/GameObjects/PlantInfoWindow_Patch.cs +++ b/BepInEx/Patches/GameObjects/PlantInfoWindow_Patch.cs @@ -23,13 +23,15 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { if(txt.name.Contains("Introduce")) { + txt.text = StringStore.TranslateText(txt.text); + 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); + txt.text = updatedText; } else { diff --git a/BepInEx/Patches/GameObjects/SeedLibrary_Patch.cs b/BepInEx/Patches/GameObjects/SeedLibrary_Patch.cs new file mode 100644 index 0000000..f2ba774 --- /dev/null +++ b/BepInEx/Patches/GameObjects/SeedLibrary_Patch.cs @@ -0,0 +1,36 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(SeedLibrary))] + public static class SeedLibrary_Patch + { + [HarmonyPatch(nameof(SeedLibrary.ChangeSafeMode))] + [HarmonyPostfix] + private static void ChangeSafeMode(SeedLibrary __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + + Transform safetyBoxButtonTransform = __instance.transform.Find("SafeBox").Find("StartSafeMode"); + + if (__instance.safeMode == false && safetyBoxButtonTransform != null) + { + foreach (TextMeshProUGUI txt in safetyBoxButtonTransform.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText("合上"); + } + } + } + } +} + + diff --git a/BepInEx/Patches/GameObjects/TravelLookMenu_Patch.cs b/BepInEx/Patches/GameObjects/TravelLookMenu_Patch.cs index ad915cd..6eeb4a2 100644 --- a/BepInEx/Patches/GameObjects/TravelLookMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/TravelLookMenu_Patch.cs @@ -9,25 +9,37 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects [HarmonyPatch(typeof(TravelLookMenu))] public static class TravelLookMenu_Patch { + public static string savedAssetString = ""; + [HarmonyPatch(nameof(TravelLookMenu.Start))] [HarmonyPostfix] private static void Postfix_Start(TravelLookMenu __instance) { - Transform quitButtonTransform = __instance.transform.Find("Quit"); - if (quitButtonTransform != null) + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) { - TextMeshProUGUI[] allTexts = quitButtonTransform.GetComponentsInChildren(true); + txt.text = StringStore.TranslateText(txt.text); + txt.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } - foreach (var textComp in allTexts) - { - if (textComp != null && textComp.text == StringStore.TranslateText("关闭")) - { - textComp.text = StringStore.TranslateText("关闭_close"); + Transform quitButtonTransform = __instance.transform.Find("Quit"); + foreach (TextMeshProUGUI txt in quitButtonTransform.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText("合上"); + txt.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } - TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - textComp.font = fontAsset; - } - } + __instance.treasureText.text = StringStore.TranslateText(__instance.treasureText.text); + savedAssetString = __instance.treasureText.text; + } + + [HarmonyPatch(nameof(TravelLookMenu.Update))] + [HarmonyPostfix] + private static void Update(TravelLookMenu __instance) + { + if (savedAssetString != __instance.treasureText.text) + { + __instance.treasureText.text = StringStore.TranslateText(__instance.treasureText.text); + savedAssetString = __instance.treasureText.text; } } } diff --git a/BepInEx/Patches/GameObjects/TreasureEvacuateMenu_Patch.cs b/BepInEx/Patches/GameObjects/TreasureEvacuateMenu_Patch.cs new file mode 100644 index 0000000..a399829 --- /dev/null +++ b/BepInEx/Patches/GameObjects/TreasureEvacuateMenu_Patch.cs @@ -0,0 +1,30 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureEvacuateMenu))] + public static class TreasureEvacuateMenu_Patch + { + [HarmonyPatch(nameof(TreasureEvacuateMenu.Start))] + [HarmonyPostfix] + private static void Start(TreasureEvacuateMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + if (txt.name.Contains("text (1)")) + { + txt.name = txt.name + "_EVACUATE"; + } + } + } + } +} + + diff --git a/BepInEx/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs b/BepInEx/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs index 7f320d9..b3990ab 100644 --- a/BepInEx/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs @@ -3,6 +3,7 @@ using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; using System.Text.RegularExpressions; using UnityEngine; +using UnityEngine.UI; namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { @@ -46,6 +47,15 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects txt.text = StringStore.TranslateText(txt.text); txt.font = fontAsset; } + + foreach (Text txt in __instance.GetComponentsInChildren()) + { + GameObject newTxtObj = Utils.ConvertToTextMeshProUGUI(txt.gameObject, txt.transform.parent, "text"); + TextMeshProUGUI newTxt = newTxtObj.GetComponent(); + newTxt.text = StringStore.TranslateText("植物商店"); + newTxt.autoSizeTextContainer = true; + newTxt.color = new Color(0, 0, 0.3922f, 1); + } } } -} +} \ No newline at end of file diff --git a/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs b/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs index 74af07a..2148408 100644 --- a/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs +++ b/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs @@ -64,7 +64,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers Log.LogWarning($"Introduce text: {component?.text}"); Log.LogWarning($"Plant name: {component2?.text}"); #endif - component.text = component.text ?? string.Empty; + //component.text = component.text ?? string.Empty; AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); diff --git a/BepInEx/Patches/Managers/InGameUI_Patch.cs b/BepInEx/Patches/Managers/InGameUI_Patch.cs index 72d2f39..48b75e0 100644 --- a/BepInEx/Patches/Managers/InGameUI_Patch.cs +++ b/BepInEx/Patches/Managers/InGameUI_Patch.cs @@ -22,12 +22,29 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers __instance.transform.GetChild(5).GetChild(0).GetComponent(), __instance.transform.GetChild(6).GetComponent(), __instance.transform.GetChild(6).GetChild(0).GetComponent()}; - TextMeshProUGUI[] array2 = array; - for (int i = 0; i < array2.Length; i++) - { - array2[i] = StringStore.TranslateText(array2[i]); - array2[i].text = array2[i].text.Replace("\n", " "); - } + TextMeshProUGUI[] array2 = array; + for (int i = 0; i < array2.Length; i++) + { + array2[i].text = array2[i].text.Replace("\n", " "); + + if (array2[i].text.Contains("配方:")) + { + string[] lines = array2[i].text.Split(":"); + lines[1] = Utils.GetPlantNameFromAlmanac(lines[1]); + if (lines[1] == "") + { + Log.LogInfo("Couldn't find plant! (Fusion Showcase)"); + lines[1] = StringStore.TranslateText(lines[1]); + } + array2[i].text = StringStore.TranslateText("配方:") + lines[1]; + array2[i].autoSizeTextContainer = true; + } + else + { + array2[i] = StringStore.TranslateText(array2[i]); + array2[i].text = array2[i].text.Replace("\n", " "); + } + } } [HarmonyPatch(nameof(InGameUI.Update))] diff --git a/BepInEx/Patches/Managers/TreasureManager_Patch.cs b/BepInEx/Patches/Managers/TreasureManager_Patch.cs new file mode 100644 index 0000000..6375434 --- /dev/null +++ b/BepInEx/Patches/Managers/TreasureManager_Patch.cs @@ -0,0 +1,31 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers +{ + [HarmonyPatch(typeof(TreasureManager))] + public static class TreasureManager_Patch + { + [HarmonyPatch(nameof(TreasureManager.Update))] + [HarmonyPostfix] + private static void Update(TreasureManager __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.evaText) + { + txt.autoSizeTextContainer = false; + + if (txt.text != "Evacuate") + { + txt.text = StringStore.TranslateText(txt.text); + txt.name = txt.text + "_EVACUATE"; + txt.font = fontAsset; + } + } + } + } +} + + diff --git a/BepInEx/PvZ Fusion Translator [BepInEx].csproj b/BepInEx/PvZ Fusion Translator [BepInEx].csproj index c82c6f6..8d5aa8d 100644 --- a/BepInEx/PvZ Fusion Translator [BepInEx].csproj +++ b/BepInEx/PvZ Fusion Translator [BepInEx].csproj @@ -107,6 +107,7 @@ + @@ -117,105 +118,107 @@ - - - - - - - - - - - + + + + - + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BepInEx/Utils.cs b/BepInEx/Utils.cs index c564633..295b479 100644 --- a/BepInEx/Utils.cs +++ b/BepInEx/Utils.cs @@ -11,11 +11,57 @@ using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.UI; using static PvZ_Fusion_Translator__BepInEx_.FileLoader; +using System.Collections.Generic; namespace PvZ_Fusion_Translator__BepInEx_ { public class Utils { + public static Dictionary> plantIndices = new Dictionary>(); + + public static void RegisterPlantIndices() + { + plantIndices = new Dictionary>(); + string originalJson; + string translatedJson; + + string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); + string dumpDir = GetAssetDir(AssetType.Dumps); + string originalPath = Path.Combine(dumpDir, "LawnStrings.json"); + string path = Path.Combine(almanacDir, "LawnStringsTranslate.json"); + + if ((!File.Exists(path)) || (!File.Exists(originalPath))) + { + Log.LogError($"LawnStringsTranslate.json file not found at path: {path}"); + } + else + { + originalJson = File.ReadAllText(originalPath); + translatedJson = File.ReadAllText(path); + AlmanacPlantBank.PlantData originalPlantData = JsonUtility.FromJson(originalJson); + AlmanacPlantBank.PlantData translatedPlantData = JsonUtility.FromJson(translatedJson); + + for (int i = 0; i < originalPlantData.plants.Count; i++) + { + var originalPlantInfo = originalPlantData.plants[i]; + AlmanacPlantBank.PlantInfo translatedPlantInfo = null; + + foreach (var info in translatedPlantData.plants) + { + if (info.seedType == originalPlantInfo.seedType) + { + translatedPlantInfo = info; + } + } + + if (translatedPlantInfo != null) + { + var temp = new KeyValuePair(translatedPlantInfo.seedType, translatedPlantInfo.name); + plantIndices.Add(originalPlantInfo.seedType, temp); + } + } + } + } internal static bool TryReplaceTexture2D(Texture2D ogTexture) { if (ogTexture != null) @@ -198,6 +244,53 @@ namespace PvZ_Fusion_Translator__BepInEx_ return thePlantName; } + public static string GetPlantNameFromAlmanac(string theOriginalPlantName) + { + string originalJson; + string translatedJson; + string thePlantName = ""; + + string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); + string dumpDir = GetAssetDir(AssetType.Dumps); + string originalPath = Path.Combine(dumpDir, "LawnStrings.json"); + string path = Path.Combine(almanacDir, "LawnStringsTranslate.json"); + + if ((!File.Exists(path)) || (!File.Exists(originalPath))) + { + Log.LogError($"LawnStringsTranslate.json file not found at path: {path}"); + thePlantName = ""; + } + else + { + bool foundPlantName = false; + + originalJson = File.ReadAllText(originalPath); + translatedJson = File.ReadAllText(path); + AlmanacPlantBank.PlantData originalPlantData = JsonUtility.FromJson(originalJson); + AlmanacPlantBank.PlantData translatedPlantData = JsonUtility.FromJson(translatedJson); + + for (int i = 0; i < originalPlantData.plants.Count; i++) + { + var originalPlantInfo = originalPlantData.plants[i]; + KeyValuePair translatedPlantInfo = plantIndices[originalPlantInfo.seedType]; + + if (originalPlantInfo.name == theOriginalPlantName) + { + thePlantName = translatedPlantInfo.Value; + foundPlantName = true; + } + } + + if (!foundPlantName) + { + Log.LogInfo("Couldn't find plant name!"); + thePlantName = ""; + } + } + + return thePlantName; + } + #if MULTI_LANGUAGE internal static void ChangeLanguage(string language) {