From f2e4e78750d90232168a455860cfff183f832907 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Wed, 15 Jul 2026 17:17:28 -0400 Subject: [PATCH] 3.8 code --- MelonLoader/FileLoader.cs | 26 +- .../BaseTextObjects/InGameText_Patch.cs | 2 +- .../GameObjects/AlmanacBuffMenu_Patch.cs | 77 +-- .../ButtonObjects/PVPPotBtn_Patch.cs | 5 +- .../ButtonObjects/UIButton_Patch.cs | 35 +- .../GameObjects/GardenStoreMenu_Patch.cs | 40 ++ .../Patches/GameObjects/MainMenu_Patch.cs | 17 +- .../PlantCardPackageBuilder_Patch.cs | 22 + .../Patches/GameObjects/SeedLibrary_Patch.cs | 23 + .../Patches/Managers/PVPScareyPot_Patch.cs | 34 ++ .../Modes/Abyss/AbyssBuffMenu_Patch.cs | 4 +- .../Patches/Modes/Abyss/AbyssGoods_Patch.cs | 4 +- .../Modes/Abyss/AbyssLevelEnter_Patch.cs | 4 +- .../Patches/Modes/Abyss/AbyssMenu_Patch.cs | 4 +- .../Abyss/AbyssSelectBuffWindow_Patch.cs | 4 +- .../Modes/Abyss/AbyssStoreMenu_Patch.cs | 4 +- .../Modes/Odyssey/MultipleChoiceMenu_Patch.cs | 2 +- .../Modes/Odyssey/ShootingManager_Patch.cs | 576 +++++++++++++++++- .../Odyssey/TravelBuffOptionButton_Patch.cs | 11 + .../Modes/Odyssey/TravelLookBuff_Patch.cs | 11 + .../Patches/Modes/Odyssey/TravelMgr_Patch.cs | 234 +++++-- .../Modes/Odyssey/TravelStoreWindow_Patch.cs | 4 +- ...PvZ Fusion Translator [MelonLoader].csproj | 5 +- 23 files changed, 975 insertions(+), 173 deletions(-) create mode 100644 MelonLoader/Patches/GameObjects/GardenStoreMenu_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/PlantCardPackageBuilder_Patch.cs create mode 100644 MelonLoader/Patches/Managers/PVPScareyPot_Patch.cs diff --git a/MelonLoader/FileLoader.cs b/MelonLoader/FileLoader.cs index 042d28b..f3d9e36 100644 --- a/MelonLoader/FileLoader.cs +++ b/MelonLoader/FileLoader.cs @@ -205,7 +205,7 @@ namespace PvZ_Fusion_Translator // load abyss buffs - Patches.Modes.Abyss.AbyssBuffMenu_Patch.LoadAbyssBuffData(); + //Patches.Modes.Abyss.AbyssBuffMenu_Patch.LoadAbyssBuffData(); SaveStrings(); DumpJson(); @@ -259,10 +259,10 @@ namespace PvZ_Fusion_Translator { LoadFSStrings(jsonString); } - else if(fileName.EndsWith("abyss_buffs")) - { - Patches.Modes.Abyss.AbyssBuffMenu_Patch.LoadAbyssBuffData(); - } + //else if(fileName.EndsWith("abyss_buffs")) + //{ + // Patches.Modes.Abyss.AbyssBuffMenu_Patch.LoadAbyssBuffData(); + //} else if (fileName.EndsWith("travel_buffs")) { LoadTravelBuffs(); @@ -295,6 +295,8 @@ namespace PvZ_Fusion_Translator LoadDetailStrings(File.ReadAllText(detailStringsPath)); } + LoadChangelogText(); + SaveStrings(); DumpJson(); } @@ -988,11 +990,11 @@ namespace PvZ_Fusion_Translator // save abyss buffs - if(Patches.Modes.Abyss.AbyssBuffMenu_Patch.abyssBuffData != new Dictionary()) - { - string abyssBuffData = SerializeWithIndentation(Patches.Modes.Abyss.AbyssBuffMenu_Patch.abyssBuffData, 2); - File.WriteAllText(Path.Combine(stringDir, "abyss_buffs.json"), abyssBuffData); - } + //if(Patches.Modes.Abyss.AbyssBuffMenu_Patch.abyssBuffData != new Dictionary()) + //{ + // string abyssBuffData = SerializeWithIndentation(Patches.Modes.Abyss.AbyssBuffMenu_Patch.abyssBuffData, 2); + // File.WriteAllText(Path.Combine(stringDir, "abyss_buffs.json"), abyssBuffData); + //} // save almanacs @@ -1047,10 +1049,10 @@ namespace PvZ_Fusion_Translator } string LawnStrings = Resources.Load("LawnStrings").text; string ZombieStrings = Resources.Load("ZombieStrings").text; - string AbyssBuffData = Resources.Load("AbyssBuffData").text; + //string AbyssBuffData = Resources.Load("AbyssBuffData").text; File.WriteAllText(Path.Combine(dumpDir, "LawnStrings.json"), LawnStrings); File.WriteAllText(Path.Combine(dumpDir, "ZombieStrings.json"), ZombieStrings); - File.WriteAllText(Path.Combine(dumpDir, "AbyssBuffData.json"), AbyssBuffData); + //File.WriteAllText(Path.Combine(dumpDir, "AbyssBuffData.json"), AbyssBuffData); // dump iz tips var izDump = DumpIZStrings(); diff --git a/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs b/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs index a3c6c4c..077eade 100644 --- a/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs +++ b/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs @@ -103,7 +103,7 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects } else if (travelMatch != "") { - txt.text = travelMatch; + txt.text = TravelMgr_Patch.AddBuffName(travelMatch); if (txt.gameObject.name.Contains("main")) { originalText = txt.text; diff --git a/MelonLoader/Patches/GameObjects/AlmanacBuffMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacBuffMenu_Patch.cs index b32868f..968af10 100644 --- a/MelonLoader/Patches/GameObjects/AlmanacBuffMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/AlmanacBuffMenu_Patch.cs @@ -9,40 +9,13 @@ using static Il2Cpp.AlmanacBuffMenu; using static PvZ_Fusion_Translator.FileLoader; using static PvZ_Fusion_Translator.Patches.Modes.Odyssey.TravelMgr_Patch; using static PvZ_Fusion_Translator.Utils; +using Unity.VisualScripting; namespace PvZ_Fusion_Translator.Patches.GameObjects { [HarmonyPatch(typeof(AlmanacBuffMenu))] public static class AlmanacBuffMenu_Patch { - public static Dictionary modifierNameDict = new Dictionary() - { - { "advancedBuffs", "COMMON_MODIFIER_TAG" }, - { "ultimateBuffs", "EPIC_MODIFIER_TAG" }, - { "debuffs", "ZOMBIE_MODIFIER_TAG" }, - { "unlocks", "UNLOCK_MODIFIER_TAG" }, - { "investmentBuffs", "INVEST_MODIFIER_TAG" } - }; - - public static Dictionary fallbackNameDict = new Dictionary() - { - { "COMMON_MODIFIER_TAG", "Common Modifier" }, - { "EPIC_MODIFIER_TAG", "Epic Modifier" }, - { "ZOMBIE_MODIFIER_TAG", "Zombie Modifier" }, - { "UNLOCK_MODIFIER_TAG", "Unlock Modifier" }, - { "INVEST_MODIFIER_TAG", "Investment Modifier" } - }; - - public static string TranslateNameTag(string originalText) - { - string res = originalText; - - string nameTag = modifierNameDict[originalText]; - res = StringStore.translationString.ContainsKey(nameTag) ? StringStore.TranslateText(nameTag) : fallbackNameDict[nameTag]; - - return res; - } - [HarmonyPatch(nameof(AlmanacBuffMenu.Awake))] [HarmonyPostfix] public static void Post_Awake(AlmanacBuffMenu __instance) @@ -54,25 +27,59 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects if (buffData.Item1 == null || buffData.Item3 == null) continue; - string nameTag = TranslateNameTag(buffData.Item1); - cardUI.cost.text = $"{nameTag} #{buffData.Item2}"; + cardUI.cost.text = (buffData.Item4) ? buffData.Item1 : $"{buffData.Item1} #{buffData.Item2}"; } Post_OnCardClick(__instance); } + [HarmonyPatch(nameof(AlmanacBuffMenu.SetAllCards))] + [HarmonyPatch(nameof(AlmanacBuffMenu.Start))] + [HarmonyPatch(nameof(AlmanacBuffMenu.InitMenu))] + [HarmonyPostfix] + public static void Post_SetAllCards(AlmanacBuffMenu __instance) + { + foreach(AlmanacCardUI cardUI in __instance.cards) + { + AlmanacBuffMenu.CardInfo cardInfo = __instance.cardInfos[cardUI]; + var buffData = FindBuffData(cardInfo.description); + if (buffData.Item1 == null || buffData.Item3 == null) continue; + + cardUI.cost.text = (buffData.Item4) ? buffData.Item1 : $"{buffData.Item1} #{buffData.Item2}"; + } + + Post_OnToolClick(__instance); + + Post_OnCardClick(__instance); + } + + [HarmonyPatch(nameof(AlmanacBuffMenu.OnToolClick))] + [HarmonyPostfix] + public static void Post_OnToolClick(AlmanacBuffMenu __instance) + { + foreach(TextMeshProUGUI txt in __instance.toolButton.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + [HarmonyPatch(nameof(AlmanacBuffMenu.OnCardClick))] [HarmonyPostfix] public static void Post_OnCardClick(AlmanacBuffMenu __instance) { var buffData = FindBuffData(__instance.buffDescription.text); - if (buffData.Item1 == null || buffData.Item3 == null) return; + if (buffData.Item1 == null || buffData.Item3 == null) + { + return; + } - string nameTag = TranslateNameTag(buffData.Item1); - __instance.buffTitle.text = $"{nameTag} #{buffData.Item2}"; + __instance.buffTitle.text = (buffData.Item4) ? buffData.Item1 : $"{buffData.Item1} #{buffData.Item2}"; __instance.buffTitle.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - __instance.buffDescription.text = buffData.Item3 + "\n\n"; + string buffFStr = StringStore.translationStringRegex.ContainsKey("BUFF_NAME_FORMAT") ? StringStore.translationStringRegex["BUFF_NAME_FORMAT"] : "{0}: {1}"; + string fBuffDesc = string.Format(buffFStr, buffData.Item1, buffData.Item3); + __instance.buffDescription.text = (buffData.Item4) ? fBuffDesc + "\n\n" : buffData.Item3 + "\n\n"; __instance.buffDescription.font = FontStore.LoadTMPFont(Utils.Language.ToString()); string colorHex = StringStore.translationString.ContainsKey("MOD_ALMANAC_COL") ? StringStore.TranslateText("MOD_ALMANAC_COL") : "#000000"; System.Drawing.Color descriptionColor = ColorTranslator.FromHtml(colorHex); @@ -86,6 +93,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects Canvas.ForceUpdateCanvases(); __instance.buffDescription.ForceMeshUpdate(); + + Post_OnToolClick(__instance); } } } diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/PVPPotBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/PVPPotBtn_Patch.cs index 375a287..2dfd98e 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/PVPPotBtn_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/PVPPotBtn_Patch.cs @@ -1,12 +1,13 @@ using HarmonyLib; using Il2Cpp; +using Il2CppPVPScaryPot; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using UnityEngine; namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects { - [HarmonyPatch(typeof(PVPPotBtn))] + /*[HarmonyPatch(typeof(PVPPotBtn))] public class PVPPotBtn_Patch { [HarmonyPostfix] @@ -38,5 +39,5 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects __instance.gameObject.SetActive(true); } } - } + }*/ } diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index 22dbe7a..515f9d8 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -46,40 +46,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects [HarmonyPostfix] public static void Postfix_OnMouseUpAsButton(UIButton __instance) { - try + foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren()) { - if (__instance.transform.childCount >= 2) - { - if (__instance.name == "EditMode") - { - TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - - TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); - TextMeshProUGUI[] extraTexts = __instance.transform.GetChild(1).GetComponentsInChildren(); - - 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()); - } - } + txt.text = StringStore.TranslateText(txt.text); + txt.font = FontStore.LoadTMPFont(Utils.Language.ToString()); } - catch (Exception) { } } } } diff --git a/MelonLoader/Patches/GameObjects/GardenStoreMenu_Patch.cs b/MelonLoader/Patches/GameObjects/GardenStoreMenu_Patch.cs new file mode 100644 index 0000000..fcb586d --- /dev/null +++ b/MelonLoader/Patches/GameObjects/GardenStoreMenu_Patch.cs @@ -0,0 +1,40 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppAlmanacData; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using System.Drawing; +using Il2CppZenGarden; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(GardenStoreMenu))] + public static class GardenStoreMenu_Patch + { + [HarmonyPatch(nameof(GardenStoreMenu.InitGoodsList))] + [HarmonyPatch(nameof(GardenStoreMenu.GetDatas))] + [HarmonyPatch(nameof(GardenStoreMenu.PurchaseGoods))] + [HarmonyPatch(nameof(GardenStoreMenu.Update))] + [HarmonyPatch(nameof(GardenStoreMenu.Start))] + [HarmonyPostfix] + public static void TranslateGardenStoreMenu(GardenStoreMenu __instance) + { + foreach(GardenShopSlot slot in __instance.GetComponentsInChildren()) + { + TranslateGardenShopSlot(slot); + } + } + + [HarmonyPatch(nameof(GardenShopSlot.Start))] + [HarmonyPostfix] + public static void TranslateGardenShopSlot(GardenShopSlot __instance) + { + foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + } +} diff --git a/MelonLoader/Patches/GameObjects/MainMenu_Patch.cs b/MelonLoader/Patches/GameObjects/MainMenu_Patch.cs index f1792c5..770d936 100644 --- a/MelonLoader/Patches/GameObjects/MainMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/MainMenu_Patch.cs @@ -11,6 +11,7 @@ using UnityEngine.UIElements; namespace PvZ_Fusion_Translator.Patches.GameObjects { + [HarmonyPatch(typeof(MainMenu))] public class MainMenu_Patch { public static void AnimOver(BaseMenu __instance) @@ -93,14 +94,16 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects messageText.text = "Hello this is multilanguage choose language over there ------>";*/ } - public static void HideLangButton(GameObject btn) + [HarmonyPatch(nameof(MainMenu.EnterUpdateUrl))] + [HarmonyPrefix] + public static bool Pre_EnterUpdateUrl(MainMenu __instance) { - btn.GetComponent().enabled = false; - } - - public static void ShowLangButton(GameObject btn) - { - btn.GetComponent().enabled = true; + System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo + { + FileName = @"https://github.com/Teyliu/PVZF-Translation", + UseShellExecute = true + }); + return false; } } } \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/PlantCardPackageBuilder_Patch.cs b/MelonLoader/Patches/GameObjects/PlantCardPackageBuilder_Patch.cs new file mode 100644 index 0000000..50c7f38 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/PlantCardPackageBuilder_Patch.cs @@ -0,0 +1,22 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(PlantCardPackageBuilder))] + public static class PlantCardPackageBuilder_Patch + { + [HarmonyPatch(nameof(PlantCardPackageBuilder.UpdateText))] + [HarmonyPostfix] + private static void UpdateText(PlantCardPackageBuilder __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + __instance.text.text = StringStore.TranslateText(__instance.text.text); + __instance.text.font = fontAsset; + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/SeedLibrary_Patch.cs b/MelonLoader/Patches/GameObjects/SeedLibrary_Patch.cs index ea01e81..f307a4f 100644 --- a/MelonLoader/Patches/GameObjects/SeedLibrary_Patch.cs +++ b/MelonLoader/Patches/GameObjects/SeedLibrary_Patch.cs @@ -31,5 +31,28 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects } } } + + [HarmonyPatch(nameof(SeedLibrary.Start))] + [HarmonyPatch(nameof(SeedLibrary.SetAllCards))] + [HarmonyPostfix] + private static void SetAllCards(SeedLibrary __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + //foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + //{ + // txt.text = StringStore.TranslateText(txt.text); + // txt.font = fontAsset; + //} + + foreach(TextMeshProUGUI txt in __instance.page.GetComponentsInChildren(true)) + { + txt.font = fontAsset; + if (!Utils.CheckForUntranslatedText(txt.text)) + { + txt.text = StringStore.TranslateText(txt.text); + } + } + } } } \ No newline at end of file diff --git a/MelonLoader/Patches/Managers/PVPScareyPot_Patch.cs b/MelonLoader/Patches/Managers/PVPScareyPot_Patch.cs new file mode 100644 index 0000000..3302de1 --- /dev/null +++ b/MelonLoader/Patches/Managers/PVPScareyPot_Patch.cs @@ -0,0 +1,34 @@ +using Il2Cpp; +using UnityEngine; +using HarmonyLib; +using Il2CppPVPScaryPot; +using PvZ_Fusion_Translator.AssetStore; + +namespace PvZ_Fusion_Translator.Patches.Managers +{ + [HarmonyPatch(typeof(PVPScareyPot))] + public static class PVPScareyPot_Patch + { + [HarmonyPatch(nameof(PVPScareyPot.Awake))] + [HarmonyPatch(nameof(PVPScareyPot.Start))] + [HarmonyPatch(nameof(PVPScareyPot.AutoRuleUpdate))] + [HarmonyPatch(nameof(PVPScareyPot.RandomCardUpdate))] + [HarmonyPatch(nameof(PVPScareyPot.Update))] + [HarmonyPostfix] + public static void TranslatePlayerDatas(PVPScareyPot __instance) + { + TranslatePlayerData(__instance.player1); + TranslatePlayerData(__instance.player2); + TranslatePlayerData(__instance.currentPlayer); + } + + public static void TranslatePlayerData(PVPScareyPot.PlayerData playerData) + { + if(playerData != null) + { + playerData.textMesh.text = StringStore.TranslateText(playerData.textMesh.text); + playerData.textMesh.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + } +} diff --git a/MelonLoader/Patches/Modes/Abyss/AbyssBuffMenu_Patch.cs b/MelonLoader/Patches/Modes/Abyss/AbyssBuffMenu_Patch.cs index b12f7eb..9353590 100644 --- a/MelonLoader/Patches/Modes/Abyss/AbyssBuffMenu_Patch.cs +++ b/MelonLoader/Patches/Modes/Abyss/AbyssBuffMenu_Patch.cs @@ -15,7 +15,7 @@ using static PvZ_Fusion_Translator.FileLoader; namespace PvZ_Fusion_Translator.Patches.Modes.Abyss { - [HarmonyPatch(typeof(AbyssBuffMenu))] + /*[HarmonyPatch(typeof(AbyssBuffMenu))] public static class AbyssBuffMenu_Patch { public static Dictionary abyssBuffData = new Dictionary(); @@ -129,5 +129,5 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Abyss return null; } - } + }*/ } diff --git a/MelonLoader/Patches/Modes/Abyss/AbyssGoods_Patch.cs b/MelonLoader/Patches/Modes/Abyss/AbyssGoods_Patch.cs index a20ee73..70a5b12 100644 --- a/MelonLoader/Patches/Modes/Abyss/AbyssGoods_Patch.cs +++ b/MelonLoader/Patches/Modes/Abyss/AbyssGoods_Patch.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace PvZ_Fusion_Translator.Patches.Modes.Abyss { - [HarmonyPatch(typeof(AbyssGoods))] + /*[HarmonyPatch(typeof(AbyssGoods))] public static class AbyssGoods_Patch { [HarmonyPostfix] @@ -18,5 +18,5 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Abyss __instance.hasText.text = StringStore.TranslateText(__instance.hasText.text, false); __instance.hasText_shadow.text = StringStore.TranslateText(__instance.hasText_shadow.text, false); } - } + }*/ } diff --git a/MelonLoader/Patches/Modes/Abyss/AbyssLevelEnter_Patch.cs b/MelonLoader/Patches/Modes/Abyss/AbyssLevelEnter_Patch.cs index 4dc73a3..ab7e8d1 100644 --- a/MelonLoader/Patches/Modes/Abyss/AbyssLevelEnter_Patch.cs +++ b/MelonLoader/Patches/Modes/Abyss/AbyssLevelEnter_Patch.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace PvZ_Fusion_Translator.Patches.Modes.Abyss { - [HarmonyPatch(typeof(AbyssLevelEnter))] + /*[HarmonyPatch(typeof(AbyssLevelEnter))] public static class AbyssLevelEnter_Patch { [HarmonyPatch(nameof(AbyssLevelEnter.SetLevel))] @@ -15,5 +15,5 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Abyss { __instance.levelName = StringStore.TranslateText(__instance.levelName); } - } + }*/ } diff --git a/MelonLoader/Patches/Modes/Abyss/AbyssMenu_Patch.cs b/MelonLoader/Patches/Modes/Abyss/AbyssMenu_Patch.cs index b6ebf8f..93c1b32 100644 --- a/MelonLoader/Patches/Modes/Abyss/AbyssMenu_Patch.cs +++ b/MelonLoader/Patches/Modes/Abyss/AbyssMenu_Patch.cs @@ -11,7 +11,7 @@ using MelonLoader.Utils; namespace PvZ_Fusion_Translator.Patches.Modes.Abyss { - [HarmonyPatch(typeof(AbyssMenu))] + /*[HarmonyPatch(typeof(AbyssMenu))] public static class AbyssMenu_Patch { [HarmonyPatch(nameof(AbyssMenu.Awake))] @@ -45,5 +45,5 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Abyss txt.font = fontAsset; } } - } + }*/ } diff --git a/MelonLoader/Patches/Modes/Abyss/AbyssSelectBuffWindow_Patch.cs b/MelonLoader/Patches/Modes/Abyss/AbyssSelectBuffWindow_Patch.cs index e4ac857..ee1c2d3 100644 --- a/MelonLoader/Patches/Modes/Abyss/AbyssSelectBuffWindow_Patch.cs +++ b/MelonLoader/Patches/Modes/Abyss/AbyssSelectBuffWindow_Patch.cs @@ -7,7 +7,7 @@ using System.Text.RegularExpressions; namespace PvZ_Fusion_Translator.Patches.Modes.Abyss { - [HarmonyPatch(typeof(AbyssSelectBuffWindow))] + /*[HarmonyPatch(typeof(AbyssSelectBuffWindow))] public static class AbyssSelectBuffWindow_Patch { [HarmonyPatch(nameof(AbyssSelectBuffWindow.OnAnimOver))] @@ -53,5 +53,5 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Abyss __instance.introduce.font = fontAsset; } } - } + }*/ } diff --git a/MelonLoader/Patches/Modes/Abyss/AbyssStoreMenu_Patch.cs b/MelonLoader/Patches/Modes/Abyss/AbyssStoreMenu_Patch.cs index 971e7d5..18946f0 100644 --- a/MelonLoader/Patches/Modes/Abyss/AbyssStoreMenu_Patch.cs +++ b/MelonLoader/Patches/Modes/Abyss/AbyssStoreMenu_Patch.cs @@ -5,7 +5,7 @@ using PvZ_Fusion_Translator.AssetStore; namespace PvZ_Fusion_Translator.Patches.Modes.Abyss { - [HarmonyPatch(typeof(AbyssStoreMenu))] + /*[HarmonyPatch(typeof(AbyssStoreMenu))] public static class AbyssStoreMenu_Patch { [HarmonyPatch(nameof(AbyssStoreMenu.Update))] @@ -20,5 +20,5 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Abyss text.font = fontAsset; } } - } + }*/ } diff --git a/MelonLoader/Patches/Modes/Odyssey/MultipleChoiceMenu_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/MultipleChoiceMenu_Patch.cs index 9540207..a8371aa 100644 --- a/MelonLoader/Patches/Modes/Odyssey/MultipleChoiceMenu_Patch.cs +++ b/MelonLoader/Patches/Modes/Odyssey/MultipleChoiceMenu_Patch.cs @@ -20,8 +20,8 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey [HarmonyPatch(nameof(MultipleChoiceMenu.Awake))] [HarmonyPatch(nameof(MultipleChoiceMenu.Cancel))] [HarmonyPatch(nameof(MultipleChoiceMenu.Refresh))] + [HarmonyPatch(nameof(MultipleChoiceMenu.TurnPage))] [HarmonyPatch(nameof(MultipleChoiceMenu.UpdateWindow))] - [HarmonyPatch(nameof(MultipleChoiceMenu.UpdateWindows))] [HarmonyPostfix] public static void Awake(MultipleChoiceMenu __instance) { diff --git a/MelonLoader/Patches/Modes/Odyssey/ShootingManager_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/ShootingManager_Patch.cs index b20146b..514e1a9 100644 --- a/MelonLoader/Patches/Modes/Odyssey/ShootingManager_Patch.cs +++ b/MelonLoader/Patches/Modes/Odyssey/ShootingManager_Patch.cs @@ -1,19 +1,583 @@ using HarmonyLib; -using Il2CppGameLevel; -using Il2Cpp; -using UnityEngine; using Il2CppGameLevel.RogueShooting; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey { [HarmonyPatch(typeof(ShootingManager))] public static class ShootingManager_Patch { - [HarmonyPatch(nameof(ShootingManager.UpgradeBuff))] - [HarmonyPostfix] - public static void UpgradeBuff(ShootingManager __instance, ref MultipleChoiceMenu menu) + [HarmonyPatch(nameof(ShootingManager.RegisterCoreBuff))] + [HarmonyPatch(nameof(ShootingManager.RegisterExpertBuff))] + [HarmonyPatch(nameof(ShootingManager.RegisterGetPlantBuff))] + [HarmonyPatch(nameof(ShootingManager.RegisterOtherBuff))] + [HarmonyPostfix] + public static void UpgradeBuff(ShootingManager __instance, ref Il2Cpp.MultipleChoiceMenu menu) { MultipleChoiceMenu_Patch.Awake(menu); } + + public static void GetBuffs() + { + /*#region code + + AbyssSwordStar t0 = new(); + Bamboo t1 = new(); + BigChomper t4 = new(); + BigGatling t5 = new(); + CabbageCannon t6 = new(); + Cabbagepult t7 = new(); + Cactus t8 = new(); + Caltrop t9 = new(); + CaltropNut t10 = new(); + CattailLour t11 = new(); + CherryChomper t12 = new(); + CherryGatling t13 = new(); + CherrySquash t14 = new(); + Chomper t15 = new(); + Cornpult t17 = new(); + DoomCactus t20 = new(); + DoomChomper t21 = new(); + DoomSniper t22 = new(); + EmeraleBlover t23 = new(); + FireMelon t24 = new(); + FumeShroom t25 = new(); + GarlicFume t26 = new(); + GloomShroom t28 = new(); + GoldCabbage t29 = new(); + HelmetGatling t30 = new(); + HypnoEmperor t31 = new(); + HypnoNut t32 = new(); + HypnoShroom t33 = new(); + IceFumeShroom t34 = new(); + IcePuff t35 = new(); + IFVIronPuff t36 = new(); + IronPuff t37 = new(); + LanternSplit t38 = new(); + LanternUmbrella t39 = new(); + LaserUmbrella t40 = new(); + LotusBamboo t41 = new(); + Melonpult t42 = new(); + NuclearSquash t43 = new(); + ObsidianSpike t44 = new(); + ObsidianWallNut t45 = new(); + PeaMine t46 = new(); + Peashooter t47 = new(); + PortalCorn t48 = new(); + PotatoMine t49 = new(); + ScaredyDoom t54 = new(); + ScaredyShroom t55 = new(); + SmallPuff t57 = new(); + SniperPea t58 = new(); + SnowGatlingPuff t59 = new(); + SpikeRock t61 = new(); + Squalour t62 = new(); + Squash t63 = new(); + StarFruit t64 = new(); + SuperChomper t66 = new(); + SuperHypno t67 = new(); + SuperMelon t68 = new(); + SuperStar t69 = new(); + SuperThreePeater t70 = new(); + SwordStar t71 = new(); + TallNut t72 = new(); + ThreeMine t73 = new(); + ThreePeater t74 = new(); + ThreeSquash t75 = new(); + UltimateBamboo t76 = new(); + UltimateBigChomper t77 = new(); + UltimateBigGatling t78 = new(); + UltimateBlover t79 = new(); + UltimateCabbage t80 = new(); + UltimateCabbageCannon t81 = new(); + UltimateCactus t82 = new(); + UltimateChomper t83 = new(); + UltimateCorn t84 = new(); + UltimateDoomScared t85 = new(); + UltimateFume t86 = new(); + UltimateGatling t87 = new(); + UltimateGloom t88 = new(); + UltimateHelmetGatling t89 = new(); + UltimateHypno t90 = new(); + UltimateLanternSplit t91 = new(); + UltimateMelon t92 = new(); + UltimateMinigun t93 = new(); + UltimatePoisonFume t94 = new(); + UltimateSniperGatling t95 = new(); + UltimateSpring t96 = new(); + UltimateStar t97 = new(); + UltimateStarTorch t98 = new(); + UltimateTallNut t99 = new(); + UltimateWinterMelon t100 = new(); + Umbrellaleaf t101 = new(); + WallNut t103 = new(); + WinterMelon t104 = new(); + + Dictionary t = new(); + + #region 3 + + if(t0.Buffs != null) + { + Utils.TryAdd(t, t0.Role, t0.Role); + } + + if(t1.Buffs != null) + { + Utils.TryAdd(t, t1.Role, t1.Role); + } + + if(t4.Buffs != null) + { + Utils.TryAdd(t, t4.Role, t4.Role); + } + + if(t5.Buffs != null) + { + Utils.TryAdd(t, t5.Role, t5.Role); + } + + if(t6.Buffs != null) + { + Utils.TryAdd(t, t6.Role, t6.Role); + } + + if(t7.Buffs != null) + { + Utils.TryAdd(t, t7.Role, t7.Role); + } + + if(t8.Buffs != null) + { + Utils.TryAdd(t, t8.Role, t8.Role); + } + + if(t9.Buffs != null) + { + Utils.TryAdd(t, t9.Role, t9.Role); + } + + if(t10.Buffs != null) + { + Utils.TryAdd(t, t10.Role, t10.Role); + } + + if(t11.Buffs != null) + { + Utils.TryAdd(t, t11.Role, t11.Role); + } + + if(t12.Buffs != null) + { + Utils.TryAdd(t, t12.Role, t12.Role); + } + + if(t13.Buffs != null) + { + Utils.TryAdd(t, t13.Role, t13.Role); + } + + if(t14.Buffs != null) + { + Utils.TryAdd(t, t14.Role, t14.Role); + } + + if(t15.Buffs != null) + { + Utils.TryAdd(t, t15.Role, t15.Role); + } + + if(t17.Buffs != null) + { + Utils.TryAdd(t, t17.Role, t17.Role); + } + + if(t20.Buffs != null) + { + Utils.TryAdd(t, t20.Role, t20.Role); + } + + if(t21.Buffs != null) + { + Utils.TryAdd(t, t21.Role, t21.Role); + } + + if(t22.Buffs != null) + { + Utils.TryAdd(t, t22.Role, t22.Role); + } + + if(t23.Buffs != null) + { + Utils.TryAdd(t, t23.Role, t23.Role); + } + + if(t24.Buffs != null) + { + Utils.TryAdd(t, t24.Role, t24.Role); + } + + if(t25.Buffs != null) + { + Utils.TryAdd(t, t25.Role, t25.Role); + } + + if(t26.Buffs != null) + { + Utils.TryAdd(t, t26.Role, t26.Role); + } + + if(t28.Buffs != null) + { + Utils.TryAdd(t, t28.Role, t28.Role); + } + + if(t29.Buffs != null) + { + Utils.TryAdd(t, t29.Role, t29.Role); + } + + if(t30.Buffs != null) + { + Utils.TryAdd(t, t30.Role, t30.Role); + } + + if(t31.Buffs != null) + { + Utils.TryAdd(t, t31.Role, t31.Role); + } + + if(t32.Buffs != null) + { + Utils.TryAdd(t, t32.Role, t32.Role); + } + + if(t33.Buffs != null) + { + Utils.TryAdd(t, t33.Role, t33.Role); + } + + if(t34.Buffs != null) + { + Utils.TryAdd(t, t34.Role, t34.Role); + } + + if(t35.Buffs != null) + { + Utils.TryAdd(t, t35.Role, t35.Role); + } + + if(t36.Buffs != null) + { + Utils.TryAdd(t, t36.Role, t36.Role); + } + + if(t37.Buffs != null) + { + Utils.TryAdd(t, t37.Role, t37.Role); + } + + if(t38.Buffs != null) + { + Utils.TryAdd(t, t38.Role, t38.Role); + } + + if(t39.Buffs != null) + { + Utils.TryAdd(t, t39.Role, t39.Role); + } + + if(t40.Buffs != null) + { + Utils.TryAdd(t, t40.Role, t40.Role); + } + + if(t41.Buffs != null) + { + Utils.TryAdd(t, t41.Role, t41.Role); + } + + if(t42.Buffs != null) + { + Utils.TryAdd(t, t42.Role, t42.Role); + } + + if(t43.Buffs != null) + { + Utils.TryAdd(t, t43.Role, t43.Role); + } + + if(t44.Buffs != null) + { + Utils.TryAdd(t, t44.Role, t44.Role); + } + + if(t45.Buffs != null) + { + Utils.TryAdd(t, t45.Role, t45.Role); + } + + if(t46.Buffs != null) + { + Utils.TryAdd(t, t46.Role, t46.Role); + } + + if(t47.Buffs != null) + { + Utils.TryAdd(t, t47.Role, t47.Role); + } + + if(t48.Buffs != null) + { + Utils.TryAdd(t, t48.Role, t48.Role); + } + + if(t49.Buffs != null) + { + Utils.TryAdd(t, t49.Role, t49.Role); + } + + if(t54.Buffs != null) + { + Utils.TryAdd(t, t54.Role, t54.Role); + } + + if(t55.Buffs != null) + { + Utils.TryAdd(t, t55.Role, t55.Role); + } + + if(t57.Buffs != null) + { + Utils.TryAdd(t, t57.Role, t57.Role); + } + + if(t58.Buffs != null) + { + Utils.TryAdd(t, t58.Role, t58.Role); + } + + if(t59.Buffs != null) + { + Utils.TryAdd(t, t59.Role, t59.Role); + } + + if(t61.Buffs != null) + { + Utils.TryAdd(t, t61.Role, t61.Role); + } + + if(t62.Buffs != null) + { + Utils.TryAdd(t, t62.Role, t62.Role); + } + + if(t63.Buffs != null) + { + Utils.TryAdd(t, t63.Role, t63.Role); + } + + if(t64.Buffs != null) + { + Utils.TryAdd(t, t64.Role, t64.Role); + } + + if(t66.Buffs != null) + { + Utils.TryAdd(t, t66.Role, t66.Role); + } + + if(t67.Buffs != null) + { + Utils.TryAdd(t, t67.Role, t67.Role); + } + + if(t68.Buffs != null) + { + Utils.TryAdd(t, t68.Role, t68.Role); + } + + if(t69.Buffs != null) + { + Utils.TryAdd(t, t69.Role, t69.Role); + } + + if(t70.Buffs != null) + { + Utils.TryAdd(t, t70.Role, t70.Role); + } + + if(t71.Buffs != null) + { + Utils.TryAdd(t, t71.Role, t71.Role); + } + + if(t72.Buffs != null) + { + Utils.TryAdd(t, t72.Role, t72.Role); + } + + if(t73.Buffs != null) + { + Utils.TryAdd(t, t73.Role, t73.Role); + } + + if(t74.Buffs != null) + { + Utils.TryAdd(t, t74.Role, t74.Role); + } + + if(t75.Buffs != null) + { + Utils.TryAdd(t, t75.Role, t75.Role); + } + + if(t76.Buffs != null) + { + Utils.TryAdd(t, t76.Role, t76.Role); + } + + if(t77.Buffs != null) + { + Utils.TryAdd(t, t77.Role, t77.Role); + } + + if(t78.Buffs != null) + { + Utils.TryAdd(t, t78.Role, t78.Role); + } + + if(t79.Buffs != null) + { + Utils.TryAdd(t, t79.Role, t79.Role); + } + + if(t80.Buffs != null) + { + Utils.TryAdd(t, t80.Role, t80.Role); + } + + if(t81.Buffs != null) + { + Utils.TryAdd(t, t81.Role, t81.Role); + } + + if(t82.Buffs != null) + { + Utils.TryAdd(t, t82.Role, t82.Role); + } + + if(t83.Buffs != null) + { + Utils.TryAdd(t, t83.Role, t83.Role); + } + + if(t84.Buffs != null) + { + Utils.TryAdd(t, t84.Role, t84.Role); + } + + if(t85.Buffs != null) + { + Utils.TryAdd(t, t85.Role, t85.Role); + } + + if(t86.Buffs != null) + { + Utils.TryAdd(t, t86.Role, t86.Role); + } + + if(t87.Buffs != null) + { + Utils.TryAdd(t, t87.Role, t87.Role); + } + + if(t88.Buffs != null) + { + Utils.TryAdd(t, t88.Role, t88.Role); + } + + if(t89.Buffs != null) + { + Utils.TryAdd(t, t89.Role, t89.Role); + } + + if(t90.Buffs != null) + { + Utils.TryAdd(t, t90.Role, t90.Role); + } + + if(t91.Buffs != null) + { + Utils.TryAdd(t, t91.Role, t91.Role); + } + + if(t92.Buffs != null) + { + Utils.TryAdd(t, t92.Role, t92.Role); + } + + if(t93.Buffs != null) + { + Utils.TryAdd(t, t93.Role, t93.Role); + } + + if(t94.Buffs != null) + { + Utils.TryAdd(t, t94.Role, t94.Role); + } + + if(t95.Buffs != null) + { + Utils.TryAdd(t, t95.Role, t95.Role); + } + + if(t96.Buffs != null) + { + Utils.TryAdd(t, t96.Role, t96.Role); + } + + if(t97.Buffs != null) + { + Utils.TryAdd(t, t97.Role, t97.Role); + } + + if(t98.Buffs != null) + { + Utils.TryAdd(t, t98.Role, t98.Role); + } + + if(t99.Buffs != null) + { + Utils.TryAdd(t, t99.Role, t99.Role); + } + + if(t100.Buffs != null) + { + Utils.TryAdd(t, t100.Role, t100.Role); + } + + if(t101.Buffs != null) + { + Utils.TryAdd(t, t101.Role, t101.Role); + } + + if(t103.Buffs != null) + { + Utils.TryAdd(t, t103.Role, t103.Role); + } + + if(t104.Buffs != null) + { + Utils.TryAdd(t, t104.Role, t104.Role); + } + + #endregion + + File.WriteAllText("tge_roles.json", FileLoader.SerializeWithIndentation(t)); + + #endregion*/ + } } } diff --git a/MelonLoader/Patches/Modes/Odyssey/TravelBuffOptionButton_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/TravelBuffOptionButton_Patch.cs index a8138a0..a20704f 100644 --- a/MelonLoader/Patches/Modes/Odyssey/TravelBuffOptionButton_Patch.cs +++ b/MelonLoader/Patches/Modes/Odyssey/TravelBuffOptionButton_Patch.cs @@ -27,6 +27,17 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey public static void TranslateOptionButton(TravelBuffOptionButton button) { + if(TravelMgr_Patch.travelBuffString.ContainsKey(button.introduce.text)) + { + string translatedBuff = travelBuffString[button.introduce.text]; + button.introduce.text = AddBuffName(translatedBuff); + } + + if(!Utils.CheckForUntranslatedText(button.introduce.text)) + { + button.introduce.text = AddBuffName(button.introduce.text); + } + if(!TravelMgr_Patch.travelBuffString.ContainsKey(button.introduce.text) && Utils.CheckForUntranslatedText(button.introduce.text)) { button.introduce.text = StringStore.TranslateText(button.introduce.text); diff --git a/MelonLoader/Patches/Modes/Odyssey/TravelLookBuff_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/TravelLookBuff_Patch.cs index 9629857..53c1360 100644 --- a/MelonLoader/Patches/Modes/Odyssey/TravelLookBuff_Patch.cs +++ b/MelonLoader/Patches/Modes/Odyssey/TravelLookBuff_Patch.cs @@ -44,6 +44,17 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey foreach (TextMeshProUGUI text in __instance.transform.FindChild("Images").FindChild("Introduce").GetComponentsInChildren()) { + if(TravelMgr_Patch.travelBuffString.ContainsKey(text.text)) + { + string translatedBuff = travelBuffString[text.text]; + text.text = AddBuffName(translatedBuff); + } + + if(!Utils.CheckForUntranslatedText(text.text)) + { + text.text = AddBuffName(text.text); + } + if(!TravelMgr_Patch.travelBuffString.ContainsKey(text.text) && Utils.CheckForUntranslatedText(text.text)) { text.text = StringStore.TranslateText(text.text); diff --git a/MelonLoader/Patches/Modes/Odyssey/TravelMgr_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/TravelMgr_Patch.cs index de356eb..e96322e 100644 --- a/MelonLoader/Patches/Modes/Odyssey/TravelMgr_Patch.cs +++ b/MelonLoader/Patches/Modes/Odyssey/TravelMgr_Patch.cs @@ -14,35 +14,81 @@ using static PvZ_Fusion_Translator.FileLoader; namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey { + public class TravelBuffInfo + { + public string name = ""; + public string desc = ""; + + public TravelBuffInfo(string name_a = "", string desc_a = "") + { + name = name_a; + desc = desc_a; + } + } + + public class TravelBuffSet + { + public SortedDictionary advancedBuffs = new(); + public SortedDictionary ultimateBuffs = new(); + public SortedDictionary debuffs = new(); + public SortedDictionary unlocks = new(); + public SortedDictionary investmentBuffs = new(); + private Dictionary> _travelBuffSets = []; + + public TravelBuffSet() + { + advancedBuffs = new(); + ultimateBuffs = new(); + debuffs = new(); + unlocks = new(); + investmentBuffs = new(); + + _travelBuffSets = new() + { + { "advancedBuffs", advancedBuffs }, + { "ultimateBuffs", ultimateBuffs }, + { "debuffs", debuffs }, + { "unlocks", unlocks }, + { "investmentBuffs", investmentBuffs } + }; + } + + public SortedDictionary TryGet(string name) + { + switch(name) + { + case "advancedBuffs": + return advancedBuffs; + case "ultimateBuffs": + return ultimateBuffs; + case "debuffs": + return debuffs; + case "unlocks": + return unlocks; + case "investmentBuffs": + return investmentBuffs; + default: + return null; + } + } + + public IEnumerator>> GetEnumerator() + { + foreach(var item in _travelBuffSets) + { + yield return new(item.Key, item.Value); + } + } + } + [HarmonyPatch(typeof(TravelMgr))] public static class TravelMgr_Patch { - public static readonly Dictionary> templateTravelBuffs = new() - { - { "advancedBuffs", new SortedDictionary() }, - { "ultimateBuffs", new SortedDictionary() }, - { "debuffs", new SortedDictionary() }, - { "unlocks", new SortedDictionary() }, - { "investmentBuffs", new SortedDictionary() } - }; - - public static Dictionary> dumpedTravelBuffs = new() - { - { "advancedBuffs", new SortedDictionary() }, - { "ultimateBuffs", new SortedDictionary() }, - { "debuffs", new SortedDictionary() }, - { "unlocks", new SortedDictionary() }, - { "investmentBuffs", new SortedDictionary() } - }; + public static readonly TravelBuffSet templateTravelBuffs = new(); - public static Dictionary> translatedTravelBuffs = new() - { - { "advancedBuffs", new SortedDictionary() }, - { "ultimateBuffs", new SortedDictionary() }, - { "debuffs", new SortedDictionary() }, - { "unlocks", new SortedDictionary() }, - { "investmentBuffs", new SortedDictionary() } - }; + public static TravelBuffSet dumpedTravelBuffs = new(); + + public static TravelBuffSet translatedTravelBuffs = new(); public static Dictionary travelBuffString = new() { @@ -63,8 +109,8 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey public static void GetText(TravelMgr __instance, ref string __result) { if (travelBuffString.ContainsKey(__result)) - { - __result = travelBuffString[__result]; + { + __result = travelBuffString[__result]; } else if(travelBuffString.ContainsKey(RemoveBuffName(__result))) { @@ -79,54 +125,47 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey public static void DumpTravelBuffs() { TravelMgr.Instance.GetPlantBuffUnlockCount(PlantType.DoomGatling); - dumpedTravelBuffs = new(templateTravelBuffs); + + dumpedTravelBuffs = new(); travelBuffString.Clear(); foreach (var pair in TravelDictionary.advancedBuffsText) { - Utils.TryAdd(dumpedTravelBuffs["advancedBuffs"], (int)pair.Key, pair.Value); + Utils.TryAdd(dumpedTravelBuffs.advancedBuffs, (int)pair.Key, new TravelBuffInfo("", pair.Value)); Utils.TryAdd(travelBuffString, pair.Value, pair.Value); } foreach (var pair in TravelDictionary.ultimateBuffsText) { - Utils.TryAdd(dumpedTravelBuffs["ultimateBuffs"], (int)pair.Key, pair.Value); + Utils.TryAdd(dumpedTravelBuffs.ultimateBuffs, (int)pair.Key, new TravelBuffInfo("", pair.Value)); Utils.TryAdd(travelBuffString, pair.Value, pair.Value); } foreach (var pair in TravelDictionary.debuffData) { - Utils.TryAdd(dumpedTravelBuffs["debuffs"], (int)pair.Key, pair.Value.Item1); + Utils.TryAdd(dumpedTravelBuffs.debuffs, (int)pair.Key, new TravelBuffInfo("", pair.Value.Item1)); Utils.TryAdd(travelBuffString, pair.Value.Item1, pair.Value.Item1); } foreach (var pair in TravelDictionary.unlocksText) { - Utils.TryAdd(dumpedTravelBuffs["unlocks"], (int)pair.Key, pair.Value); + Utils.TryAdd(dumpedTravelBuffs.unlocks, (int)pair.Key, new TravelBuffInfo("", pair.Value)); Utils.TryAdd(travelBuffString, pair.Value, pair.Value); } foreach (var pair in TravelMgr.InvestBuffsData) { - Utils.TryAdd(dumpedTravelBuffs["investmentBuffs"], (int)pair.Key, pair.Value.GetDescription()); + Utils.TryAdd(dumpedTravelBuffs.investmentBuffs, (int)pair.Key, new TravelBuffInfo("", pair.Value.GetDescription())); Utils.TryAdd(travelBuffString, pair.Value.GetDescription(), pair.Value.GetDescription()); } - File.WriteAllText(Path.Combine(GetAssetDir(AssetType.Dumps), "travel_buffs.json"), JsonSerializer.Serialize(dumpedTravelBuffs, new JsonSerializerOptions - { - WriteIndented = true, - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping - })); + File.WriteAllText(Path.Combine(GetAssetDir(AssetType.Dumps), "travel_buffs.json"), SerializeWithIndentation(dumpedTravelBuffs)); string translatedTravelBuffsPath = Path.Combine(GetAssetDir(AssetType.Strings, Utils.Language), "travel_buffs.json"); if (!File.Exists(translatedTravelBuffsPath)) { - File.WriteAllText(translatedTravelBuffsPath, JsonSerializer.Serialize(dumpedTravelBuffs, new JsonSerializerOptions - { - WriteIndented = true, - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping - })); + File.WriteAllText(translatedTravelBuffsPath, SerializeWithIndentation(dumpedTravelBuffs)); translatedTravelBuffs = dumpedTravelBuffs; } } @@ -138,30 +177,30 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey DumpTravelBuffs(); - Dictionary> travelBuffs = JsonSerializer.Deserialize>>(travelBuffsContent); + TravelBuffSet travelBuffs = Newtonsoft.Json.JsonConvert.DeserializeObject(travelBuffsContent); translatedTravelBuffs = travelBuffs; travelBuffString.Clear(); foreach(var i in travelBuffs) { - var originalBuffSet = dumpedTravelBuffs[i.Key]; + var originalBuffSet = dumpedTravelBuffs.TryGet(i.Item1); foreach(var j in originalBuffSet) { - string originalBuff = j.Value; - var translatedBuffSet = travelBuffs[i.Key]; + TravelBuffInfo originalBuff = j.Value; + var translatedBuffSet = travelBuffs.TryGet(i.Item1); - if (j.Value == originalBuff) + if (j.Value.desc == originalBuff.desc) { if (translatedBuffSet.ContainsKey(j.Key)) { - Utils.TryAdd(travelBuffString, originalBuff, translatedBuffSet[j.Key]); + Utils.TryAdd(travelBuffString, originalBuff.desc, translatedBuffSet[j.Key].desc); } } - else if(j.Value == RemoveBuffName(originalBuff)) + else if(j.Value.desc == RemoveBuffName(originalBuff.desc)) { if (translatedBuffSet.ContainsKey(j.Key)) { - Utils.TryAdd(travelBuffString, originalBuff, translatedBuffSet[j.Key]); + Utils.TryAdd(travelBuffString, originalBuff.desc, translatedBuffSet[j.Key].desc); } } @@ -185,14 +224,14 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey foreach (var i in dumpedTravelBuffs) { - foreach (var j in dumpedTravelBuffs[i.Key]) + foreach (var j in dumpedTravelBuffs.TryGet(i.Item1)) { - if (j.Value == originalText || j.Value == RemoveBuffName(originalText)) + if (j.Value.desc == originalText || j.Value.desc == RemoveBuffName(originalText)) { - var translatedBuffSet = translatedTravelBuffs[i.Key]; + var translatedBuffSet = translatedTravelBuffs.TryGet(i.Item1); if (translatedBuffSet.ContainsKey(j.Key)) { - res = translatedBuffSet[j.Key]; + res = translatedBuffSet[j.Key].desc; } break; } @@ -215,16 +254,53 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey return res; } - public static ValueTuple FindBuffData(string buffText) + public static Dictionary modifierNameDict = new Dictionary() { - ValueTuple res = new(); + { "advancedBuffs", "COMMON_MODIFIER_TAG" }, + { "ultimateBuffs", "EPIC_MODIFIER_TAG" }, + { "debuffs", "ZOMBIE_MODIFIER_TAG" }, + { "unlocks", "UNLOCK_MODIFIER_TAG" }, + { "investmentBuffs", "INVEST_MODIFIER_TAG" } + }; + + public static Dictionary fallbackNameDict = new Dictionary() + { + { "COMMON_MODIFIER_TAG", "Common Modifier" }, + { "EPIC_MODIFIER_TAG", "Epic Modifier" }, + { "ZOMBIE_MODIFIER_TAG", "Zombie Modifier" }, + { "UNLOCK_MODIFIER_TAG", "Unlock Modifier" }, + { "INVEST_MODIFIER_TAG", "Investment Modifier" } + }; + + public static string TranslateNameTag(string originalText) + { + string res = originalText; + + string nameTag = modifierNameDict[originalText]; + res = StringStore.translationString.ContainsKey(nameTag) ? StringStore.TranslateText(nameTag) : fallbackNameDict[nameTag]; + + return res; + } + + public static ValueTuple FindBuffData(string buffText) + { + ValueTuple res = new(); foreach(var pair1 in translatedTravelBuffs) { - foreach(var pair2 in pair1.Value) + foreach(var pair2 in pair1.Item2) { - if(buffText == pair2.Value) + if(buffText == pair2.Value.desc) { - res.Item1 = pair1.Key; + if(pair2.Value.name != "") + { + res.Item1 = pair2.Value.name; + res.Item4 = true; + } + else + { + res.Item1 = TranslateNameTag(pair1.Item1); + res.Item4 = false; + } res.Item2 = pair2.Key; } } @@ -232,11 +308,20 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey foreach(var pair1 in dumpedTravelBuffs) { - foreach(var pair2 in pair1.Value) + foreach(var pair2 in pair1.Item2) { - if(buffText == pair2.Value) + if(buffText == pair2.Value.desc) { - res.Item1 = pair1.Key; + if(pair2.Value.name != "") + { + res.Item1 = pair2.Value.name; + res.Item4 = true; + } + else + { + res.Item1 = TranslateNameTag(pair1.Item1); + res.Item4 = false; + } res.Item2 = pair2.Key; } } @@ -255,5 +340,28 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey return res; } + + public static string fallbackFBuffStr = "{0}: {1}"; + + public static string AddBuffName(string buffText) + { + string translatedBuff = buffText; + if(Utils.CheckForUntranslatedText(buffText)) + { + if(travelBuffString.ContainsKey(buffText)) + { + translatedBuff = travelBuffString[buffText]; + } + } + var buffData = FindBuffData(translatedBuff); + if(buffData.Item1 != null && buffData.Item3 != null) + { + string buffFStr = StringStore.translationStringRegex.ContainsKey("BUFF_NAME_FORMAT") ? StringStore.translationStringRegex["BUFF_NAME_FORMAT"] : "{0}: {1}"; + string fBuffDesc = string.Format(buffFStr, buffData.Item1, buffData.Item3); + translatedBuff = fBuffDesc; + } + + return translatedBuff; + } } } diff --git a/MelonLoader/Patches/Modes/Odyssey/TravelStoreWindow_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/TravelStoreWindow_Patch.cs index b0dd5bf..b8fc49f 100644 --- a/MelonLoader/Patches/Modes/Odyssey/TravelStoreWindow_Patch.cs +++ b/MelonLoader/Patches/Modes/Odyssey/TravelStoreWindow_Patch.cs @@ -27,11 +27,11 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey string startText = match.Groups[1].Value; string affinityText = match.Groups[3].Value; string affinities = TranslateAffinities(affinityText); - __instance.introduce.text = startText + affinities; + __instance.introduce.text = AddBuffName(startText) + affinities; } else { - __instance.introduce.text = originalText; + __instance.introduce.text = AddBuffName(originalText); } foreach (var text in __instance.buttonText) diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 8eb8423..af66eba 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -13,7 +13,7 @@ latest enable Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate - C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.7 + C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.8 AnyCPU;ARM64;x64 @@ -405,6 +405,7 @@ + @@ -422,7 +423,9 @@ + +