This commit is contained in:
SillyStar-Github 2026-05-01 16:58:57 -04:00
parent 0515bba2b7
commit 22e503bd32
49 changed files with 1218 additions and 321 deletions

View file

@ -155,6 +155,9 @@ namespace PvZ_Fusion_Translator.AssetStore
if (__instance.clip == null)
return;
if (Il2CppRhythmGame.RhythmGameManager.Instance != null && __instance.clip.name == "loon")
return;
if (LogSounds)
MelonLogger.Msg($"Playing \"{__instance.clip.name}\" from object \"{__instance.gameObject.name}\"");

View file

@ -1,4 +1,4 @@
using MelonLoader;
/*using MelonLoader;
using MelonLoader.Utils;
using System;
using System.Collections.Generic;
@ -112,3 +112,4 @@ namespace PvZ_Fusion_Translator.AssetStore
}
}
}
*/

View file

@ -1,4 +1,6 @@
using Il2CppTMPro;
using Il2CppSystem.Runtime.Remoting.Messaging;
using Il2CppTMPro;
using System.Diagnostics;
using System.Text.RegularExpressions;
using UnityEngine;
@ -87,6 +89,12 @@ namespace PvZ_Fusion_Translator.AssetStore
public static TextMeshPro TranslateText(TextMeshPro originalTMP, bool isLog = false)
{
/*var frame = new StackTrace().GetFrame(1);
var method = frame.GetMethod();
var className = method.DeclaringType.Name;
Console.WriteLine($"TextMeshPro: {className}.{method.Name}");*/
#if MULTI_LANGUAGE
string currentLanguage = Utils.Language.ToString();
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(currentLanguage);
@ -103,6 +111,12 @@ namespace PvZ_Fusion_Translator.AssetStore
public static TextMeshProUGUI TranslateText(TextMeshProUGUI originalTMP, bool isLog = false)
{
/*var frame = new StackTrace().GetFrame(1);
var method = frame.GetMethod();
var className = method.DeclaringType.Name;
Console.WriteLine($"tmp pro ugui: {className}.{method.Name}");*/
#if MULTI_LANGUAGE
string currentLanguage = Utils.Language.ToString();
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(currentLanguage);
@ -119,6 +133,12 @@ namespace PvZ_Fusion_Translator.AssetStore
public static string TranslateText(string originalText, bool isLog = false)
{
/*var frame = new StackTrace().GetFrame(1);
var method = frame.GetMethod();
var className = method.DeclaringType.Name;
Console.WriteLine($"string: {className}.{method.Name}");*/
string text = DoTranslateText(originalText, false);
string checkText;
#if DEBUG

View file

@ -32,7 +32,7 @@ namespace PvZ_Fusion_Translator
base.OnInitializeMelon();
Instance = this;
DllStore.Init(MelonLoader.InternalUtils.UnityInformationHandler.GameVersion);
//DllStore.Init(MelonLoader.InternalUtils.UnityInformationHandler.GameVersion);
Config();
#if MULTI_LANGUAGE
@ -51,7 +51,7 @@ namespace PvZ_Fusion_Translator
{
dtStart = DateTime.Now;
replaceTextureRoutine = MelonCoroutines.Start(TextureStore.ReplaceTexturesCoroutine());
TravelMgr_Patch.DumpTravelBuffs();
LoadTravelBuffs();
}
public override void OnDeinitializeMelon()
@ -60,7 +60,7 @@ namespace PvZ_Fusion_Translator
#if MULTI_LANGUAGE
FileLoader.SaveLanguage();
#endif
DllStore.UpdateNewDll();
//DllStore.UpdateNewDll();
#if OBFUSCATE && !RELEASE
CheckSumStore.ConvertMD5Json();
#endif

View file

@ -1,10 +1,10 @@
using Il2Cpp;
using Il2CppAlmanacData;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using JetBrains.Annotations;
using MelonLoader;
using MelonLoader.TinyJSON;
using Newtonsoft.Json;
using NVorbis.Contracts;
using PvZ_Fusion_Translator.AssetStore;
using PvZ_Fusion_Translator.Patches.GameObjects;
using PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects;
@ -80,22 +80,6 @@ namespace PvZ_Fusion_Translator
}
}
// load travel_buffs
string travelBuffsContent = Utils.GetDataFromWeb($"https://raw.githubusercontent.com/Teyliu/PVZF-Translation/refs/heads/main/PvZ_Fusion_Translator/Localization/{Utils.Language.ToString()}/Strings/travel_buffs.json").Result;
if(travelBuffsContent != null)
{
TravelMgr_Patch.translatedTravelBuffs = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(travelBuffsContent);
}
else
{
string travelBuffsPath = Path.Combine(GetAssetDir(AssetType.Strings, Utils.Language), "travel_buffs.json");
if(File.Exists(travelBuffsPath))
{
TravelMgr_Patch.translatedTravelBuffs = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(File.ReadAllText(travelBuffsPath));
}
}
// load changelog
LoadChangelogText();
@ -170,6 +154,20 @@ namespace PvZ_Fusion_Translator
}
}
string detailStringsContent = Utils.GetDataFromWeb($"https://raw.githubusercontent.com/Teyliu/PVZF-Translation/refs/heads/3.6/PvZ_Fusion_Translator/Localization/{Utils.Language.ToString()}/Almanac/DetailStrings.json").Result;
if(detailStringsContent != null)
{
LoadDetailStrings(detailStringsContent);
}
else
{
string path = Path.Combine(almanacDir, "DetailStringsTranslate.json");
if(File.Exists(path))
{
LoadDetailStrings(File.ReadAllText(path));
}
}
// load abyss buffs
Patches.Modes.Abyss.AbyssBuffMenu_Patch.LoadAbyssBuffData();
@ -210,10 +208,6 @@ namespace PvZ_Fusion_Translator
{
LoadTranslationRegexs(jsonString);
}
else if(fileName.EndsWith("travel_buffs"))
{
TravelMgr_Patch.translatedTravelBuffs = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(jsonString);
}
else if(fileName.EndsWith("tips_iz"))
{
LoadIZStrings(jsonString);
@ -242,10 +236,16 @@ namespace PvZ_Fusion_Translator
AlmanacPlantMenu_Patch.almanacJson = File.ReadAllText(plantAlmanacPath);
}
string zombieAlmanacPlant = Path.Combine(almanacDir, "ZombieStringsTranslate.json");
if(File.Exists(zombieAlmanacPlant))
string zombieAlmanacPath = Path.Combine(almanacDir, "ZombieStringsTranslate.json");
if(File.Exists(zombieAlmanacPath))
{
AlmanacZombieMenu_Patch.almanacJson = File.ReadAllText(zombieAlmanacPlant);
AlmanacZombieMenu_Patch.almanacJson = File.ReadAllText(zombieAlmanacPath);
}
string detailStringsPath = Path.Combine(almanacDir, "DetailStringsTranslate.json");
if(File.Exists(detailStringsPath))
{
LoadDetailStrings(File.ReadAllText(detailStringsPath));
}
SaveStrings();
@ -326,6 +326,31 @@ namespace PvZ_Fusion_Translator
}
}
internal static void LoadDetailStrings(string content)
{
var detailStringsDump = DumpDetailStrings();
var detailStringsData = detailStringsDump.Item1;
var detailStrings = detailStringsDump.Item2;
var translatedDetailStrings = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, string>>(content);
AlmanacSelectMenu_Patch.detailStrings = translatedDetailStrings;
foreach (var detailString in detailStringsData.details)
{
if (translatedDetailStrings.ContainsKey(detailString.title))
{
if(!AlmanacSelectMenu_Patch.detailTranslateStrings.ContainsKey(detailString.text))
{
AlmanacSelectMenu_Patch.detailTranslateStrings.Add(detailString.text, translatedDetailStrings[detailString.title]);
}
else
{
AlmanacSelectMenu_Patch.detailTranslateStrings[detailString.text] = translatedDetailStrings[detailString.title];
}
}
}
}
internal static void LoadChangelogText()
{
string stringDir = FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language);
@ -351,6 +376,41 @@ namespace PvZ_Fusion_Translator
NoticePauseMenu_Patch.changelogText = changelogText;
}
internal static void LoadTravelBuffs()
{
if (!Utils.useLocal)
{
string travelBuffsContent = Utils.GetDataFromWeb($"https://raw.githubusercontent.com/Teyliu/PVZF-Translation/refs/heads/main/PvZ_Fusion_Translator/Localization/{Utils.Language.ToString()}/Strings/travel_buffs.json").Result;
if (travelBuffsContent != null)
{
TravelMgr_Patch.translatedTravelBuffs = TravelMgr_Patch.GenerateTranslatedTravelBuffs(travelBuffsContent);
}
else
{
string travelBuffsPath = Path.Combine(GetAssetDir(AssetType.Strings, Utils.Language), "travel_buffs.json");
if (File.Exists(travelBuffsPath))
{
TravelMgr_Patch.translatedTravelBuffs = TravelMgr_Patch.GenerateTranslatedTravelBuffs(File.ReadAllText(travelBuffsPath));
}
}
}
else
{
string stringDir = FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language);
foreach (string filepath in Directory.EnumerateFiles(stringDir, "*.json", SearchOption.AllDirectories))
{
string fileName = Path.GetFileNameWithoutExtension(filepath);
string jsonString = File.ReadAllText(filepath);
if (fileName.EndsWith("travel_buffs"))
{
TravelMgr_Patch.translatedTravelBuffs = TravelMgr_Patch.GenerateTranslatedTravelBuffs(jsonString);
}
}
}
}
public static bool loadDefaultTextures = MelonPreferences.GetEntryValue<bool>("PvZ_Fusion_Translator", "DefaultTextures");
internal static void LoadTextures()
{
@ -850,12 +910,6 @@ namespace PvZ_Fusion_Translator
File.WriteAllText(Path.Combine(stringDir, "tips_fs.json"), fsLevelTipDictionary);
// save travel buffs
string travelBuffs = SerializeWithIndentation(TravelMgr_Patch.translatedTravelBuffs);
File.WriteAllText(Path.Combine(stringDir, "travel_buffs.json"), travelBuffs);
// save changelog
if(NoticePauseMenu_Patch.changelogText != "")
@ -888,6 +942,13 @@ namespace PvZ_Fusion_Translator
File.WriteAllText(Path.Combine(almanacDir, "ZombieStringsTranslate.json"), AlmanacZombieMenu_Patch.almanacJson);
}
if(AlmanacSelectMenu_Patch.detailStrings != new Dictionary<string, string>())
{
string detailStrings = SerializeWithIndentation(AlmanacSelectMenu_Patch.detailStrings);
File.WriteAllText(Path.Combine(almanacDir, "DetailStringsTranslate.json"), detailStrings);
}
}
public static string SerializeWithIndentation<T>(T value, int size = 4, char indentChar = ' ')
@ -944,7 +1005,18 @@ namespace PvZ_Fusion_Translator
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
}));
Dictionary<Achievement, AchievementObject> achievementsList = new Dictionary<Achievement, AchievementObject>();
// dump almanac mechanics
var detailStringsDump = DumpDetailStrings();
var detailStringsData = detailStringsDump.Item1;
var detailStrings = detailStringsDump.Item2;
File.WriteAllText(Path.Combine(dumpDir, "DetailStrings.json"), System.Text.Json.JsonSerializer.Serialize(detailStrings, new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
}));
/*Dictionary<Achievement, AchievementObject> achievementsList = new Dictionary<Achievement, AchievementObject>();
foreach (Il2CppSystem.Collections.Generic.KeyValuePair<Achievement, Il2CppSystem.Tuple<string, string>> entry in AchievementClip.achievementsText)
{
achievementsList.Add(entry.Key, new AchievementObject(entry.Key, entry.Value.Item1, entry.Value.Item2));
@ -953,7 +1025,7 @@ namespace PvZ_Fusion_Translator
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
}));
}));*/
}
public static ValueTuple<Il2CppArrayBase<TextAsset>, Dictionary<string, string>> DumpIZStrings()
@ -988,6 +1060,26 @@ namespace PvZ_Fusion_Translator
return new ValueTuple<Il2CppArrayBase<TextAsset>, Dictionary<string, string>>(fusionShowcaseData, fusionShowcaseDataDump);
}
public static ValueTuple<Il2CppAlmanacData.AlmanacData, Dictionary<string, string>> DumpDetailStrings()
{
string detailStringsData = Resources.Load<TextAsset>("detailstrings").text;
Il2CppAlmanacData.AlmanacData detailStrings = JsonUtility.FromJson<Il2CppAlmanacData.AlmanacData>(detailStringsData);
Dictionary<string, string> detailStringsDump = new Dictionary<string, string>();
foreach (var detailString in detailStrings.details)
{
if(detailStringsDump.ContainsKey(detailString.title))
{
detailStringsDump[detailString.title] = detailString.text;
}
else
{
detailStringsDump.Add(detailString.title, detailString.text);
}
}
return new ValueTuple<Il2CppAlmanacData.AlmanacData, Dictionary<string, string>>(detailStrings, detailStringsDump);
}
#if DEBUG
public static void DumpUntranslatedStrings(string text)
{

View file

@ -1,10 +1,9 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppAlmanacData;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using PvZ_Fusion_Translator.Patches.Modes.Odyssey;
//using PvZ_Fusion_Translator.Patches.Modes.Odyssey;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using UnityEngine;
@ -68,6 +67,7 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
string originalText = txt.text;
string lockedPlantMatch = CheckLockedMessage(originalText);
string travelMatch = TravelMgr_Patch.MatchTravelBuff(originalText);
int godsGachaCheck = CheckGodsGachaPopup(originalText);
string godsGachaMatch = "";
@ -114,6 +114,10 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
{
txt.text = superEditorPlantMatch;
}
else if(lockedPlantMatch != "")
{
txt.text = lockedPlantMatch;
}
else if((Regex.Match(txt.text, @"(<color[^>]*>.*?</color>)", RegexOptions.Singleline).Success) && (!StringStore.translationString.ContainsKey(txt.text) && !StringStore.fsTipCollectionString.ContainsKey(txt.text) && !StringStore.izTipCollectionString.ContainsKey(txt.text)))
{
txt.text = StringStore.TranslateColorText(txt.text, true);
@ -146,14 +150,20 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
public static string namePlantedPattern = "种植了:([^\\s]+)";
public static string nameUpgradedPattern = "升级成功:([^\\s]+) -> ([^\\s]+)";
public static string nameAlreadyPlantedPattern = "场上已经有一个([^\\s]+)了";
public static string upgradePathRemovedPattern = "已移除路线:([^\\s]+)";
public static string lockedPlantPattern = "^([^\\s:]+)\\+([^\\s:]+)";
public static string multiLockedPlantPattern = "^或 ([^\\s:]+)\\+([^\\s:]+)";
public static Dictionary<string, string> fallbackFStrs = new Dictionary<string, string>()
{
{"种植了:([^\\s]+)", "{0} planted!"},
{"升级成功:([^\\s]+) -> ([^\\s]+)", "{0} successfully upgraded to {1}!"},
{"场上已经有一个([^\\s]+)了", "{0} already exists on the lawn!"},
{"已移除路线:([^\\s]+)", "Upgrade Path removed for {0}" },
{ @"([^\s]+)\((\d+)\)", "{0}({1})" }
{ namePlantedPattern, "{0} planted!"},
{ nameUpgradedPattern, "{0} successfully upgraded to {1}!"},
{ nameAlreadyPlantedPattern, "{0} already exists on the lawn!"},
{ upgradePathRemovedPattern, "Upgrade Path removed for {0}" },
{ @"([^\s]+)\((\d+)\)", "{0}({1})" },
{ lockedPlantPattern, "{0} + {1}" },
{ multiLockedPlantPattern, "or {0} + {1}" }
};
public static int CheckGodsGachaPopup(string originalText)
@ -219,13 +229,35 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
return res;
}
public static string TranslatePlantNameParts(string originalText, string pattern, string fallback)
{
string res = "";
string fStr = "";
Match match = Regex.Match(originalText, pattern);
if(match.Success)
{
GroupCollection groups = match.Groups;
fStr = StringStore.translationStringRegex.ContainsKey(pattern) ? StringStore.translationStringRegex[pattern] : fallback;
List<string> dynamicParts = [];
for(int i = 1; i < groups.Count; i++)
{
string group = groups[i].Value;
string plantName = Utils.GetPlantNameFromAlmanac(group);
if (plantName == "") plantName = StringStore.TranslateText(group);
dynamicParts.Add(plantName);
}
res = string.Format(fStr, [.. dynamicParts]);
}
return res;
}
public static string CheckSuperEditorPopup(string originalText)
{
string res = "";
if(Regex.IsMatch(originalText, "已移除路线:([^\\s]+)"))
if(Regex.IsMatch(originalText, upgradePathRemovedPattern))
{
res = TranslatePlantNameParts(originalText, "已移除路线:([^\\s]+)");
res = TranslatePlantNameParts(originalText, upgradePathRemovedPattern);
}
else if(Regex.IsMatch(originalText, "当前全部基础植物:(.*)"))
{
@ -254,5 +286,64 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
return res;
}
public static string CheckLockedMessage(string originalText)
{
string res = "";
Regex lockedPlantRegex = new Regex(lockedPlantPattern);
Regex multiLockedPlantRegex = new Regex(multiLockedPlantPattern);
if(lockedPlantRegex.IsMatch(originalText))
{
if(originalText.Contains("\n"))
{
string[] lines = originalText.Split("\n");
if (lockedPlantRegex.IsMatch(lines[0]))
{
string firstLine = lines[0];
Match match = lockedPlantRegex.Match(firstLine);
GroupCollection groups = match.Groups;
Log.LogDebug(Utils.plantIndiceStrings.ContainsKey(groups[1].Value));
Log.LogDebug(Utils.plantIndiceStrings.ContainsKey(groups[2].Value));
if (Utils.plantIndiceStrings.ContainsKey(groups[1].Value) && Utils.plantIndiceStrings.ContainsKey(groups[2].Value))
{
firstLine = TranslatePlantNameParts(firstLine, lockedPlantPattern);
List<string> translatedLines = new List<string>() { firstLine };
for(int i = 1; i < lines.Length; i++)
{
string nextLine = lines[i];
Log.LogDebug(nextLine);
string translatedNextLine = TranslatePlantNameParts(nextLine, multiLockedPlantPattern);
translatedLines.Add(translatedNextLine);
}
res = string.Join("\n", translatedLines);
}
else
{
return "";
}
}
}
else
{
if (lockedPlantRegex.IsMatch(originalText))
{
Match match = lockedPlantRegex.Match(originalText);
GroupCollection groups = match.Groups;
if (Utils.plantIndiceStrings.ContainsKey(groups[1].Value) && Utils.plantIndiceStrings.ContainsKey(groups[2].Value))
{
res = TranslatePlantNameParts(originalText, lockedPlantPattern);
}
else
{
return "";
}
}
}
}
return res;
}
}
}

