Update to the current progress. Patch to translate mod (LibraHp's) using translation_strings

This commit is contained in:
TuanAnh2901 2025-08-13 12:35:24 +07:00
parent 299b41f1ab
commit 0e9debc5b8
16 changed files with 319 additions and 57 deletions

View file

@ -3,15 +3,17 @@ using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils;
using TMPro;
using HarmonyLib;
using PvZ_Fusion_Translator__BepInEx_;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using PvZ_Fusion_Translator__BepInEx_.Patches.Managers;
using System;
using System.IO;
using System.Reflection;
using UnityEngine;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInPlugin("PVZFusionTranslator_BepInEx", "PvZ Fusion Translator", "2.8.1")]
[BepInProcess("PlantsVsZombiesRH.exe")]
public class Core : BasePlugin
{
@ -89,6 +91,7 @@ public class Core : BasePlugin
{
Utils.OpenTrello();
}
TowerManager_Patch.UpdateText();
}
public void OnGUI()

View file

@ -2,7 +2,9 @@
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using PvZ_Fusion_Translator__BepInEx_.Patches.Managers;
using UnityEngine.UI;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.BaseTextObjects
{
@ -21,6 +23,10 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.BaseTextObjects
if (__instance.name.StartsWith("LevelName"))
{
__instance.text = __instance.text.Replace("\n", " ");
if (__instance.name == "LevelName2" || __instance.name == "LevelName3")
{
TowerManager_Patch.updatedText.Add(__instance.transform);
}
}
if (__instance.transform.parent != null && __instance.transform.parent.name.StartsWith("Window"))
{

View file

@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
@ -48,6 +48,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
textMesh.text = StringStore.TranslateText(textMesh.text);
}
}
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
text.text = StringStore.TranslateText(text.text);
text.font = fontAsset;
}
}
[HarmonyPatch(nameof(AbyssMenu2.Start))]
@ -56,7 +62,6 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
UpdateAbyss2Text(__instance);
Utils.ConvertButtonText(__instance.transform, "Goback");
Utils.ConvertButtonText(__instance.transform, "Help");
Utils.ConvertButtonText(__instance.transform, "Bag");
}

View file

@ -26,7 +26,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
txt.font = fontAsset;
}
Utils.ConvertButtonText(__instance.transform, "Goback");
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
text.text = StringStore.TranslateText(text.text);
text.font = fontAsset;
}
}
[HarmonyPatch(nameof(AbyssMenu.UpdateLevelInfo))]

View file

@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
@ -106,8 +106,17 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
StringStore.TranslateTextTransform(pageScaryPotTransform.Find("LastPage"));
}
foreach(TextMeshProUGUI txt in mainTransform.GetComponentsInChildren<TextMeshProUGUI>())
Transform pageEndlessLevelTransform = levelsTransform.transform.Find("PageEndlessLevel");
if (pageEndlessLevelTransform != null)
{
StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("BackToIndex"));
StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("Nextpage"));
StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("LastPage"));
}
foreach (TextMeshProUGUI txt in mainTransform.GetComponentsInChildren<TextMeshProUGUI>())
{
// Still dump untranslated strings for modded plants and zombies
FileLoader.DumpUntranslatedStrings(txt.text);
txt.text = StringStore.TranslateText(txt.text);
}

View file

@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
@ -15,6 +15,21 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
private static void Postfix_Start(UIButton __instance)
{
try
{
// Also handle TMP components directly under the button
if (__instance.transform.childCount >= 2)
{
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
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());
text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
}
else
{
// Convert and translate legacy Text components
Text[] textComponents = __instance.GetComponentsInChildren<Text>(true);
@ -36,16 +51,6 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
}
}
}
// Also handle TMP components directly under the button
if (__instance.transform.childCount >= 2)
{
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
StringStore.TranslateTextUI(text, false);
StringStore.TranslateTextUI(textShadow, false);
text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
}
}
catch (Exception) { }
@ -62,8 +67,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
StringStore.TranslateTextUI(text, false);
StringStore.TranslateTextUI(textShadow, false);
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());
text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
}
}

View file

@ -0,0 +1,17 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(UIProgress2))]
public static class UIProgress2_Patch
{
[HarmonyPatch(nameof(UIProgress2.Update))]
[HarmonyPostfix]
private static void Update(UIProgress2 __instance)
{
__instance.t.text = StringStore.TranslateText(__instance.t.text);
}
}
}

View file

