Port the patches to BepInEx

This commit is contained in:
TuanAnh2901 2025-09-28 18:22:43 +07:00
parent 17d233d8d1
commit 68b428f9f4
25 changed files with 677 additions and 90 deletions

1
.gitignore vendored
View file

@ -132,3 +132,4 @@ 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
/MelonLoader/bin/ReleaseMulti/net6.0

View file

@ -42,6 +42,10 @@ namespace PvZ_Fusion_Translator__BepInEx_
{
try
{
// Clear existing dictionaries to prevent duplicate key errors
AudioClips.Clear();
AudioClipNames.Clear();
if (!Directory.Exists(customAudioPath))
Directory.CreateDirectory(customAudioPath);

View file

@ -11,6 +11,10 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore
internal static void Init()
{
// Clear existing dictionaries to prevent duplicate key errors
fontAssetDict.Clear();
fontAssetDictSecondary.Clear();
string fontsDir = Path.Combine(Core.Instance.modsDirectory, "[Custom Fonts]");
#if MULTI_LANGUAGE
@ -27,7 +31,10 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore
TMP_FontAsset fontAsset = FontHandler.LoadTMPFont(fontPath, true);
fontAsset.name = fileName;
fontAssetDict.Add(fileName, fontAsset);
if (!fontAssetDict.ContainsKey(fileName))
{
fontAssetDict.Add(fileName, fontAsset);
}
Log.LogInfo($"Font for language '{fileName}' loaded");
}
@ -65,18 +72,32 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore
{
if (fileName.EndsWith("_Fallback"))
{
fontAssetDictSecondary.Add(fileNameLanguage + "_Almanac", fontAssetDictSecondary[fileNameLanguage]);
if (!fontAssetDictSecondary.ContainsKey(fileNameLanguage + "_Almanac"))
{
fontAssetDictSecondary.Add(fileNameLanguage + "_Almanac", fontAssetDictSecondary[fileNameLanguage]);
}
fontAssetDictSecondary.Remove(fileNameLanguage);
}
else
{
fontAssetDictSecondary.Add(fileNameLanguage + "_Fallback", fontAssetDictSecondary[fileNameLanguage]);
if (!fontAssetDictSecondary.ContainsKey(fileNameLanguage + "_Fallback"))
{
fontAssetDictSecondary.Add(fileNameLanguage + "_Fallback", fontAssetDictSecondary[fileNameLanguage]);
}
fontAssetDictSecondary.Remove(fileNameLanguage);
}
fontAssetDictSecondary.Add(fileName, fallbackFont);
if (!fontAssetDictSecondary.ContainsKey(fileName))
{
fontAssetDictSecondary.Add(fileName, fallbackFont);
}
}
else
fontAssetDictSecondary.Add(fileNameLanguage, fallbackFont);
{
if (!fontAssetDictSecondary.ContainsKey(fileNameLanguage))
{
fontAssetDictSecondary.Add(fileNameLanguage, fallbackFont);
}
}
// Log.LogInfo($"Fallback font for language '{fileNameLanguage}' loaded");
}

View file

@ -19,7 +19,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.BaseTextObjects
__instance = StringStore.TranslateText(__instance);
__instance.autoSizeTextContainer = false;
return;
} else if (!(__instance.transform.name.Contains("AlmanacZombie") || __instance.transform.name.Contains("AlmanacPlant")))
} else if (!(__instance.transform.name.Contains("AlmanacZombie") || __instance.transform.name.Contains("AlmanacPlant") || __instance.transform.name.Contains("Name") || __instance.transform.name.Contains("Tips") || __instance.transform.parent.name.Contains("Signboard") || __instance.transform.parent.name.Contains("text")))
{
__instance = StringStore.TranslateText(__instance);
__instance.autoSizeTextContainer = true;

View file

@ -1,5 +1,4 @@
using HarmonyLib;
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
@ -18,8 +17,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
if (__instance.name == "Goback")
{
Transform backgroundTransform = parentTransform.Find("Background");
backgroundTransform.Find("Name").GetComponent<TMP_Text>().autoSizeTextContainer = true;
backgroundTransform.Find("Shadow").GetComponent<TMP_Text>().autoSizeTextContainer = true;
if(backgroundTransform != null)
{
backgroundTransform.Find("Name").GetComponent<TMP_Text>().autoSizeTextContainer = true;
backgroundTransform.Find("Shadow").GetComponent<TMP_Text>().autoSizeTextContainer = true;
}
}
Transform levelTransform = parentTransform.Find("Levels");

View file

@ -232,7 +232,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
}
child.gameObject.SetActive(true);
Task.Delay(1000).ContinueWith(_ =>
System.Threading.Tasks.Task.Delay(1000).ContinueWith(_ =>
{
if (button != null && child != null && child.gameObject.activeSelf)
{
@ -242,9 +242,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
}
}
private static void ToggleCustomAssets(string type)
{
if (type != "Textures" && type != "Audio") return;
private static void ToggleCustomAssets(string type)
{
if (type != "Textures" && type != "Audio") return;
if (type == "Textures")
{

View file

@ -0,0 +1,40 @@
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(ExploreEnterWindow))]
public static class ExploreEnterWindow_Patch
{
[HarmonyPatch(nameof(ExploreEnterWindow.Awake))]
[HarmonyPostfix]
private static void Awake(ExploreEnterWindow __instance)
{
PlantType thePlantType = (PlantType)__instance.selfType;
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
StringStore.TranslateText(txt);
}
__instance.nameText.text = Utils.GetPlantNameFromAlmanac(thePlantType);
}
[HarmonyPatch(nameof(ExploreEnterWindow.SetInfo))]
[HarmonyPostfix]
private static void SetInfo(ExploreEnterWindow __instance)
{
PlantType thePlantType = (PlantType)__instance.selfType;
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
StringStore.TranslateText(txt);
}
__instance.nameText.text = Utils.GetPlantNameFromAlmanac(thePlantType);
}
}
}

