From ba7c713a37f346ed187c4dd6ae2056332a224e22 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Fri, 14 Nov 2025 17:53:58 -0500 Subject: [PATCH] odyssey id system fixes + file protection added --- .../Patches/GameObjects/AbyssMenu_Patch.cs | 23 +------- .../GameObjects/NoticePauseMenu_Patch.cs | 19 +++++-- .../TravelBuffOptionButton_Patch.cs | 56 +++++++++---------- .../GameObjects/TravelLookBuff_Patch.cs | 50 ++++++++--------- .../Patches/Managers/TravelMgr_Patch.cs | 7 +++ 5 files changed, 75 insertions(+), 80 deletions(-) diff --git a/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs index a197572..6e6f415 100644 --- a/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs @@ -41,27 +41,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects foreach (TextMeshProUGUI txt in __instance.levelInfo) { - string regexStr = "第(\\d+)关\n场景:([^\\s]+)\n总波数:(\\d+)波\n特殊环境:([^\\s:]+)\n减伤强度:(\\d+)"; - - Regex regex = new Regex(regexStr); - - if(regex.IsMatch(txt.text)) - { - Match match = regex.Match(txt.text); - int groupCount = match.Groups.Count; - - List dynamicParts = []; - - 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); - } - - txt.text = string.Format(StringStore.translationStringRegex[regexStr], [.. dynamicParts]); - txt.font = fontAsset; - } + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; } } } diff --git a/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs b/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs index 8dfa0b1..768eea8 100644 --- a/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs @@ -2,10 +2,8 @@ using Il2Cpp; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; -using System.Text.Json; using UnityEngine; using UnityEngine.UI; -using UnityEngine.UIElements; namespace PvZ_Fusion_Translator.Patches.GameObjects { @@ -20,6 +18,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects TextMeshProUGUI contentText = contentObject.GetComponent(); File.WriteAllText(Path.Combine(FileLoader.GetAssetDir(FileLoader.AssetType.Dumps), "changelog.txt"), contentText.text); + + string stringDir = FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language); + string changelogDir = Path.Combine(stringDir, "changelog.txt"); + + if (!File.Exists(changelogDir)) + { + File.WriteAllText(changelogDir, contentText.text); + } } [HarmonyPostfix] @@ -27,12 +33,15 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects private static void Post_Awake(NoticeMenu __instance) { TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - string changelogText = File.ReadAllText(Path.Combine(FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language), "changelog.txt")); - + string stringDir = FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language); + string changelogDir = Path.Combine(stringDir, "changelog.txt"); + + string changelogText = File.ReadAllText(changelogDir); + GameObject contentObject = __instance.transform.FindChild("Scroll View").GetChild(0).GetChild(0).gameObject; //bc normal Find or FindChild didn't work TextMeshProUGUI contentText = contentObject.GetComponent(); - contentText.text = changelogText; + contentText.text = changelogText; ContentSizeFitter sizeFitter = contentObject.AddComponent(); sizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; diff --git a/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs b/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs index 5a754be..7acebb0 100644 --- a/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TravelBuffOptionButton_Patch.cs @@ -6,35 +6,35 @@ 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) + // { + // __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex]; + // } - [HarmonyPatch(nameof(TravelBuffOptionButton.Awake))] - [HarmonyPostfix] - private static void Awake(TravelBuffOptionButton __instance) - { - __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex]; - } + // [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.OnAnimOver))] + // [HarmonyPostfix] + // private static void OnAnimOver(TravelBuffOptionButton __instance) + // { + // __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex]; + // } - [HarmonyPatch(nameof(TravelBuffOptionButton.SetBackground))] - [HarmonyPostfix] - private static void SetBackground(TravelBuffOptionButton __instance) - { - __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex]; - } - } + // [HarmonyPatch(nameof(TravelBuffOptionButton.SetBackground))] + // [HarmonyPostfix] + // private static void SetBackground(TravelBuffOptionButton __instance) + // { + // __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex]; + // } + //} } diff --git a/MelonLoader/Patches/GameObjects/TravelLookBuff_Patch.cs b/MelonLoader/Patches/GameObjects/TravelLookBuff_Patch.cs index 4bbd844..2b7cd8d 100644 --- a/MelonLoader/Patches/GameObjects/TravelLookBuff_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TravelLookBuff_Patch.cs @@ -4,44 +4,42 @@ using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using static PvZ_Fusion_Translator.Patches.Managers.TravelMgr_Patch; using UnityEngine; +using MelonLoader; namespace PvZ_Fusion_Translator.Patches.GameObjects { [HarmonyPatch(typeof(TravelLookBuff))] public static class TravelLookBuff_Patch { - private static void TranslateTexts(TravelLookBuff __instance) + [HarmonyPatch(nameof(TravelLookBuff.Clear))] + [HarmonyPostfix] + public static void Post_Clear(TravelLookBuff __instance) { - string buffText = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex]; + __instance.introduce.text = StringStore.TranslateText("无"); + __instance.set = false; + } - __instance.introduce.text = buffText; - - Transform transform = __instance.rectTransform.transform; - var component1 = transform.GetChild(0).GetComponent(); - var component2 = transform.GetChild(1).GetComponent(); - - if (component1 != null) component1.text = StringStore.TranslateText(component1.text); - if (component2 != null) component2.text = StringStore.TranslateText(component2.text); + [HarmonyPatch(nameof(TravelLookBuff.OnMouseUpAsButton))] + [HarmonyPostfix] + public static void Post_OnMouseUpAsButton(TravelLookBuff __instance) + { + foreach (TextMeshProUGUI text in __instance.transform.FindChild("Images").FindChild("Button").GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } } [HarmonyPatch(nameof(TravelLookBuff.SetBuff))] [HarmonyPostfix] - private static void SetBuff(TravelLookBuff __instance) => TranslateTexts(__instance); + public static void Post_SetBuff(TravelLookBuff __instance) + { + List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; + string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); - [HarmonyPatch(nameof(TravelLookBuff.OnMouseUpAsButton))] - [HarmonyPostfix] - private static void OnMouseUpAsButton(TravelLookBuff __instance) => TranslateTexts(__instance); - - [HarmonyPatch(nameof(TravelLookBuff.Clear))] - [HarmonyPostfix] - private static void Clear(TravelLookBuff __instance) => TranslateTexts(__instance); - - [HarmonyPatch(nameof(TravelLookBuff.SetText), new Type[] { typeof(string) })] - [HarmonyPostfix] - private static void SetText_String(TravelLookBuff __instance) => TranslateTexts(__instance); - - [HarmonyPatch(nameof(TravelLookBuff.SetText), new Type[] { typeof(bool), typeof(int) })] - [HarmonyPostfix] - private static void SetText_Bool(TravelLookBuff __instance) => TranslateTexts(__instance); + foreach (TextMeshProUGUI text in __instance.transform.FindChild("Images").FindChild("Button").GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + } + } } } \ No newline at end of file diff --git a/MelonLoader/Patches/Managers/TravelMgr_Patch.cs b/MelonLoader/Patches/Managers/TravelMgr_Patch.cs index 8161db6..013e6a2 100644 --- a/MelonLoader/Patches/Managers/TravelMgr_Patch.cs +++ b/MelonLoader/Patches/Managers/TravelMgr_Patch.cs @@ -63,6 +63,13 @@ namespace PvZ_Fusion_Translator.Patches.Managers File.WriteAllText(Path.Combine(dumpDir, "travel_buffs.json"), JsonSerializer.Serialize(dumpedTravelBuffs, options)); string stringDir = FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language); + string travelBuffDir = Path.Combine(stringDir, "travel_buffs.json"); + + if(!File.Exists(travelBuffDir)) + { + File.WriteAllText(travelBuffDir, JsonSerializer.Serialize(dumpedTravelBuffs, options)); + } + string travelBuffs = File.ReadAllText(Path.Combine(stringDir, "travel_buffs.json")); translatedTravelBuffs = JsonSerializer.Deserialize>>(travelBuffs);