View file

@ -17,6 +17,14 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
{
if (!string.IsNullOrEmpty(__instance.text))
{
if(__instance.transform.parent != null)
{
if(__instance.transform.parent.name.Contains("DrawCardsText"))
{
Log.LogDebug("skipping drawcardstext");
return;
}
if(__instance.transform.parent.parent != null)
{
if (__instance.transform.parent.parent.name.Contains("AbyssBagMenu"))
@ -24,6 +32,7 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
return;
}
}
}
__instance = StringStore.TranslateText(__instance);
__instance.autoSizeTextContainer = false;
@ -47,7 +56,7 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
}
}
[HarmonyPatch(nameof(TextMeshProUGUI.Awake))]
/*[HarmonyPatch(nameof(TextMeshProUGUI.Awake))]
[HarmonyPostfix]
private static void Awake(TextMeshProUGUI __instance)
{
@ -77,9 +86,10 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
// __instance.ForceMeshUpdate();
}
}*/
}
}
[HarmonyPatch(typeof(TMP_SubMeshUI))]
/*[HarmonyPatch(typeof(TMP_SubMeshUI))]
public static class TMP_SubMeshUI_Patch
{
[HarmonyPatch(nameof(TMP_SubMeshUI.OnEnable))]
@ -93,5 +103,5 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
__instance.textComponent.text = StringStore.TranslateText(text);
}
}
}
}*/
}