View file

@ -0,0 +1,48 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(ExploreMenu))]
public static class ExploreMenu_Patch
{
[HarmonyPatch(nameof(ExploreMenu.Awake))]
[HarmonyPostfix]
private static void Awake(ExploreMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
}
Transform randomLevelTextTransform = __instance.transform.FindChild("RandomLevel");
foreach (TextMeshProUGUI txt in randomLevelTextTransform.GetComponentsInChildren<TextMeshProUGUI>())
{
if (txt.name.Contains("Text (TMP)"))
{
txt.autoSizeTextContainer = true;
if (txt.name == "Text (TMP)")
{
txt.transform.localPosition = new Vector3(94.4225f, -45.1565f, 0f);
}
}
}
}
[HarmonyPatch(nameof(ExploreMenu.UpdateWindows))]
[HarmonyPostfix]
private static void UpdateWindows(ExploreMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
}
}
}
}

View file

@ -0,0 +1,51 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(GardenBagMenu))]
public static class GardenBagMenu_Patch
{
[HarmonyPatch(nameof(GardenBagMenu.SetTreasureCards))]
[HarmonyPostfix]
private static void SetTreasureCards(GardenBagMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
if(txt.transform.parent.name.Contains("Close"))
{
txt.text = StringStore.TranslateText("合上");
}
else
{
txt.text = StringStore.TranslateText(txt.text);
}
txt.font = fontAsset;
}
}
[HarmonyPatch(nameof(GardenBagMenu.SetTreasureCard))]
[HarmonyPostfix]
private static void SetTreasureCard(GardenBagMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
if (txt.transform.parent.name.Contains("Close"))
{
txt.text = StringStore.TranslateText("合上");
}
else
{
txt.text = StringStore.TranslateText(txt.text);
}
txt.font = fontAsset;
}
}
}
}

View file

@ -0,0 +1,24 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(GardenCard))]
public static class GardenCard_Patch
{
[HarmonyPatch(nameof(GardenCard.Start))]
[HarmonyPostfix]
private static void Start(GardenCard __instance)
{
__instance.text.text = StringStore.TranslateText(__instance.text.text).Replace("26", "16");
}
[HarmonyPatch(nameof(GardenCard.ChangeCardSprite))]
[HarmonyPostfix]
private static void ChangeCardSprite(GardenCard __instance)
{
__instance.text.text = StringStore.TranslateText(__instance.text.text).Replace("26", "16");
}
}
}

View file

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

View file

