2.8 stuff

This commit is contained in:
SillyStar-Github 2025-08-09 00:21:52 -04:00
parent 872ef5b96c
commit 9db378c57e
9 changed files with 189 additions and 48 deletions

View file

@ -1,6 +1,8 @@
using MelonLoader; using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Utils; using MelonLoader.Utils;
using PvZ_Fusion_Translator.AssetStore; using PvZ_Fusion_Translator.AssetStore;
using PvZ_Fusion_Translator.Patches.Managers;
using UnityEngine; using UnityEngine;
[assembly: MelonInfo(typeof(PvZ_Fusion_Translator.Core), "PvZ Fusion Translator", "231.0.0", "dynaslash / arifrios1st / lancerx0 / JustNull / Dakosha / Mamoru-kun / cassidy", null)] [assembly: MelonInfo(typeof(PvZ_Fusion_Translator.Core), "PvZ Fusion Translator", "231.0.0", "dynaslash / arifrios1st / lancerx0 / JustNull / Dakosha / Mamoru-kun / cassidy", null)]
@ -71,6 +73,8 @@ namespace PvZ_Fusion_Translator
{ {
Utils.OpenTrello(); Utils.OpenTrello();
} }
TowerManager_Patch.UpdateText();
} }
public override void OnGUI() public override void OnGUI()

View file

@ -1,6 +1,9 @@
using HarmonyLib; using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro; using Il2CppTMPro;
using PvZ_Fusion_Translator.Patches.Managers;
using PvZ_Fusion_Translator.AssetStore; using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
namespace PvZ_Fusion_Translator.Patches.BaseTextObjects namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
@ -20,7 +23,11 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
if (__instance.name.StartsWith("LevelName")) if (__instance.name.StartsWith("LevelName"))
{ {
__instance.text = __instance.text.Replace("\n", " "); __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")) if (__instance.transform.parent != null && __instance.transform.parent.name.StartsWith("Window"))
{ {
__instance.fontSizeMin = 10; __instance.fontSizeMin = 10;

View file

@ -16,37 +16,43 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
{ {
try try
{ {
// Convert and translate legacy Text components
Text[] textComponents = __instance.GetComponentsInChildren<Text>(true);
TextMeshProUGUI[] textMeshComponents = __instance.GetComponentsInChildren<TextMeshProUGUI>(true);
foreach (Text textComponent in textComponents)
{
if (textComponent != null && !string.IsNullOrEmpty(textComponent.text))
{
string translatedText = StringStore.TranslateText(textComponent.text);
if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true);
if (newTMP != null)
{
newTMP.text = translatedText;
}
}
}
}
// Also handle TMP components directly under the button // Also handle TMP components directly under the button
if (__instance.transform.childCount >= 2) if (__instance.transform.childCount >= 2)
{ {
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>(); TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>(); TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
StringStore.TranslateTextUI(text, false); text.text = StringStore.TranslateText(text.text, false);
StringStore.TranslateTextUI(textShadow, 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; text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
} }
else
{
// Convert and translate legacy Text components
Text[] textComponents = __instance.GetComponentsInChildren<Text>(true);
TextMeshProUGUI[] textMeshComponents = __instance.GetComponentsInChildren<TextMeshProUGUI>(true);
foreach (Text textComponent in textComponents)
{
if (textComponent != null && !string.IsNullOrEmpty(textComponent.text))
{
string translatedText = StringStore.TranslateText(textComponent.text);
if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true);
if (newTMP != null)
{
newTMP.text = translatedText;
}
}
}
}
}
} }
catch (Exception) { } catch (Exception) { }
} }
@ -62,8 +68,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>(); TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>(); TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
StringStore.TranslateTextUI(text, false); text.text = StringStore.TranslateText(text.text, false);
StringStore.TranslateTextUI(textShadow, 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; text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
} }
} }

View file

