From cf90e910db6eb3711101f43aa0b5a8dbc331118b Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Sun, 16 Nov 2025 00:43:59 -0500 Subject: [PATCH] abyss fixes + misc fixes before fusion showcase editor --- MelonLoader/AssetStore/StringStore.cs | 40 +++++- .../BaseTextObjects/InGameText_Patch.cs | 12 +- .../GameObjects/AbyssBuffMenu_Patch.cs | 104 +++++++++++++++ .../Patches/GameObjects/AbyssMenu_Patch.cs | 4 +- .../ButtonObjects/UIButton_Patch.cs | 37 ++++-- .../GameObjects/ExploreMakeMenu_Patch.cs | 24 ++++ .../Patches/GameObjects/ExploreMenu_Patch.cs | 8 -- .../TravelBuffOptionButton_Patch.cs | 55 ++++---- .../GameObjects/TravelLookBuff_Patch.cs | 6 + .../Patches/Managers/AbyssBuffData_Patch.cs | 125 ++++++++++++++++++ .../Patches/Managers/AbyssInfo_Patch.cs | 12 ++ .../Patches/Managers/IZBottomMenu_Patch.cs | 3 +- .../Patches/Managers/TravelMgr_Patch.cs | 26 +++- ...PvZ Fusion Translator [MelonLoader].csproj | 4 + 14 files changed, 405 insertions(+), 55 deletions(-) create mode 100644 MelonLoader/Patches/GameObjects/AbyssBuffMenu_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/ExploreMakeMenu_Patch.cs create mode 100644 MelonLoader/Patches/Managers/AbyssBuffData_Patch.cs create mode 100644 MelonLoader/Patches/Managers/AbyssInfo_Patch.cs diff --git a/MelonLoader/AssetStore/StringStore.cs b/MelonLoader/AssetStore/StringStore.cs index ce75493..24ec52b 100644 --- a/MelonLoader/AssetStore/StringStore.cs +++ b/MelonLoader/AssetStore/StringStore.cs @@ -122,10 +122,46 @@ namespace PvZ_Fusion_Translator.AssetStore checkText = text; return checkText; - } - public static string DoTranslateText(string originalText, bool isLog = false) + public static string TranslateText(string originalText, string pattern, bool isLog = false) + { + if (TestRegex(originalText, pattern) && translationStringRegex.ContainsKey(pattern)) + { + // Extract dynamic parts from the original text + var regex = new Regex(pattern); + var match = regex.Match(originalText); + int groupCount = match.Groups.Count; + + if (isLog) + Log.LogDebug("Text found in translationStringRegex {0}: {1}", match, groupCount); + + // List to hold formatted dynamic parts + List dynamicParts = []; + + // Loop through each group and determine its translation + for (int i = 1; i < groupCount; i++) + { + string groupValue = match.Groups[i].Value; + string translatedValue = translationString.ContainsKey(groupValue) + ? translationString[groupValue] + : groupValue; + dynamicParts.Add(translatedValue); + } + + // Format the output string with dynamic parts + return string.Format(translationStringRegex[pattern], [.. dynamicParts]); + } + else + { + if (isLog) + Log.LogDebug($"Text '{originalText}' not translated"); + FileLoader.DumpUntranslatedStrings(originalText); + return originalText; + } + } + + public static string DoTranslateText(string originalText, bool isLog = false) { if (string.IsNullOrEmpty(originalText)) { diff --git a/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs b/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs index 02257db..2cd2294 100644 --- a/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs +++ b/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs @@ -2,6 +2,7 @@ using Il2Cpp; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; +using PvZ_Fusion_Translator.Patches.Managers; namespace PvZ_Fusion_Translator.Patches.BaseTextObjects { @@ -25,7 +26,16 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects foreach (TextMeshProUGUI txt in __instance.textMeshes) { - txt.text = StringStore.TranslateText(txt.text, true); + string travelMatch = TravelMgr_Patch.MatchTravelBuff(txt.text); + + if(travelMatch != "") + { + txt.text = travelMatch; + } + else + { + txt.text = StringStore.TranslateText(txt.text, true); + } txt.font = fontAsset; } } diff --git a/MelonLoader/Patches/GameObjects/AbyssBuffMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AbyssBuffMenu_Patch.cs new file mode 100644 index 0000000..c460d9d --- /dev/null +++ b/MelonLoader/Patches/GameObjects/AbyssBuffMenu_Patch.cs @@ -0,0 +1,104 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using MelonLoader.TinyJSON; +using PvZ_Fusion_Translator.AssetStore; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Text.RegularExpressions; +using UnityEngine.TextCore.Text; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(AbyssBuffMenu))] + public static class AbyssBuffMenu_Patch + { + public static Dictionary abyssBuffData = new Dictionary(); + + [HarmonyPatch(nameof(AbyssBuffMenu.Awake))] + [HarmonyPostfix] + public static void Post_Awake(AbyssBuffMenu __instance) + { + LoadAbyssBuffData(); + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + } + + TranslateWindows(__instance, fontAsset); + } + + [HarmonyPatch(nameof(AbyssBuffMenu.SelectWindow))] + [HarmonyPostfix] + public static void Post_SelectWindow(AbyssBuffMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + TranslateWindows(__instance, fontAsset); + } + + [HarmonyPatch(nameof(AbyssBuffMenu.SetFavorite))] + [HarmonyPostfix] + public static void Post_SetFavorite(AbyssBuffMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + } + } + + public static void TranslateWindows(AbyssBuffMenu __instance, TMP_FontAsset fontAsset) + { + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + if (abyssBuffData.ContainsKey(text.text)) + { + text.text = abyssBuffData[text.text]; + text.font = fontAsset; + } + else + { + foreach (var x in abyssBuffData) + { + if (x.Key.Contains("{value}")) + { + string pattern = Regex.Escape(x.Key).Replace("\\{value}", "(\\d+)"); + if (Regex.IsMatch(text.text, pattern)) + { + var regex = new Regex(pattern); + var match = regex.Match(text.text); + + text.text = String.Format(x.Value.Replace("value", "0"), match.Groups[1].Value); + text.font = fontAsset; + break; + } + } + } + } + } + + foreach(AbyssBuffWindow window in __instance.GetComponentsInChildren()) + { + window.buffName.autoSizeTextContainer = true; + } + } + + public static void LoadAbyssBuffData() + { + abyssBuffData.Clear(); + + string abyssBuffText = File.ReadAllText(Path.Combine(FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language), "abyss_buffs.json")); + abyssBuffData = JsonSerializer.Deserialize>(abyssBuffText); + } + } +} diff --git a/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs index 6e6f415..abef5ee 100644 --- a/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs @@ -22,7 +22,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects foreach (TextMeshProUGUI txt in __instance.levelInfo) { - txt.text = StringStore.TranslateText(txt.text, false); + txt.text = StringStore.TranslateText(txt.text, pattern: "第(\\d+)关\n场景:([^\\s]+)\n总波数:(\\d+)波\n特殊环境:([^\\s]+)\n难度:(\\d+)"); txt.font = fontAsset; } @@ -41,7 +41,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects foreach (TextMeshProUGUI txt in __instance.levelInfo) { - txt.text = StringStore.TranslateText(txt.text); + txt.text = StringStore.TranslateText(txt.text, pattern: "第(\\d+)关\n场景:([^\\s]+)\n总波数:(\\d+)波\n特殊环境:([^\\s]+)\n难度:(\\d+)"); txt.font = fontAsset; } } diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index 4173c95..032f495 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -27,11 +27,6 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); textShadow.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - - if(!text.name.Contains("_EVACUATE")) - { - text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true; - } } else { @@ -69,15 +64,33 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects { if (__instance.transform.childCount >= 2) { - TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); - TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent(); + if(__instance.name == "EditMode") + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - text.text = StringStore.TranslateText(text.text, false); - textShadow.text = StringStore.TranslateText(textShadow.text, false); + TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); + TextMeshProUGUI[] extraTexts = __instance.transform.GetChild(1).GetComponentsInChildren(); - text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - textShadow.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true; + text.text = StringStore.TranslateText(text.text, false); + text.font = fontAsset; + + foreach(TextMeshProUGUI extraText in extraTexts) + { + extraText.text = StringStore.TranslateText(extraText.text, false); + extraText.font = fontAsset; + } + } + else + { + TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); + TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent(); + + text.text = StringStore.TranslateText(text.text, false); + textShadow.text = StringStore.TranslateText(textShadow.text, false); + + text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + textShadow.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } } } catch (Exception) { } diff --git a/MelonLoader/Patches/GameObjects/ExploreMakeMenu_Patch.cs b/MelonLoader/Patches/GameObjects/ExploreMakeMenu_Patch.cs new file mode 100644 index 0000000..bb60b5f --- /dev/null +++ b/MelonLoader/Patches/GameObjects/ExploreMakeMenu_Patch.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(ExploreMakeMenu))] + public static class ExploreMakeMenu_Patch + { + [HarmonyPatch(nameof(ExploreMakeMenu.Awake))] + [HarmonyPostfix] + private static void Awake(ExploreMakeMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs b/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs index ea685bd..918fe3a 100644 --- a/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs @@ -21,14 +21,6 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects } Transform randomLevelTextTransform = __instance.transform.FindChild("RandomLevel"); - foreach(TextMeshProUGUI txt in randomLevelTextTransform.GetComponentsInChildren()) - { - if (txt.name.Contains("(TMP)")) - { - Log.LogDebug(txt.transform.parent.name); - txt.autoSizeTextContainer = true; - } - } } [HarmonyPatch(nameof(ExploreMenu.UpdateWindows))] diff --git a/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs b/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs index 7acebb0..49585e7 100644 --- a/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs @@ -6,35 +6,34 @@ using static PvZ_Fusion_Translator.Patches.Managers.TravelMgr_Patch; namespace PvZ_Fusion_Translator.Patches.GameObjects { - //[HarmonyPatch(typeof(TravelBuffOptionButton))] - //public static class TravelBuffOptionButton_Patch - //{ - // [HarmonyPatch(nameof(TravelBuffOptionButton.SetBuff))] - // [HarmonyPostfix] - // private static void SetBuff(TravelBuffOptionButton __instance) - // { - // __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex]; - // } + [HarmonyPatch(typeof(TravelBuffOptionButton))] + public static class TravelBuffOptionButton_Patch + { + [HarmonyPatch(nameof(TravelBuffOptionButton.SetBuff))] + [HarmonyPostfix] + private static void SetBuff(TravelBuffOptionButton __instance) + { + List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; + string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); - // [HarmonyPatch(nameof(TravelBuffOptionButton.Awake))] - // [HarmonyPostfix] - // private static void Awake(TravelBuffOptionButton __instance) - // { - // __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex]; - // } + } - // [HarmonyPatch(nameof(TravelBuffOptionButton.OnAnimOver))] - // [HarmonyPostfix] - // private static void OnAnimOver(TravelBuffOptionButton __instance) - // { - // __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex]; - // } + [HarmonyPatch(nameof(TravelBuffOptionButton.Awake))] + [HarmonyPostfix] + private static void Awake(TravelBuffOptionButton __instance) + { + List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; + string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); - // [HarmonyPatch(nameof(TravelBuffOptionButton.SetBackground))] - // [HarmonyPostfix] - // private static void SetBackground(TravelBuffOptionButton __instance) - // { - // __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex]; - // } - //} + } + + [HarmonyPatch(nameof(TravelBuffOptionButton.OnAnimOver))] + [HarmonyPostfix] + private static void OnAnimOver(TravelBuffOptionButton __instance) + { + List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; + string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + + } + } } diff --git a/MelonLoader/Patches/GameObjects/TravelLookBuff_Patch.cs b/MelonLoader/Patches/GameObjects/TravelLookBuff_Patch.cs index 2b7cd8d..1004d00 100644 --- a/MelonLoader/Patches/GameObjects/TravelLookBuff_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TravelLookBuff_Patch.cs @@ -17,6 +17,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects { __instance.introduce.text = StringStore.TranslateText("无"); __instance.set = false; + + foreach (TextMeshProUGUI text in __instance.transform.FindChild("Images").FindChild("Button").GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } } [HarmonyPatch(nameof(TravelLookBuff.OnMouseUpAsButton))] @@ -35,6 +40,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects { List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + __instance.introduce.text = buffText; foreach (TextMeshProUGUI text in __instance.transform.FindChild("Images").FindChild("Button").GetComponentsInChildren()) { diff --git a/MelonLoader/Patches/Managers/AbyssBuffData_Patch.cs b/MelonLoader/Patches/Managers/AbyssBuffData_Patch.cs new file mode 100644 index 0000000..0858150 --- /dev/null +++ b/MelonLoader/Patches/Managers/AbyssBuffData_Patch.cs @@ -0,0 +1,125 @@ +//using HarmonyLib; +//using Il2Cpp; +//using MelonLoader; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Text.Json; +//using System.Threading.Tasks; +//using Unity.VisualScripting; +//using UnityEngine; + +//namespace PvZ_Fusion_Translator.Patches.Managers +//{ +// [HarmonyPatch(typeof(AbyssBuffData))] +// public static class AbyssBuffData_Patch +// { +// [HarmonyPatch(nameof(AbyssBuffData.LoadData))] +// [HarmonyPostfix] +// public static void Pre_LoadData(AbyssBuffData __instance) +// { +// string originalAbyssBuffStr = Resources.Load("AbyssBuffData").text; +// Dictionary> originalAbyssBuffData = JsonSerializer.Deserialize>>(originalAbyssBuffStr); +// List infos = originalAbyssBuffData["infos"]; +// Il2CppSystem.Collections.Generic.Dictionary> result = new(); + +// string abyssBuffDataDir = Path.Combine(FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language), "abyss_buffs.json"); +// if (!File.Exists(abyssBuffDataDir)) +// { +// File.WriteAllText(abyssBuffDataDir, originalAbyssBuffStr); +// } + +// Dictionary abyssBuffData = JsonSerializer.Deserialize>(File.ReadAllText(abyssBuffDataDir)); + +// for (int i = 0; i < infos.Count; i++) +// { +// AbyssBuffInfo originalTuple = infos[i]; +// Il2CppSystem.ValueTuple translatedTuple = new(); + +// translatedTuple.Item1 = abyssBuffData.ContainsKey(originalTuple.name) ? abyssBuffData[originalTuple.name] : originalTuple.name; +// translatedTuple.Item2 = abyssBuffData.ContainsKey(originalTuple.introduce) ? abyssBuffData[originalTuple.introduce] : originalTuple.introduce; +// translatedTuple.Item3 = originalTuple.value; + +// foreach (var x in AbyssBuffData.buffDatas) +// { +// if (x.Value.Item1 == originalTuple.name) +// { +// AbyssBuffData.buffDatas[x.Key] = translatedTuple; +// break; +// } +// } +// } +// } +// } + +// public enum AbyssBuffClone +// { +// 生存_聚塑, +// 生存_启命, +// 生存_坚定, +// 生存_弥合, +// 生存_警戒, +// 生存_霸体, +// 生存_共存, +// 生存_护盾, +// 生存_治疗, +// 生存_主宰, +// 寒冰_聚塑, +// 寒冰_刺骨, +// 寒冰_凛风, +// 寒冰_冻结, +// 寒冰_保护, +// 寒冰_折磨, +// 寒冰_扩散, +// 寒冰_凝神, +// 寒冰_破冰, +// 寒冰_永冻, +// 魅惑_聚塑, +// 魅惑_感应, +// 魅惑_催眠, +// 魅惑_无畏, +// 魅惑_脆弱, +// 魅惑_黑曜, +// 魅惑_转世, +// 魅惑_支援, +// 魅惑_沉重, +// 魅惑_共鸣, +// 烈焰_聚塑, +// 烈焰_爆破, +// 烈焰_怒火, +// 烈焰_红唇, +// 烈焰_融化, +// 烈焰_燃烧, +// 烈焰_浴火, +// 烈焰_鬼火, +// 烈焰_诅咒, +// 烈焰_太阳, +// 通用_断水, +// 通用_千斤, +// 通用_急迫, +// 通用_折扣, +// 通用_密植, +// 通用_超级, +// 通用_究极, +// 通用_极速, +// 通用_强力, +// 通用_专注, +// 通用_迸发, +// 通用_投资, +// 通用_机遇, +// 通用_命运, +// 通用_时停, +// 通用_升级, +// 蒜毒_聚塑, +// 蒜毒_腐蚀, +// 蒜毒_侵蚀, +// 蒜毒_血清, +// 蒜毒_混乱, +// 蒜毒_虚弱, +// 蒜毒_反胃, +// 蒜毒_虫噬, +// 蒜毒_百毒, +// 蒜毒_爆裂 +// } +//} \ No newline at end of file diff --git a/MelonLoader/Patches/Managers/AbyssInfo_Patch.cs b/MelonLoader/Patches/Managers/AbyssInfo_Patch.cs new file mode 100644 index 0000000..1ac118d --- /dev/null +++ b/MelonLoader/Patches/Managers/AbyssInfo_Patch.cs @@ -0,0 +1,12 @@ +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.Threading.Tasks; + +//namespace PvZ_Fusion_Translator.Patches.Managers +//{ +// public class AbyssInfo_Patch +// { +// } +//} diff --git a/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs b/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs index 0aa9001..976806b 100644 --- a/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs +++ b/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs @@ -26,7 +26,8 @@ namespace PvZ_Fusion_Translator.Patches.Managers if(new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text)) { - array[i].text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]); + string customName = (StringStore.translationString.ContainsKey(parts[0] + "_IZ")) ? parts[0] + "_IZ" : parts[0]; + array[i].text = string.Format(fStr, StringStore.TranslateText(customName), parts[1]); } array[i] = StringStore.TranslateText(array[i]); diff --git a/MelonLoader/Patches/Managers/TravelMgr_Patch.cs b/MelonLoader/Patches/Managers/TravelMgr_Patch.cs index 013e6a2..3c8c863 100644 --- a/MelonLoader/Patches/Managers/TravelMgr_Patch.cs +++ b/MelonLoader/Patches/Managers/TravelMgr_Patch.cs @@ -21,6 +21,14 @@ namespace PvZ_Fusion_Translator.Patches.Managers { BuffType.Debuff, "debuffs" }, }; + public static Dictionary> dumpedTravelBuffs = new Dictionary>() + { + { "advancedUpgrades", [] }, + { "ultimateUpgrades", [] }, + { "strongUltimates", [] }, + { "debuffs", [] } + }; + public static Dictionary> translatedTravelBuffs = new Dictionary>(); public static void DumpTravelBuffs(Il2CppSystem.Collections.Generic.Dictionary source, Dictionary> dest, string index) @@ -35,13 +43,29 @@ namespace PvZ_Fusion_Translator.Patches.Managers } } + public static string MatchTravelBuff(string originalText) + { + string res = ""; + + foreach(var i in dumpedTravelBuffs) + { + if(i.Value.Contains(originalText)) + { + res = translatedTravelBuffs[i.Key][i.Value.IndexOf(originalText)]; + break; + } + } + + return res; + } + [HarmonyPatch(nameof(TravelMgr.Awake))] [HarmonyPrefix] private static void Pre_Awake(TravelMgr __instance) { // Dump buffs - Dictionary> dumpedTravelBuffs = new Dictionary>() + dumpedTravelBuffs = new Dictionary>() // reset dump { { "advancedUpgrades", [] }, { "ultimateUpgrades", [] }, diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index e3f3910..c4889cd 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -400,6 +400,8 @@ + + @@ -457,6 +459,8 @@ + +