View file

@ -13,7 +13,11 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
{
if (!string.IsNullOrEmpty(__instance.text))
{
if (__instance.transform.parent.name.StartsWith("AlmanacHelp") || __instance.transform.parent.name.StartsWith("CardBank"))
if(__instance.transform.parent.name.Contains("DrawCardsText"))
{
return;
}
else if (__instance.transform.parent.name.StartsWith("AlmanacHelp") || __instance.transform.parent.name.StartsWith("CardBank"))
{
__instance = StringStore.TranslateText(__instance);
__instance.autoSizeTextContainer = false;

View file

@ -0,0 +1,32 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
using System.Text.RegularExpressions;
using Unity.VisualScripting;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
[HarmonyPatch(typeof(AlmanacCardUI))]
public static class AlmanacCardUI_Patch
{
[HarmonyPatch(nameof(AlmanacCardUI.Awake))]
[HarmonyPostfix]
public static void Awake(AlmanacCardUI __instance)
{
if (!Utils.CheckForUntranslatedText(__instance.cost.text)) return;
__instance.cost.text = StringStore.TranslateText(__instance.cost.text);
}
[HarmonyPatch(nameof(AlmanacCardUI.OnPointerDown))]
[HarmonyPostfix]
public static void OnPointerDown(AlmanacCardUI __instance)
{
foreach(AlmanacCardUI almanacCardUI in __instance.menu.GetComponentsInChildren<AlmanacCardUI>())
{
AlmanacCardUI_Patch.Awake(almanacCardUI);
}
}
}
}

View file

@ -1,5 +1,6 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppAlmanacData;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using System.Text.RegularExpressions;
@ -7,7 +8,7 @@ using Unity.Collections;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using static Il2Cpp.AlmanacPlantBank;
using UnityEngine.UIElements;
using static PvZ_Fusion_Translator.FileLoader;
using static PvZ_Fusion_Translator.Utils;
@ -26,7 +27,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>(true))
{
bool isPlantName = text.gameObject.name.Contains("Name") && text.transform.parent.name != "Background";
if (text.gameObject.name != "Description" && !isPlantName)
if (text.gameObject.name != "Description" && !isPlantName && !text.gameObject.name.Contains("Cost"))
{
text.text = StringStore.TranslateText(text.text);
text.font = font;
@ -34,6 +35,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
}
}
foreach(AlmanacCardUI almanacCardUI in __instance.GetComponentsInChildren<AlmanacCardUI>())
{
AlmanacCardUI_Patch.Awake(almanacCardUI);
}
// skin button resize
AlmanacPlantWindow window = __instance.window;
@ -63,7 +69,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(currentLanguage);
PlantData plantData = JsonUtility.FromJson<PlantData>(json);
AlmanacData plantData = JsonUtility.FromJson<AlmanacData>(json);
Il2CppSystem.Collections.Generic.List<PlantType> searchedPlants = new();

View file

@ -34,9 +34,9 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
TMP_FontAsset fontAsset = (hasAlmanacFont) ? FontStore.LoadTMPFontAlmanac(Utils.Language.ToString()) : FontStore.LoadTMPFont(Utils.Language.ToString());
AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
Il2CppAlmanacData.AlmanacData plantData = JsonUtility.FromJson<Il2CppAlmanacData.AlmanacData>(json);
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
foreach (Il2CppAlmanacData.PlantInfo plantInfo in plantData.plants)
{
if (plantInfo.seedType == (int)__instance.currentPlantType)
{

View file

@ -0,0 +1,56 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppAlmanacData;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using System.Text.RegularExpressions;
using Unity.Collections;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using static PvZ_Fusion_Translator.FileLoader;
using static PvZ_Fusion_Translator.Utils;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
[HarmonyPatch(typeof(AlmanacSelectMenu))]
public static class AlmanacSelectMenu_Patch
{
public static Dictionary<string, string> detailStrings = new Dictionary<string, string>();
public static Dictionary<string, string> detailTranslateStrings = new Dictionary<string, string>();
[HarmonyPatch(nameof(AlmanacSelectMenu.Awake))]
[HarmonyPostfix]
public static void Awake(AlmanacSelectMenu __instance)
{
TranslateAlmanacSelectMenu(__instance);
foreach(UIButton uiButton in __instance.GetComponentsInChildren<UIButton>())
{
if(uiButton.gameObject.name.Contains("Selection(Clone)"))
{
uiButton.clickEvent.AddListener(new Action(() => { TranslateAlmanacSelectMenu(__instance); }));
}
}
}
[HarmonyPatch(nameof(AlmanacSelectMenu.InitMenu))]
[HarmonyPostfix]
public static void InitMenu(AlmanacSelectMenu __instance)
{
TranslateAlmanacSelectMenu(__instance);
}
public static void TranslateAlmanacSelectMenu(AlmanacSelectMenu __instance)
{
TMP_FontAsset font = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.text = detailTranslateStrings.ContainsKey(txt.text) ? detailTranslateStrings[txt.text] : StringStore.TranslateText(txt.text);
txt.font = font;
}
}
}
}

View file

@ -16,13 +16,15 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
{
public static string almanacJson = "";
[HarmonyPatch(nameof(AlmanacZombieMenu.Awake))]
[HarmonyPatch(nameof(AlmanacZombieMenu.Start))]
[HarmonyPostfix]
private static void Awake(AlmanacZombieMenu __instance)
private static void Start(AlmanacZombieMenu __instance)
{
TMP_FontAsset font = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>(true))
{
if (text.gameObject.name.Contains("Cost")) continue;
bool isZombieName = text.gameObject.name.Contains("Name") && text.transform.parent.name != "Background";
if (text.gameObject.name != "Description" && !isZombieName)
{

View file

@ -33,10 +33,10 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
TMP_FontAsset fontAsset = (hasAlmanacFont) ? FontStore.LoadTMPFontAlmanac(Utils.Language.ToString()) : FontStore.LoadTMPFont(Utils.Language.ToString());
ZombieAlmanacData zombieAlmanacData = JsonUtility.FromJson<ZombieAlmanacData>(json);
Il2CppAlmanacData.AlmanacData zombieAlmanacData = JsonUtility.FromJson<Il2CppAlmanacData.AlmanacData>(json);
var zombieDataDic = ZombieDataManager.zombieDataDic;
foreach (ZombieInfo zombieInfo in zombieAlmanacData.zombies)
foreach (Il2CppAlmanacData.ZombieInfo zombieInfo in zombieAlmanacData.zombies)
{
if (zombieInfo.theZombieType == __instance.currentZombieType)
{

View file

@ -37,6 +37,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
TMP_FontAsset font = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
if (text.gameObject.name.Contains("Cost")) continue;
if(text.text == "关闭")
{
text.text = StringStore.TranslateText("合上");

View file

@ -1,5 +1,6 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppAlmanacData;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
@ -34,12 +35,15 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
MainMenu_Patch.AnimOver(__instance);
}
TranslateBaseMenu(__instance, "Level");
TranslateBaseMenu(__instance, "Levels");
TranslateBaseMenu(__instance, "CustomLevel");
TranslateBaseMenuTransform(__instance, "Level");
TranslateBaseMenuTransform(__instance, "Levels");
TranslateBaseMenuTransform(__instance, "CustomLevel");
StringStore.TranslateTextTransform(__instance.transform.Find("Goback"));
StringStore.TranslateTextTransform(__instance.transform.Find("Switich"));
}
public static void TranslateBaseMenu(BaseMenu __instance, string levelsName)
public static void TranslateBaseMenuTransform(BaseMenu __instance, string levelsName)
{
Transform levels = __instance.transform.Find(levelsName);
if (levels != null)
@ -52,9 +56,6 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
StringStore.TranslateTextTransform(child);
}
}
StringStore.TranslateTextTransform(__instance.transform.Find("Goback"));
StringStore.TranslateTextTransform(__instance.transform.Find("Switich"));
}
}
}

View file

@ -32,35 +32,6 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
}
}
foreach(TextMeshProUGUI text in __instance.transform.GetComponentsInChildren<TextMeshProUGUI>())
{
text.text = StringStore.TranslateText(text.text);
}
}
[HarmonyPatch(nameof(InGameBtn.ChangeStrings))]
[HarmonyPostfix]
private static void ChangeStrings(InGameBtn __instance)
{
Transform sceneText = __instance.transform.FindChild("SceneText");
if(sceneText != null)
{
TextMeshProUGUI sceneTextTMP = sceneText.transform.GetComponent<TextMeshProUGUI>();
if(sceneTextTMP != null)
{
sceneTextTMP = AssetStore.StringStore.TranslateText(sceneTextTMP);
}
Transform sceneTextShadow = sceneText.transform.FindChild("SceneText");
if(sceneTextShadow != null)
{
TextMeshProUGUI sceneTextShadowTMP = sceneTextShadow.transform.GetComponent<TextMeshProUGUI>();
if (sceneTextShadowTMP != null)
{
sceneTextShadowTMP = AssetStore.StringStore.TranslateText(sceneTextShadowTMP);
}
}
}
foreach(TextMeshProUGUI text in __instance.transform.GetComponentsInChildren<TextMeshProUGUI>())
{
text.text = StringStore.TranslateText(text.text);

View file

@ -1,4 +1,4 @@
using HarmonyLib;
/*using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using UnityEngine;
@ -34,3 +34,4 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
}
}
*/

View file

@ -1,4 +1,4 @@
using HarmonyLib;
/*using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
@ -50,3 +50,4 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
}
}
}
*/

View file

@ -1,24 +1,24 @@
using HarmonyLib;
using Il2Cpp;
using PvZ_Fusion_Translator.AssetStore;
//using HarmonyLib;
//using Il2Cpp;
//using PvZ_Fusion_Translator.AssetStore;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
[HarmonyPatch(typeof(CustomSettings))]
public static class CustomSettings_Patch
{
[HarmonyPatch(nameof(CustomSettings.Awake))]
[HarmonyPostfix]
private static void Awake(CustomSettings __instance)
{
__instance.textMesh = StringStore.TranslateText(__instance.textMesh);
}
//namespace PvZ_Fusion_Translator.Patches.GameObjects
//{
// [HarmonyPatch(typeof(CustomSettings))]
// public static class CustomSettings_Patch
// {
// [HarmonyPatch(nameof(CustomSettings.Awake))]
// [HarmonyPostfix]
// private static void Awake(CustomSettings __instance)
// {
// __instance.textMesh = StringStore.TranslateText(__instance.textMesh);
// }
[HarmonyPatch(nameof(CustomSettings.ChangeText))]
[HarmonyPostfix]
private static void ChangeText(CustomSettings __instance)
{
__instance.textMesh = StringStore.TranslateText(__instance.textMesh);
}
}
}
// [HarmonyPatch(nameof(CustomSettings.ChangeText))]
// [HarmonyPostfix]
// private static void ChangeText(CustomSettings __instance)
// {
// __instance.textMesh = StringStore.TranslateText(__instance.textMesh);
// }
// }
//}

View file

@ -1,4 +1,4 @@
using HarmonyLib;
/*using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
@ -43,3 +43,4 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
}
}
}
*/

View file

@ -2,6 +2,7 @@
using Il2Cpp;
using PvZ_Fusion_Translator.AssetStore;
using System.Text.RegularExpressions;
using Il2CppZenGarden;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{

View file

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Il2Cpp;
using UnityEngine;
using HarmonyLib;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
[HarmonyPatch(typeof(LevelResultMenu))]
public static class LevelResultMenu_Patch
{
[HarmonyPatch(nameof(LevelResultMenu.Awake))]
[HarmonyPatch(nameof(LevelResultMenu.Start))]
[HarmonyPatch(nameof(LevelResultMenu.ShowResult))]
[HarmonyPostfix]
public static void Awake(LevelResultMenu __instance)
{
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
}
}
}
}

View file

@ -15,9 +15,9 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
{
public static void AnimOver(BaseMenu __instance)
{
Transform changelogObj = __instance.transform.Find("Grave/UpdateInfo");
Transform changelogObj = __instance.transform.Find("Grave/UpdateInfoButton");
Transform langObj = UnityEngine.Object.Instantiate(changelogObj, changelogObj.position + new Vector3(0.0f, 0.855f), changelogObj.rotation, __instance.transform.Find("Grave"));
langObj.name = "Languages";
langObj.name = "LanguagesButton";
__instance.collider2Ds.Add(langObj.GetComponent<Collider2D>());
UIButton langBtn = langObj.GetComponent<UIButton>();

View file

@ -1,4 +1,4 @@
using HarmonyLib;
/*using HarmonyLib;
using Il2Cpp;
using PvZ_Fusion_Translator.AssetStore;
@ -14,4 +14,4 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
__instance.textMesh.text = StringStore.TranslateText(__instance.textMesh.text);
}
}
}
}*/

View file

@ -1,4 +1,4 @@
using HarmonyLib;
/*using HarmonyLib;
using Il2Cpp;
using PvZ_Fusion_Translator.AssetStore;
@ -19,3 +19,4 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
}
}
}
*/

View file

@ -161,13 +161,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
if (fIndex > -1 && found)
{
string fStr = HPStrings.ElementAt(fIndex).Value;
string DPS = originalText.Split("\n")[1].Replace("DPS:", "");
DPS = StringStore.TranslateText(DPS);
switch (fIndex)
{
case 0:
finalText = string.Format(fStr, __instance.lastDamage, DPS, __instance.totalDamage);
finalText = string.Format(fStr, __instance.lastDamage, __instance.CurrentDPS, __instance.totalDamage);
break;
default:
break;

View file

@ -1,4 +1,4 @@
using HarmonyLib;
/*using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
@ -125,4 +125,4 @@ namespace PvZ_Fusion_Translator.Patches.Managers
return true;
}
}
}
}*/

View file

@ -1,4 +1,4 @@
using HarmonyLib;
/*using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
@ -197,4 +197,4 @@ namespace PvZ_Fusion_Translator.Patches.Managers
__instance.skinButton.transform.GetChild(2).Translate(new Vector3(-0.35f, 0));
}
}
}
}*/

View file

@ -1,8 +1,9 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using Il2CppSystem.Collections.Generic;
using PvZ_Fusion_Translator.AssetStore;
using PvZ_Fusion_Translator.Patches.BaseTextObjects;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.TextCore.Text;
using static MelonLoader.MelonLogger;
@ -12,48 +13,66 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
[HarmonyPatch(typeof(DrawCardManager))]
public static class DrawCardManager_Patch
{
public static TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
[HarmonyPatch(nameof(DrawCardManager.Awake))]
[HarmonyPostfix]
private static void Awake(DrawCardManager __instance)
{
fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
}
[HarmonyPatch(nameof(DrawCardManager.UpdateText))]
[HarmonyPostfix]
private static void Postfix_UpdateText(DrawCardManager __instance)
{
Il2CppSystem.Collections.Generic.List<TextMeshProUGUI> texts = __instance.texts;
__instance.upName = StringStore.TranslateText(__instance.upName);
if (texts != null && texts.Count > 0)
KeyValuePair<string, string> regexPair = new KeyValuePair<string, string>("抽取次数:\n(\\d+)/(\\d+)\n当前up植物:\n([^\\s]+)\nup刷新倒计时:\n(\\d+)", "Draw Count:\n{0}/{1}\nCurrent Up:\n{2}\nNext Up in: \n{3}s");
foreach(TextMeshProUGUI txt in __instance.texts)
{
foreach (TextMeshProUGUI textComponent in texts)
if(Regex.IsMatch(txt.text, regexPair.Key))
{
if (textComponent != null)
{
string translatedText = StringStore.TranslateText(textComponent.text);
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
textComponent.text = translatedText;
textComponent.font = fontAsset;
}
txt.text = TranslateGashaponText(txt.text, regexPair.Key, regexPair.Value, __instance.up);
txt.font = fontAsset;
}
}
}
[HarmonyPatch(nameof(DrawCardManager.Update))]
public static string TranslateGashaponText(string originalText, string pattern, string fallback, PlantType up)
{
string res = "";
string fStr = "";
Match match = Regex.Match(originalText, pattern);
if(match.Success)
{
GroupCollection groups = match.Groups;
fStr = StringStore.translationStringRegex.ContainsKey(pattern) ? StringStore.translationStringRegex[pattern] : fallback;
List<string> dynamicParts = [];
for(int i = 1; i < groups.Count; i++)
{
string group = groups[i].Value;
string translatedGroup = "";
if(i == 3 && up != PlantType.Peashooter)
{
translatedGroup = Utils.GetPlantNameFromAlmanac(up);
}
else
{
translatedGroup = StringStore.TranslateText(group);
}
dynamicParts.Add(translatedGroup);
}
res = string.Format(fStr, [.. dynamicParts]);
}
return res;
}
/*[HarmonyPatch(nameof(DrawCardManager.Update))]
[HarmonyPostfix]
private static void Postfix_Update(DrawCardManager __instance)
{
Il2CppSystem.Collections.Generic.List<TextMeshProUGUI> texts = __instance.texts;
__instance.upName = StringStore.TranslateText(__instance.upName);
if (texts != null && texts.Count > 0)
{
foreach (TextMeshProUGUI textComponent in texts)
{
if (textComponent != null)
{
string translatedText = StringStore.TranslateText(textComponent.text);
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
textComponent.text = translatedText;
textComponent.font = fontAsset;
}
}
}
}
Postfix_UpdateText(__instance);
}*/
}
}

View file

@ -3,6 +3,7 @@ using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator;
using PvZ_Fusion_Translator.AssetStore;
using PvZ_Fusion_Translator.Patches.BaseTextObjects;
using System.Text.RegularExpressions;
using Unity.Collections;
@ -11,83 +12,42 @@ namespace PvZ_Fusion_Translator.Patches.Managers
[HarmonyPatch(typeof(InGameUI))]
public static class InGameUI_Patch
{
public static string travelAdventurePattern = "^旅行冒险 ([^\\s:]+)";
public static string travelAdventureFallback = "Odyssey Adventure: {0}";
[HarmonyPatch(nameof(InGameUI.Start))]
[HarmonyPostfix]
private static void Start(InGameUI __instance)
{
foreach (TextMeshProUGUI text in __instance.T)
{
if (text.text == null) continue;
string originalText = text.text;
text.text = text.text.Replace("\n", " ");
Regex checkFusionChallenge = new Regex("^超级([^\\s:]+)(:?挑战1?)");
if (text.text.Contains("配方:") && !checkFusionChallenge.IsMatch(text.text))
{
string[] lines = text.text.Split(":");
lines[1] = Utils.GetPlantNameFromAlmanac(lines[1]);
if (lines[1] == "")
{
Log.LogError("Couldn't find plant! (Fusion Showcase)");
lines[1] = StringStore.TranslateText(lines[1]);
}
text.text = StringStore.TranslateText("配方:") + lines[1];
text.autoSizeTextContainer = true;
}
else
{
text.text = (StringStore.translationString.ContainsKey(text.text + "_MG")) ? StringStore.TranslateText(text.text + "_MG") : StringStore.TranslateText(text.text);
text.text = text.text.Replace("\n", " ");
}
}
SetLevelName(__instance);
}
[HarmonyPatch(nameof(InGameUI.SetUniqueText))]
[HarmonyPostfix]
private static void SetUniqueText(InGameUI __instance)
{
foreach (TextMeshProUGUI text in __instance.T)
{
if (text.text == null) continue;
string originalText = text.text;
text.text = text.text.Replace("\n", " ");
Regex checkFusionChallenge = new Regex("^超级([^\\s:]+)(:?挑战1?)");
if (text.text.Contains("配方:") && !checkFusionChallenge.IsMatch(text.text))
{
string[] lines = text.text.Split(":");
lines[1] = Utils.GetPlantNameFromAlmanac(lines[1]);
if (lines[1] == "")
{
Log.LogError("Couldn't find plant! (Fusion Showcase)");
lines[1] = StringStore.TranslateText(lines[1]);
}
text.text = StringStore.TranslateText("配方:") + lines[1];
text.autoSizeTextContainer = true;
}
else
{
text.text = (StringStore.translationString.ContainsKey(text.text + "_MG")) ? StringStore.TranslateText(text.text + "_MG") : StringStore.TranslateText(text.text);
text.text = text.text.Replace("\n", " ");
}
}
SetLevelName(__instance);
}
[HarmonyPatch(nameof(InGameUI.SetLevelName))]
[HarmonyPostfix]
private static void SetLevelName(InGameUI __instance)
{
foreach (TextMeshProUGUI text in __instance.T)
foreach (TextMeshProUGUI text in __instance.levelNameText)
{
if (text.text == null) continue;
string originalText = text.text;
text.text = text.text.Replace("\n", " ");
Regex checkFusionChallenge = new Regex("^超级([^\\s:]+)(:?挑战1?)");
if (text.text.Contains("配方:") && !checkFusionChallenge.IsMatch(text.text))
Regex checkFusionChallenge = new Regex("^超级([^\\s:]+)(:?挑战1?)");
Regex checkTravelAdv = new Regex(travelAdventurePattern);
if(checkTravelAdv.IsMatch(originalText))
{
text.text = InGameText_Patch.TranslatePlantNameParts(originalText, travelAdventurePattern, travelAdventureFallback);
}
else if (text.text.Contains("配方:") && !checkFusionChallenge.IsMatch(text.text))
{
string[] lines = text.text.Split(":");
lines[1] = Utils.GetPlantNameFromAlmanac(lines[1]);
@ -106,5 +66,22 @@ namespace PvZ_Fusion_Translator.Patches.Managers
}
}
}
/*[HarmonyPatch(nameof(InGameUI.Update))]
[HarmonyPostfix]
private static void Update(InGameUI __instance)
{
if (!__instance.board.boardTag.isDrawCards) return;
KeyValuePair<string, string> regexPair = new KeyValuePair<string, string>("抽取次数:\n(\\d+)/(\\d+)\n当前up植物:\n([^\\s]+)\nup刷新倒计时:\n(\\d+)", "Draw Count:\n{0}/{1}\nCurrent Up:\n{2}\nNext Up in: \n{3}s");
foreach(TextMeshProUGUI txt in __instance.DrawCardsHead.GetComponentsInChildren<TextMeshProUGUI>())
{
if(Regex.IsMatch(txt.text, regexPair.Key))
{
txt.text = InGameText_Patch.TranslatePlantNameParts(txt.text, regexPair.Key, regexPair.Value);
}
}
}*/
}
}

View file

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Il2Cpp;
using HarmonyLib;
using UnityEngine;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
{
[HarmonyPatch(typeof(MultipleChoiceMenu))]
public static class MultipleChoiceMenu_Patch
{
[HarmonyPatch(nameof(MultipleChoiceMenu.Awake))]
[HarmonyPatch(nameof(MultipleChoiceMenu.UpdateWindow))]
[HarmonyPatch(nameof(MultipleChoiceMenu.Refresh))]
[HarmonyPatch(nameof(MultipleChoiceMenu.Cancel))]
[HarmonyPostfix]
public static void Awake(MultipleChoiceMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(BaseWindow window in __instance.windows)
{
foreach(TextMeshProUGUI txt in window.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.font = fontAsset;
txt.text = StringStore.TranslateText(txt.text);
}
}
}
}
}

View file

@ -16,29 +16,33 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
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))]
[HarmonyPatch(nameof(OppositeBuffManager.SetText))]
[HarmonyPostfix]
private static void Awake(OppositeBuffManager __instance)
private static void SetText(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);
/*if (TravelMgr_Patch.travelBuffString.ContainsKey(__result))
{
__result = TravelMgr_Patch.travelBuffString[__result];
}
else if(TravelMgr_Patch.travelBuffString.ContainsKey(TravelMgr_Patch.RemoveBuffName(__result)))
{
__result = TravelMgr_Patch.travelBuffString[TravelMgr_Patch.RemoveBuffName(__result)];
}*/
}
public static void TranslateOppositeText(Il2CppSystem.Collections.Generic.List<TextMeshProUGUI> textList, BuffType buffType, int buffIndex, bool isBad = false)
public static void TranslateOppositeText(Il2CppSystem.Collections.Generic.List<TextMeshProUGUI> textList, Il2CppSystem.Object buff, bool isBad = false)
{
string buff = translatedTravelBuffs[buffLinks[buffType]][buffIndex];
string buffText = TravelMgr.Instance.GetText(buff);
foreach (var text in textList)
{
if (isBad)
{
text.text = string.Format(badFormat, buff);
text.text = string.Format(badFormat, buffText);
}
else
{
text.text = buff;
text.text = buffText;
}
text.font = fontAsset;

View file

@ -0,0 +1,41 @@
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 UnityEngine;
namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
{
[HarmonyPatch(typeof(TravelAdvantureMenu))]
public static class TravelAdvantureMenu_Patch
{
[HarmonyPatch(nameof(TravelAdvantureMenu.Awake))]
[HarmonyPostfix]
public static void Awake(TravelAdvantureMenu __instance)
{
foreach(CustomButton_enterGame button in __instance.GetComponentsInChildren<CustomButton_enterGame>())
{
string plantName = Utils.GetPlantNameFromAlmanac(button.levelName.text);
button.levelName.text = (plantName != "") ? plantName : StringStore.TranslateText(button.levelName.text);
}
}
[HarmonyPatch(nameof(TravelAdvantureMenu.LookWeak))]
[HarmonyPostfix]
public static void LookWeak(TravelAdvantureMenu __instance)
{
Awake(__instance);
}
[HarmonyPatch(nameof(TravelAdvantureMenu.LookUlti))]
[HarmonyPostfix]
public static void LookUlti(TravelAdvantureMenu __instance)
{
Awake(__instance);
}
}
}

View file

@ -27,11 +27,11 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
public static void TranslateOptionButton(TravelBuffOptionButton button)
{
SortedDictionary<int, string> buffSet = translatedTravelBuffs[buffLinks[button.buffType]];
/*SortedDictionary<int, string> buffSet = translatedTravelBuffs[buffLinks[button.buffType]];
string buff = button.show != null && button.introduce.text != "词条已选完" ? buffSet[button.buffIndex] : StringStore.TranslateText("词条已选完");
button.introduce.text = buff;
button.introduce.text = buff;*/
}
}

View file

@ -38,9 +38,9 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
[HarmonyPostfix]
public static void Post_SetBuff(TravelLookBuff __instance)
{
SortedDictionary<int, string> buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]];
/*SortedDictionary<int, string> buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]];
string buffText = buffSet.ContainsKey(__instance.buffIndex) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text);
__instance.introduce.text = buffText;
__instance.introduce.text = buffText;*/
foreach (TextMeshProUGUI text in __instance.transform.FindChild("Images").FindChild("Button").GetComponentsInChildren<TextMeshProUGUI>())
{

View file

@ -1,5 +1,6 @@
using HarmonyLib;
using Il2Cpp;
using PvZ_Fusion_Translator.AssetStore;
using System;
using System.Collections.Generic;
using System.Linq;
@ -34,6 +35,11 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
{ "investmentBuffs", new SortedDictionary<int, string>() }
};
public static Dictionary<string, string> travelBuffString = new()
{
};
public static Dictionary<BuffType, string> buffLinks = new()
{
{ BuffType.AdvancedBuff, "advancedBuffs" },
@ -43,6 +49,24 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
{ BuffType.InvestmentBuff, "investmentBuffs" }
};
[HarmonyPatch(nameof(TravelMgr.GetText))]
[HarmonyPostfix]
public static void GetText(TravelMgr __instance, ref string __result)
{
if (travelBuffString.ContainsKey(__result))
{
__result = travelBuffString[__result];
}
else if(travelBuffString.ContainsKey(RemoveBuffName(__result)))
{
__result = travelBuffString[RemoveBuffName(__result)];
}
else
{
__result = StringStore.TranslateText(__result);
}
}
public static void DumpTravelBuffs()
{
TravelMgr.Instance.GetPlantBuffUnlockCount(PlantType.DoomGatling);
@ -50,26 +74,31 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
foreach (var pair in TravelDictionary.advancedBuffsText)
{
dumpedTravelBuffs["advancedBuffs"].Add((int)pair.Key, pair.Value);
travelBuffString.Add(pair.Value, pair.Value);
}
foreach (var pair in TravelDictionary.ultimateBuffsText)
{
dumpedTravelBuffs["ultimateBuffs"].Add((int)pair.Key, pair.Value);
travelBuffString.Add(pair.Value, pair.Value);
}
foreach (var pair in TravelDictionary.debuffData)
{
dumpedTravelBuffs["debuffs"].Add((int)pair.Key, pair.Value.Item1);
travelBuffString.Add(pair.Value.Item1, pair.Value.Item1);
}
foreach (var pair in TravelDictionary.unlocksText)
{
dumpedTravelBuffs["unlocks"].Add((int)pair.Key, pair.Value);
travelBuffString.Add(pair.Value, pair.Value);
}
foreach (var pair in TravelMgr.InvestBuffsData)
{
dumpedTravelBuffs["investmentBuffs"].Add((int)pair.Key, pair.Value.GetDescription());
travelBuffString.Add(pair.Value.GetDescription(), pair.Value.GetDescription());
}
File.WriteAllText(Path.Combine(GetAssetDir(AssetType.Dumps), "travel_buffs.json"), JsonSerializer.Serialize(dumpedTravelBuffs, new JsonSerializerOptions
@ -91,6 +120,72 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
}
}
//System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(travelBuffsContent);
public static Dictionary<string, SortedDictionary<int, string>> GenerateTranslatedTravelBuffs(string travelBuffsContent)
{
TravelMgr_Patch.DumpTravelBuffs();
Dictionary<string, SortedDictionary<int, string>> travelBuffs = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(travelBuffsContent);
// save travel buffs
string travelBuffsToSave = SerializeWithIndentation(travelBuffs);
string stringDir = GetAssetDir(AssetType.Strings, Utils.Language);
File.WriteAllText(Path.Combine(stringDir, "travel_buffs.json"), travelBuffsToSave);
foreach(var i in travelBuffs)
{
var originalBuffSet = dumpedTravelBuffs[i.Key];
foreach(var j in originalBuffSet)
{
string originalBuff = j.Value;
var translatedBuffSet = travelBuffs[i.Key];
if (j.Value == originalBuff)
{
if (translatedBuffSet.ContainsKey(j.Key))
{
if(travelBuffString.ContainsKey(originalBuff))
{
travelBuffString[originalBuff] = translatedBuffSet[j.Key];
}
else
{
travelBuffString.Add(originalBuff, translatedBuffSet[j.Key]);
}
}
}
else if(j.Value == RemoveBuffName(originalBuff))
{
if (translatedBuffSet.ContainsKey(j.Key))
{
if(travelBuffString.ContainsKey(originalBuff))
{
travelBuffString[RemoveBuffName(originalBuff)] = translatedBuffSet[j.Key];
}
else
{
travelBuffString.Add(RemoveBuffName(originalBuff), translatedBuffSet[j.Key]);
}
}
}
else
{
Log.LogInfo("Couldnt find this buff");
}
/*var translatedBuffSet = travelBuffs[i.Key];
if(translatedBuffSet.ContainsKey(j.Key))
{
string translatedBuff = travelBuffs[i.Key][j.Key];
travelBuffString[originalBuff] = translatedBuff;
}*/
}
}
return travelBuffs;
}
public static string MatchTravelBuff(string originalText)
{
string res = "";
@ -101,7 +196,11 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
{
if (j.Value == originalText || j.Value == RemoveBuffName(originalText))
{
res = translatedTravelBuffs[i.Key][j.Key];
var translatedBuffSet = translatedTravelBuffs[i.Key];
if (translatedBuffSet.ContainsKey(j.Key))
{
res = translatedBuffSet[j.Key];
}
break;
}
}

View file

@ -15,14 +15,14 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
[HarmonyPostfix]
private static void SetType(TravelStoreWindow __instance)
{
var buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]];
/*var buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]];
string buff = __instance.show != null && __instance.introduce.text != "词条已选完" ? buffSet[__instance.buffIndex] : StringStore.TranslateText("词条已选完");
string buff = __instance.show != null && __instance.introduce.text != "词条已选完" ? buffSet[__instance.buffIndex] : StringStore.TranslateText("词条已选完");*/
string originalText = __instance.introduce.text;
string affinities = TranslateAffinities(originalText);
__instance.introduce.text = buff + affinities;
__instance.introduce.text = originalText + affinities;
foreach (var text in __instance.buttonText)
{

View file

@ -0,0 +1,59 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppGameLevel;
using PvZ_Fusion_Translator.AssetStore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading.Tasks;
using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor
{
[HarmonyPatch(typeof(CustomButton_enterGame))]
public static class CustomButton_enterGame_Patch
{
[HarmonyPatch(nameof(CustomButton_enterGame.LoadOnlineLevelAsync))]
[HarmonyPostfix]
public static void LoadOnlineLevelAsync(CustomButton_enterGame __instance)
{
Dictionary<string, TranslatedLevelData> dumpData = new Dictionary<string, TranslatedLevelData>();
var level = __instance;
if(level.onlineLevelInfo != null)
{
string levelId = level.onlineLevelInfo.levelId;
if(levelId != null)
{
if(CustomLevelMenu_Patch.translatedLevelData.ContainsKey(levelId))
{
TranslatedLevelData levelData = CustomLevelMenu_Patch.translatedLevelData[levelId];
level.levelName.text = levelData.name;
level.serializedLevel.name = levelData.name;
level.serializedLevel.boardConfig.startTip = levelData.startTip;
}
else
{
TranslatedLevelData dumpedLevelData = new TranslatedLevelData(level.levelData.Name, level.serializedLevel.boardConfig.startTip);
dumpData.Add(levelId, dumpedLevelData);
}
}
}
else
{
level.levelName.text = StringStore.TranslateText(level.levelData.Name);
}
string dumpPath = Path.Combine(FileLoader.GetAssetDir(FileLoader.AssetType.Dumps), "custom_level_data.json");
File.WriteAllText(dumpPath, System.Text.Json.JsonSerializer.Serialize(dumpData, new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
}));
}
}
}

View file

@ -36,13 +36,20 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor
}
}
[HarmonyPatch(nameof(CustomLevelMenu.InitWindows))]
[HarmonyPatch(nameof(CustomLevelMenu.InitLocalWindows))]
[HarmonyPostfix]
public static void InitWindows(CustomLevelMenu __instance)
{
TranslateLevelButtons(__instance);
}
[HarmonyPatch(nameof(CustomLevelMenu.InitOnlineWindow))]
[HarmonyPostfix]
public static void InitOnlineWindow(CustomLevelMenu __instance)
{
TranslateLevelButtons(__instance);
}
[HarmonyPatch(nameof(CustomLevelMenu.ReloadFiles))]
[HarmonyPostfix]
public static void ReloadFiles(CustomLevelMenu __instance)
@ -56,14 +63,16 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor
foreach(CustomButton_enterGame level in __instance.levels)
{
string levelId = level.levelData.levelId;
if(level.onlineLevelInfo != null)
{
string levelId = level.onlineLevelInfo.levelId;
if(levelId != null)
{
if(translatedLevelData.ContainsKey(levelId))
{
TranslatedLevelData levelData = translatedLevelData[levelId];
level.levelName.text = levelData.name;
level.levelData.Name = levelData.name;
level.serializedLevel.name = levelData.name;
level.serializedLevel.boardConfig.startTip = levelData.startTip;
}
else
@ -72,6 +81,7 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor
dumpData.Add(levelId, dumpedLevelData);
}
}
}
else
{
level.levelName.text = StringStore.TranslateText(level.levelData.Name);

View file

@ -1,14 +1,17 @@
using MelonLoader;
using HarmonyLib;
using UnityEngine;
using HarmonyLib;
using Il2Cpp;
using Il2CppGameLevel;
using Il2CppTMPro;
using MelonLoader;
using PvZ_Fusion_Translator.AssetStore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading.Tasks;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor
{
@ -34,6 +37,44 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor
string translatedText = StringStore.TranslateText(__instance.title.text);
__instance.title.text = translatedText;
__instance.title2.text = translatedText;
TranslateLevelData(__instance.levelData);
}
public static void TranslateLevelData(CustomLevelData levelData)
{
Dictionary<string, TranslatedLevelData> dumpData = new Dictionary<string, TranslatedLevelData>();
if(levelData != null)
{
string levelId = levelData.levelId;
if(levelId != null)
{
if(CustomLevelMenu_Patch.translatedLevelData.ContainsKey(levelId))
{
TranslatedLevelData translatedLevelData = CustomLevelMenu_Patch.translatedLevelData[levelId];
levelData.Name = translatedLevelData.name;
levelData.SerializedLevelData.name = translatedLevelData.name;
levelData.SerializedLevelData.boardConfig.startTip = translatedLevelData.startTip;
}
else
{
TranslatedLevelData dumpedLevelData = new TranslatedLevelData(levelData.Name, levelData.SerializedLevelData.boardConfig.startTip);
dumpData.Add(levelId, dumpedLevelData);
}
}
}
else
{
levelData.Name = StringStore.TranslateText(levelData.Name);
}
string dumpPath = Path.Combine(FileLoader.GetAssetDir(FileLoader.AssetType.Dumps), "custom_level_data.json");
File.WriteAllText(dumpPath, System.Text.Json.JsonSerializer.Serialize(dumpData, new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
}));
}
}
}

