Merge pull request #3 from Teyliu/Dakosha
All of Dakosha's amazing latest fixes
This commit is contained in:
commit
51a28c2a07
10 changed files with 220 additions and 125 deletions
|
|
@ -29,7 +29,7 @@ namespace PvZ_Fusion_Translator.AssetStore
|
|||
// UI - Playing
|
||||
{ @"-------UI - Playing" , "UI - Playing-------" },
|
||||
{ @"快捷键:(\d+)" , "<size=20>Hotkey: {0}" },
|
||||
{ @"场上敌人数量:(\d+)" , "Zombies: {0}" },
|
||||
{ @"场上敌人数量:(\d+)$" , "Zombies: {0}" },
|
||||
{ @"难度:(\d+)" , "Difficulty: {0}" },
|
||||
|
||||
// UI - Adventure Mode
|
||||
|
|
@ -117,8 +117,8 @@ namespace PvZ_Fusion_Translator.AssetStore
|
|||
{ @"-------Strings - Others" , "Strings - Others-------" },
|
||||
// { @"HP:(\d+)/(\d+)\s+一类:(\d+)/(\d+)" , "HP: {0}/{1}\nArmor: {2}/{3}" },
|
||||
// { @"HP:(\d+)/(\d+)\s+二类:(\d+)/(\d+)" , "HP: {0}/{1}\nArmor: {2}/{3}" },
|
||||
{ @"^HP:(\d+)/(\d+)\s+([^\s+])类:(\d+)/(\d+)" , "HP: {0}/{1}\nArmor: {3}/{4}" },
|
||||
{ @"^HP:(\d+)/(\d+)" , "HP: {0}/{1}" },
|
||||
// { @"^HP:(\d+)/(\d+)\s+([^\s+])类:(\d+)/(\d+)" , "HP: {0}/{1}\nArmor: {3}/{4}" },
|
||||
// { @"^HP:(\d+)/(\d+)" , "HP: {0}/{1}" },
|
||||
// { @"平衡性调整(([^\s]+))" , "Balance Adjustment ({0})" },
|
||||
{ @"旅行:守护 (\d+)轮已经完成" , "Odyssey: Last Stand | {0} Rounds Completed"},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using Il2Cpp;
|
||||
using MelonLoader;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects;
|
||||
using PvZ_Fusion_Translator.Patches.OtherManagers;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
|
|
@ -76,6 +77,7 @@ namespace PvZ_Fusion_Translator
|
|||
{
|
||||
StringStore.translationStringRegex[key] = value;
|
||||
}
|
||||
Zombie_Patch.LoadHPStrings();
|
||||
}
|
||||
}
|
||||
SaveStrings();
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
using HarmonyLib;
|
||||
using Il2Cpp;
|
||||
using Il2CppTMPro;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using UnityEngine;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||
{
|
||||
[HarmonyPatch(typeof(EveManager))]
|
||||
public static class EveManager_UIButton_Patch
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(EveManager.Balanced))]
|
||||
private static void Start(EveManager __instance)
|
||||
{
|
||||
Transform sceneText = __instance.transform.FindChild("text");
|
||||
if(sceneText != null)
|
||||
{
|
||||
TextMeshProUGUI sceneTextTMP = sceneText.transform.GetComponent<TextMeshProUGUI>();
|
||||
if(sceneTextTMP != null)
|
||||
{
|
||||
sceneTextTMP.text = StringStore.TranslateText(sceneTextTMP.text);
|
||||
}
|
||||
}
|
||||
Transform sceneTextShadow = sceneText.transform.FindChild("text2");
|
||||
if(sceneTextShadow != null)
|
||||
{
|
||||
TextMeshProUGUI sceneTextShadowTMP = sceneTextShadow.transform.GetComponent<TextMeshProUGUI>();
|
||||
if (sceneTextShadowTMP != null)
|
||||
{
|
||||
sceneTextShadowTMP.text = StringStore.TranslateText(sceneTextShadowTMP.text);
|
||||
}
|
||||
}
|
||||
|
||||
if (__instance.name.Equals("Balanced"))
|
||||
{
|
||||
__instance.gameObject.SetActive(false);
|
||||
__instance.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,6 @@
|
|||
using Il2Cpp;
|
||||
using Il2CppTMPro;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore.Text;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||
{
|
||||
|
|
@ -13,29 +10,32 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
|||
{
|
||||
[HarmonyPatch(nameof(UIButton.Start))]
|
||||
[HarmonyPostfix]
|
||||
private static void Postfix_Start(UIButton __instance)
|
||||
public static void Start(UIButton __instance)
|
||||
{
|
||||
Text[] textComponents = __instance.GetComponentsInChildren<Text>(true);
|
||||
|
||||
foreach (Text textComponent in textComponents)
|
||||
try
|
||||
{
|
||||
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;
|
||||
//Debug.Log($"Converted and translated text: {textComponent.text} -> {translatedText}");
|
||||
}
|
||||
}
|
||||
}
|
||||
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) { }
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(UIButton.OnMouseUpAsButton))]
|
||||
[HarmonyPostfix]
|
||||
public static void OnMouseUpAsButton(UIButton __instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
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) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,47 @@
|
|||
#if FIX
|
||||
using HarmonyLib;
|
||||
using HarmonyLib;
|
||||
using Il2Cpp;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using UnityEngine;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
||||
{
|
||||
[HarmonyPatch(typeof(Plant))]
|
||||
public static class Plant_Patch
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(Plant.UpdateHealthText))]
|
||||
private static void UpdateHealthText(Plant __instance)
|
||||
{
|
||||
Transform healthTransform = __instance.transform.Find("health");
|
||||
if (healthTransform != null)
|
||||
{
|
||||
StringStore.TranslateTextTransform(__instance.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
[HarmonyPatch(typeof(Plant))]
|
||||
public static class Plant_Patch
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(Plant.Awake))]
|
||||
private static void Awake(Plant __instance)
|
||||
{
|
||||
if (!(__instance.thePlantType == PlantType.SuperMachineNut || __instance.thePlantType == PlantType.MachineNut))
|
||||
return;
|
||||
__instance.healthSlider.healthText.text = __instance.healthSlider.healthTextShadow.text = ChangeHPText(__instance.healthSlider.healthTextShadow.text);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(Plant.UpdateText))]
|
||||
private static void Update(Plant __instance)
|
||||
{
|
||||
if (!(__instance.thePlantType == PlantType.SuperMachineNut || __instance.thePlantType == PlantType.MachineNut))
|
||||
return;
|
||||
if (__instance.thePlantHealth < __instance.thePlantMaxHealth)
|
||||
return;
|
||||
__instance.healthSlider.healthText.text = __instance.healthSlider.healthTextShadow.text = ChangeHPText(__instance.healthSlider.healthTextShadow.text);
|
||||
}
|
||||
|
||||
static string ChangeHPText(string originalText)
|
||||
{
|
||||
var regex = new Regex(@"(\d+)\d\d\d/(\d)000");
|
||||
if (regex.IsMatch(originalText))
|
||||
{
|
||||
var match = regex.Match(originalText);
|
||||
int groupCount = match.Groups.Count;
|
||||
|
||||
List<string> dynamicParts = new List<string>();
|
||||
|
||||
for (int i = 1; i < groupCount; i++)
|
||||
dynamicParts.Add(match.Groups[i].Value);
|
||||
return originalText = string.Format("{0}k/{1}k", [.. dynamicParts]);
|
||||
}
|
||||
return originalText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using HarmonyLib;
|
||||
using Il2Cpp;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
||||
{
|
||||
[HarmonyPatch(typeof(TrainingDummy), nameof(TrainingDummy.UpdateHealthText))]
|
||||
public static class TrainingDummy_Patch
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
public static void UpdateHealthText(TrainingDummy __instance)
|
||||
{
|
||||
Zombie_Patch.TranslateHpUI(__instance.healthText);
|
||||
Zombie_Patch.TranslateHpUI(__instance.healthTextShadow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using HarmonyLib;
|
||||
using Il2Cpp;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
||||
{
|
||||
[HarmonyPatch(typeof(UltimateChomper), nameof(UltimateChomper.UpdateText))]
|
||||
public static class UltimateChomper_Patch
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
public static void UpdateText(UltimateChomper __instance)
|
||||
{
|
||||
StringStore.TranslateText(__instance.killingText);
|
||||
StringStore.TranslateText(__instance.killingTextShadow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,99 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HarmonyLib;
|
||||
using Il2Cpp;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using Il2CppTMPro;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
||||
{
|
||||
class Zombie_Patch
|
||||
[HarmonyPatch(typeof(Zombie))]
|
||||
public static class Zombie_Patch
|
||||
{
|
||||
private static Dictionary<string, string> HPStrings = new Dictionary<string, string>()
|
||||
{
|
||||
{ "最后一击:(\\d+)\nDPS:(.+)$", "Last damage: {0}\nDPS: {1}" },
|
||||
{ "^HP:(\\d+)/(\\d+)\n\\D+(\\d+)/(\\d+)\n\\D+(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 1 armor: {2}/{3}\nType 2 armor: {4}/{5}" },
|
||||
{ "^HP:(\\d+)/(\\d+)\n\\D+(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 1 armor: {2}/{3}" },
|
||||
{ "^HP:(\\d+)/(\\d+)$", "HP: {0}/{1}" },
|
||||
};
|
||||
|
||||
public static void LoadHPStrings()
|
||||
{
|
||||
foreach (var hp in HPStrings)
|
||||
if (StringStore.translationStringRegex.ContainsKey(hp.Key))
|
||||
HPStrings[hp.Key] = StringStore.translationStringRegex[hp.Key];
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(Zombie.Start))]
|
||||
[HarmonyPostfix]
|
||||
public static void Start(Zombie __instance)
|
||||
{
|
||||
TranslateHpUI(__instance.healthText);
|
||||
TranslateHpUI(__instance.healthTextShadow);
|
||||
if (__instance.theFirstArmorHealth == 0 && __instance.theSecondArmorHealth != 0)
|
||||
{
|
||||
__instance.healthText.text = __instance.healthText.text.Replace("Type 1", "Type 2");
|
||||
__instance.healthTextShadow.text = __instance.healthText.text.Replace("Type 1", "Type 2");
|
||||
}
|
||||
if (__instance.healthText.transform.rotation != Quaternion.Euler(0, 0, 0))
|
||||
__instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(Zombie.Update))]
|
||||
[HarmonyPrefix]
|
||||
public static void Update(Zombie __instance)
|
||||
{
|
||||
if (__instance.theZombieType == ZombieType.TrainingDummy || !Board.Instance.showZombieHealth)
|
||||
return;
|
||||
TranslateHpUI(__instance.healthText);
|
||||
TranslateHpUI(__instance.healthTextShadow);
|
||||
if (__instance.theFirstArmorHealth == 0 && __instance.theSecondArmorHealth != 0)
|
||||
{
|
||||
__instance.healthText.text = __instance.healthText.text.Replace("Type 1", "Type 2");
|
||||
__instance.healthTextShadow.text = __instance.healthText.text.Replace("Type 1", "Type 2");
|
||||
}
|
||||
if (__instance.healthText.transform.rotation != Quaternion.Euler(0f, 0f, 0f))
|
||||
__instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
|
||||
}
|
||||
|
||||
public static void TranslateHpUI(TextMeshPro textTMP)
|
||||
{
|
||||
if (textTMP)
|
||||
{
|
||||
string origText = textTMP.text;
|
||||
string translatedText = TranslateHPText(origText);
|
||||
textTMP.text = translatedText == origText ? origText : translatedText;
|
||||
textTMP.autoSizeTextContainer = false;
|
||||
if (translatedText != origText)
|
||||
textTMP.font = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public static string TranslateHPText(string originalText)
|
||||
{
|
||||
foreach (var entry in HPStrings)
|
||||
{
|
||||
var regex = new Regex(entry.Key);
|
||||
if (regex.IsMatch(originalText))
|
||||
{
|
||||
var match = regex.Match(originalText);
|
||||
int groupCount = match.Groups.Count;
|
||||
|
||||
List<string> dynamicParts = new List<string>();
|
||||
|
||||
for (int i = 1; i < groupCount; i++)
|
||||
{
|
||||
string groupValue = match.Groups[i].Value;
|
||||
string translatedValue = StringStore.translationString.ContainsKey(groupValue)
|
||||
? StringStore.translationString[groupValue]
|
||||
: groupValue;
|
||||
dynamicParts.Add(translatedValue);
|
||||
}
|
||||
return originalText = string.Format(entry.Value, [.. dynamicParts]);
|
||||
}
|
||||
}
|
||||
return originalText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,42 +7,33 @@ using UnityEngine;
|
|||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||
{
|
||||
[HarmonyPatch(typeof(TravelStore))]
|
||||
internal class TravelStore_Patch
|
||||
public static class TravelStore_Patch
|
||||
{
|
||||
[HarmonyPatch(nameof(TravelStore.Update))]
|
||||
[HarmonyPostfix]
|
||||
private static void Update(TravelStore __instance)
|
||||
{
|
||||
foreach (TextMeshProUGUI text in __instance.introduces)
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
}
|
||||
|
||||
Transform moneyTransform = __instance.transform.Find("Money");
|
||||
if (moneyTransform != null)
|
||||
{
|
||||
StringStore.TranslateTextTransform(moneyTransform);
|
||||
}
|
||||
|
||||
foreach (TextMeshProUGUI text in __instance.points)
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
}
|
||||
{
|
||||
foreach (TextMeshProUGUI intr in __instance.introduces)
|
||||
StringStore.TranslateTextUI(intr);
|
||||
foreach (var textMesh in __instance.points)
|
||||
StringStore.TranslateTextUI(textMesh);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(TravelStore.SetText), new Type[] { typeof(string)})]
|
||||
[HarmonyPostfix]
|
||||
private static void ShowText(TravelStore __instance)
|
||||
{
|
||||
foreach (TextMeshProUGUI text in __instance.introduces)
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
}
|
||||
|
||||
foreach (TextMeshProUGUI text in __instance.points)
|
||||
[HarmonyPatch(nameof(TravelStore.RefreshBuff))]
|
||||
[HarmonyPostfix]
|
||||
private static void RefreshBuff(TravelStore __instance)
|
||||
{
|
||||
foreach (TravelBuff buff in __instance.travelBuffs)
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
TextMeshProUGUI cost = buff.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
||||
if (!cost.text.Contains('0'))
|
||||
StringStore.TranslateTextUI(cost);
|
||||
cost.font = Resources.Load<TMP_FontAsset>("fonts/Dynamic");
|
||||
}
|
||||
foreach (TextMeshProUGUI intr in __instance.introduces)
|
||||
StringStore.TranslateTextUI(intr);
|
||||
foreach (var textMesh in __instance.points)
|
||||
StringStore.TranslateTextUI(textMesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<LangVersion>latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Configurations>Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate</Configurations>
|
||||
<GamePath>D:\PvZ Fusion\Game Files</GamePath>
|
||||
<GamePath>G:\ML-Fusion 2.6.1\Game Files</GamePath>
|
||||
<Platforms>AnyCPU;ARM64;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
@ -406,6 +406,8 @@
|
|||
<Compile Include="Patches\GameObjects\AbyssSettlementMenu_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\ButtonObjects\NormalBtn_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\ButtonObjects\UIButton_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\MinorObjects\TrainingDummy_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\MinorObjects\UltimateChomper_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\OtherMenu_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssCheckSellMenu_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssBuffButton_Patch.cs" />
|
||||
|
|
@ -437,7 +439,6 @@
|
|||
<Compile Include="Patches\Managers\AlmanacPlantBank_Patch.cs" />
|
||||
<Compile Include="Patches\Managers\DifficultyMgr_Patch.cs" />
|
||||
<Compile Include="Patches\Managers\EndlessMgr_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\ButtonObjects\EveBtn_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\GardenPlant_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\Close_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\CustomSettings_Patch.cs" />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue