diff --git a/.gitignore b/.gitignore index c2e129d..615b362 100644 --- a/.gitignore +++ b/.gitignore @@ -134,3 +134,4 @@ MelonLoader/bin/x64/Debug/net6.0/WebSocketDotNet.dll .HOWTO-sync-MelonLoader-from-origin-main.txt /MelonLoader/bin/ReleaseMulti/net6.0 BepInEx/Patches/GameObjects/changes.txt +/Assembly-CSharp \ No newline at end of file diff --git a/BepInEx/AssetStore/StringStore.cs b/BepInEx/AssetStore/StringStore.cs index 4f6c70b..0fc5372 100644 --- a/BepInEx/AssetStore/StringStore.cs +++ b/BepInEx/AssetStore/StringStore.cs @@ -166,6 +166,16 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore } } + public static string TranslateColorText(string originalText, bool isLog = false) + { + string pattern = @"(]*>.*?)"; + if (TestRegex(originalText, pattern)) + { + return DoTranslateText(originalText, isLog); + } + return originalText; + } + public static string DoTranslateText(string originalText, bool isLog = false) { if (string.IsNullOrEmpty(originalText)) @@ -219,7 +229,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore return originalText; } - private static bool TestRegex(string originalText, string pattern) + public static bool TestRegex(string originalText, string pattern) { return Regex.IsMatch(originalText, pattern); } diff --git a/BepInEx/Core.cs b/BepInEx/Core.cs index 4c488b8..6d58a9d 100644 --- a/BepInEx/Core.cs +++ b/BepInEx/Core.cs @@ -42,9 +42,9 @@ public class Core : BasePlugin { Log = base.Log; Instance = this; + LoadConfig(); MonoInstance = AddComponent(); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly()); - LoadConfig(); dtStart = DateTime.Now; FileLoader.LoadLanguage(); diff --git a/BepInEx/Patches/BaseTextObjects/InGameText_Patch.cs b/BepInEx/Patches/BaseTextObjects/InGameText_Patch.cs index 83934f2..2687306 100644 --- a/BepInEx/Patches/BaseTextObjects/InGameText_Patch.cs +++ b/BepInEx/Patches/BaseTextObjects/InGameText_Patch.cs @@ -3,21 +3,21 @@ using System; using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; using PvZ_Fusion_Translator__BepInEx_.Patches.Managers; +using UnityEngine; namespace PvZ_Fusion_Translator__BepInEx_.Patches.BaseTextObjects { [HarmonyPatch(typeof(InGameText))] public static class InGameText_Patch { - [HarmonyPatch(nameof(InGameText.ShowText), new Type[] { typeof(string), typeof(float), typeof(bool) })] + [HarmonyPatch(nameof(InGameText.ShowText), new Type[] { typeof(string), typeof(float), typeof(bool), typeof(bool) })] [HarmonyPrefix] - private static void ShowText(InGameText __instance, ref string text) => text = StringStore.TranslateText(text, true); + private static void ShowText_Pre(InGameText __instance, ref string text) => text = StringStore.TranslateText(text, true); - [HarmonyPatch(nameof(InGameText.ShowText), new Type[] { typeof(string), typeof(float), typeof(bool) })] + [HarmonyPatch(nameof(InGameText.ShowText), new Type[] { typeof(string), typeof(float), typeof(bool), typeof(bool) })] [HarmonyPostfix] - private static void ShowText(InGameText __instance) + private static void ShowText_Post(InGameText __instance) { - #if MULTI_LANGUAGE TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); #else @@ -26,17 +26,36 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.BaseTextObjects foreach (TextMeshProUGUI txt in __instance.textMeshes) { - string travelMatch = TravelMgr_Patch.MatchTravelBuff(txt.text); + string travelMatch = TravelMgr_Patch.MatchTravelBuff(txt.text); + string originalText = txt.text; - if (travelMatch != "") - { - txt.text = travelMatch; - } - else - { - txt.text = StringStore.TranslateText(txt.text, true); - } - txt.font = fontAsset; + if (txt.gameObject.name.Contains("shadow")) + { + continue; + } + + if (travelMatch != "") + { + txt.text = travelMatch; + if (txt.gameObject.name.Contains("main")) + { + originalText = txt.text; + Transform shadowText = txt.transform.parent.Find("Text_shadow"); + if (shadowText != null) + { + shadowText.GetComponent().text = Utils.RemoveColorTags(originalText); + } + } + } + else if(System.Text.RegularExpressions.Regex.Match(txt.text, @"(]*>.*?)", System.Text.RegularExpressions.RegexOptions.Singleline).Success) + { + txt.text = StringStore.TranslateColorText(txt.text); + } + else + { + txt.text = StringStore.TranslateText(txt.text, true); + } + txt.font = fontAsset; } } } diff --git a/BepInEx/Patches/GameObjects/AdvantureEvolutionMenu_Patch.cs b/BepInEx/Patches/GameObjects/AdvantureEvolutionMenu_Patch.cs new file mode 100644 index 0000000..23fe212 --- /dev/null +++ b/BepInEx/Patches/GameObjects/AdvantureEvolutionMenu_Patch.cs @@ -0,0 +1,20 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(AdvantureEvolutionMenu))] + public static class AdvantureEvolutionMenu_Patch + { + [HarmonyPatch(nameof(AdvantureEvolutionMenu.Awake))] + [HarmonyPostfix] + private static void Awake(AdvantureEvolutionMenu __instance) + { + foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/AdvantureHelpMenu_Patch.cs b/BepInEx/Patches/GameObjects/AdvantureHelpMenu_Patch.cs new file mode 100644 index 0000000..7ba5af7 --- /dev/null +++ b/BepInEx/Patches/GameObjects/AdvantureHelpMenu_Patch.cs @@ -0,0 +1,20 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(AdvantureHelpMenu))] + public static class AdvantureHelpMenu_Patch + { + [HarmonyPatch(nameof(AdvantureHelpMenu.Awake))] + [HarmonyPostfix] + private static void Awake(AdvantureHelpMenu __instance) + { + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/AdvantureMenu2_Patch.cs b/BepInEx/Patches/GameObjects/AdvantureMenu2_Patch.cs new file mode 100644 index 0000000..f0926c1 --- /dev/null +++ b/BepInEx/Patches/GameObjects/AdvantureMenu2_Patch.cs @@ -0,0 +1,27 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(AdvantureMenu2))] + public static class AdvantureMenu2_Patch + { + [HarmonyPatch(nameof(AdvantureMenu2.Awake))] + [HarmonyPostfix] + private static void Awake(AdvantureMenu2 __instance) + { + foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } + } + + [HarmonyPatch(nameof(AdvantureMenu2.AdjustDifficulty))] + [HarmonyPostfix] + private static void AdjustDifficulty(AdvantureMenu2 __instance) + { + __instance.difficulty.text = StringStore.TranslateText(__instance.difficulty.text); + } + } +} diff --git a/BepInEx/Patches/GameObjects/AdvantureMenu_Patch.cs b/BepInEx/Patches/GameObjects/AdvantureMenu_Patch.cs new file mode 100644 index 0000000..7360d02 --- /dev/null +++ b/BepInEx/Patches/GameObjects/AdvantureMenu_Patch.cs @@ -0,0 +1,63 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(AdvantureMenu))] + public static class AdvantureMenu_Patch + { + [HarmonyPatch(nameof(AdvantureMenu.Start))] + [HarmonyPostfix] + private static void Start(AdvantureMenu __instance) + { + TranslateAdvantureMenu(__instance); + } + + [HarmonyPatch(nameof(AdvantureMenu.ChangeDifficulty))] + [HarmonyPostfix] + private static void ChangeDifficulty(AdvantureMenu __instance) + { + TranslateAdvantureMenu(__instance); + } + + [HarmonyPatch(nameof(AdvantureMenu.GetChapterDifficulty))] + [HarmonyPostfix] + private static void GetChapterDifficulty(AdvantureMenu __instance) + { + TranslateAdvantureMenu(__instance); + } + + [HarmonyPatch(nameof(AdvantureMenu.UpdateChapterDifficulty))] + [HarmonyPostfix] + private static void UpdateChapterDifficulty(AdvantureMenu __instance) + { + TranslateAdvantureMenu(__instance); + } + + [HarmonyPatch(nameof(AdvantureMenu.UpdateStarCount))] + [HarmonyPostfix] + private static void UpdateStarCount(AdvantureMenu __instance) + { + TranslateAdvantureMenu(__instance); + } + + public static void TranslateAdvantureMenu(AdvantureMenu __instance) + { + bool hasSBString = StringStore.translationString.ContainsKey(__instance.difficulty.text + "_SB"); + __instance.difficulty.text = Utils.RemoveSizeTags(hasSBString ? StringStore.TranslateText(__instance.difficulty.text + "_SB") : StringStore.TranslateText(__instance.difficulty.text)); + __instance.chapterDifficulty.text = StringStore.TranslateText(__instance.chapterDifficulty.text); + __instance.starCount.text = StringStore.TranslateText(__instance.starCount.text); + + foreach (TextMeshProUGUI text in __instance.title) + { + text.text = StringStore.TranslateText(text.text); + } + + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/AdvantureMissionMenu_Patch.cs b/BepInEx/Patches/GameObjects/AdvantureMissionMenu_Patch.cs new file mode 100644 index 0000000..a26a9e3 --- /dev/null +++ b/BepInEx/Patches/GameObjects/AdvantureMissionMenu_Patch.cs @@ -0,0 +1,55 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(AdvantureMissionMenu))] + public static class AdvantureMissionMenu_Patch + { + [HarmonyPatch(nameof(AdvantureMissionMenu.Awake))] + [HarmonyPostfix] + private static void Awake(AdvantureMissionMenu __instance) + { + foreach (TextMeshProUGUI text in __instance.contant.GetComponentsInChildren()) + { + text.text = StringStore.TranslateColorText(text.text); + } + + //foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + //{ + // text.text = StringStore.TranslateText(text.text); + //} + } + + [HarmonyPatch(nameof(AdvantureMissionMenu.InitText))] + [HarmonyPostfix] + private static void InitText(AdvantureMissionMenu __instance) + { + foreach (TextMeshProUGUI text in __instance.contant.GetComponentsInChildren()) + { + text.text = StringStore.TranslateColorText(text.text); + } + + //foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + //{ + // text.text = StringStore.TranslateText(text.text); + //} + } + + [HarmonyPatch(nameof(AdvantureMissionMenu.SwitchAward))] + [HarmonyPostfix] + private static void SwitchAward(AdvantureMissionMenu __instance) + { + foreach(TextMeshProUGUI text in __instance.contant.GetComponentsInChildren()) + { + text.text = StringStore.TranslateColorText(text.text); + } + + //foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + //{ + // text.text = StringStore.TranslateText(text.text); + //} + } + } +} diff --git a/BepInEx/Patches/GameObjects/AdvantureStarMenu_Patch.cs b/BepInEx/Patches/GameObjects/AdvantureStarMenu_Patch.cs new file mode 100644 index 0000000..1d9541a --- /dev/null +++ b/BepInEx/Patches/GameObjects/AdvantureStarMenu_Patch.cs @@ -0,0 +1,60 @@ +using HarmonyLib; +using TMPro; +using PvZ_Fusion_Translator__BepInEx_.AssetStore; + +namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects +{ + [HarmonyPatch(typeof(AdvantureStarMenu))] + public static class AdvantureStarMenu_Patch + { + [HarmonyPatch(nameof(AdvantureStarMenu.Awake))] + [HarmonyPostfix] + private static void Awake(AdvantureStarMenu __instance) + { + foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } + } + + [HarmonyPatch(nameof(AdvantureStarMenu.GetNodes))] + [HarmonyPostfix] + private static void GetNodes(AdvantureStarMenu __instance) + { + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } + } + + [HarmonyPatch(nameof(AdvantureStarMenu.UpdateStarText))] + [HarmonyPostfix] + private static void UpdateStarText(AdvantureStarMenu __instance) + { + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } + } + + [HarmonyPatch(nameof(AdvantureStarMenu.InitTalents))] + [HarmonyPostfix] + private static void InitTalents(AdvantureStarMenu __instance) + { + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } + } + + [HarmonyPatch(nameof(AdvantureStarMenu.ResetAward))] + [HarmonyPostfix] + private static void ResetAward(AdvantureStarMenu __instance) + { + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } + } + } +} diff --git a/BepInEx/Patches/GameObjects/AlmanacZombieWindow_Patch.cs b/BepInEx/Patches/GameObjects/AlmanacZombieWindow_Patch.cs index 8e16f2e..f20926a 100644 --- a/BepInEx/Patches/GameObjects/AlmanacZombieWindow_Patch.cs +++ b/BepInEx/Patches/GameObjects/AlmanacZombieWindow_Patch.cs @@ -47,11 +47,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects TMP_FontAsset fontAsset = null; fontAsset = (hasAlmanacFont) ? FontStore.LoadTMPFontAlmanac(Utils.Language.ToString()) : FontStore.LoadTMPFont(Utils.Language.ToString()); - ZombieAlmanacData zombieData = null; - zombieData = JsonUtility.FromJson(json); + ZombieAlmanacData zombieAlmanacData = null; + zombieAlmanacData = JsonUtility.FromJson(json); + var zombieDataDic = ZombieDataManager.zombieDataDic; bool foundMatch = false; - foreach (ZombieInfo zombieInfo in zombieData.zombies) + foreach (ZombieInfo zombieInfo in zombieAlmanacData.zombies) { if (zombieInfo == null) continue; if (zombieInfo.theZombieType == __instance.currentZombieType) @@ -76,7 +77,17 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { string info = zombieInfo.info ?? ""; string introduce = zombieInfo.introduce ?? ""; - __instance.showedZombieIntroduce.text = Utils.RemoveSizeTags(info) + "\n\n" + Utils.RemoveSizeTags(introduce) + "\n\n"; + + ZombieDataManager.ZombieData zombieData = zombieDataDic[__instance.currentZombieType]; + + string spawnInfo = ""; + string spawnInfoFormat = StringStore.translationStringRegex["出怪等级: (\\d+)\\n出怪权重: (\\d+)"]; + if(spawnInfoFormat != null) + { + spawnInfo = string.Format(spawnInfoFormat, new object[] { zombieData.summonLevel, zombieData.summonWeight }) + "\n\n"; + } + + __instance.showedZombieIntroduce.text = Utils.RemoveSizeTags(info) + "\n\n" + spawnInfo + Utils.RemoveSizeTags(introduce) + "\n\n"; __instance.showedZombieIntroduce.font = fontAsset; __instance.showedZombieIntroduce.margin = new Vector4(3, 2, 12, 0); __instance.showedZombieIntroduce.enableWordWrapping = true; diff --git a/BepInEx/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs index e3bdbfe..6c79998 100644 --- a/BepInEx/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs +++ b/BepInEx/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs @@ -248,20 +248,18 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects if (type == "Textures") { - Utils.customTextures = !Utils.customTextures; ConfigEntry customTexturesEntry; Core.Instance.Config.TryGetEntry(new ConfigDefinition("PvZ_Fusion_Translator", "DefaultTextures"), out customTexturesEntry); - customTexturesEntry.BoxedValue = !Utils.customTextures; + customTexturesEntry.BoxedValue = !customTexturesEntry.Value; // Toggle the config value TextureStore.Reload(); Coroutine replaceTextureRoutine = Core.MonoInstance.StartCoroutine(TextureStore.ReplaceTexturesCoroutine()); } if (type == "Audio") { - Utils.customAudio = !Utils.customAudio; ConfigEntry customAudioEntry; Core.Instance.Config.TryGetEntry(new ConfigDefinition("PvZ_Fusion_Translator", "DefaultAudio"), out customAudioEntry); - customAudioEntry.BoxedValue = !Utils.customAudio; + customAudioEntry.BoxedValue = !customAudioEntry.Value; // Toggle the config value } Core.Instance.Config.Save(); } diff --git a/BepInEx/Patches/GameObjects/MinorObjects/Zombie_Patch.cs b/BepInEx/Patches/GameObjects/MinorObjects/Zombie_Patch.cs index b4d4d86..ff271df 100644 --- a/BepInEx/Patches/GameObjects/MinorObjects/Zombie_Patch.cs +++ b/BepInEx/Patches/GameObjects/MinorObjects/Zombie_Patch.cs @@ -18,7 +18,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects { "^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}" }, + { "^HP:(\\d+)/(\\d+)$", "HP: {0}/{1}" } }; public static void LoadHPStrings() @@ -57,7 +57,20 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects if (textTMP) { string origText = textTMP.text; - string translatedText = TranslateHPText(origText, __instance); + string translatedText = origText; + string pattern = "(\\d+)阶\\n([\\s\\S]+)"; + if (StringStore.TestRegex(translatedText, pattern)) + { + var match = Regex.Match(translatedText, pattern, RegexOptions.Singleline); + string tier = match.Groups[1].Value; + string healthText = TranslateHPText(match.Groups[2].Value, __instance); + string fStr = StringStore.translationStringRegex[pattern]; + translatedText = string.Format(fStr, new object[] { tier, healthText }); + } + else + { + translatedText = TranslateHPText(origText, __instance); + } textTMP.text = translatedText == origText ? origText : translatedText; textTMP.autoSizeTextContainer = false; if (translatedText != origText) @@ -91,8 +104,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects for (int i = 0; i < HPStrings.Count; i++) { var hp = HPStrings.ElementAt(i); - Regex regex = new Regex(hp.Key); - if (regex.IsMatch(originalText)) + if(Regex.Match(originalText, hp.Key, RegexOptions.Singleline).Success) { fIndex = i; found = true; @@ -146,6 +158,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects { string fStr = HPStrings.ElementAt(fIndex).Value; string DPS = originalText.Split("\n")[1].Replace("DPS:", ""); + DPS = StringStore.TranslateText(DPS); switch (fIndex) { diff --git a/BepInEx/Patches/GameObjects/NoticePauseMenu_Patch.cs b/BepInEx/Patches/GameObjects/NoticePauseMenu_Patch.cs index 8ce33ea..0579148 100644 --- a/BepInEx/Patches/GameObjects/NoticePauseMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/NoticePauseMenu_Patch.cs @@ -12,9 +12,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects public class NoticePauseMenu_Patch { [HarmonyPrefix] - [HarmonyPatch(nameof(NoticeMenu.Awake))] - private static void Pre_Awake(NoticeMenu __instance) - { + [HarmonyPatch(nameof(NoticeMenu.Awake))] + private static void Pre_Awake(NoticeMenu __instance) + { GameObject contentObject = __instance.transform.FindChild("Scroll View/Viewport/Content").gameObject; TextMeshProUGUI contentText = contentObject.GetComponent(); @@ -28,6 +28,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects File.WriteAllText(changelogDir, contentText.text); } } + [HarmonyPostfix] [HarmonyPatch(nameof(NoticeMenu.Awake))] private static void Post_Awake(NoticeMenu __instance) @@ -42,6 +43,17 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects TextMeshProUGUI contentText = contentObject.GetComponent(); contentText.text = changelogText; + contentText.margin = new Vector4(6, 2, 12, 0); + + contentText.enableWordWrapping = true; + contentText.overflowMode = TextOverflowModes.ScrollRect; + + Canvas.ForceUpdateCanvases(); + contentText.ForceMeshUpdate(); + + //float textHeight = contentText.preferredHeight; + //RectTransform contentRect = contentObject.GetComponent(); + //contentRect.sizeDelta = new Vector2(contentRect.sizeDelta.x, textHeight); ContentSizeFitter sizeFitter = contentObject.AddComponent(); sizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; diff --git a/BepInEx/Patches/Managers/CanvasUpUI_Patch.cs b/BepInEx/Patches/Managers/CanvasUpUI_Patch.cs index 5b9bf16..c73b142 100644 --- a/BepInEx/Patches/Managers/CanvasUpUI_Patch.cs +++ b/BepInEx/Patches/Managers/CanvasUpUI_Patch.cs @@ -15,13 +15,13 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers { [HarmonyPatch(nameof(CanvasUpUI.Start))] [HarmonyPostfix] - public static void Start(IZBottomMenu __instance) + public static void Start(CanvasUpUI __instance) { TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren()) { - string originalKey = StringStore.translationString.FirstOrDefault(x => x.Value.Replace("\n", " ") == text.text).Key; + string originalKey = StringStore.translationString.FirstOrDefault(x => (x.Value == text.text || x.Value.Replace("\n", "") == text.text)).Key; text.text = (StringStore.translationString.ContainsKey(originalKey + "_MG")) ? StringStore.TranslateText(originalKey + "_MG") : StringStore.TranslateText(text.text); if(text.gameObject.name.Contains("LevelName")) { diff --git a/BepInEx/PvZ Fusion Translator [BepInEx].csproj b/BepInEx/PvZ Fusion Translator [BepInEx].csproj index 669b76c..d1a8ddf 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_ - D:\PvZ Fusion\BepInEx Game Files + C:\Users\Admin\Downloads\PvZ FUSION VH FANMADE C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.1.1 Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate;DebugMulti AnyCPU;x64 @@ -135,6 +135,12 @@ + + + + + + diff --git a/BepInEx/Utils.cs b/BepInEx/Utils.cs index 663474a..a09ed3a 100644 --- a/BepInEx/Utils.cs +++ b/BepInEx/Utils.cs @@ -341,9 +341,16 @@ namespace PvZ_Fusion_Translator__BepInEx_ public static bool CheckForUntranslatedText(string text) { Regex regex = new("\\p{IsCJKUnifiedIdeographs}+"); - Match match = regex.Match(text); - - return match.Success; + try + { + Match match = regex.Match(text); + return match.Success; + } + catch(Exception e) + { + Log.LogError(e); + } + return false; } @@ -380,8 +387,8 @@ namespace PvZ_Fusion_Translator__BepInEx_ public static string mainCategory = "PvZ_Fusion_Translator"; - public static bool customTextures = !Core.Instance.configDefaultTextures.Value; - public static bool customAudio = !Core.Instance.configDefaultAudio.Value; + public static bool customTextures => Core.Instance != null && !Core.Instance.configDefaultTextures.Value; + public static bool customAudio => Core.Instance != null && !Core.Instance.configDefaultAudio.Value; public enum LanguageEnum {