diff --git a/BepInEx/Core.cs b/BepInEx/Core.cs index d674cf8..d37b7f4 100644 --- a/BepInEx/Core.cs +++ b/BepInEx/Core.cs @@ -13,7 +13,7 @@ using System.IO; using System.Reflection; using UnityEngine; -[BepInPlugin("PVZFusionTranslator_BepInEx", "PvZ Fusion Translator", "2.8.1")] +[BepInPlugin("PVZFusionTranslator_BepInEx", "PvZ Fusion Translator", "3.0.1")] [BepInProcess("PlantsVsZombiesRH.exe")] public class Core : BasePlugin { diff --git a/BepInEx/Patches/GameObjects/AbyssBagMenu_Patch.cs b/BepInEx/Patches/GameObjects/AbyssBagMenu_Patch.cs index d2800f3..d363dae 100644 --- a/BepInEx/Patches/GameObjects/AbyssBagMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/AbyssBagMenu_Patch.cs @@ -14,16 +14,15 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { [HarmonyPatch(nameof(AbyssBagMenu.Awake))] [HarmonyPostfix] - private static void MoveFromBag(AbyssCheckInBag __instance) + private static void Awake_Post(AbyssCheckInBag __instance) { - AbyssMenu2.Instance.UpdateIcons(); - Utils.ConvertButtonText(__instance.transform, "Goback"); - foreach (TextMeshProUGUI text in __instance.transform.FindChild("Background").GetComponentsInChildren()) { + text.text = text.text + "_深渊"; text.text = StringStore.TranslateText("背包_深渊"); text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); } + AbyssMenu2.Instance.UpdateIcons(); } } } diff --git a/BepInEx/Patches/GameObjects/AbyssMenu2_Patch.cs b/BepInEx/Patches/GameObjects/AbyssMenu2_Patch.cs index 2a0763e..7ba42ee 100644 --- a/BepInEx/Patches/GameObjects/AbyssMenu2_Patch.cs +++ b/BepInEx/Patches/GameObjects/AbyssMenu2_Patch.cs @@ -63,6 +63,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects UpdateAbyss2Text(__instance); Utils.ConvertButtonText(__instance.transform, "Help"); + + // custom bag text :D + + __instance.transform.FindChild("Bag").FindChild("text").GetComponent().text += "_深渊"; + Utils.ConvertButtonText(__instance.transform, "Bag"); } diff --git a/BepInEx/Patches/GameObjects/ButtonObjects/CustomLevelEnter_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/CustomLevelEnter_Patch.cs index a4029f7..e1fe940 100644 --- a/BepInEx/Patches/GameObjects/ButtonObjects/CustomLevelEnter_Patch.cs +++ b/BepInEx/Patches/GameObjects/ButtonObjects/CustomLevelEnter_Patch.cs @@ -7,32 +7,33 @@ using System.Linq; namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects { - [HarmonyPatch(typeof(CustomLevelEnter))] - public static class CustomLevelEnter_Patch + [HarmonyPatch(typeof(CustomLevelEnter))] + public static class CustomLevelEnter_Patch { - [HarmonyPatch(nameof(CustomLevelEnter.Start))] - [HarmonyPostfix] - private static void Show(CustomLevelEnter __instance) - { + [HarmonyPatch(nameof(CustomLevelEnter.Start))] + [HarmonyPostfix] + private static void Show(CustomLevelEnter __instance) + { TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren()) - { - string text = txt.text; - Transform menuTransform = __instance.transform.parent.parent.parent.parent.parent.parent; - string customIZStringKey = StringStore.translationString.FirstOrDefault(x => x.Value == text).Key + "_IZ"; - bool hasCustomIZString = StringStore.translationString.ContainsKey(customIZStringKey); + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + string text = txt.text; + Transform menuTransform = __instance.transform.parent.parent.parent.parent.parent.parent; // guys i'm really sorry please forgive me + string customIZStringKey = StringStore.translationString.FirstOrDefault(x => x.Value == text).Key + "_IZ"; // dawg what the fuck + bool hasCustomIZString = StringStore.translationString.ContainsKey(customIZStringKey); - if (hasCustomIZString && menuTransform.name.Contains("IZMenu")) - { - txt.text = StringStore.TranslateText(customIZStringKey); - } - else - { - txt.text = StringStore.TranslateText(text); - } - txt.font = fontAsset; + if (hasCustomIZString && menuTransform.name.Contains("IZMenu")) + { + txt.text = StringStore.TranslateText(customIZStringKey); + } + else + { + txt.text = StringStore.TranslateText(text); + } + + txt.font = fontAsset; } - } - } + } + } } diff --git a/BepInEx/Patches/GameObjects/ButtonObjects/MainMenu_Btn_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/MainMenu_Btn_Patch.cs index de4cfd2..15b67f5 100644 --- a/BepInEx/Patches/GameObjects/ButtonObjects/MainMenu_Btn_Patch.cs +++ b/BepInEx/Patches/GameObjects/ButtonObjects/MainMenu_Btn_Patch.cs @@ -6,26 +6,26 @@ 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; + //[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 (__instance.transform.parent.name == "recipe") + // { + // textToShow = "探索模式"; + // } + // else if (__instance.name == "mysterious") + // { + // textToShow = "神秘模式"; + // } - if (textToShow != null) - { - InGameText.Instance.ShowText(textToShow, 2.0f); - } - } + // if (textToShow != null) + // { + // InGameText.Instance.ShowText(textToShow, 2.0f); + // } + //} } } diff --git a/BepInEx/Patches/GameObjects/MinorObjects/TrainingDummy_Patch.cs b/BepInEx/Patches/GameObjects/MinorObjects/TrainingDummy_Patch.cs index a28a6d5..3b34a5a 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, null); - Zombie_Patch.TranslateHpUI(__instance.healthTextShadow, null); + Zombie_Patch.TranslateHpUI_T(__instance.healthText, __instance); + Zombie_Patch.TranslateHpUI_T(__instance.healthTextShadow, __instance); } } } \ 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 48289f2..d74a9cd 100644 --- a/BepInEx/Patches/GameObjects/MinorObjects/Zombie_Patch.cs +++ b/BepInEx/Patches/GameObjects/MinorObjects/Zombie_Patch.cs @@ -17,6 +17,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects { "最后一击:(\\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+)\n二类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 2 armor: {2}/{3}" }, { "^HP:(\\d+)/(\\d+)$", "HP: {0}/{1}" }, }; @@ -31,13 +32,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects [HarmonyPostfix] public static void Start(Zombie __instance) { - TranslateHpUI(__instance.healthText); - TranslateHpUI(__instance.healthTextShadow); - if (__instance.theFirstArmorHealth == 0 && __instance.theSecondArmorHealth != 0) - { - __instance.healthText.text = __instance.healthText.text.Replace("Type 1", "Type 2"); - __instance.healthTextShadow.text = __instance.healthText.text.Replace("Type 1", "Type 2"); - } + TranslateHpUI(__instance.healthText, __instance); + TranslateHpUI(__instance.healthTextShadow, __instance); + if (__instance.healthText.transform.rotation != Quaternion.Euler(0, 0, 0)) __instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f); } @@ -48,23 +45,19 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects { if (__instance.theZombieType == ZombieType.TrainingDummy || !Board.Instance.showZombieHealth) return; - TranslateHpUI(__instance.healthText); - TranslateHpUI(__instance.healthTextShadow); - if (__instance.theFirstArmorHealth == 0 && __instance.theSecondArmorHealth != 0) - { - __instance.healthText.text = __instance.healthText.text.Replace("Type 1", "Type 2"); - __instance.healthTextShadow.text = __instance.healthText.text.Replace("Type 1", "Type 2"); - } + TranslateHpUI(__instance.healthText, __instance); + TranslateHpUI(__instance.healthTextShadow, __instance); + if (__instance.healthText.transform.rotation != Quaternion.Euler(0f, 0f, 0f)) __instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f); } - public static void TranslateHpUI(TextMeshPro textTMP, Zombie __instance = null) + public static void TranslateHpUI(TextMeshPro textTMP, Zombie __instance) { if (textTMP) { string origText = textTMP.text; - string translatedText = __instance == null ? TranslateHPText(origText) : TranslateHPText(origText, __instance); + string translatedText = TranslateHPText(origText, __instance); textTMP.text = translatedText == origText ? origText : translatedText; textTMP.autoSizeTextContainer = false; if (translatedText != origText) @@ -72,30 +65,95 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects } } - public static string TranslateHPText(string originalText) + public static void TranslateHpUI_T(TextMeshPro textTMP, TrainingDummy __instance) { - foreach (var entry in HPStrings) + if (textTMP) { - var regex = new Regex(entry.Key); + string origText = textTMP.text; + string translatedText = TranslateHPText_T(origText, __instance); + textTMP.text = translatedText == origText ? origText : translatedText; + textTMP.autoSizeTextContainer = false; + if (translatedText != origText) + textTMP.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + + 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)) { - var match = regex.Match(originalText); - int groupCount = match.Groups.Count; - - List dynamicParts = new List(); - - for (int i = 1; i < groupCount; i++) - { - string groupValue = match.Groups[i].Value; - string translatedValue = StringStore.translationString.ContainsKey(groupValue) - ? StringStore.translationString[groupValue] - : groupValue; - dynamicParts.Add(translatedValue); - } - return originalText = string.Format(entry.Value, [.. dynamicParts]); + fIndex = i; + found = true; } } - return originalText; + + 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, __instance.theSecondArmorHealth, __instance.theSecondArmorMaxHealth); + break; + case 4: + finalText = string.Format(fStr, __instance.theHealth, __instance.theMaxHealth); + break; + default: + break; + } + } + + return finalText; + } + + public static string TranslateHPText_T(string originalText, TrainingDummy __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; + string DPS = originalText.Split("\n")[1].Replace("DPS:", ""); + + switch (fIndex) + { + case 0: + finalText = string.Format(fStr, __instance.lastDamage, DPS, __instance.totalDamage); + break; + default: + break; + } + } + + return finalText; } public static string TranslateHPText(string originalText, Zombie __instance) diff --git a/BepInEx/Patches/GameObjects/TravelStore_Patch.cs b/BepInEx/Patches/GameObjects/TravelStore_Patch.cs index c29a8ee..9a4d339 100644 --- a/BepInEx/Patches/GameObjects/TravelStore_Patch.cs +++ b/BepInEx/Patches/GameObjects/TravelStore_Patch.cs @@ -7,17 +7,17 @@ using System.Linq; namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { - [HarmonyPatch(typeof(TravelStore))] + [HarmonyPatch(typeof(TravelStore))] public static class TravelStore_Patch { [HarmonyPatch(nameof(TravelStore.Update))] - [HarmonyPostfix] - private static void Update(TravelStore __instance) + [HarmonyPostfix] + private static void Update(TravelStore __instance) { foreach (TextMeshProUGUI intr in __instance.introduces) - StringStore.TranslateTextUI(intr); + intr.text = StringStore.TranslateText(intr.text); foreach (var textMesh in __instance.points) - StringStore.TranslateTextUI(textMesh); + textMesh.text = StringStore.TranslateText(textMesh.text); } [HarmonyPatch(nameof(TravelStore.RefreshBuff))] @@ -27,7 +27,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects foreach (TravelBuff buff in __instance.travelBuffs) { TextMeshProUGUI cost = buff.transform.GetChild(1).GetComponent(); - StringStore.TranslateTextUI(cost); + cost.text = StringStore.TranslateText(cost.text); cost.font = FontStore.LoadTMPFont(Utils.Language.ToString()); FileLoader.DumpUntranslatedStrings(cost.text); } diff --git a/BepInEx/Patches/Managers/IZBottomMenu_Patch.cs b/BepInEx/Patches/Managers/IZBottomMenu_Patch.cs index 628ae9a..c704832 100644 --- a/BepInEx/Patches/Managers/IZBottomMenu_Patch.cs +++ b/BepInEx/Patches/Managers/IZBottomMenu_Patch.cs @@ -21,15 +21,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers ]; for (int i = 0; i < array.Length; i++) { - string pattern = "([^\\s]+),推荐难度:(\\d+)"; + string fStr = StringStore.translationStringRegex["([^\\s]+),推荐难度:(\\d+)"]; string[] parts = array[i].text.Split(",推荐难度:"); - if (new Regex(pattern).IsMatch(array[i].text)) + if (new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text)) { - if (StringStore.translationStringRegex.TryGetValue(pattern, out string fmt)) - { - array[i].text = string.Format(fmt, StringStore.TranslateText(parts[0]), parts[1]); - } + array[i].text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]); } array[i] = StringStore.TranslateText(array[i]); @@ -48,15 +45,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers ]; for (int i = 0; i < array.Length; i++) { - string pattern = "([^\\s]+),推荐难度:(\\d+)"; + string fStr = StringStore.translationStringRegex["([^\\s]+),推荐难度:(\\d+)"]; string[] parts = array[i].text.Split(",推荐难度:"); - if (new Regex(pattern).IsMatch(array[i].text)) + if (new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text)) { - if (StringStore.translationStringRegex.TryGetValue(pattern, out string fmt)) - { - array[i].text = string.Format(fmt, StringStore.TranslateText(parts[0]), parts[1]); - } + array[i].text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]); } array[i] = StringStore.TranslateText(array[i]); diff --git a/BepInEx/Patches/Managers/InGameUI_Patch.cs b/BepInEx/Patches/Managers/InGameUI_Patch.cs index 753f06f..d88bf54 100644 --- a/BepInEx/Patches/Managers/InGameUI_Patch.cs +++ b/BepInEx/Patches/Managers/InGameUI_Patch.cs @@ -8,25 +8,24 @@ using UnityEngine; namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers { [HarmonyPatch(typeof(InGameUI))] - public static class InGameUI_Patch - { - [HarmonyPatch(nameof(InGameUI.Start))] - [HarmonyPostfix] - private static void Start(InGameUI __instance) - { - TextMeshProUGUI[] array = new TextMeshProUGUI[] - { - __instance.transform.GetChild(4).GetComponent(), - __instance.transform.GetChild(4).GetChild(0).GetComponent(), - __instance.transform.GetChild(5).GetComponent(), - __instance.transform.GetChild(5).GetChild(0).GetComponent(), - __instance.transform.GetChild(6).GetComponent(), - __instance.transform.GetChild(6).GetChild(0).GetComponent()}; + public static class InGameUI_Patch + { + [HarmonyPatch(nameof(InGameUI.Start))] + [HarmonyPostfix] + private static void Start(InGameUI __instance) + { + TextMeshProUGUI[] array = new TextMeshProUGUI[] + { + __instance.transform.GetChild(4).GetComponent(), + __instance.transform.GetChild(4).GetChild(0).GetComponent(), + __instance.transform.GetChild(5).GetComponent(), + __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].text = array2[i].text.Replace("\n", " "); - Regex checkFusionChallenge = new Regex("^超级([^\\s:]+)(:?挑战1?)"); if (array2[i].text.Contains("配方:") && !checkFusionChallenge.IsMatch(array2[i].text)) @@ -47,102 +46,6 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers array2[i].text = array2[i].text.Replace("\n", " "); } } - } - - [HarmonyPatch(nameof(InGameUI.Update))] - [HarmonyPostfix] - private static void Update(InGameUI __instance) - { - ApplyShovelBankTranslations(__instance.transform); - } - - private static void ApplyShovelBankTranslations(Transform root) - { - var shovelBank = root.Find("ShovelBank"); - if (!shovelBank) return; - - 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; - - 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; - } - } - } - } - - [HarmonyPatch(typeof(InGameUI_IZ))] - public static class InGameUI_IZ_Patch - { - [HarmonyPatch(nameof(InGameUI_IZ.Awake))] - [HarmonyPostfix] - private static void Awake(InGameUI_IZ __instance) - { - TextMeshProUGUI[] array = new TextMeshProUGUI[] - { - __instance.transform.GetChild(4).GetComponent(), - __instance.transform.GetChild(4).GetChild(0).GetComponent(), - __instance.transform.GetChild(5).GetComponent(), - __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", " "); - } - } - - // [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; - - // 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; - - // 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/Utils.cs b/BepInEx/Utils.cs index 98a2e9b..0c54af1 100644 --- a/BepInEx/Utils.cs +++ b/BepInEx/Utils.cs @@ -1,4 +1,8 @@ -using System; +using BepInEx; +using BepInEx.Configuration; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text.RegularExpressions; @@ -10,8 +14,8 @@ using Unity.VisualScripting.FullSerializer; using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.UI; +using static AlmanacPlantBank; using static PvZ_Fusion_Translator__BepInEx_.FileLoader; -using System.Collections.Generic; namespace PvZ_Fusion_Translator__BepInEx_ { @@ -166,51 +170,6 @@ 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; - //} - public static string GetPlantNameFromAlmanac(PlantType thePlantType) { string json; @@ -219,12 +178,11 @@ namespace PvZ_Fusion_Translator__BepInEx_ 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"); if (!File.Exists(path)) { Log.LogError($"LawnStringsTranslate.json file not found at path: {path}"); - Log.LogError("Plant name could not be found! (Big Garden)"); + Log.LogError("Plant name could not be found!"); thePlantName = ""; } else @@ -250,6 +208,7 @@ namespace PvZ_Fusion_Translator__BepInEx_ string translatedJson; string thePlantName = ""; + string currentLanguage = Utils.Language.ToString(); string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); string dumpDir = GetAssetDir(AssetType.Dumps); string originalPath = Path.Combine(dumpDir, "LawnStrings.json"); @@ -258,6 +217,7 @@ namespace PvZ_Fusion_Translator__BepInEx_ if ((!File.Exists(path)) || (!File.Exists(originalPath))) { Log.LogError($"LawnStringsTranslate.json file not found at path: {path}"); + Log.LogError("Plant name could not be found!"); thePlantName = ""; } else @@ -271,7 +231,7 @@ namespace PvZ_Fusion_Translator__BepInEx_ for (int i = 0; i < originalPlantData.plants.Count; i++) { - var originalPlantInfo = originalPlantData.plants[i]; + AlmanacPlantBank.PlantInfo originalPlantInfo = originalPlantData.plants[i]; KeyValuePair translatedPlantInfo = plantIndices[originalPlantInfo.seedType]; if (originalPlantInfo.name == theOriginalPlantName) @@ -291,12 +251,96 @@ namespace PvZ_Fusion_Translator__BepInEx_ return thePlantName; } + 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"); + + 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); + + foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in zombieData.zombies) + { + if ((int)zombieInfo.theZombieType == (int)theZombieType) + { + theZombieName = zombieInfo.name; + } + } + } + + return theZombieName; + } + + public static Dictionary> plantIndices = new Dictionary>(); + + public static void RegisterPlantIndices() + { + plantIndices = new Dictionary>(); + string originalJson; + string translatedJson; + + string currentLanguage = Utils.Language.ToString(); + 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))) + { + Log.LogError($"LawnStringsTranslate.json file not found at path: {path}"); + } + else if ((!File.Exists(originalPath))) + { + Log.LogError($"LawnStrings.json file not found at path: {originalPath}"); + } + + 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++) + { + PlantInfo originalPlantInfo = originalPlantData.plants[i]; + PlantInfo translatedPlantInfo = null; + + foreach (PlantInfo info in translatedPlantData.plants) + { + if (info.seedType == originalPlantInfo.seedType) + { + translatedPlantInfo = info; + } + } + + if (translatedPlantInfo != null) + { + KeyValuePair temp = new KeyValuePair(translatedPlantInfo.seedType, translatedPlantInfo.name); + plantIndices.Add(originalPlantInfo.seedType, temp); + } + } + } + } + public static bool CheckForUntranslatedText(string text) - { + { Regex regex = new("\\p{IsCJKUnifiedIdeographs}+"); Match match = regex.Match(text); - return match.Success; + return match.Success; }