From e9f276289bc906ab3f99994cecce6bca8f41797a Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Sun, 12 Oct 2025 22:39:00 -0400 Subject: [PATCH 1/3] hungarian -> turkish --- BepInEx/Utils.cs | 2 +- MelonLoader/Utils.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BepInEx/Utils.cs b/BepInEx/Utils.cs index 07b9b7d..34e66b7 100644 --- a/BepInEx/Utils.cs +++ b/BepInEx/Utils.cs @@ -354,7 +354,7 @@ namespace PvZ_Fusion_Translator__BepInEx_ // Ukrainian, // Slovak, Polish, - Hungarian, + Turkish, Arabic, LANG_END diff --git a/MelonLoader/Utils.cs b/MelonLoader/Utils.cs index bcdc1bf..71000c3 100644 --- a/MelonLoader/Utils.cs +++ b/MelonLoader/Utils.cs @@ -344,7 +344,7 @@ namespace PvZ_Fusion_Translator // Ukrainian, // Slovak, Polish, - Hungarian, + Turkish, Arabic, LANG_END From 204f45b629594664a15806b18f37874a8cbfc84f Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Wed, 15 Oct 2025 03:08:27 -0400 Subject: [PATCH 2/3] hopeful regex performance improvement? --- BepInEx/AssetStore/StringStore.cs | 15 ++++++++++----- MelonLoader/AssetStore/StringStore.cs | 9 +++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/BepInEx/AssetStore/StringStore.cs b/BepInEx/AssetStore/StringStore.cs index a24d6fc..5be9b0b 100644 --- a/BepInEx/AssetStore/StringStore.cs +++ b/BepInEx/AssetStore/StringStore.cs @@ -147,11 +147,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore // Regex-based dynamic translation foreach (var entry in translationStringRegex) { - var regex = new Regex(entry.Key); - if (regex.IsMatch(originalText)) + if (TestRegex(originalText, entry.Key)) { - // Extract dynamic parts from the original text - var match = regex.Match(originalText); + // Extract dynamic parts from the original text + var regex = new Regex(entry.Key); + var match = regex.Match(originalText); int groupCount = match.Groups.Count; if (isLog) @@ -180,7 +180,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore return originalText; } - private static TextAlignmentOptions TextAnchorToTMPAlignment(TextAnchor anchor) + private static bool TestRegex(string originalText, string pattern) + { + return Regex.IsMatch(originalText, pattern); + } + + private static TextAlignmentOptions TextAnchorToTMPAlignment(TextAnchor anchor) { return anchor switch { diff --git a/MelonLoader/AssetStore/StringStore.cs b/MelonLoader/AssetStore/StringStore.cs index c22f781..ce75493 100644 --- a/MelonLoader/AssetStore/StringStore.cs +++ b/MelonLoader/AssetStore/StringStore.cs @@ -145,10 +145,10 @@ namespace PvZ_Fusion_Translator.AssetStore // Regex-based dynamic translation foreach (var entry in translationStringRegex) { - var regex = new Regex(entry.Key); - if (regex.IsMatch(originalText)) + if (TestRegex(originalText, entry.Key)) { // Extract dynamic parts from the original text + var regex = new Regex(entry.Key); var match = regex.Match(originalText); int groupCount = match.Groups.Count; @@ -178,6 +178,11 @@ namespace PvZ_Fusion_Translator.AssetStore return originalText; } + private static bool TestRegex(string originalText, string pattern) + { + return Regex.IsMatch(originalText, pattern); + } + private static TextAlignmentOptions TextAnchorToTMPAlignment(TextAnchor anchor) { return anchor switch From 26490c8243a0111a4a29b62493831147794bafa0 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Mon, 20 Oct 2025 16:28:59 -0400 Subject: [PATCH 3/3] more shovel --- BepInEx/Patches/Managers/InGameUI_Patch.cs | 26 ++++++ .../Patches/Managers/InGameUI_Patch.cs | 80 ++++++++++++------- 2 files changed, 79 insertions(+), 27 deletions(-) diff --git a/BepInEx/Patches/Managers/InGameUI_Patch.cs b/BepInEx/Patches/Managers/InGameUI_Patch.cs index d88bf54..04ff14f 100644 --- a/BepInEx/Patches/Managers/InGameUI_Patch.cs +++ b/BepInEx/Patches/Managers/InGameUI_Patch.cs @@ -47,5 +47,31 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers } } } + + [HarmonyPatch(nameof(InGameUI.Update))] + [HarmonyPostfix] + private static void Update(InGameUI __instance) + { + foreach(TextMeshProUGUI txt in __instance.ShovelBank.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + } + + [HarmonyPatch(typeof(InGameUI_IZ))] + public static class InGameUI_IZ_Patch + { + [HarmonyPatch(nameof(InGameUI_IZ.Update))] + [HarmonyPostfix] + private static void Update(InGameUI_IZ __instance) + { + foreach (TextMeshProUGUI txt in __instance.shovel.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } } } diff --git a/MelonLoader/Patches/Managers/InGameUI_Patch.cs b/MelonLoader/Patches/Managers/InGameUI_Patch.cs index 6254169..20971ec 100644 --- a/MelonLoader/Patches/Managers/InGameUI_Patch.cs +++ b/MelonLoader/Patches/Managers/InGameUI_Patch.cs @@ -8,45 +8,71 @@ using Unity.Collections; namespace PvZ_Fusion_Translator.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()}; - TextMeshProUGUI[] array2 = array; - for (int i = 0; i < array2.Length; i++) - { + [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()}; + 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?)"); + Regex checkFusionChallenge = new Regex("^超级([^\\s:]+)(:?挑战1?)"); - if (array2[i].text.Contains("配方:") && !checkFusionChallenge.IsMatch(array2[i].text)) + if (array2[i].text.Contains("配方:") && !checkFusionChallenge.IsMatch(array2[i].text)) { string[] lines = array2[i].text.Split(":"); lines[1] = Utils.GetPlantNameFromAlmanac(lines[1]); if (lines[1] == "") { - Log.LogError("Couldn't find plant! (Fusion Showcase)"); + Log.LogError("Couldn't find plant! (Fusion Showcase)"); lines[1] = StringStore.TranslateText(lines[1]); } array2[i].text = StringStore.TranslateText("配方:") + lines[1]; - array2[i].autoSizeTextContainer = true; + array2[i].autoSizeTextContainer = true; } - else - { + else + { array2[i] = StringStore.TranslateText(array2[i]); array2[i].text = array2[i].text.Replace("\n", " "); } - } - } - } + } + } + + [HarmonyPatch(nameof(InGameUI.Update))] + [HarmonyPostfix] + private static void Update(InGameUI __instance) + { + foreach (TextMeshProUGUI txt in __instance.ShovelBank.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + } + + [HarmonyPatch(typeof(InGameUI_IZ))] + public static class InGameUI_IZ_Patch + { + [HarmonyPatch(nameof(InGameUI_IZ.Update))] + [HarmonyPostfix] + private static void Update(InGameUI_IZ __instance) + { + foreach (TextMeshProUGUI txt in __instance.shovel.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + } }