bepinex port + misc changes

This commit is contained in:
SillyStar-Github 2025-11-26 23:34:59 -05:00
parent f743f9c491
commit 2260a8f5d1
9 changed files with 119 additions and 226 deletions

View file

@ -114,6 +114,14 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
StringStore.TranslateTextTransform(pageEndlessLevelTransform.Find("LastPage"));
}
Transform pageNewAdvantureLevelTransform = levelsTransform.transform.Find("PageNewAdvantureLevel");
if (pageNewAdvantureLevelTransform != null)
{
StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("BackToIndex"));
StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("Nextpage"));
StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("LastPage"));
}
foreach (TextMeshProUGUI txt in mainTransform.GetComponentsInChildren<TextMeshProUGUI>())
{
// Still dump untranslated strings for modded plants and zombies

View file

@ -11,13 +11,16 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
{
[HarmonyPostfix]
[HarmonyPatch(nameof(NormalBtn.OnMouseUpAsButton))]
public static void OnMouseUpAsButton(NormalBtn __instance)
{
Transform banTransform = __instance.transform.GetChild(0);
if (banTransform != null)
{
banTransform.GetComponent<TextMeshPro>().text = StringStore.TranslateText(banTransform.GetComponent<TextMeshPro>().text);
}
public static void OnMouseUpAsButton(NormalBtn __instance)
{
if (__instance.transform.childCount > 0)
{
Transform banTransform = __instance.transform.GetChild(0);
if (banTransform != null)
{
banTransform.GetComponent<TextMeshPro>().text = StringStore.TranslateText(banTransform.GetComponent<TextMeshPro>().text);
}
}
}
}
}
}

View file

@ -3,6 +3,7 @@ using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using static PvZ_Fusion_Translator__BepInEx_.Patches.Managers.TravelMgr_Patch;
using UnityEngine;
using System.Collections.Generic;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
@ -16,6 +17,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
foreach (TravelBuffOptionButton button in __instance.options)
{
button.introduce.text = translatedTravelBuffs[buffLinks[button.buffType]][button.buffIndex];
List<string> buffSet = translatedTravelBuffs[buffLinks[button.buffType]];
string buffText = (button.buffIndex < buffSet.Count && button.show != null) ? buffSet[button.buffIndex] : StringStore.TranslateText(button.introduce.text);
button.introduce.text = buffText;
}
}
}

View file

@ -16,7 +16,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
private static void SetBuff(TravelBuffOptionButton __instance)
{
List<string> buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]];
string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text);
string buffText = (__instance.buffIndex < buffSet.Count && __instance.show != null) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text);
__instance.introduce.text = buffText;
}
[HarmonyPatch(nameof(TravelBuffOptionButton.Awake))]
@ -24,7 +25,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
private static void Awake(TravelBuffOptionButton __instance)
{
List<string> buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]];
string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text);
string buffText = (__instance.buffIndex < buffSet.Count && __instance.show != null) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text);
__instance.introduce.text = buffText;
}
[HarmonyPatch(nameof(TravelBuffOptionButton.OnAnimOver))]
@ -32,7 +34,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
private static void OnAnimOver(TravelBuffOptionButton __instance)
{
List<string> buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]];
string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text);
string buffText = (__instance.buffIndex < buffSet.Count && __instance.show != null) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text);
__instance.introduce.text = buffText;
}
}
}

View file