View file

@ -0,0 +1,75 @@
using Il2Cpp;
using Il2CppGameLevel;
using HarmonyLib;
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Il2CppGameLevel.EventNodes;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor.GameLevel.EventNodes
{
[HarmonyPatch(typeof(RuntimeEventNodeEditor))]
public static class RuntimeEventNodeEditor_Patch
{
[HarmonyPatch(nameof(RuntimeEventNodeEditor.AddNode))]
[HarmonyPostfix]
public static void AddNode(RuntimeEventNodeEditor __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(var nodeUI in __instance.nodeUIs)
{
string nodeName = nodeUI.key;
RuntimeNodeUI node = nodeUI.Value;
foreach(TextMeshProUGUI txt in node.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.text = StringStore.translationString.ContainsKey(txt.text + "_code") ? StringStore.TranslateText(txt.text + "_code") : StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
[HarmonyPatch(nameof(RuntimeEventNodeEditor.Update))]
[HarmonyPostfix]
public static void Update(RuntimeEventNodeEditor __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(var node in __instance.nodeUIs)
{
RuntimeNodeUI nodeUI = node.value;
if(nodeUI.Node.nodeType == "PlantTypeValueNode")
{
Transform buttonTransform = nodeUI.transform.Find("Header/ValueEditContainer/Button(Clone)/Label");
TextMeshProUGUI txt = buttonTransform.GetComponent<TextMeshProUGUI>();
if (!txt.gameObject.name.Contains("Label")) continue;
if (!Utils.CheckForUntranslatedText(txt.text)) continue;
string plantName = Utils.GetPlantNameFromAlmanac(nodeUI.Node.GetPortValue<PlantType>(nodeUI.Node.GetOutputPorts()[0].portName, PlantType.Nothing));
txt.text = (plantName != "") ? plantName : StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
else if(nodeUI.Node.nodeType == "ZombieTypeValueNode")
{
Transform buttonTransform = nodeUI.transform.Find("Header/ValueEditContainer/Button(Clone)/Label");
TextMeshProUGUI txt = buttonTransform.GetComponent<TextMeshProUGUI>();
if (!txt.gameObject.name.Contains("Label")) continue;
if (!Utils.CheckForUntranslatedText(txt.text)) continue;
string zombieName = Utils.GetZombieNameFromAlmanac(nodeUI.Node.GetPortValue<ZombieType>(nodeUI.Node.GetOutputPorts()[0].portName, ZombieType.Nothing));
txt.text = (zombieName != "") ? zombieName : StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
}
}

View file

@ -0,0 +1,79 @@
using Il2Cpp;
using Il2CppGameLevel;
using HarmonyLib;
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Il2CppGameLevel.EventNodes;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor.GameLevel.EventNodes
{
[HarmonyPatch(typeof(RuntimeNodeUI))]
public static class RuntimeNodeUI_Patch
{
[HarmonyPatch(nameof(RuntimeNodeUI.Awake))]
[HarmonyPostfix]
public static void Awake(RuntimeNodeUI __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.text = StringStore.translationString.ContainsKey(txt.text + "_code") ? StringStore.TranslateText(txt.text + "_code") : StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
[HarmonyPatch(nameof(RuntimeNodeUI.Initialize))]
[HarmonyPostfix]
public static void Initialize(RuntimeNodeUI __instance)
{
Awake(__instance);
}
[HarmonyPatch(nameof(RuntimeNodeUI.UpdateDisplay))]
[HarmonyPostfix]
public static void UpdateDisplay(RuntimeNodeUI __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
if(__instance.Node.nodeType == "PlantTypeValueNode")
{
foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
if(txt.gameObject.name.Contains("Label"))
{
string plantName = Utils.GetPlantNameFromAlmanac(__instance.Node.GetPortValue<PlantType>(__instance.Node.nodeName, PlantType.Nothing));
txt.text = (plantName != "") ? plantName : StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
if(__instance.Node.nodeType == "ZombieTypeValueNode")
{
foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
if(txt.gameObject.name.Contains("Label"))
{
string zombieName = Utils.GetZombieNameFromAlmanac(__instance.Node.GetPortValue<ZombieType>(__instance.Node.nodeName, ZombieType.Nothing));
txt.text = (zombieName != "") ? zombieName : StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
}
[HarmonyPatch(nameof(RuntimeNodeUI.UpdateSelectionVisual))]
[HarmonyPostfix]
public static void UpdateSelectionVisual(RuntimeNodeUI __instance)
{
UpdateDisplay(__instance);
}
}
}

View file

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Il2Cpp;
using Il2CppRhythmGameEditor;
using Il2CppRhythmGame;
using HarmonyLib;
using UnityEngine;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor.RhythmGameEditor
{
[HarmonyPatch(typeof(RhythmGameChartEditorUI))]
public static class RhythmGameChartEditorUI_Patch
{
[HarmonyPatch(nameof(RhythmGameChartEditorUI.Awake))]
[HarmonyPostfix]
public static void Awake(RhythmGameChartEditorUI __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.font = fontAsset;
if (!Utils.CheckForUntranslatedText(txt.text)) continue;
txt.text = StringStore.TranslateText(txt.text);
}
foreach(TextMeshProUGUI txt in __instance.dropdown.GetComponentsInChildren<TextMeshProUGUI>(true))
{
txt.text = StringStore.TranslateText(txt.text);
}
}
[HarmonyPatch(nameof(RhythmGameChartEditorUI.Start))]
[HarmonyPostfix]
public static void Start(RhythmGameChartEditorUI __instance)
{
Awake(__instance);
}
[HarmonyPatch(nameof(RhythmGameChartEditorUI.InitializeSubSystems))]
[HarmonyPostfix]
public static void InitializeSubSystems(RhythmGameChartEditorUI __instance)
{
Awake(__instance);
}
[HarmonyPatch(nameof(RhythmGameChartEditorUI.Update))]
[HarmonyPostfix]
public static void Update(RhythmGameChartEditorUI __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(TextMeshProUGUI txt in __instance.transform.Find("TopPanel").GetComponentsInChildren<TextMeshProUGUI>())
{
txt.font = fontAsset;
txt.text = StringStore.TranslateText(txt.text);
}
foreach(TheButton btn in __instance.transform.GetComponentsInChildren<TheButton>())
{
foreach(TextMeshProUGUI txt in btn.GetComponentsInChildren<TextMeshProUGUI>())
{
if (!Utils.CheckForUntranslatedText(txt.text)) continue;
txt.text = StringStore.TranslateText(txt.text);
}
}
foreach(TextMeshProUGUI txt in __instance.dropdown.GetComponentsInChildren<TextMeshProUGUI>(true))
{
if (!Utils.CheckForUntranslatedText(txt.text)) continue;
txt.text = Utils.RemoveSizeTags(StringStore.TranslateText(txt.text));
}
}
[HarmonyPatch(nameof(RhythmGameChartEditorUI.UpdateUI))]
[HarmonyPostfix]
public static void UpdateUI(RhythmGameChartEditorUI __instance)
{
foreach(TextMeshProUGUI txt in __instance.dropdown.GetComponentsInChildren<TextMeshProUGUI>(true))
{
txt.text = StringStore.TranslateText(txt.text);
}
}
[HarmonyPatch(nameof(RhythmGameChartEditorUI.UpdateSelectedNoteInfo))]
[HarmonyPostfix]
public static void UpdateSelectedNoteInfo(RhythmGameChartEditorUI __instance)
{
__instance.selectedNoteInfoText.text = StringStore.TranslateText(__instance.selectedNoteInfoText.text);
}
}
}

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using Il2Cpp;
using Il2CppRhythmGame;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor.RhythmGameEditor
{
[HarmonyPatch(typeof(RhythmGameManager))]
public static class RhythmGameManager_Patch
{
[HarmonyPatch(nameof(RhythmGameManager.Awake))]
[HarmonyPatch(nameof(RhythmGameManager.ComboUpdate))]
[HarmonyPostfix]
public static void Awake(RhythmGameManager __instance)
{
if(__instance.comboText)
{
__instance.comboText.autoSizeTextContainer = false;
__instance.comboText.ForceMeshUpdate();
}
}
[HarmonyPatch(nameof(RhythmGameManager.OnNoteClicked))]
[HarmonyPostfix]
public static void OnNoteClicked(RhythmGameManager __instance)
{
if (!__instance.particle) return;
TextParticle txtParticle = __instance.particle.GetComponent<TextParticle>();
if(txtParticle)
{
TextMeshPro txt = txtParticle.text.GetComponent<TextMeshPro>();
if(txt)
{
string originalKey = StringStore.translationString.FirstOrDefault(x => x.Value == txt.text).Key;
txt.text = StringStore.translationString.ContainsKey(originalKey + "_RG") ? StringStore.TranslateText(originalKey + "_RG") : StringStore.TranslateText(txt.text);
txt.autoSizeTextContainer = false;
txt.ForceMeshUpdate();
}
}
}
}
}

View file

@ -1,4 +1,4 @@
using HarmonyLib;
/*using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using Newtonsoft.Json;
@ -68,3 +68,4 @@ namespace PvZ_Fusion_Translator.Patches.OtherManagers
}
}
}
*/

View file

@ -2,6 +2,7 @@
using Il2Cpp;
using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
using Il2CppZenGarden;
namespace PvZ_Fusion_Translator.Patches.OtherManagers
{
@ -13,7 +14,6 @@ namespace PvZ_Fusion_Translator.Patches.OtherManagers
public static void Update(GardenUI __instance)
{
__instance.currentPageText = StringStore.TranslateText(__instance.currentPageText, false);
__instance.currentPageText2 = StringStore.TranslateText(__instance.currentPageText2, false);
// Transform PageText = __instance.transform.Find("PageText");
// StringStore.TranslateTextTransform(PageText.transform);

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.5</GamePath>
<GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.6.1</GamePath>
<Platforms>AnyCPU;ARM64;x64</Platforms>
</PropertyGroup>
@ -402,7 +402,10 @@
<Compile Include="Log.cs" />
<Compile Include="ModFeatures.cs" />
<Compile Include="AssetStore\AudioStore.cs" />
<Compile Include="Patches\GameObjects\AlmanacCardUI_Patch.cs" />
<Compile Include="Patches\GameObjects\AlmanacSelectMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\ConfirmMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\LevelResultMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\LoseMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\GameLose_Patch.cs" />
<Compile Include="Patches\GameObjects\PlayerSaveMenu_Patch.cs" />
@ -412,6 +415,8 @@
<Compile Include="Patches\GameObjects\PlantDataMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\WarningMenu_Patch.cs" />
<Compile Include="Patches\Modes\Abyss\AbyssBuffMenu_Patch.cs" />
<Compile Include="Patches\Modes\Odyssey\MultipleChoiceMenu_Patch.cs" />
<Compile Include="Patches\Modes\Odyssey\TravelAdvantureMenu_Patch.cs" />
<Compile Include="Patches\Modes\Odyssey\TravelInvestMenu_Patch.cs" />
<Compile Include="Patches\Modes\Odyssey\SynergyDisplay_Patch.cs" />
<Compile Include="Patches\Modes\Odyssey\TravelStoreWindow_Patch.cs" />
@ -508,12 +513,17 @@
<Compile Include="Patches\Managers\TowerManager_Patch.cs" />
<Compile Include="Patches\Managers\SaveMenu_Patch.cs" />
<Compile Include="Patches\Modes\Odyssey\TravelBuffOptionButton_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\CustomButton_enterGame_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\CustomOnlineMenu_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\CustomMenuPage_shooting_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\CustomLevelMenu_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\CustomMenuPage_page3_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\CustomMenuPage_initZombies_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\GameLevel\EventNodes\RuntimeNodeUI_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\GameLevel\EventNodes\RuntimeEventNodeEditor_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\GameLevel\LevelManager_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\RhythmGame\RhythmGameChartEditorUI_Patch.cs" />
<Compile Include="Patches\Modes\Super Editor\RhythmGame\RhythmGameManager_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" />

View file

@ -16,7 +16,6 @@ using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Experimental.Rendering;
using UnityEngine.UI;
using static Il2Cpp.AlmanacPlantBank;
using static MelonLoader.MelonLogger;
using static PvZ_Fusion_Translator.FileLoader;
@ -153,65 +152,15 @@ namespace PvZ_Fusion_Translator
newGoBackText.color = color;
}
public static string GetPlantNameFromAlmanac(PlantType thePlantType)
{
string json;
string thePlantName = "";
json = AlmanacPlantMenu_Patch.almanacJson;
AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
{
if (plantInfo.seedType == (int)thePlantType)
{
thePlantName = plantInfo.name;
}
}
return thePlantName;
}
public static string GetPlantNameFromAlmanac(string theOriginalPlantName, bool log = false)
{
string originalJson;
string translatedJson;
string thePlantName = "";
string currentLanguage = Utils.Language.ToString();
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
string dumpDir = GetAssetDir(AssetType.Dumps);
string originalPath = Path.Combine(dumpDir, "LawnStrings.json");
string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
if ((!File.Exists(originalPath)))
{
if(log)
{
Log.LogError($"LawnStringsTranslate.json file not found at path: {path}");
Log.LogError("Plant name could not be found!");
}
thePlantName = "";
}
else
public static string GetPlantNameFromAlmanac(PlantType thePlantType, bool log = false)
{
bool foundPlantName = false;
string thePlantName = "";
originalJson = File.ReadAllText(originalPath);
translatedJson = AlmanacPlantMenu_Patch.almanacJson;
AlmanacPlantBank.PlantData originalPlantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(originalJson);
AlmanacPlantBank.PlantData translatedPlantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(translatedJson);
for(int i = 0; i < originalPlantData.plants.Count; i++)
if(plantIndices.ContainsKey((int)thePlantType))
{
AlmanacPlantBank.PlantInfo originalPlantInfo = originalPlantData.plants[i];
KeyValuePair<int, string> translatedPlantInfo = plantIndices[originalPlantInfo.seedType];
if (originalPlantInfo.name == theOriginalPlantName)
{
thePlantName = translatedPlantInfo.Value;
foundPlantName = true;
}
thePlantName = plantIndices[(int)thePlantType].Value;
}
if (!foundPlantName)
@ -222,6 +171,28 @@ namespace PvZ_Fusion_Translator
}
thePlantName = "";
}
return thePlantName;
}
public static string GetPlantNameFromAlmanac(string theOriginalPlantName, bool log = false)
{
bool foundPlantName = false;
string thePlantName = "";
if(plantIndiceStrings.ContainsKey(theOriginalPlantName))
{
foundPlantName = true;
thePlantName = plantIndiceStrings[theOriginalPlantName];
}
if (!foundPlantName)
{
if(log)
{
Log.LogInfo("Couldn't find plant name!");
}
thePlantName = "";
}
return thePlantName;
@ -235,9 +206,9 @@ namespace PvZ_Fusion_Translator
string currentLanguage = Utils.Language.ToString();
json = AlmanacZombieMenu_Patch.almanacJson;
ZombieAlmanacData zombieData = JsonUtility.FromJson<ZombieAlmanacData>(json);
Il2CppAlmanacData.AlmanacData zombieData = JsonUtility.FromJson<Il2CppAlmanacData.AlmanacData>(json);
foreach (ZombieInfo zombieInfo in zombieData.zombies)
foreach (Il2CppAlmanacData.ZombieInfo zombieInfo in zombieData.zombies)
{
if ((int)zombieInfo.theZombieType == (int)theZombieType)
{
@ -249,10 +220,12 @@ namespace PvZ_Fusion_Translator
}
public static Dictionary<int, KeyValuePair<int, string>> plantIndices = new Dictionary<int, KeyValuePair<int, string>>();
public static Dictionary<string, string> plantIndiceStrings = new Dictionary<string, string>();
public static void RegisterPlantIndices()
{
plantIndices = new Dictionary<int, KeyValuePair<int, string>>();
plantIndiceStrings = new Dictionary<string, string>();
string originalJson;
string translatedJson;
@ -270,15 +243,19 @@ namespace PvZ_Fusion_Translator
{
originalJson = File.ReadAllText(originalPath);
translatedJson = AlmanacPlantMenu_Patch.almanacJson;
AlmanacPlantBank.PlantData originalPlantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(originalJson);
AlmanacPlantBank.PlantData translatedPlantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(translatedJson);
Il2CppAlmanacData.AlmanacData originalPlantData = JsonUtility.FromJson<Il2CppAlmanacData.AlmanacData>(originalJson);
Il2CppAlmanacData.AlmanacData translatedPlantData = JsonUtility.FromJson<Il2CppAlmanacData.AlmanacData>(translatedJson);
for (int i = 0; i < originalPlantData.plants.Count; i++)
{
PlantInfo originalPlantInfo = originalPlantData.plants[i];
PlantInfo translatedPlantInfo = null;
Il2CppAlmanacData.PlantInfo originalPlantInfo = originalPlantData.plants[i];
if(!plantIndiceStrings.ContainsKey(originalPlantInfo.name))
{
plantIndiceStrings.Add(originalPlantInfo.name, originalPlantInfo.name);
}
Il2CppAlmanacData.PlantInfo translatedPlantInfo = null;
foreach (PlantInfo info in translatedPlantData.plants)
foreach (Il2CppAlmanacData.PlantInfo info in translatedPlantData.plants)
{
if (info.seedType == originalPlantInfo.seedType)
{
@ -290,6 +267,7 @@ namespace PvZ_Fusion_Translator
{
KeyValuePair<int, string> temp = new KeyValuePair<int, string>(translatedPlantInfo.seedType, translatedPlantInfo.name);
plantIndices.Add(originalPlantInfo.seedType, temp);
plantIndiceStrings[originalPlantInfo.name] = translatedPlantInfo.name;
}
}
}