From ea21392df0f80231c106d684ea3cf909522b2cab Mon Sep 17 00:00:00 2001 From: TuanAnh2901 Date: Fri, 6 Jun 2025 02:51:12 +0700 Subject: [PATCH] more BUGS at Chess and Gachapon --- .../{UIButton.cs => UIButton_Patch.cs} | 2 - .../Patches/Managers/ChessManager_Patch.cs | 38 +++++++++++++++++++ .../Patches/Managers/DrawCardManager_Patch.cs | 36 ++++++++++++++++++ ...PvZ Fusion Translator [MelonLoader].csproj | 4 +- 4 files changed, 77 insertions(+), 3 deletions(-) rename MelonLoader/Patches/GameObjects/ButtonObjects/{UIButton.cs => UIButton_Patch.cs} (94%) create mode 100644 MelonLoader/Patches/Managers/ChessManager_Patch.cs create mode 100644 MelonLoader/Patches/Managers/DrawCardManager_Patch.cs diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs similarity index 94% rename from MelonLoader/Patches/GameObjects/ButtonObjects/UIButton.cs rename to MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index 4f608d3..d497e4d 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -31,8 +31,6 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects if (newTMP != null) { newTMP.text = translatedText; - - // Optional: Log successful conversion and translation //Debug.Log($"Converted and translated text: {textComponent.text} -> {translatedText}"); } } diff --git a/MelonLoader/Patches/Managers/ChessManager_Patch.cs b/MelonLoader/Patches/Managers/ChessManager_Patch.cs new file mode 100644 index 0000000..8ff4841 --- /dev/null +++ b/MelonLoader/Patches/Managers/ChessManager_Patch.cs @@ -0,0 +1,38 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using UnityEngine.TextCore.Text; +using UnityEngine.UI; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(ChessManager))] + public static class ChessManager_Patch + { + [HarmonyPatch(nameof(ChessManager.Start))] + [HarmonyPostfix] + private static void Postfix_Start(ChessManager __instance) + { + __instance.textMesh.text = StringStore.TranslateText(__instance.textMesh.text); + __instance.textMesh.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + + [HarmonyPatch(nameof(ChessManager.Update))] + [HarmonyPostfix] + private static void Postfix_Update(ChessManager __instance) + { + __instance.textMesh.text = StringStore.TranslateText(__instance.textMesh.text); + __instance.textMesh.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + + [HarmonyPatch(nameof(ChessManager.UpdateText))] + [HarmonyPostfix] + private static void Postfix_UpdateText(ChessManager __instance) + { + __instance.textMesh.text = StringStore.TranslateText(__instance.textMesh.text); + __instance.textMesh.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } +} diff --git a/MelonLoader/Patches/Managers/DrawCardManager_Patch.cs b/MelonLoader/Patches/Managers/DrawCardManager_Patch.cs new file mode 100644 index 0000000..3b90229 --- /dev/null +++ b/MelonLoader/Patches/Managers/DrawCardManager_Patch.cs @@ -0,0 +1,36 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using Il2CppSystem.Collections.Generic; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using UnityEngine.TextCore.Text; +using static MelonLoader.MelonLogger; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(DrawCardManager))] + public static class DrawCardManager_Patch + { + [HarmonyPatch(nameof(DrawCardManager.UpdateText))] + [HarmonyPostfix] + private static void Postfix_UpdateText(DrawCardManager __instance) + { + Il2CppSystem.Collections.Generic.List texts = __instance.texts; + + if (texts != null && texts.Count > 0) + { + foreach (TextMeshProUGUI textComponent in texts) + { + if (textComponent != null) + { + string translatedText = StringStore.TranslateText(textComponent.text); + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + textComponent.text = translatedText; + textComponent.font = fontAsset; + } + } + } + } + } +} diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index fb34bed..a2e65b8 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -405,7 +405,7 @@ - + @@ -426,7 +426,9 @@ + +