@ -0,0 +1,25 @@
using HarmonyLib;
using TMPro;
using BepInEx.Unity.IL2CPP;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(PlayerShootingMenu))]
public static class PlayerShootingMenu_Patch
{
[HarmonyPatch(nameof(PlayerShootingMenu.Update))]
[HarmonyPostfix]
private static void Update(PlayerShootingMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
}

View file

@ -0,0 +1,36 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
using System.Text.RegularExpressions;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(PlayerShootingWindow))]
public static class PlayerShootingWindow_Patch
{
[HarmonyPatch(nameof(PlayerShootingWindow.SetType))]
[HarmonyPostfix]
private static void SetType(PlayerShootingWindow __instance)
{
Transform introduceTransform = __instance.transform.FindChild("Images").FindChild("Introduce");
TextMeshProUGUI introduceText = introduceTransform.GetComponent<TextMeshProUGUI>();
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
introduceText.text = StringStore.TranslateText(introduceText.text);
introduceText.font = fontAsset;
}
[HarmonyPatch(nameof(PlayerShootingWindow.OnAnimOver))]
[HarmonyPostfix]
private static void OnAnimOver(PlayerShootingWindow __instance)
{
Transform introduceTransform = __instance.transform.FindChild("Images").FindChild("Introduce");
TextMeshProUGUI introduceText = introduceTransform.GetComponent<TextMeshProUGUI>();
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
introduceText.text = StringStore.TranslateText(introduceText.text);
introduceText.font = fontAsset;
}
}
}

View file

@ -1,21 +1,21 @@
using HarmonyLib;
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
//using HarmonyLib;
//using System;
//using TMPro;
//using PvZ_Fusion_Translator__BepInEx_.AssetStore;
//using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(TowerOption))]
public static class TowerOption_Patch
{
[HarmonyPatch(nameof(TowerOption.Start))]
[HarmonyPostfix]
private static void Postfix_Start(TowerOption __instance)
{
//TextMeshProUGUI[] allTexts = __instance.GetComponentsInChildren<TextMeshProUGUI>(true);
__instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
__instance.introduce.font = FontStore.LoadTMPFont(Utils.Language.ToString());
}
}
}
//namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
//{
// [HarmonyPatch(typeof(TowerOption))]
// public static class TowerOption_Patch
// {
// [HarmonyPatch(nameof(TowerOption.Start))]
// [HarmonyPostfix]
// private static void Postfix_Start(TowerOption __instance)
// {
// //TextMeshProUGUI[] allTexts = __instance.GetComponentsInChildren<TextMeshProUGUI>(true);
// __instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
// __instance.introduce.font = FontStore.LoadTMPFont(Utils.Language.ToString());
// }
// }
//}

View file

@ -0,0 +1,39 @@
using HarmonyLib;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using TMPro;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(TowerUpgradeMenu))]
public static class TowerUpgradeMenu_Patch
{
[HarmonyPatch(nameof(TowerUpgradeMenu.Awake))]
[HarmonyPostfix]
private static void Awake(TowerUpgradeMenu __instance)
{
__instance.des.text = StringStore.TranslateText(__instance.des.text);
__instance.des2.text = StringStore.TranslateText(__instance.des2.text);
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
text.text = StringStore.TranslateText(text.text);
text.font = FontStore.LoadTMPFont(Utils.Language.ToString());
}
}
[HarmonyPatch(nameof(TowerUpgradeMenu.SetText))]
[HarmonyPostfix]
private static void SetText(TowerUpgradeMenu __instance)
{
__instance.des.text = StringStore.TranslateText(__instance.des.text);
__instance.des2.text = StringStore.TranslateText(__instance.des2.text);
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
text.text = StringStore.TranslateText(text.text);
text.font = FontStore.LoadTMPFont(Utils.Language.ToString());
}
}
}
}

View file

@ -0,0 +1,21 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(TravelBuffMenu))]
public static class TravelBuffMenu_Patch
{
[HarmonyPatch(nameof(TravelBuffMenu.RefeshOptions))]
[HarmonyPostfix]
private static void RefeshOptions(TravelBuffMenu __instance)
{
foreach (TravelBuffOptionButton button in __instance.options)
{
button.introduce.text = StringStore.TranslateText(button.introduce.text);
}
}
}
}

View file

@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
@ -10,7 +10,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(nameof(TravelBuffOptionButton.SetBuff))]
[HarmonyPostfix]
private static void Start(TravelBuffOptionButton __instance)
private static void SetBuff(TravelBuffOptionButton __instance)
{
__instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
}

View file