@ -0,0 +1,51 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
using UnityEngine.UIElements;
using static PvZ_Fusion_Translator__BepInEx_.FileLoader;
using System;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(PlantInfoWindow))]
public static class PlantInfoWindow_Patch
{
[HarmonyPatch(nameof(PlantInfoWindow.InitText))]
[HarmonyPostfix]
private static void InitText(PlantInfoWindow __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
PlantType thePlantType = __instance.plant.thePlantType;
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
if(txt.name.Contains("Introduce"))
{
string text = txt.text;
string[] lines = text.Split("\n");
lines[0] = Utils.GetPlantNameFromAlmanac(thePlantType);
string updatedText = String.Join("\n", lines);
txt.text = StringStore.TranslateText(updatedText);
}
else
{
txt.text = StringStore.TranslateText(txt.text);
}
txt.font = fontAsset;
}
Transform parentWindowTransform = __instance.transform.parent;
Transform returnPlantTransform = parentWindowTransform.FindChild("Close");
foreach(TextMeshProUGUI txt in returnPlantTransform.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText("合上");
}
}
}
}

View file

@ -0,0 +1,24 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(TreasureConfirmMenu))]
public static class TreasureConfirmMenu_Patch
{
[HarmonyPatch(nameof(TreasureConfirmMenu.SetText))]
[HarmonyPostfix]
private static void SetText(TreasureConfirmMenu __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 TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(TreasureEquipmentMenu))]
public static class TreasureEquipmentMenu_Patch
{
[HarmonyPatch(nameof(TreasureEquipmentMenu.Awake))]
[HarmonyPostfix]
private static void Awake(TreasureEquipmentMenu __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;
}
}
[HarmonyPatch(nameof(TreasureEquipmentMenu.UpdateCards))]
[HarmonyPostfix]
private static void UpdateCards(TreasureEquipmentMenu __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,24 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(TreasureMainMenu))]
public static class TreasureMainMenu_Patch
{
[HarmonyPatch(nameof(TreasureMainMenu.Update))]
[HarmonyPostfix]
private static void Update(TreasureMainMenu __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,24 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(TreasureStoreMenu))]
public static class TreasureStoreMenu_Patch
{
[HarmonyPatch(nameof(TreasureStoreMenu.InitCards))]
[HarmonyPostfix]
private static void InitCards(TreasureStoreMenu __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,51 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using System.Text.RegularExpressions;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(TreasureUpgradeMenu))]
public static class TreasureUpgradeMenu_Patch
{
[HarmonyPatch(nameof(TreasureUpgradeMenu.Start))]
[HarmonyPostfix]
private static void Start(TreasureUpgradeMenu __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;
}
}
[HarmonyPatch(nameof(TreasureUpgradeMenu.UpgradeWareHouse))]
[HarmonyPostfix]
private static void UpgradeWareHouse(TreasureUpgradeMenu __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;
}
}
[HarmonyPatch(nameof(TreasureUpgradeMenu.InitWareHouseUpgrade))]
[HarmonyPostfix]
private static void InitWareHouseUpgrade(TreasureUpgradeMenu __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,63 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(TreasureWarehouseMenu))]
public static class TreasureWarehouseMenu_Patch
{
[HarmonyPatch(nameof(TreasureWarehouseMenu.InitCards))]
[HarmonyPostfix]
private static void InitCards(TreasureWarehouseMenu __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;
}
}
[HarmonyPatch(nameof(TreasureWarehouseMenu.QuickSell))]
[HarmonyPostfix]
private static void QuickSell(TreasureWarehouseMenu __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;
}
}
[HarmonyPatch(nameof(TreasureWarehouseMenu.FastSell))]
[HarmonyPostfix]
private static void FastSell(TreasureWarehouseMenu __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;
}
}
[HarmonyPatch(nameof(TreasureWarehouseMenu.EnterStore))]
[HarmonyPostfix]
private static void EnterStore(TreasureWarehouseMenu __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

@ -62,54 +62,74 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
TextMeshPro component2 = __instance.zombieName.GetComponent<TextMeshPro>();
TextMeshPro component3 = __instance.zombieName.transform.GetChild(0).GetComponent<TextMeshPro>();
AlmanacMgrZombie.ZombieAlmanacData zombieData = JsonUtility.FromJson<AlmanacMgrZombie.ZombieAlmanacData>(json);
foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in zombieData.zombies)
try
{
if (zombieInfo.theZombieType == __instance.theZombieType)
{
component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce;
component.overflowMode = TextOverflowModes.Page;
component2.text = zombieInfo.name;
component2.autoSizeTextContainer = true;
component3.text = Utils.RemoveColorTags(zombieInfo.name);
component3.autoSizeTextContainer = true;
AlmanacMgrZombie.ZombieAlmanacData zombieData = JsonUtility.FromJson<AlmanacMgrZombie.ZombieAlmanacData>(json);
if (hasAlmanacFont)
component.font = almanacFontAsset;
else
component.font = fontAsset;
component2.font = fontAsset;
component3.font = fontAsset;
if (zombieData != null && zombieData.zombies != null)
{
foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in zombieData.zombies)
{
if (zombieInfo.theZombieType == __instance.theZombieType)
{
component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce;
component.overflowMode = TextOverflowModes.Page;
component2.text = zombieInfo.name;
component2.autoSizeTextContainer = true;
component3.text = Utils.RemoveColorTags(zombieInfo.name);
component3.autoSizeTextContainer = true;
if (hasAlmanacFont)
component.font = almanacFontAsset;
else
component.font = fontAsset;
component2.font = fontAsset;
component3.font = fontAsset;
}
}
}
}
catch (System.Exception ex)
{
Log.LogError($"Error parsing JSON in AlmanacMgrZombie_Patch: {ex.Message}");
}
if (File.Exists(moddedPath))
{
string moddedJson;
moddedJson = File.ReadAllText(moddedPath);
AlmanacMgrZombie.ZombieAlmanacData moddedZombieData = JsonUtility.FromJson<AlmanacMgrZombie.ZombieAlmanacData>(moddedJson);
foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in moddedZombieData.zombies)
try
{
if (zombieInfo.theZombieType == __instance.theZombieType)
{
component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce;
component.overflowMode = TextOverflowModes.Page;
component2.text = zombieInfo.name;
component2.autoSizeTextContainer = true;
component3.text = Utils.RemoveColorTags(zombieInfo.name);
component3.autoSizeTextContainer = true;
string moddedJson;
moddedJson = File.ReadAllText(moddedPath);
if (hasAlmanacFont)
component.font = almanacFontAsset;
else
component.font = fontAsset;
component2.font = fontAsset;
component3.font = fontAsset;
AlmanacMgrZombie.ZombieAlmanacData moddedZombieData = JsonUtility.FromJson<AlmanacMgrZombie.ZombieAlmanacData>(moddedJson);
if (moddedZombieData != null && moddedZombieData.zombies != null)
{
foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in moddedZombieData.zombies)
{
if (zombieInfo.theZombieType == __instance.theZombieType)
{
component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce;
component.overflowMode = TextOverflowModes.Page;
component2.text = zombieInfo.name;
component2.autoSizeTextContainer = true;
component3.text = Utils.RemoveColorTags(zombieInfo.name);
component3.autoSizeTextContainer = true;
if (hasAlmanacFont)
component.font = almanacFontAsset;
else
component.font = fontAsset;
component2.font = fontAsset;
component3.font = fontAsset;
}
}
}
}
catch (System.Exception ex)
{
Log.LogError($"Error parsing modded JSON in AlmanacMgrZombie_Patch: {ex.Message}");
}
}
DumpAlmanacModdedZombies(__instance);
return;
@ -141,9 +161,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
if (Input.GetKey(KeyCode.LeftControl))
{
FileLoader.DumpUntranslatedStrings(__instance.info.GetComponent<TextMeshPro>().text);
Log.LogInfo($"Info: {__instance.info.GetComponent<TextMeshPro>().text}");
//Log.LogInfo($"Info: {__instance.info.GetComponent<TextMeshPro>().text}");
FileLoader.DumpUntranslatedStrings(__instance.zombieName.GetComponent<TextMeshPro>().text);
Log.LogInfo($"Zombie Name: {__instance.zombieName.GetComponent<TextMeshPro>().text}");
//Log.LogInfo($"Zombie Name: {__instance.zombieName.GetComponent<TextMeshPro>().text}");
}
}
}

View file

@ -0,0 +1,21 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
{
[HarmonyPatch(typeof(Garden))]
public static class Garden_Patch
{
[HarmonyPatch(nameof(Garden.Awake))]
[HarmonyPostfix]
private static void Awake(Garden __instance)
{
foreach (TextMeshPro text in __instance.GetComponentsInChildren<TextMeshPro>())
{
text.text = StringStore.TranslateText(text.text);
text.font = FontStore.LoadTMPFont(Utils.Language.ToString());
}
}
}
}

View file

@ -90,40 +90,40 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
}
}
[HarmonyPatch(nameof(InGameUI_IZ.Update))]
[HarmonyPostfix]
private static void Update(InGameUI_IZ __instance)
{
ApplyShovelBankTranslations(__instance.transform);
}
// [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;
// private static void ApplyShovelBankTranslations(Transform root)
// {
// var shovelBank = root.Find("ShovelBank");
// if (!shovelBank) return;
string currentLanguage = Utils.Language.ToString();
var fontAsset = FontStore.LoadTMPFont(currentLanguage);
// 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<TextMeshProUGUI>();
if (tmp == null) continue;
// for (int i = 0; i < shovelBank.childCount; i++)
// {
// var child = shovelBank.GetChild(i);
// var tmp = child.GetComponent<TextMeshProUGUI>();
// 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;
}
}
}
// 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;
// }
// }
// }
}
}