@ -8,19 +8,18 @@ using System.Linq;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(TravelStore))]
public static class TravelStore_Patch
{
[HarmonyPatch(nameof(TravelStore.Update))]
[HarmonyPostfix]
private static void Update(TravelStore __instance)
{
foreach(TextMeshProUGUI text in __instance.introduces)
foreach (TextMeshProUGUI text in __instance.introduces)
{
if(__instance.currentSelect != null)
if (__instance.currentSelect != null)
{
var buffList = translatedTravelBuffs[buffLinks[(BuffType)__instance.currentSelect.theBuffType]];
if(__instance.currentSelect.theBuffNumber < buffList.Count)
if (__instance.currentSelect.theBuffNumber < buffList.Count && __instance.currentSelect.theBuffNumber > -1)
{
text.text = buffList[__instance.currentSelect.theBuffNumber];
}
@ -45,18 +44,26 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
TextMeshProUGUI cost = buff.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
cost.text = StringStore.TranslateText(cost.text);
cost.font = FontStore.LoadTMPFont(Utils.Language.ToString());
//FileLoader.DumpUntranslatedStrings(cost.text);
}
foreach (TextMeshProUGUI text in __instance.introduces)
{
if (__instance.currentSelect != null)
{
text.text = translatedTravelBuffs[buffLinks[(BuffType)__instance.currentSelect.theBuffType]][__instance.currentSelect.theBuffNumber];
var buffList = translatedTravelBuffs[buffLinks[(BuffType)__instance.currentSelect.theBuffType]];
if (__instance.currentSelect.theBuffNumber < buffList.Count && __instance.currentSelect.theBuffNumber > -1)
{
text.text = buffList[__instance.currentSelect.theBuffNumber];
}
else
{
text.text = StringStore.TranslateText(text.text);
}
}
}
foreach (var textMesh in __instance.points)
{
textMesh.text = StringStore.TranslateText(textMesh.text);
{
textMesh.text = StringStore.TranslateText(textMesh.text);
}
}
}

View file

@ -1,89 +1,48 @@
using HarmonyLib;
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
{
[HarmonyPatch(typeof(OppositeBuffManager))]
public static class OppositeBuffManager_Patch
{
#if TESTING
[HarmonyPatch(nameof(OppositeBuffManager.InitBuffPool))]
[HarmonyPostfix]
private static void InitBuffPool(OppositeBuffManager __instance)
{
foreach(TextMeshProUGUI text in __instance.textA_bad)
{
string stripText = text.text.Replace("但", "");
string translatedText = StringStore.TranslateText(stripText);
string replacementText = StringStore.translationString["但"] + translatedText;
text.text = replacementText;
}
foreach(TextMeshProUGUI text in __instance.textA_good)
{
text.text = StringStore.TranslateText(text.text);
}
[HarmonyPatch(typeof(OppositeBuffManager))]
public static class OppositeBuffManager_Patch
{
public static Dictionary<BuffType, string> buffLinks = TravelMgr_Patch.buffLinks;
public static Dictionary<string, List<string>> translatedTravelBuffs = TravelMgr_Patch.translatedTravelBuffs;
public static string badPattern = @"^但(.*)";
public static string badFormat = StringStore.translationStringRegex.ContainsKey(badPattern) ? StringStore.translationStringRegex[badPattern] : "But, {0}";
public static TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(TextMeshProUGUI text in __instance.textB_bad)
{
string stripText = text.text.Replace("但", "");
string translatedText = StringStore.TranslateText(stripText);
string replacementText = StringStore.translationString["但"] + translatedText;
text.text = replacementText;
}
foreach(TextMeshProUGUI text in __instance.textB_good)
{
text.text = StringStore.TranslateText(text.text);
}
}
[HarmonyPatch(nameof(OppositeBuffManager.Awake))]
[HarmonyPostfix]
private static void Awake(OppositeBuffManager __instance)
{
TranslateOppositeText(__instance.textA_bad, BuffType.Debuff, __instance.buffA.theDebuffID, true);
TranslateOppositeText(__instance.textA_good, __instance.buffA.theOptionType, __instance.buffA.theOptionID);
TranslateOppositeText(__instance.textB_bad, BuffType.Debuff, __instance.buffB.theDebuffID, true);
TranslateOppositeText(__instance.textB_good, __instance.buffB.theOptionType, __instance.buffB.theOptionID);
}
[HarmonyPatch(nameof(OppositeBuffManager.SetText), new Type[] { typeof(TextMeshProUGUI), typeof(BuffType), typeof(int)})]
[HarmonyPostfix]
private static void SetText(OppositeBuffManager __instance)
{
foreach(TextMeshProUGUI text in __instance.textA_bad)
{
string stripText = text.text.Replace("?", "");
string translatedText = StringStore.TranslateText(stripText);
string replacementText = StringStore.translationString["但"] + translatedText;
text.text = replacementText;
}
foreach(TextMeshProUGUI text in __instance.textA_good)
{
text.text = StringStore.TranslateText(text.text);
}
public static void TranslateOppositeText(Il2CppSystem.Collections.Generic.List<TextMeshProUGUI> textList, BuffType buffType, int buffIndex, bool isBad = false)
{
string buff = translatedTravelBuffs[buffLinks[buffType]][buffIndex];
foreach(TextMeshProUGUI text in __instance.textB_bad)
{
string stripText = text.text.Replace("但", "");
string translatedText = StringStore.TranslateText(stripText);
string replacementText = StringStore.translationString["但"] + translatedText;
text.text = replacementText;
}
foreach(TextMeshProUGUI text in __instance.textB_good)
{
text.text = StringStore.TranslateText(text.text);
}
}
#endif
foreach (var text in textList)
{
if (isBad)
{
text.text = string.Format(badFormat, buff);
}
else
{
text.text = buff;
}
[HarmonyPatch(nameof(OppositeBuffManager.SetText), new Type[] { typeof(TextMeshProUGUI), typeof(BuffType), typeof(int)})]
[HarmonyPostfix]
private static void SetText(OppositeBuffManager __instance, ref TextMeshProUGUI text)
{
StringStore.TranslateTextUI(text);
}
[HarmonyPatch(nameof(OppositeBuffManager.Awake))]
[HarmonyPostfix]
private static void Awake(OppositeBuffManager __instance)
{
StringStore.TranslateTextUI(__instance.textA_bad[0]);
StringStore.TranslateTextUI(__instance.textA_bad[1]);
StringStore.TranslateTextUI(__instance.textB_bad[0]);
StringStore.TranslateTextUI(__instance.textB_bad[1]);
}
}
text.font = fontAsset;
}
}
}
}

View file

@ -1,49 +0,0 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using PvZ_Fusion_Translator.Patches.Managers;
using System.Text.RegularExpressions;
using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
[HarmonyPatch(typeof(OppositeBuffManager))]
public static class OppositeBuffManager_Patch
{
public static Dictionary<BuffType, string> buffLinks = TravelMgr_Patch.buffLinks;
public static Dictionary<string, List<string>> translatedTravelBuffs = TravelMgr_Patch.translatedTravelBuffs;
public static string badPattern = @"^但(.*)";
public static string badFormat = StringStore.translationStringRegex.ContainsKey(badPattern) ? StringStore.translationStringRegex[badPattern] : "But, {0}";
public static TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
[HarmonyPatch(nameof(OppositeBuffManager.Awake))]
[HarmonyPostfix]
private static void Awake(OppositeBuffManager __instance)
{
TranslateOppositeText(__instance.textA_bad, BuffType.Debuff, __instance.buffA.theDebuffID, true);
TranslateOppositeText(__instance.textA_good, __instance.buffA.theOptionType, __instance.buffA.theOptionID);
TranslateOppositeText(__instance.textB_bad, BuffType.Debuff, __instance.buffB.theDebuffID, true);
TranslateOppositeText(__instance.textB_good, __instance.buffB.theOptionType, __instance.buffB.theOptionID);
}
public static void TranslateOppositeText(Il2CppSystem.Collections.Generic.List<TextMeshProUGUI> textList, BuffType buffType, int buffIndex, bool isBad = false)
{
string buff = translatedTravelBuffs[buffLinks[buffType]][buffIndex];
foreach(var text in textList)
{
if(isBad)
{
text.text = string.Format(badFormat, buff);
}
else
{
text.text = buff;
}
text.font = fontAsset;
}
}
}
}

View file

@ -2,88 +2,47 @@
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using System.Text.RegularExpressions;
using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.Managers
{
[HarmonyPatch(typeof(OppositeBuffManager))]
public static class OppositeBuffManager_Patch
{
#if TESTING
[HarmonyPatch(nameof(OppositeBuffManager.InitBuffPool))]
[HarmonyPostfix]
private static void InitBuffPool(OppositeBuffManager __instance)
{
foreach(TextMeshProUGUI text in __instance.textA_bad)
{
string stripText = text.text.Replace("但", "");
string translatedText = StringStore.TranslateText(stripText);
string replacementText = StringStore.translationString["但"] + translatedText;
text.text = replacementText;
}
foreach(TextMeshProUGUI text in __instance.textA_good)
{
text.text = StringStore.TranslateText(text.text);
}
[HarmonyPatch(typeof(OppositeBuffManager))]
public static class OppositeBuffManager_Patch
{
public static Dictionary<BuffType, string> buffLinks = TravelMgr_Patch.buffLinks;
public static Dictionary<string, List<string>> translatedTravelBuffs = TravelMgr_Patch.translatedTravelBuffs;
public static string badPattern = @"^但(.*)";
public static string badFormat = StringStore.translationStringRegex.ContainsKey(badPattern) ? StringStore.translationStringRegex[badPattern] : "But, {0}";
public static TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(TextMeshProUGUI text in __instance.textB_bad)
{
string stripText = text.text.Replace("但", "");
string translatedText = StringStore.TranslateText(stripText);
string replacementText = StringStore.translationString["但"] + translatedText;
text.text = replacementText;
}
foreach(TextMeshProUGUI text in __instance.textB_good)
{
text.text = StringStore.TranslateText(text.text);
}
}
[HarmonyPatch(nameof(OppositeBuffManager.Awake))]
[HarmonyPostfix]
private static void Awake(OppositeBuffManager __instance)
{
TranslateOppositeText(__instance.textA_bad, BuffType.Debuff, __instance.buffA.theDebuffID, true);
TranslateOppositeText(__instance.textA_good, __instance.buffA.theOptionType, __instance.buffA.theOptionID);
TranslateOppositeText(__instance.textB_bad, BuffType.Debuff, __instance.buffB.theDebuffID, true);
TranslateOppositeText(__instance.textB_good, __instance.buffB.theOptionType, __instance.buffB.theOptionID);
}
[HarmonyPatch(nameof(OppositeBuffManager.SetText), new Type[] { typeof(TextMeshProUGUI), typeof(BuffType), typeof(int)})]
[HarmonyPostfix]
private static void SetText(OppositeBuffManager __instance)
{
foreach(TextMeshProUGUI text in __instance.textA_bad)
{
string stripText = text.text.Replace("但", "");
string translatedText = StringStore.TranslateText(stripText);
string replacementText = StringStore.translationString["但"] + translatedText;
text.text = replacementText;
}
foreach(TextMeshProUGUI text in __instance.textA_good)
{
text.text = StringStore.TranslateText(text.text);
}
public static void TranslateOppositeText(Il2CppSystem.Collections.Generic.List<TextMeshProUGUI> textList, BuffType buffType, int buffIndex, bool isBad = false)
{
string buff = translatedTravelBuffs[buffLinks[buffType]][buffIndex];
foreach(TextMeshProUGUI text in __instance.textB_bad)
{
string stripText = text.text.Replace("但", "");
string translatedText = StringStore.TranslateText(stripText);
string replacementText = StringStore.translationString["但"] + translatedText;
text.text = replacementText;
}
foreach(TextMeshProUGUI text in __instance.textB_good)
{
text.text = StringStore.TranslateText(text.text);
}
}
#endif
foreach(var text in textList)
{
if(isBad)
{
text.text = string.Format(badFormat, buff);
}
else
{
text.text = buff;
}
[HarmonyPatch(nameof(OppositeBuffManager.SetText), new Type[] { typeof(TextMeshProUGUI), typeof(BuffType), typeof(int)})]
[HarmonyPostfix]
private static void SetText(OppositeBuffManager __instance, ref TextMeshProUGUI text)
{
StringStore.TranslateTextUI(text);
}
[HarmonyPatch(nameof(OppositeBuffManager.Awake))]
[HarmonyPostfix]
private static void Awake(OppositeBuffManager __instance)
{
StringStore.TranslateTextUI(__instance.textA_bad[0]);
StringStore.TranslateTextUI(__instance.textA_bad[1]);
StringStore.TranslateTextUI(__instance.textB_bad[0]);
StringStore.TranslateTextUI(__instance.textB_bad[1]);
}
}
text.font = fontAsset;
}
}
}
}

View file

@ -401,7 +401,7 @@
<Compile Include="ModFeatures.cs" />
<Compile Include="AssetStore\AudioStore.cs" />
<Compile Include="Patches\GameObjects\AbyssBuffMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\OppositeBuffManager_Patch.cs" />
<Compile Include="Patches\Managers\OppositeBuffManager_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\ExploreMakeSceneButton_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\ExploreMakeZombieButton_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\BackToIndex_Patch.cs" />
@ -494,7 +494,6 @@
<Compile Include="Patches\Managers\InGameUI_Patch.cs" />
<Compile Include="Patches\Managers\IZBottomMenu_Patch.cs" />
<Compile Include="Patches\OtherManagers\MenuText_Patch.cs" />
<Compile Include="Patches\Managers\OppositeBuffManager_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\OptionBtn_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\OptLanguageBtn_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\PauseMenu_Btn_Patch.cs" />