diff --git a/MelonLoader/AssetStore/DllStore.cs b/MelonLoader/AssetStore/DllStore.cs index 54eea26..18ea2e5 100644 --- a/MelonLoader/AssetStore/DllStore.cs +++ b/MelonLoader/AssetStore/DllStore.cs @@ -14,7 +14,6 @@ namespace PvZ_Fusion_Translator.AssetStore public static Dictionary dllData = new Dictionary() { { "Blooms_QOL.dll", null }, - { "HideMetalObjects.dll", null }, { "PvZ_Fusion_Translator.dll", null } }; public static bool updateOnClose = false; @@ -93,7 +92,7 @@ namespace PvZ_Fusion_Translator.AssetStore string programName = "PvZ_Fusion_Translator.Resources.ModUpdateUtil.exe"; using var exeResourceStream = assembly.GetManifestResourceStream(programName); - string tempPath = Path.Combine(Path.GetTempPath(), "ModUpdateUtil.exe"); + string tempPath = Path.Combine(MelonEnvironment.ModsDirectory, "ModUpdateUtil.exe"); using (var fileStream = File.Create(tempPath)) { exeResourceStream.CopyTo(fileStream); @@ -102,10 +101,14 @@ namespace PvZ_Fusion_Translator.AssetStore Process.Start(new ProcessStartInfo { FileName = tempPath, - Arguments = $"{processId.ToString()} {string.Join(",", dllData.Keys)} {MelonEnvironment.ModsDirectory}", + Arguments = $"{processId.ToString()} {string.Join(",", dllData.Keys)} \"{MelonEnvironment.ModsDirectory}\"", UseShellExecute = true }); } + else + { + Log.LogError("Cannot update on close! All .dll data is null!"); + } } } } diff --git a/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs b/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs index 936ac63..bf7678b 100644 --- a/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs +++ b/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs @@ -20,10 +20,6 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects [HarmonyPostfix] public static void ShowText(InGameText __instance) { - if(__instance.textHead == null) return; - - if(!__instance.textHead.active || !__instance.textMesh.gameObject.active) return; - TranslateInGameText(__instance); } @@ -31,10 +27,6 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects [HarmonyPostfix] public static void DebugWarning(InGameText __instance) { - if(__instance.textHead == null) return; - - if(!__instance.textHead.active || !__instance.textMesh.gameObject.active) return; - TranslateInGameText(__instance); } @@ -42,24 +34,39 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects [HarmonyPostfix] public static void Update(InGameText __instance) { - if(__instance.textHead == null) return; - - if(!__instance.textHead.active || !__instance.textMesh.gameObject.active) return; - TranslateInGameText(__instance); } public static void TranslateInGameText(InGameText __instance) { - if (__instance.textMesh == null) return; + TextMeshProUGUI txt = null; - if(!__instance.textHead.active || !__instance.textMesh.gameObject.active) return; + if (__instance.textMesh == null || __instance.textHead == null) + { + if (__instance.TryGetComponent(out TextMeshProUGUI selfTxt)) + { + txt = selfTxt; + } + } + else + { + txt = __instance.textMesh; + } + + if(txt != null) + { + if (!txt.gameObject.active) return; + + TranslateInGameTextMesh(txt); + } + } + + public static void TranslateInGameTextMesh(TextMeshProUGUI txt) + { + if (txt == null) return; TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - currentText = __instance.textMesh.text; - - TextMeshProUGUI txt = __instance.textMesh; string originalText = txt.text; string travelMatch = TravelMgr_Patch.MatchTravelBuff(originalText); int godsGachaCheck = CheckGodsGachaPopup(originalText); diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs index b1821de..45d94df 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/OptLanguageBtn_Patch.cs @@ -137,7 +137,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects data.IsNextButton = false; btn.gameObject.SetActive(true); - UpdateButtonText(btn, Utils.LanguageNames[lang], FontStore.LoadTMPFont(lang.ToString())); + string languageName = Utils.LanguageNames.ContainsKey(lang) ? Utils.LanguageNames[lang] : lang.ToString(); + UpdateButtonText(btn, languageName, FontStore.LoadTMPFont(lang.ToString())); } else { @@ -160,7 +161,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects data.Toggle = toggle; data.IsNextButton = false; btn.gameObject.SetActive(true); - string buttonText = Utils.ToggleNames[toggle]; + string buttonText = Utils.ToggleNames.ContainsKey(toggle) ? Utils.ToggleNames[toggle] : toggle.ToString(); UpdateButtonText(btn, StringStore.TranslateText(buttonText), FontStore.LoadTMPFont(Utils.Language.ToString())); string sourceMsg = ""; switch(i) diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/GameLose_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/GameLose_Patch.cs new file mode 100644 index 0000000..340fd95 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/MinorObjects/GameLose_Patch.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HarmonyLib; +using UnityEngine; +using Il2Cpp; +using PvZ_Fusion_Translator.Patches.BaseTextObjects; + +namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects +{ + [HarmonyPatch(typeof(GameLose))] + public static class GameLose_Patch + { + [HarmonyPatch(nameof(GameLose.UpdateSecondChanceTimer))] + public static void UpdateSecondChanceTimer(GameLose __instance) + { + if (InGameText.Instance == null) return; + + if (InGameText.Instance.timer < 0) return; + + InGameText_Patch.TranslateInGameText(InGameText.Instance); + } + } +} diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/Plant_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/Plant_Patch.cs index 0e0cbb2..b46f0db 100644 --- a/MelonLoader/Patches/GameObjects/MinorObjects/Plant_Patch.cs +++ b/MelonLoader/Patches/GameObjects/MinorObjects/Plant_Patch.cs @@ -4,7 +4,7 @@ using System.Text.RegularExpressions; namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects { - [HarmonyPatch(typeof(Plant))] + /*[HarmonyPatch(typeof(Plant))] public static class Plant_Patch { [HarmonyPostfix] @@ -43,5 +43,5 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects } return originalText; } - } + }*/ } \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/Zombie_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/Zombie_Patch.cs index ea643de..f3c9346 100644 --- a/MelonLoader/Patches/GameObjects/MinorObjects/Zombie_Patch.cs +++ b/MelonLoader/Patches/GameObjects/MinorObjects/Zombie_Patch.cs @@ -14,9 +14,9 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects private static Dictionary HPStrings = new Dictionary() { { "最后一击:(\\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+)\n一类:(\\d+)/(\\d+)\n二类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nT1 armor: {2}/{3}\nT2 armor: {4}/{5}" }, + { "^HP:(\\d+)/(\\d+)\n一类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nT1 armor: {2}/{3}" }, + { "^HP:(\\d+)/(\\d+)\n二类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nT2 armor: {2}/{3}" }, { "^HP:(\\d+)/(\\d+)$", "HP: {0}/{1}" } }; @@ -38,12 +38,15 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects __instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f); } - [HarmonyPatch(nameof(Zombie.Update))] - [HarmonyPrefix] + [HarmonyPatch(nameof(Zombie.UpdateHealthText))] + [HarmonyPostfix] public static void Update(Zombie __instance) { if (__instance.theZombieType == ZombieType.TrainingDummy || !Board.Instance.showZombieHealth) return; + + if (__instance.healthText == null || __instance.healthTextShadow == null) return; + TranslateHpUI(__instance.healthText, __instance); TranslateHpUI(__instance.healthTextShadow, __instance); diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 18fcea9..e3817b7 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -404,6 +404,7 @@ + diff --git a/MelonLoader/Resources/ModUpdateUtil.exe b/MelonLoader/Resources/ModUpdateUtil.exe index 1514752..fa4a746 100644 Binary files a/MelonLoader/Resources/ModUpdateUtil.exe and b/MelonLoader/Resources/ModUpdateUtil.exe differ diff --git a/MelonLoader/Utils.cs b/MelonLoader/Utils.cs index d8ce77b..4be0228 100644 --- a/MelonLoader/Utils.cs +++ b/MelonLoader/Utils.cs @@ -562,7 +562,7 @@ namespace PvZ_Fusion_Translator Chinese_cn, French, //Italian, - //German, + German, Spanish, @@ -593,6 +593,7 @@ namespace PvZ_Fusion_Translator { LanguageEnum.English, "English"}, { LanguageEnum.Chinese_cn, "简体中文"}, { LanguageEnum.French, "Français"}, + { LanguageEnum.German, "Deutsch"}, { LanguageEnum.Spanish, "Español"}, { LanguageEnum.Vietnamese, "Tiếng Việt"}, { LanguageEnum.Japanese, "日本語"},