View file

@ -13,7 +13,7 @@
https://nuget.samboy.dev/v3/index.json
</RestoreAdditionalProjectSources>
<RootNamespace>PvZ_Fusion_Translator__BepInEx_</RootNamespace>
<GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion_2.8.2-BepInEx</GamePath>
<GamePath>D:\PvZ Fusion\BepInEx Game Files</GamePath>
<Configurations>Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate;DebugMulti</Configurations>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
@ -203,6 +203,19 @@
<Compile Include="Patches\OtherManagers\ThanksMenu_Patch.cs" />
<Compile Include="Patches\Managers\UIMgr_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\Zombie_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\TreasureMoney_Patch.cs" />
<Compile Include="Patches\GameObjects\ExploreEnterWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\ExploreMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\GardenBagMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\GardenCard_Patch.cs" />
<Compile Include="Patches\GameObjects\PlantInfoWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureConfirmMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureEquipmentMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureMainMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureStoreMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureUpgradeMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureWarehouseMenu_Patch.cs" />
<Compile Include="Patches\Managers\Garden_Patch.cs" />
<Compile Include="Utils.cs" />
</ItemGroup>

View file

@ -112,6 +112,51 @@ namespace PvZ_Fusion_Translator__BepInEx_
newGoBackText.color = color;
}
public static string GetPlantNameFromAlmanac(PlantType thePlantType)
{
string json;
string thePlantName = "";
string currentLanguage = Utils.Language.ToString();
string almanacDir = FileLoader.GetAssetDir(FileLoader.AssetType.Almanac, Utils.Language);
string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json");
if (!File.Exists(path))
{
Log.LogError($"LawnStringsTranslate.json file not found at path: {path}");
Log.LogError("Plant name could not be found! (Big Garden)");
thePlantName = "";
}
else
{
try
{
json = File.ReadAllText(path);
AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
if (plantData != null && plantData.plants != null)
{
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
{
if (plantInfo.seedType == (int)thePlantType)
{
// Remove any ID numbers from the name (e.g., "Peashooter (0)" -> "Peashooter", "Peashooter26" -> "Peashooter")
thePlantName = System.Text.RegularExpressions.Regex.Replace(plantInfo.name, @"\s*\(\d+\)$|\d+$", "");
break;
}
}
}
}
catch (System.Exception ex)
{
Log.LogError($"Error parsing JSON in GetPlantNameFromAlmanac: {ex.Message}");
thePlantName = "";
}
}
return thePlantName;
}
#if MULTI_LANGUAGE
internal static void ChangeLanguage(string language)
{
@ -181,4 +226,5 @@ namespace PvZ_Fusion_Translator__BepInEx_
TOGGLE_END
}
}
}

View file

@ -1,4 +1,5 @@
using HarmonyLib;
using System.Numerics;
using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
@ -18,12 +19,17 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
if(txt.name.Contains("Text (TMP)"))
}
Transform randomLevelTextTransform = __instance.transform.FindChild("RandomLevel");
foreach (TextMeshProUGUI txt in randomLevelTextTransform.GetComponentsInChildren<TextMeshProUGUI>())
{
if (txt.name.Contains("Text (TMP)"))
{
txt.autoSizeTextContainer = true;
if(txt.name == "Text (TMP)")
if (txt.name == "Text (TMP)")
{
txt.transform.localPosition = new Vector3(94.4225f, -45.1565f, 0f);
txt.transform.localPosition = new UnityEngine.Vector3(94.4225f, -45.1565f, 0f);
}
}
}

View file

@ -13,7 +13,7 @@
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Configurations>Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate</Configurations>
<GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.0</GamePath>
<GamePath>D:\PvZ Fusion\Game Files</GamePath>
<Platforms>AnyCPU;ARM64;x64</Platforms>
</PropertyGroup>