@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using System;
using System.IO;
using System.Linq;
@ -128,4 +128,54 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
return true;
}
}
// Patch to translate the modded almanac zombie names and info
[HarmonyPatch(typeof(AlmanacMgrZombie))]
public static partial class AlmanacMgrZombie_Patch
{
[HarmonyPatch(nameof(AlmanacMgrZombie.Start))]
[HarmonyPostfix]
public static void TranslateTextAlmanac(AlmanacMgrZombie __instance)
{
string currentLanguage = Utils.Language.ToString();
__instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
__instance.introduce.font = FontStore.LoadTMPFont(currentLanguage);
// Dump the texts if needed
if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftControl))
{
FileLoader.DumpUntranslatedStrings(__instance.info.GetComponent<TextMeshPro>().text);
FileLoader.DumpUntranslatedStrings(__instance.zombieName.GetComponent<TextMeshPro>().text);
}
// translate all TMP components in info
foreach (TextMeshPro text in __instance.info.GetComponentsInChildren<TextMeshPro>())
{
if (text != null)
{
text.text = StringStore.TranslateText(text.text);
text.name = StringStore.TranslateText(text.name);
text.font = FontStore.LoadTMPFont(currentLanguage);
}
}
foreach (TextMeshPro text in __instance.zombieName.GetComponentsInChildren<TextMeshPro>())
{
if (text != null)
{
text.text = StringStore.TranslateText(text.text);
text.name = StringStore.TranslateText(text.name);
text.font = FontStore.LoadTMPFont(currentLanguage);
}
}
// Translate zombieName and its child
__instance.zombieName.name = StringStore.TranslateText(__instance.zombieName.name);
__instance.zombieName.GetComponent<TextMeshPro>().font = FontStore.LoadTMPFont(currentLanguage);
__instance.zombieName.transform.GetChild(0).name = StringStore.TranslateText(__instance.zombieName.transform.GetChild(0).name);
// Get both for less testing
__instance.zombieName.GetComponent<TextMeshPro>().text = StringStore.TranslateText(__instance.zombieName.GetComponent<TextMeshPro>().text);
__instance.zombieName.transform.GetChild(0).GetComponent<TextMeshPro>().text = StringStore.TranslateText(__instance.zombieName.transform.GetChild(0).GetComponent<TextMeshPro>().text);
__instance.zombieName.transform.GetChild(0).GetComponent<TextMeshPro>().font = FontStore.LoadTMPFont(currentLanguage);
}
}
}

View file

@ -0,0 +1,33 @@
using HarmonyLib;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using TMPro;
using BepInEx.Unity.IL2CPP;
using System.Collections.Generic;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
{
[HarmonyPatch(typeof(TowerManager))]
public static class TowerManager_Patch
{
public static List<Transform> updatedText = [];
public static void UpdateText()
{
foreach (Transform transform in updatedText)
{
if (transform != null)
{
transform.GetComponent<TextMeshProUGUI>().text = StringStore.TranslateText(transform.GetComponent<TextMeshProUGUI>().text);
}
}
}
[HarmonyPatch(nameof(TowerManager.Update))]
[HarmonyPostfix]
public static void Update(TowerManager __instance)
{
}
}
}

View file

@ -120,6 +120,9 @@
<Compile Include="AssetStore\AudioStore.cs" />
<Compile Include="Patches\GameObjects\Board_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\Jigsaw_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\UIProgress2_Patch.cs" />
<Compile Include="Patches\GameObjects\PlayerShootingMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\PlayerShootingWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\ShootingSelectWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\FruitNinjaSelectWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\RogueCardWindow_Patch.cs" />
@ -151,6 +154,8 @@
<Compile Include="Patches\GameObjects\AbyssMenu2_Patch.cs" />
<Compile Include="Patches\GameObjects\AbyssMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TowerOption_Patch.cs" />
<Compile Include="Patches\GameObjects\TowerUpgradeMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TravelBuffMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TravelLookBuff_Patch.cs" />
<Compile Include="Patches\GameObjects\ShootingMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TravelLookMenu_Patch.cs" />
@ -159,6 +164,7 @@
<Compile Include="Patches\Managers\DrawCardManager_Patch.cs" />
<Compile Include="Patches\Managers\SaveMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TravelBuffOptionButton_Patch.cs" />
<Compile Include="Patches\Managers\TowerManager_Patch.cs" />
<Compile Include="Patches\OtherManagers\AchievementClip_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\Advanture_Btn_Patch.cs" />
<Compile Include="Patches\Managers\AlmanacMgrZombie_Patch.cs" />