From 25621b7df08a476af0ed7497d0dcb5ffaaeee138 Mon Sep 17 00:00:00 2001 From: TuanAnh2901 Date: Sat, 27 Dec 2025 16:34:10 +0700 Subject: [PATCH] Sync MelonLoader from origin/main (keep BepInEx changes) --- BepInEx/Patches/GameObjects/BaseMenu_Patch.cs | 8 ++ .../ButtonObjects/NormalBtn_Patch.cs | 19 +-- .../GameObjects/TravelBuffMenu_Patch.cs | 4 + .../TravelBuffOptionButton_Patch.cs | 9 +- .../Patches/GameObjects/TravelStore_Patch.cs | 23 ++-- .../Managers/AlmanacPlantBank_Patch.cs | 18 +++ .../Managers/OppositeBuffManager_Patch.cs | 117 ++++++------------ .../PvZ Fusion Translator [BepInEx].csproj | 6 +- MelonLoader/Core.cs | 2 +- .../GameObjects/AlmanacPlantMenu_Patch.cs | 85 +------------ .../ExploreMakeZombieButton_Patch.cs | 6 +- .../ButtonObjects/UIButton_Patch.cs | 40 ++++++ .../Patches/GameObjects/EveBuffMenu_Patch.cs | 38 ++++++ .../GameObjects/EveOptionWindow_Patch.cs | 50 ++++++++ .../GameObjects/MinorObjects/Brain_Patch.cs | 57 +++++++++ .../GameObjects/NoticePauseMenu_Patch.cs | 2 +- .../GameObjects/PlantDamageMenu_Patch.cs | 37 ++++++ .../Patches/Managers/IZBottomMenu_Patch.cs | 36 ++---- ...PvZ Fusion Translator [MelonLoader].csproj | 4 + MelonLoader/Utils.cs | 44 +++++++ 20 files changed, 395 insertions(+), 210 deletions(-) create mode 100644 MelonLoader/Patches/GameObjects/EveBuffMenu_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/EveOptionWindow_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/MinorObjects/Brain_Patch.cs create mode 100644 MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs diff --git a/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs b/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs index fa05462..a5b96c8 100644 --- a/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/BaseMenu_Patch.cs @@ -114,6 +114,14 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("LastPage")); } + Transform pageNewAdvantureLevelTransform = levelsTransform.transform.Find("PageNewAdvantureLevel"); + if (pageNewAdvantureLevelTransform != null) + { + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("BackToIndex")); + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("Nextpage")); + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("LastPage")); + } + foreach (TextMeshProUGUI txt in mainTransform.GetComponentsInChildren()) { // Still dump untranslated strings for modded plants and zombies diff --git a/BepInEx/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs index 674fbc7..79ad47d 100644 --- a/BepInEx/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs +++ b/BepInEx/Patches/GameObjects/ButtonObjects/NormalBtn_Patch.cs @@ -11,13 +11,16 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects { [HarmonyPostfix] [HarmonyPatch(nameof(NormalBtn.OnMouseUpAsButton))] - public static void OnMouseUpAsButton(NormalBtn __instance) - { - Transform banTransform = __instance.transform.GetChild(0); - if (banTransform != null) - { - banTransform.GetComponent().text = StringStore.TranslateText(banTransform.GetComponent().text); - } + public static void OnMouseUpAsButton(NormalBtn __instance) + { + if (__instance.transform.childCount > 0) + { + Transform banTransform = __instance.transform.GetChild(0); + if (banTransform != null) + { + banTransform.GetComponent().text = StringStore.TranslateText(banTransform.GetComponent().text); + } + } } - } + } } \ No newline at end of file diff --git a/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs b/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs index 3d49ad1..2532e0c 100644 --- a/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs +++ b/BepInEx/Patches/GameObjects/TravelBuffMenu_Patch.cs @@ -3,6 +3,7 @@ using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; using static PvZ_Fusion_Translator__BepInEx_.Patches.Managers.TravelMgr_Patch; using UnityEngine; +using System.Collections.Generic; namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { @@ -16,6 +17,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects foreach (TravelBuffOptionButton button in __instance.options) { button.introduce.text = translatedTravelBuffs[buffLinks[button.buffType]][button.buffIndex]; + List buffSet = translatedTravelBuffs[buffLinks[button.buffType]]; + string buffText = (button.buffIndex < buffSet.Count && button.show != null) ? buffSet[button.buffIndex] : StringStore.TranslateText(button.introduce.text); + button.introduce.text = buffText; } } } diff --git a/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs b/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs index 2b07a77..9c67c46 100644 --- a/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs +++ b/BepInEx/Patches/GameObjects/TravelBuffOptionButton_Patch.cs @@ -16,7 +16,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects private static void SetBuff(TravelBuffOptionButton __instance) { List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; - string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + string buffText = (__instance.buffIndex < buffSet.Count && __instance.show != null) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + __instance.introduce.text = buffText; } [HarmonyPatch(nameof(TravelBuffOptionButton.Awake))] @@ -24,7 +25,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects private static void Awake(TravelBuffOptionButton __instance) { List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; - string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + string buffText = (__instance.buffIndex < buffSet.Count && __instance.show != null) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + __instance.introduce.text = buffText; } [HarmonyPatch(nameof(TravelBuffOptionButton.OnAnimOver))] @@ -32,7 +34,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects private static void OnAnimOver(TravelBuffOptionButton __instance) { List buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]]; - string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + string buffText = (__instance.buffIndex < buffSet.Count && __instance.show != null) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text); + __instance.introduce.text = buffText; } } } diff --git a/BepInEx/Patches/GameObjects/TravelStore_Patch.cs b/BepInEx/Patches/GameObjects/TravelStore_Patch.cs index a8c54a5..5635ef8 100644 --- a/BepInEx/Patches/GameObjects/TravelStore_Patch.cs +++ b/BepInEx/Patches/GameObjects/TravelStore_Patch.cs @@ -8,19 +8,18 @@ using System.Linq; namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects { - [HarmonyPatch(typeof(TravelStore))] public static class TravelStore_Patch { [HarmonyPatch(nameof(TravelStore.Update))] [HarmonyPostfix] private static void Update(TravelStore __instance) { - foreach(TextMeshProUGUI text in __instance.introduces) + foreach (TextMeshProUGUI text in __instance.introduces) { - if(__instance.currentSelect != null) + if (__instance.currentSelect != null) { var buffList = translatedTravelBuffs[buffLinks[(BuffType)__instance.currentSelect.theBuffType]]; - if(__instance.currentSelect.theBuffNumber < buffList.Count) + if (__instance.currentSelect.theBuffNumber < buffList.Count && __instance.currentSelect.theBuffNumber > -1) { text.text = buffList[__instance.currentSelect.theBuffNumber]; } @@ -45,18 +44,26 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects TextMeshProUGUI cost = buff.transform.GetChild(1).GetComponent(); cost.text = StringStore.TranslateText(cost.text); cost.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - //FileLoader.DumpUntranslatedStrings(cost.text); } + foreach (TextMeshProUGUI text in __instance.introduces) { if (__instance.currentSelect != null) { - text.text = translatedTravelBuffs[buffLinks[(BuffType)__instance.currentSelect.theBuffType]][__instance.currentSelect.theBuffNumber]; + var buffList = translatedTravelBuffs[buffLinks[(BuffType)__instance.currentSelect.theBuffType]]; + if (__instance.currentSelect.theBuffNumber < buffList.Count && __instance.currentSelect.theBuffNumber > -1) + { + text.text = buffList[__instance.currentSelect.theBuffNumber]; + } + else + { + text.text = StringStore.TranslateText(text.text); + } } } foreach (var textMesh in __instance.points) - { - textMesh.text = StringStore.TranslateText(textMesh.text); + { + textMesh.text = StringStore.TranslateText(textMesh.text); } } } diff --git a/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs b/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs index a99abb7..5d70093 100644 --- a/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs +++ b/BepInEx/Patches/Managers/AlmanacPlantBank_Patch.cs @@ -204,5 +204,23 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers banText.text = StringStore.TranslateText(banText.text); } } + + [HarmonyPatch(nameof(AlmanacPlantBank.Start))] + [HarmonyPostfix] + public static void Post_Start(AlmanacPlantBank __instance) + { + GameObject skinTextObj = __instance.skinButton.transform.GetChild(0).gameObject; + GameObject skinShadowTextObj = UnityEngine.Object.Instantiate(skinTextObj, parent: __instance.skinButton.transform); + TextMeshPro skinShadowText = skinShadowTextObj.GetComponent(); + skinShadowText.text = StringStore.TranslateText("换肤_S"); + skinShadowText.sortingOrder -= 2; + skinShadowTextObj.transform.Translate(new Vector3(0.015f, -0.015f, 0)); + skinTextObj.transform.Translate(new Vector3(-0.022f, 0)); + skinShadowTextObj.transform.Translate(new Vector3(-0.022f, 0)); + __instance.skinButton.transform.localScale /= 1.75f; + __instance.skinButton.transform.Translate(new Vector3(-0.075f, -0.15f, 0)); + __instance.skinButton.transform.GetChild(1).Translate(new Vector3(0.35f, 0)); + __instance.skinButton.transform.GetChild(2).Translate(new Vector3(-0.35f, 0)); + } } } \ No newline at end of file diff --git a/BepInEx/Patches/Managers/OppositeBuffManager_Patch.cs b/BepInEx/Patches/Managers/OppositeBuffManager_Patch.cs index 8111a9c..b35fa41 100644 --- a/BepInEx/Patches/Managers/OppositeBuffManager_Patch.cs +++ b/BepInEx/Patches/Managers/OppositeBuffManager_Patch.cs @@ -1,89 +1,48 @@ using HarmonyLib; -using System; -using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using TMPro; +using UnityEngine; namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers { - [HarmonyPatch(typeof(OppositeBuffManager))] - public static class OppositeBuffManager_Patch - { -#if TESTING - [HarmonyPatch(nameof(OppositeBuffManager.InitBuffPool))] - [HarmonyPostfix] - private static void InitBuffPool(OppositeBuffManager __instance) - { - foreach(TextMeshProUGUI text in __instance.textA_bad) - { - string stripText = text.text.Replace("但", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textA_good) - { - text.text = StringStore.TranslateText(text.text); - } + [HarmonyPatch(typeof(OppositeBuffManager))] + public static class OppositeBuffManager_Patch + { + public static Dictionary buffLinks = TravelMgr_Patch.buffLinks; + public static Dictionary> translatedTravelBuffs = TravelMgr_Patch.translatedTravelBuffs; + public static string badPattern = @"^但(.*)"; + public static string badFormat = StringStore.translationStringRegex.ContainsKey(badPattern) ? StringStore.translationStringRegex[badPattern] : "But, {0}"; + public static TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - foreach(TextMeshProUGUI text in __instance.textB_bad) - { - string stripText = text.text.Replace("但", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textB_good) - { - text.text = StringStore.TranslateText(text.text); - } - } + [HarmonyPatch(nameof(OppositeBuffManager.Awake))] + [HarmonyPostfix] + private static void Awake(OppositeBuffManager __instance) + { + TranslateOppositeText(__instance.textA_bad, BuffType.Debuff, __instance.buffA.theDebuffID, true); + TranslateOppositeText(__instance.textA_good, __instance.buffA.theOptionType, __instance.buffA.theOptionID); + TranslateOppositeText(__instance.textB_bad, BuffType.Debuff, __instance.buffB.theDebuffID, true); + TranslateOppositeText(__instance.textB_good, __instance.buffB.theOptionType, __instance.buffB.theOptionID); + } - [HarmonyPatch(nameof(OppositeBuffManager.SetText), new Type[] { typeof(TextMeshProUGUI), typeof(BuffType), typeof(int)})] - [HarmonyPostfix] - private static void SetText(OppositeBuffManager __instance) - { - foreach(TextMeshProUGUI text in __instance.textA_bad) - { - string stripText = text.text.Replace("?", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textA_good) - { - text.text = StringStore.TranslateText(text.text); - } + public static void TranslateOppositeText(Il2CppSystem.Collections.Generic.List textList, BuffType buffType, int buffIndex, bool isBad = false) + { + string buff = translatedTravelBuffs[buffLinks[buffType]][buffIndex]; - foreach(TextMeshProUGUI text in __instance.textB_bad) - { - string stripText = text.text.Replace("但", ""); - string translatedText = StringStore.TranslateText(stripText); - string replacementText = StringStore.translationString["但"] + translatedText; - text.text = replacementText; - } - foreach(TextMeshProUGUI text in __instance.textB_good) - { - text.text = StringStore.TranslateText(text.text); - } - } -#endif + foreach (var text in textList) + { + if (isBad) + { + text.text = string.Format(badFormat, buff); + } + else + { + text.text = buff; + } - [HarmonyPatch(nameof(OppositeBuffManager.SetText), new Type[] { typeof(TextMeshProUGUI), typeof(BuffType), typeof(int)})] - [HarmonyPostfix] - private static void SetText(OppositeBuffManager __instance, ref TextMeshProUGUI text) - { - StringStore.TranslateTextUI(text); - } - - [HarmonyPatch(nameof(OppositeBuffManager.Awake))] - [HarmonyPostfix] - private static void Awake(OppositeBuffManager __instance) - { - StringStore.TranslateTextUI(__instance.textA_bad[0]); - StringStore.TranslateTextUI(__instance.textA_bad[1]); - StringStore.TranslateTextUI(__instance.textB_bad[0]); - StringStore.TranslateTextUI(__instance.textB_bad[1]); - } - - } + text.font = fontAsset; + } + } + } } diff --git a/BepInEx/PvZ Fusion Translator [BepInEx].csproj b/BepInEx/PvZ Fusion Translator [BepInEx].csproj index 9fc2fa2..5efe955 100644 --- a/BepInEx/PvZ Fusion Translator [BepInEx].csproj +++ b/BepInEx/PvZ Fusion Translator [BepInEx].csproj @@ -13,7 +13,8 @@ https://nuget.samboy.dev/v3/index.json PvZ_Fusion_Translator__BepInEx_ - D:\PvZ Fusion\BepInEx Game Files + C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.1.1-BepInEx + C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.1.1 Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate;DebugMulti AnyCPU;x64 @@ -592,8 +593,7 @@ - - + diff --git a/MelonLoader/Core.cs b/MelonLoader/Core.cs index 54cddc8..c9eb3b3 100644 --- a/MelonLoader/Core.cs +++ b/MelonLoader/Core.cs @@ -35,7 +35,7 @@ namespace PvZ_Fusion_Translator AudioStore.Init(); FontStore.Init(); Utils.RegisterPlantIndices(); - + //Utils.RegisterRecipeLinks(); } public override void OnLateInitializeMelon() diff --git a/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs index 3dbf239..80ab13e 100644 --- a/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs @@ -7,6 +7,7 @@ using Unity.Collections; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; +using static Il2Cpp.AlmanacPlantBank; using static PvZ_Fusion_Translator.FileLoader; using static PvZ_Fusion_Translator.Utils; @@ -50,7 +51,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects public static bool SearchChanged(AlmanacPlantMenu __instance, ref TMP_InputField inputField) { string search = inputField.text; - if (search != StringStore.TranslateText("搜索")) + if (search != StringStore.TranslateText("搜索") && search != "") { string currentLanguage = Utils.Language.ToString(); string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); @@ -62,30 +63,12 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects TMP_FontAsset fontAsset = FontStore.LoadTMPFont(currentLanguage); - AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); + PlantData plantData = JsonUtility.FromJson(json); Il2CppSystem.Collections.Generic.List searchedPlants = new(); - foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants) + foreach (PlantInfo plantInfo in plantData.plants) { - //List uniqueIngredients = GetIngredients(plantInfo.seedType); - - //// ingredient-based search - - //foreach(int i in uniqueIngredients) - //{ - // string name = Utils.GetPlantNameFromAlmanac((PlantType)i); - - // if(name.ToLower().Contains(search.ToLower())) - // { - // searchedPlants.Add((PlantType)i); - // } - //} - - // keyword-based search - - // name-based search - if (plantInfo.name.ToLower().Contains(search.ToLower())) { searchedPlants.Add((PlantType)plantInfo.seedType); @@ -99,65 +82,5 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects return true; } - - private static List GetIngredients(int theSeedType) - { - List ingredientPairs = new(); - Il2CppSystem.Array mixData = MixData.data.Cast(); - int rows = mixData.GetLength(0); - int columns = mixData.GetLength(1); - - for(int i = 0; i < rows; i++) - { - for(int j = 0; j < columns; j++) - { - if(ContainsFormula(theSeedType)) - { - if (mixData.GetValue(i, j).Unbox() == theSeedType) - { - if (!ingredientPairs.Contains(i)) - { - ingredientPairs.Add(i); - } - - if (!ingredientPairs.Contains(j)) - { - ingredientPairs.Add(j); - } - } - } - else - { - return ingredientPairs; - } - - } - } - - return ingredientPairs; - } - - private static bool ContainsFormula(int theSeedType) - { - bool contains = false; - - Il2CppSystem.Array mixData = MixData.data.Cast(); - int rows = mixData.GetLength(0); - int columns = mixData.GetLength(1); - - for (int i = 0; i < rows; i++) - { - for (int j = 0; j < columns; j++) - { - if (mixData.GetValue(i, j).Unbox() == theSeedType) - { - contains = true; - return contains; - } - } - } - - return contains; - } } } diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs index da7b212..49d638f 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/ExploreMakeZombieButton_Patch.cs @@ -13,8 +13,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects [HarmonyPatch(nameof(ExploreMakeZombieButton.Start))] public static void Start(ExploreMakeZombieButton __instance) { - //__instance.sceneText.text = Utils.GetZombieNameFromAlmanac(__instance.theZombieType); - //__instance.sceneText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - } + __instance.sceneText.text = Utils.GetZombieNameFromAlmanac(__instance.theZombieType); + __instance.sceneText.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } } } \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index cc57702..22dbe7a 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -41,5 +41,45 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects } } } + + [HarmonyPatch(nameof(UIButton.OnMouseUpAsButton))] + [HarmonyPostfix] + public static void Postfix_OnMouseUpAsButton(UIButton __instance) + { + try + { + 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()); + } + } + } + catch (Exception) { } + } } } diff --git a/MelonLoader/Patches/GameObjects/EveBuffMenu_Patch.cs b/MelonLoader/Patches/GameObjects/EveBuffMenu_Patch.cs new file mode 100644 index 0000000..51725ab --- /dev/null +++ b/MelonLoader/Patches/GameObjects/EveBuffMenu_Patch.cs @@ -0,0 +1,38 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(EveBuffMenu))] + public static class EveBuffMenu_Patch + { + [HarmonyPatch(nameof(EveBuffMenu.Start))] + [HarmonyPostfix] + private static void Start(EveBuffMenu __instance) + { + foreach (EveOptionWindow window in __instance.windows) + { + EveOptionWindow_Patch.TranslateEveOptionWindow(window); + } + + foreach (TextMeshProUGUI text in __instance.quitButton.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText("合上"); + } + } + + [HarmonyPatch(nameof(EveBuffMenu.InitWindows))] + [HarmonyPostfix] + private static void InitWindows(EveBuffMenu __instance) + { + foreach(EveOptionWindow window in __instance.windows) + { + EveOptionWindow_Patch.TranslateEveOptionWindow(window); + } + } + } +} diff --git a/MelonLoader/Patches/GameObjects/EveOptionWindow_Patch.cs b/MelonLoader/Patches/GameObjects/EveOptionWindow_Patch.cs new file mode 100644 index 0000000..3d0a4c0 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/EveOptionWindow_Patch.cs @@ -0,0 +1,50 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(EveOptionWindow))] + public static class EveOptionWindow_Patch + { + [HarmonyPatch(nameof(EveOptionWindow.SetType))] + [HarmonyPostfix] + private static void SetType(EveOptionWindow __instance) + { + TranslateEveOptionWindow(__instance); + } + + [HarmonyPatch(nameof(EveOptionWindow.OnAnimOver))] + [HarmonyPostfix] + private static void OnAnimOver(EveOptionWindow __instance) + { + TranslateEveOptionWindow(__instance); + } + + [HarmonyPatch(nameof(EveOptionWindow.SelectedByRow))] + [HarmonyPostfix] + private static void SelectedByRow(EveOptionWindow __instance) + { + TranslateEveOptionWindow(__instance); + } + + public static void TranslateEveOptionWindow(EveOptionWindow __instance) + { + Transform introduceTransform = __instance.transform.FindChild("Images").FindChild("Introduce"); + TextMeshProUGUI introduceText = introduceTransform.GetComponent(); + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + introduceText.text = StringStore.TranslateText(introduceText.text); + introduceText.font = fontAsset; + + foreach (TextMeshProUGUI text in __instance.buttonText) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + } + } + } +} diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/Brain_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/Brain_Patch.cs new file mode 100644 index 0000000..58a09e7 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/MinorObjects/Brain_Patch.cs @@ -0,0 +1,57 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using System.Text.RegularExpressions; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects +{ + [HarmonyPatch(typeof(Brain))] + public static class Brain_Patch + { + [HarmonyPostfix] + [HarmonyPatch(nameof(Brain.Awake))] + private static void Awake(Brain __instance) + { + // reposition original points + Transform pointsTransform = __instance.points.transform; + GameObject pointsObject = __instance.points.gameObject; + pointsTransform.position = new Vector3(-6.5f, pointsTransform.position.y, pointsTransform.position.z); + + // instantiate and move new shadow + GameObject pointsShadowObject = UnityEngine.Object.Instantiate(pointsObject, parent: pointsTransform); + pointsShadowObject.SetActive(true); + Transform pointsShadowTransform = pointsShadowObject.transform; + pointsShadowTransform.position = new Vector3(-6.485f, pointsTransform.position.y - 0.015f, pointsTransform.position.z); + + // set points text + TextMeshPro pointsShadowText = pointsShadowObject.GetComponent(); + pointsShadowText.text = __instance.points.text; + pointsShadowText.sortingOrder -= 2; + pointsShadowText.color = Color.black; + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(Brain.Update))] + private static void Update(Brain __instance) + { + if(__instance.transform.Find("Points").GetChild(0) != null) + { + TextMeshPro shadowText = __instance.transform.Find("Points").GetChild(0).GetComponent(); + shadowText.text = __instance.points.text; + } + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(Brain.WinAction))] + private static void WinAction(Brain __instance) + { + if (__instance.transform.Find("Points").GetChild(0) != null) + { + TextMeshPro shadowText = __instance.transform.Find("Points").GetChild(0).GetComponent(); + shadowText.text = __instance.points.text; + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs b/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs index 2e73634..cdfd61e 100644 --- a/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/NoticePauseMenu_Patch.cs @@ -38,7 +38,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects 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 + GameObject contentObject = __instance.transform.FindChild("Scroll View/Viewport/Content").gameObject; TextMeshProUGUI contentText = contentObject.GetComponent(); contentText.text = changelogText; diff --git a/MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs b/MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs new file mode 100644 index 0000000..c5e3bb1 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs @@ -0,0 +1,37 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(PlantDamageMenu))] + public static class PlantDamageMenu_Patch + { + [HarmonyPatch(nameof(PlantDamageMenu.Awake))] + [HarmonyPostfix] + private static void Awake(PlantDamageMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + } + } + + [HarmonyPatch(nameof(PlantDamageMenu.InitCards))] + [HarmonyPostfix] + private static void InitCards(PlantDamageMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = fontAsset; + } + } + } +} diff --git a/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs b/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs index 976806b..8630912 100644 --- a/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs +++ b/MelonLoader/Patches/Managers/IZBottomMenu_Patch.cs @@ -14,24 +14,19 @@ namespace PvZ_Fusion_Translator.Patches.Managers [HarmonyPostfix] public static void ChangeStringz(IZBottomMenu __instance) { - TextMeshProUGUI[] array = - [ - __instance.transform.GetChild(0).GetComponent(), - __instance.transform.GetChild(0).GetChild(0).GetComponent(), - ]; - for (int i = 0; i < array.Length; i++) + foreach(TextMeshProUGUI text in __instance.levelName) { string fStr = StringStore.translationStringRegex["([^\\s]+),推荐难度:(\\d+)"]; - string[] parts = array[i].text.Split(",推荐难度:"); + string[] parts = text.text.Split(",推荐难度:"); - if(new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text)) + if(new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(text.text)) { string customName = (StringStore.translationString.ContainsKey(parts[0] + "_IZ")) ? parts[0] + "_IZ" : parts[0]; - array[i].text = string.Format(fStr, StringStore.TranslateText(customName), parts[1]); + text.text = string.Format(fStr, StringStore.TranslateText(customName), parts[1]); } - - array[i] = StringStore.TranslateText(array[i]); - array[i].text = array[i].text.Replace("\n", " "); + + text.text = StringStore.TranslateText(text.text); + text.text = text.text.Replace("\n", " "); } } @@ -39,23 +34,18 @@ namespace PvZ_Fusion_Translator.Patches.Managers [HarmonyPostfix] public static void SetLevelName(IZBottomMenu __instance) { - TextMeshProUGUI[] array = - [ - __instance.transform.GetChild(0).GetComponent(), - __instance.transform.GetChild(0).GetChild(0).GetComponent(), - ]; - for (int i = 0; i < array.Length; i++) + foreach(TextMeshProUGUI text in __instance.levelName) { string fStr = StringStore.translationStringRegex["([^\\s]+),推荐难度:(\\d+)"]; - string[] parts = array[i].text.Split(",推荐难度:"); + string[] parts = text.text.Split(",推荐难度:"); - if (new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text)) + if (new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(text.text)) { - array[i].text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]); + text.text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]); } - array[i] = StringStore.TranslateText(array[i]); - array[i].text = array[i].text.Replace("\n", " "); + text.text = StringStore.TranslateText(text.text); + text.text = text.text.Replace("\n", " "); } } } diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index e2604aa..9d1f60d 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -406,6 +406,10 @@ + + + + diff --git a/MelonLoader/Utils.cs b/MelonLoader/Utils.cs index e44fad9..6bb2e79 100644 --- a/MelonLoader/Utils.cs +++ b/MelonLoader/Utils.cs @@ -7,6 +7,7 @@ using PvZ_Fusion_Translator.AssetStore; using PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects; using System.Diagnostics; using System.Text.RegularExpressions; +using Unity.Burst.Intrinsics; using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.UI; @@ -299,6 +300,49 @@ namespace PvZ_Fusion_Translator } } + public static Dictionary> recipeLinks = new Dictionary>(); + + public static void RegisterRecipeLinks() + { + recipeLinks.Clear(); + + Il2CppSystem.Array mixData = MixData.data.Cast(); + int rows = mixData.GetLength(0); + int columns = mixData.GetLength(1); + + foreach (PlantType plantType in Enum.GetValues(typeof(PlantType))) + { + int seedType = (int)plantType; + + recipeLinks.Add(seedType, new()); + + if(seedType > 0) + { + foreach (PlantType checkType in Enum.GetValues(typeof(PlantType))) + { + if(checkType > 0) + { + int[] checks = [mixData.GetValue(seedType, (int)checkType).Unbox(), mixData.GetValue((int)checkType, seedType).Unbox()]; + + if (checks[0] != 0) + { + recipeLinks[seedType].Add(checks[0]); + } + + if (checks[1] != 0) + { + recipeLinks[seedType].Add(checks[1]); + } + } + } + } + if (recipeLinks[seedType].Count > 0) + { + Log.LogDebug($"Found {recipeLinks[seedType].Count} fusions for {seedType}!"); + } + } + } + public static bool CheckForUntranslatedText(string text) { Regex regex = new("\\p{IsCJKUnifiedIdeographs}+");