diff --git a/.gitignore b/.gitignore index f8d1c11..bad0472 100644 --- a/.gitignore +++ b/.gitignore @@ -131,3 +131,4 @@ MelonLoader/bin/x64/Debug/net6.0/UnityEngine.WindModule.dll MelonLoader/bin/x64/Debug/net6.0/UnityEngine.XRModule.dll MelonLoader/bin/x64/Debug/net6.0/WebSocketDotNet.dll /BepInEx/bin/Debug/net6.0 +.HOWTO-sync-MelonLoader-from-origin-main.txt \ No newline at end of file diff --git a/BepInEx/ModFeatures.cs b/BepInEx/ModFeatures.cs index 913ac20..b63a432 100644 --- a/BepInEx/ModFeatures.cs +++ b/BepInEx/ModFeatures.cs @@ -1,4 +1,4 @@ -#if DEBUG +//#if DEBUG using System; using System.Collections.Generic; using PvZ_Fusion_Translator__BepInEx_.AssetStore; @@ -77,4 +77,4 @@ namespace PvZ_Fusion_Translator__BepInEx_ } } } -#endif \ No newline at end of file +//#endif \ No newline at end of file diff --git a/BepInEx/Patches/Managers/InGameUI_Patch.cs b/BepInEx/Patches/Managers/InGameUI_Patch.cs index 6217816..f1c4d88 100644 --- a/BepInEx/Patches/Managers/InGameUI_Patch.cs +++ b/BepInEx/Patches/Managers/InGameUI_Patch.cs @@ -3,6 +3,7 @@ using System; using TMPro; using PvZ_Fusion_Translator__BepInEx_.AssetStore; using System.Text.RegularExpressions; +using UnityEngine; namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers { @@ -28,5 +29,101 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers array2[i].text = array2[i].text.Replace("\n", " "); } } + + [HarmonyPatch(nameof(InGameUI.Update))] + [HarmonyPostfix] + private static void Update(InGameUI __instance) + { + ApplyShovelBankTranslations(__instance.transform); + } + + private static void ApplyShovelBankTranslations(Transform root) + { + var shovelBank = root.Find("ShovelBank"); + if (!shovelBank) return; + + string currentLanguage = Utils.Language.ToString(); + var fontAsset = FontStore.LoadTMPFont(currentLanguage); + + + for (int i = 0; i < shovelBank.childCount; i++) + { + var child = shovelBank.GetChild(i); + var tmp = child.GetComponent(); + if (tmp == null) continue; + + string orig = tmp.text; + string translated = StringStore.TranslateText(orig, false); + if (translated != orig) + { + tmp.text = translated; + if (fontAsset != null) tmp.font = fontAsset; + } + else + { + if (fontAsset != null) tmp.font = fontAsset; + } + } + } + } + + [HarmonyPatch(typeof(InGameUI_IZ))] + public static class InGameUI_IZ_Patch + { + [HarmonyPatch(nameof(InGameUI_IZ.Awake))] + [HarmonyPostfix] + private static void Awake(InGameUI_IZ __instance) + { + TextMeshProUGUI[] array = new TextMeshProUGUI[] + { + __instance.transform.GetChild(4).GetComponent(), + __instance.transform.GetChild(4).GetChild(0).GetComponent(), + __instance.transform.GetChild(5).GetComponent(), + __instance.transform.GetChild(5).GetChild(0).GetComponent(), + __instance.transform.GetChild(6).GetComponent(), + __instance.transform.GetChild(6).GetChild(0).GetComponent()}; + TextMeshProUGUI[] array2 = array; + for (int i = 0; i < array2.Length; i++) + { + array2[i] = StringStore.TranslateText(array2[i]); + array2[i].text = array2[i].text.Replace("\n", " "); + } + } + + [HarmonyPatch(nameof(InGameUI_IZ.Update))] + [HarmonyPostfix] + private static void Update(InGameUI_IZ __instance) + { + ApplyShovelBankTranslations(__instance.transform); + } + + private static void ApplyShovelBankTranslations(Transform root) + { + var shovelBank = root.Find("ShovelBank"); + if (!shovelBank) return; + + string currentLanguage = Utils.Language.ToString(); + var fontAsset = FontStore.LoadTMPFont(currentLanguage); + + + for (int i = 0; i < shovelBank.childCount; i++) + { + var child = shovelBank.GetChild(i); + var tmp = child.GetComponent(); + if (tmp == null) continue; + + string orig = tmp.text; + string translated = StringStore.TranslateText(orig, false); + if (translated != orig) + { + tmp.text = translated; + if (fontAsset != null) tmp.font = fontAsset; + } + else + { + if (fontAsset != null) tmp.font = fontAsset; + } + } + } } } diff --git a/MelonLoader/ModFeatures.cs b/MelonLoader/ModFeatures.cs index 0b4b53b..0bc356e 100644 --- a/MelonLoader/ModFeatures.cs +++ b/MelonLoader/ModFeatures.cs @@ -1,4 +1,4 @@ -#if DEBUG +//#if DEBUG using PvZ_Fusion_Translator.AssetStore; using UnityEngine; @@ -75,4 +75,4 @@ namespace PvZ_Fusion_Translator } } } -#endif \ No newline at end of file +//#endif \ No newline at end of file diff --git a/MelonLoader/Patches/Managers/InGameUI_Patch.cs b/MelonLoader/Patches/Managers/InGameUI_Patch.cs index 11bd088..273a48c 100644 --- a/MelonLoader/Patches/Managers/InGameUI_Patch.cs +++ b/MelonLoader/Patches/Managers/InGameUI_Patch.cs @@ -3,6 +3,7 @@ using Il2Cpp; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using System.Text.RegularExpressions; +using PvZ_Fusion_Translator; namespace PvZ_Fusion_Translator.Patches.Managers { @@ -28,5 +29,72 @@ namespace PvZ_Fusion_Translator.Patches.Managers array2[i].text = array2[i].text.Replace("\n", " "); } } + + [HarmonyPatch(nameof(InGameUI.Update))] + [HarmonyPostfix] + private static void Update(InGameUI __instance) + { + ApplyShovelBankTranslations(__instance.transform); + } + + private static void ApplyShovelBankTranslations(Transform root) + { + var shovelBank = root.FindChild("ShovelBank"); + if (!shovelBank) return; + + string currentLanguage = Utils.Language.ToString(); + var fontAsset = FontStore.LoadTMPFont(currentLanguage); + + for (int i = 0; i < shovelBank.childCount; i++) + { + var child = shovelBank.GetChild(i); + var hasTmp = child.TryGetComponent(out var comp); + if (!hasTmp) continue; + + string orig = comp.text; + string translated = StringStore.TranslateText(orig, false); + if (translated != orig) + { + comp.text = translated; + if (fontAsset != null) comp.font = fontAsset; + } + else + { + if (fontAsset != null) comp.font = fontAsset; + } + } + } } + + [HarmonyPatch(typeof(InGameUI_IZ))] + public static class InGameUI_IZ_Patch + { + + [HarmonyPatch(nameof(InGameUI_IZ.Start))] + [HarmonyPostfix] + private static void Start(InGameUI_IZ __instance) + { + TextMeshProUGUI[] array = new TextMeshProUGUI[] + { + __instance.transform.GetChild(4).GetComponent(), + __instance.transform.GetChild(4).GetChild(0).GetComponent(), + __instance.transform.GetChild(5).GetComponent(), + __instance.transform.GetChild(5).GetChild(0).GetComponent(), + __instance.transform.GetChild(6).GetComponent(), + __instance.transform.GetChild(6).GetChild(0).GetComponent()}; + TextMeshProUGUI[] array2 = array; + for (int i = 0; i < array2.Length; i++) + { + array2[i] = StringStore.TranslateText(array2[i]); + array2[i].text = array2[i].text.Replace("\n", " "); + } + } + + [HarmonyPatch(nameof(InGameUI_IZ.Update))] + [HarmonyPostfix] + private static void Update(InGameUI_IZ __instance) + { + InGameUI_Patch.ApplyShovelBankTranslations(__instance.transform); + } + } } diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 86bba9f..6787667 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_2.8.2 + D:\PvZ Fusion\Game Files AnyCPU;ARM64;x64