@ -0,0 +1,25 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator.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,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(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 HarmonyLib;
using Il2Cpp; //using Il2Cpp;
using Il2CppTMPro; //using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore; //using PvZ_Fusion_Translator.AssetStore;
using UnityEngine; //using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.GameObjects //namespace PvZ_Fusion_Translator.Patches.GameObjects
{ //{
[HarmonyPatch(typeof(TowerOption))] // [HarmonyPatch(typeof(TowerOption))]
public static class TowerOption_Patch // public static class TowerOption_Patch
{ // {
[HarmonyPatch(nameof(TowerOption.Start))] // [HarmonyPatch(nameof(TowerOption.Start))]
[HarmonyPostfix] // [HarmonyPostfix]
private static void Postfix_Start(TowerOption __instance) // private static void Postfix_Start(TowerOption __instance)
{ // {
//TextMeshProUGUI[] allTexts = __instance.GetComponentsInChildren<TextMeshProUGUI>(true); // //TextMeshProUGUI[] allTexts = __instance.GetComponentsInChildren<TextMeshProUGUI>(true);
__instance.introduce.text = StringStore.TranslateText(__instance.introduce.text); // __instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
__instance.introduce.font = FontStore.LoadTMPFont(Utils.Language.ToString()); // __instance.introduce.font = FontStore.LoadTMPFont(Utils.Language.ToString());
} // }
} // }
} //}}

View file

@ -0,0 +1,23 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
[HarmonyPatch(typeof(TowerUpgradeMenu))]
public static class TowerUpgradeMenu_Patch
{
[HarmonyPatch(nameof(TowerUpgradeMenu.Update))]
[HarmonyPostfix]
private static void Update(TowerUpgradeMenu __instance)
{
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,32 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator.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

@ -13,7 +13,7 @@
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Configurations>Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate</Configurations> <Configurations>Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate</Configurations>
<GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion-2.7</GamePath> <GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion-2.8</GamePath>
<Platforms>AnyCPU;ARM64;x64</Platforms> <Platforms>AnyCPU;ARM64;x64</Platforms>
</PropertyGroup> </PropertyGroup>
@ -402,6 +402,8 @@
<Compile Include="AssetStore\AudioStore.cs" /> <Compile Include="AssetStore\AudioStore.cs" />
<Compile Include="Patches\GameObjects\Board_Patch.cs" /> <Compile Include="Patches\GameObjects\Board_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\Jigsaw_Patch.cs" /> <Compile Include="Patches\GameObjects\MinorObjects\Jigsaw_Patch.cs" />
<Compile Include="Patches\GameObjects\PlayerShootingWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\PlayerShootingMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\ShootingSelectWindow_Patch.cs" /> <Compile Include="Patches\GameObjects\ShootingSelectWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\FruitNinjaSelectWindow_Patch.cs" /> <Compile Include="Patches\GameObjects\FruitNinjaSelectWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\RogueCardWindow_Patch.cs" /> <Compile Include="Patches\GameObjects\RogueCardWindow_Patch.cs" />
@ -432,6 +434,7 @@
<Compile Include="Patches\GameObjects\AbyssDevelopMenu_Patch.cs" /> <Compile Include="Patches\GameObjects\AbyssDevelopMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\AbyssMenu2_Patch.cs" /> <Compile Include="Patches\GameObjects\AbyssMenu2_Patch.cs" />
<Compile Include="Patches\GameObjects\AbyssMenu_Patch.cs" /> <Compile Include="Patches\GameObjects\AbyssMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TowerUpgradeMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TowerOption_Patch.cs" /> <Compile Include="Patches\GameObjects\TowerOption_Patch.cs" />
<Compile Include="Patches\GameObjects\TravelLookBuff_Patch.cs" /> <Compile Include="Patches\GameObjects\TravelLookBuff_Patch.cs" />
<Compile Include="Patches\GameObjects\ShootingMenu_Patch.cs" /> <Compile Include="Patches\GameObjects\ShootingMenu_Patch.cs" />
@ -439,6 +442,7 @@
<Compile Include="Patches\Managers\ChessManager_Patch.cs" /> <Compile Include="Patches\Managers\ChessManager_Patch.cs" />
<Compile Include="Patches\Managers\CustomLevelShower_Patch.cs" /> <Compile Include="Patches\Managers\CustomLevelShower_Patch.cs" />
<Compile Include="Patches\Managers\DrawCardManager_Patch.cs" /> <Compile Include="Patches\Managers\DrawCardManager_Patch.cs" />
<Compile Include="Patches\Managers\TowerManager_Patch.cs" />
<Compile Include="Patches\Managers\SaveMenu_Patch.cs" /> <Compile Include="Patches\Managers\SaveMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TravelBuffOptionButton_Patch.cs" /> <Compile Include="Patches\GameObjects\TravelBuffOptionButton_Patch.cs" />
<Compile Include="Patches\OtherManagers\AchievementClip_Patch.cs" /> <Compile Include="Patches\OtherManagers\AchievementClip_Patch.cs" />