diff --git a/.idea/.idea.PvZ Fusion Translator/.idea/.gitignore b/.idea/.idea.PvZ Fusion Translator/.idea/.gitignore
new file mode 100644
index 0000000..115ad6a
--- /dev/null
+++ b/.idea/.idea.PvZ Fusion Translator/.idea/.gitignore
@@ -0,0 +1,15 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/.idea.PvZ Fusion Translator.iml
+/contentModel.xml
+/projectSettingsUpdater.xml
+/modules.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Ignored default folder with query files
+/queries/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/.idea.PvZ Fusion Translator/.idea/.name b/.idea/.idea.PvZ Fusion Translator/.idea/.name
new file mode 100644
index 0000000..82e789d
--- /dev/null
+++ b/.idea/.idea.PvZ Fusion Translator/.idea/.name
@@ -0,0 +1 @@
+PvZ Fusion Translator
\ No newline at end of file
diff --git a/.idea/.idea.PvZ Fusion Translator/.idea/indexLayout.xml b/.idea/.idea.PvZ Fusion Translator/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/.idea/.idea.PvZ Fusion Translator/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.PvZ Fusion Translator/.idea/misc.xml b/.idea/.idea.PvZ Fusion Translator/.idea/misc.xml
new file mode 100644
index 0000000..104c42f
--- /dev/null
+++ b/.idea/.idea.PvZ Fusion Translator/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.PvZ Fusion Translator/.idea/vcs.xml b/.idea/.idea.PvZ Fusion Translator/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/.idea.PvZ Fusion Translator/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MelonLoader/AssetStore/FontStore.cs b/MelonLoader/AssetStore/FontStore.cs
index 75d5b03..e497378 100644
--- a/MelonLoader/AssetStore/FontStore.cs
+++ b/MelonLoader/AssetStore/FontStore.cs
@@ -1,4 +1,8 @@
using Il2CppTMPro;
+using MelonLoader;
+using System.Reflection;
+using UnityEngine;
+using UnityEngine.TextCore.Text;
namespace PvZ_Fusion_Translator.AssetStore
{
@@ -11,28 +15,24 @@ namespace PvZ_Fusion_Translator.AssetStore
{
string fontsDir = Path.Combine(Core.Instance.modsDirectory, "[Custom Fonts]");
+ AssetBundle assetBundle = Utils.GetAssetBundle(Path.Combine(fontsDir, "translation"));
+
#if MULTI_LANGUAGE
- foreach (string file in Directory.GetFiles(fontsDir))
+ foreach (string file in assetBundle.GetAllAssetNames())
{
string fileName = Path.GetFileNameWithoutExtension(file);
- string fileExtension = Path.GetExtension(file);
- if (fileExtension == ".ttf" || fileExtension == ".otf")
+ if (!fileName.EndsWith("_almanac") && !fileName.EndsWith("_fallback"))
{
- if (!fileName.EndsWith("_Almanac") && !fileName.EndsWith("_Fallback"))
- {
- string fontPath = Path.Combine("PvZ_Fusion_Translator", "[Custom Fonts]", fileName + fileExtension);
+ TMP_FontAsset fontAsset = assetBundle.LoadAsset(file);
- TMP_FontAsset fontAsset = FontHandler.LoadTMPFont(fontPath, true);
- fontAsset.name = fileName;
- fontAssetDict.Add(fileName, fontAsset);
+ fontAssetDict.Add(fileName, fontAsset);
- Log.LogInfo($"Font for language '{fileName}' loaded");
- }
+ Log.LogInfo($"Font for language '{fileName}' loaded");
}
}
- InitFallback();
+ InitFallback(assetBundle);
#else
string defaultFontDir = Path.Combine("PvZ_Fusion_Translator", "[Custom Fonts]", "English.ttf");
@@ -41,43 +41,38 @@ namespace PvZ_Fusion_Translator.AssetStore
#endif
}
- internal static void InitFallback()
+ internal static void InitFallback(AssetBundle assetBundle)
{
string fontsDir = Path.Combine(Core.Instance.modsDirectory, "[Custom Fonts]");
- foreach (string file in Directory.GetFiles(fontsDir))
- {
+
+ foreach (string file in assetBundle.GetAllAssetNames())
+ {
string fileName = Path.GetFileNameWithoutExtension(file);
- string fileExtension = Path.GetExtension(file);
- if (fileExtension == ".ttf" || fileExtension == ".otf")
+ if (fileName.EndsWith("_almanac") || fileName.EndsWith("_fallback"))
{
- if (fileName.EndsWith("_Almanac") || fileName.EndsWith("_Fallback"))
+ TMP_FontAsset fallbackFont = assetBundle.LoadAsset(file);
+
+ string fileNameLanguage = fileName.Replace("_fallback", "").Replace("_almanac", "");
+
+ if (fontAssetDictSecondary.ContainsKey(fileNameLanguage))
{
- string fallbackPath = Path.Combine("PvZ_Fusion_Translator", "[Custom Fonts]", fileName + fileExtension);
- TMP_FontAsset fallbackFont = FontHandler.LoadTMPFont(fallbackPath, true);
- fallbackFont.name = fileName;
-
- string fileNameLanguage = fileName.Replace("_Fallback", "").Replace("_Almanac", "");
-
- if (fontAssetDictSecondary.ContainsKey(fileNameLanguage))
+ if (fileName.EndsWith("_Fallback"))
{
- if (fileName.EndsWith("_Fallback"))
- {
- fontAssetDictSecondary.Add(fileNameLanguage + "_Almanac", fontAssetDictSecondary[fileNameLanguage]);
- fontAssetDictSecondary.Remove(fileNameLanguage);
- }
- else
- {
- fontAssetDictSecondary.Add(fileNameLanguage + "_Fallback", fontAssetDictSecondary[fileNameLanguage]);
- fontAssetDictSecondary.Remove(fileNameLanguage);
- }
- fontAssetDictSecondary.Add(fileName, fallbackFont);
+ fontAssetDictSecondary.Add(fileNameLanguage + "_almanac", fontAssetDictSecondary[fileNameLanguage]);
+ fontAssetDictSecondary.Remove(fileNameLanguage);
}
else
- fontAssetDictSecondary.Add(fileNameLanguage, fallbackFont);
-
- // Log.LogInfo($"Fallback font for language '{fileNameLanguage}' loaded");
+ {
+ fontAssetDictSecondary.Add(fileNameLanguage + "_fallback", fontAssetDictSecondary[fileNameLanguage]);
+ fontAssetDictSecondary.Remove(fileNameLanguage);
+ }
+ fontAssetDictSecondary.Add(fileName, fallbackFont);
}
+ else
+ fontAssetDictSecondary.Add(fileNameLanguage, fallbackFont);
+
+ // Log.LogInfo($"Fallback font for language '{fileNameLanguage}' loaded");
}
}
AddFallback();
@@ -98,15 +93,15 @@ namespace PvZ_Fusion_Translator.AssetStore
Log.LogInfo("Fallback font for language '" + lang + "' added");
continue;
}
- if (fontAssetDictSecondary.ContainsKey(lang + "_Almanac"))
+ if (fontAssetDictSecondary.ContainsKey(lang + "_almanac"))
{
- fontAssetDict[lang].fallbackFontAssetTable.Add(fontAssetDictSecondary[lang + "_Almanac"]);
+ fontAssetDict[lang].fallbackFontAssetTable.Add(fontAssetDictSecondary[lang + "_almanac"]);
Log.LogInfo("Fallback font for language '" + lang + "' added");
continue;
}
- if (fontAssetDictSecondary.ContainsKey(lang + "_Fallback"))
+ if (fontAssetDictSecondary.ContainsKey(lang + "_fallback"))
{
- fontAssetDict[lang].fallbackFontAssetTable.Add(fontAssetDictSecondary[lang + "_Fallback"]);
+ fontAssetDict[lang].fallbackFontAssetTable.Add(fontAssetDictSecondary[lang + "_fallback"]);
Log.LogInfo("Fallback font for language '" + lang + "' added");
continue;
}
@@ -116,7 +111,7 @@ namespace PvZ_Fusion_Translator.AssetStore
#if MULTI_LANGUAGE
public static TMP_FontAsset LoadTMPFont(string language)
{
- if (fontAssetDict.TryGetValue(language, out TMP_FontAsset font))
+ if (fontAssetDict.TryGetValue(language.ToLower(), out TMP_FontAsset font))
{
TMP_FontAsset fontAsset = font;
if (fontAsset.fallbackFontAssetTable != null)
@@ -125,7 +120,7 @@ namespace PvZ_Fusion_Translator.AssetStore
}
return fontAsset;
}
- return fontAssetDict.GetValueOrDefault("English");
+ return fontAssetDict.GetValueOrDefault("english");
}
#else
public static TMP_FontAsset LoadTMPFont()
@@ -144,15 +139,15 @@ namespace PvZ_Fusion_Translator.AssetStore
return almanacAsset;
}
}
- if (fontAssetDictSecondary.ContainsKey(language + "_Almanac"))
+ if (fontAssetDictSecondary.ContainsKey(language + "_almanac"))
{
- if (fontAssetDictSecondary.TryGetValue(language + "_Almanac", out TMP_FontAsset almanacAsset))
+ if (fontAssetDictSecondary.TryGetValue(language + "_almanac", out TMP_FontAsset almanacAsset))
{
return almanacAsset;
}
}
- return fontAssetDict.GetValueOrDefault("English");
+ return fontAssetDict.GetValueOrDefault("english");
}
#if MULTI_LANGUAGE
diff --git a/MelonLoader/AssetStore/StringStore.cs b/MelonLoader/AssetStore/StringStore.cs
index 9c6f39c..b7c2995 100644
--- a/MelonLoader/AssetStore/StringStore.cs
+++ b/MelonLoader/AssetStore/StringStore.cs
@@ -1,6 +1,5 @@
-using Il2CppSystem.Runtime.Remoting.Messaging;
-using Il2CppTMPro;
-using System.Diagnostics;
+using Il2CppTMPro;
+using PvZ_Fusion_Translator.Patches.BaseTextObjects;
using System.Text.RegularExpressions;
using UnityEngine;
@@ -90,17 +89,12 @@ namespace PvZ_Fusion_Translator.AssetStore
izTipCollectionString.Clear();
fsLevelTipDictionary.Clear();
fsTipCollectionString.Clear();
+ InGameText_Patch.currentText = "";
FileLoader.LoadStrings();
}
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);
@@ -139,12 +133,6 @@ 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
@@ -183,9 +171,7 @@ namespace PvZ_Fusion_Translator.AssetStore
for (int i = 1; i < groupCount; i++)
{
string groupValue = match.Groups[i].Value;
- string translatedValue = translationString.ContainsKey(groupValue)
- ? translationString[groupValue]
- : groupValue;
+ string translatedValue = DoTranslateString(groupValue);
dynamicParts.Add(translatedValue);
}
@@ -232,7 +218,7 @@ namespace PvZ_Fusion_Translator.AssetStore
}
}
- public static string DoTranslateText(string originalText, bool isLog = false)
+ public static string DoTranslateString(string originalText, bool isLog = false)
{
if (string.IsNullOrEmpty(originalText))
{
@@ -275,6 +261,73 @@ namespace PvZ_Fusion_Translator.AssetStore
}
return customLevelString[originalText];
}
+
+ if (Utils.plantIndiceString.ContainsKey(originalText))
+ {
+ if(isLog)
+ {
+ Log.LogDebug($"Text '{originalText}' found in plantIndiceString");
+ }
+ return Utils.plantIndiceString[originalText];
+ }
+
+ return originalText;
+ }
+
+ public static string DoTranslateText(string originalText, bool isLog = false)
+ {
+ if (string.IsNullOrEmpty(originalText))
+ {
+ if (isLog)
+ Log.LogError("Text Null or Empty");
+
+ return string.Empty;
+ }
+
+ if (!Utils.CheckForUntranslatedText(originalText) && !(originalText).Contains("_")) return originalText;
+
+ if (translationString.ContainsKey(originalText))
+ {
+ if (isLog)
+ Log.LogDebug($"Text '{originalText} found in translationString");
+ return translationString[originalText];
+ }
+
+ if(izTipCollectionString.ContainsKey(originalText))
+ {
+ if(isLog)
+ {
+ Log.LogDebug($"Text '{originalText}' found in izTipCollectionString");
+ }
+ return izTipCollectionString[originalText];
+ }
+
+ if(fsTipCollectionString.ContainsKey(originalText))
+ {
+ if(isLog)
+ {
+ Log.LogDebug($"Text '{originalText}' found in fsTipCollectionString");
+ }
+ return fsTipCollectionString[originalText];
+ }
+
+ if(customLevelString.ContainsKey(originalText))
+ {
+ if(isLog)
+ {
+ Log.LogDebug($"Text '{originalText}' found in customLevelString");
+ }
+ return customLevelString[originalText];
+ }
+
+ if (Utils.plantIndiceString.ContainsKey(originalText))
+ {
+ if(isLog)
+ {
+ Log.LogDebug($"Text '{originalText}' found in plantIndiceString");
+ }
+ return Utils.plantIndiceString[originalText];
+ }
// Regex-based dynamic translation
foreach (var entry in translationStringRegex)
@@ -296,9 +349,7 @@ namespace PvZ_Fusion_Translator.AssetStore
for (int i = 1; i < groupCount; i++)
{
string groupValue = match.Groups[i].Value;
- string translatedValue = translationString.ContainsKey(groupValue)
- ? translationString[groupValue]
- : groupValue;
+ string translatedValue = DoTranslateString(groupValue);
dynamicParts.Add(translatedValue);
}
diff --git a/MelonLoader/Core.cs b/MelonLoader/Core.cs
index 0cd8137..a93977c 100644
--- a/MelonLoader/Core.cs
+++ b/MelonLoader/Core.cs
@@ -1,13 +1,8 @@
-using Il2Cpp;
-using Il2CppTMPro;
-using MelonLoader;
+using MelonLoader;
using MelonLoader.Utils;
using PvZ_Fusion_Translator.AssetStore;
using PvZ_Fusion_Translator.Patches.Managers;
-using PvZ_Fusion_Translator.Patches.Modes.Odyssey;
using PvZ_Fusion_Translator.Patches.Modes.Super_Editor;
-using System.Runtime.CompilerServices;
-using System.Text.Json;
using UnityEngine;
using static PvZ_Fusion_Translator.FileLoader;
@@ -21,6 +16,7 @@ namespace PvZ_Fusion_Translator
private static DateTime dtStart;
private static DateTime? dtStartToast;
private static string toast_txt;
+ public static bool isInitialized = false;
public static Core Instance { get; private set; }
object replaceTextureRoutine = null;
@@ -32,8 +28,6 @@ namespace PvZ_Fusion_Translator
base.OnInitializeMelon();
Instance = this;
- //DllStore.Init(MelonLoader.InternalUtils.UnityInformationHandler.GameVersion);
-
Config();
#if MULTI_LANGUAGE
FileLoader.LoadLanguage();
@@ -42,9 +36,8 @@ namespace PvZ_Fusion_Translator
StringStore.Init();
AudioStore.Init();
FontStore.Init();
- Utils.RegisterPlantIndices();
- //Utils.RegisterRecipeLinks();
+ isInitialized = true;
}
public override void OnLateInitializeMelon()
@@ -52,6 +45,7 @@ namespace PvZ_Fusion_Translator
dtStart = DateTime.Now;
replaceTextureRoutine = MelonCoroutines.Start(TextureStore.ReplaceTexturesCoroutine());
LoadTravelBuffs();
+ Utils.RegisterPlantIndices();
}
public override void OnDeinitializeMelon()
diff --git a/MelonLoader/FileLoader.cs b/MelonLoader/FileLoader.cs
index d838940..042d28b 100644
--- a/MelonLoader/FileLoader.cs
+++ b/MelonLoader/FileLoader.cs
@@ -159,14 +159,14 @@ namespace PvZ_Fusion_Translator
if(plantAlmanacContent != null)
{
- AlmanacPlantMenu_Patch.almanacJson = plantAlmanacContent;
+ AlmanacPlantMenu_Patch.LoadPlantAlmanacData(plantAlmanacContent);
}
else
{
string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
if(File.Exists(path))
{
- AlmanacPlantMenu_Patch.almanacJson = File.ReadAllText(path);
+ AlmanacPlantMenu_Patch.LoadPlantAlmanacData(File.ReadAllText(path));
}
}
@@ -199,6 +199,10 @@ namespace PvZ_Fusion_Translator
}
}
+ // load travel_buffs
+
+ LoadTravelBuffs();
+
// load abyss buffs
Patches.Modes.Abyss.AbyssBuffMenu_Patch.LoadAbyssBuffData();
@@ -259,6 +263,10 @@ namespace PvZ_Fusion_Translator
{
Patches.Modes.Abyss.AbyssBuffMenu_Patch.LoadAbyssBuffData();
}
+ else if (fileName.EndsWith("travel_buffs"))
+ {
+ LoadTravelBuffs();
+ }
}
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
@@ -272,7 +280,7 @@ namespace PvZ_Fusion_Translator
if(File.Exists(plantAlmanacPath))
{
- AlmanacPlantMenu_Patch.almanacJson = File.ReadAllText(plantAlmanacPath);
+ AlmanacPlantMenu_Patch.LoadPlantAlmanacData(File.ReadAllText(plantAlmanacPath));
}
string zombieAlmanacPath = Path.Combine(almanacDir, "ZombieStringsTranslate.json");
@@ -429,6 +437,10 @@ namespace PvZ_Fusion_Translator
changelogText = changelogContent;
}
}
+ else
+ {
+ changelogText = File.ReadAllText(changelogDir);
+ }
NoticePauseMenu_Patch.changelogText = changelogText;
}
@@ -441,14 +453,14 @@ namespace PvZ_Fusion_Translator
if (travelBuffsContent != null)
{
- TravelMgr_Patch.translatedTravelBuffs = TravelMgr_Patch.GenerateTranslatedTravelBuffs(travelBuffsContent);
+ 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));
+ TravelMgr_Patch.GenerateTranslatedTravelBuffs(File.ReadAllText(travelBuffsPath));
}
}
}
@@ -462,7 +474,7 @@ namespace PvZ_Fusion_Translator
string jsonString = File.ReadAllText(filepath);
if (fileName.EndsWith("travel_buffs"))
{
- TravelMgr_Patch.translatedTravelBuffs = TravelMgr_Patch.GenerateTranslatedTravelBuffs(jsonString);
+ TravelMgr_Patch.GenerateTranslatedTravelBuffs(jsonString);
}
}
}
diff --git a/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs b/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs
index 3b77165..a3c6c4c 100644
--- a/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs
+++ b/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs
@@ -1,5 +1,6 @@
using HarmonyLib;
using Il2Cpp;
+using Il2CppCore;
using Il2CppAlmanacData;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
@@ -73,7 +74,8 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
int godsGachaCheck = CheckGodsGachaPopup(originalText);
string godsGachaMatch = "";
string superEditorPlantMatch = CheckSuperEditorPopup(originalText);
- string customLevelRegexMatch = CheckCustomLevelRegex(originalText);
+ string customLevelRegexMatch = CheckCustomLevelRegex(originalText);
+ string qualityCheckMatch = CheckQualityUpgrade(originalText);
switch(godsGachaCheck)
{
@@ -112,6 +114,10 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
}
}
}
+ else if(qualityCheckMatch != "")
+ {
+ txt.text = qualityCheckMatch;
+ }
else if(superEditorPlantMatch != "")
{
txt.text = superEditorPlantMatch;
@@ -164,8 +170,10 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
public static string nameAlreadyPlantedPattern = "场上已经有一个([^\\s]+)了";
public static string upgradePathRemovedPattern = "已移除路线:([^\\s]+)";
- public static string lockedPlantPattern = "^([^\\s:]+)\\+([^\\s:]+)";
- public static string multiLockedPlantPattern = "^或 ([^\\s:]+)\\+([^\\s:]+)";
+ public static string lockedPlantPattern = "^([\\s\\S]+)\\+([\\S]+)$";
+ public static string multiLockedPlantPattern = "^或 ([\\s\\S]+)\\+([\\S]+)$";
+
+ public static string qualityChangePattern = "诸神注视着你,并选中了一个他们喜欢的词条\n植物【([\\S]+)】的词条【强化:([\\S]+)】获得品质升级\n当前品质:([\\S]+)";
public static Dictionary fallbackFStrs = new Dictionary()
{
@@ -175,7 +183,8 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
{ upgradePathRemovedPattern, "Upgrade Path removed for {0}" },
{ @"([^\s]+)\((\d+)\)", "{0}({1})" },
{ lockedPlantPattern, "{0} + {1}" },
- { multiLockedPlantPattern, "or {0} + {1}" }
+ { multiLockedPlantPattern, "or {0} + {1}" },
+ { qualityChangePattern, "The gods are watching you, and they have granted you an upgrade!\nThe {1} upgrade for {0} has been upgraded.\nCurrent Quality: {2}" }
};
public static int CheckGodsGachaPopup(string originalText)
@@ -205,13 +214,13 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
switch(type)
{
case 1:
- res = TranslatePlantNameParts(originalText, namePlantedPattern);
+ res = StringStore.TranslateText(originalText, namePlantedPattern);
break;
case 2:
- res = TranslatePlantNameParts(originalText, nameUpgradedPattern);
+ res = StringStore.TranslateText(originalText, nameUpgradedPattern);
break;
case 3:
- res = TranslatePlantNameParts(originalText, nameAlreadyPlantedPattern);
+ res = StringStore.TranslateText(originalText, nameAlreadyPlantedPattern);
break;
default:
break;
@@ -269,7 +278,7 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
if(Regex.IsMatch(originalText, upgradePathRemovedPattern))
{
- res = TranslatePlantNameParts(originalText, upgradePathRemovedPattern);
+ res = StringStore.TranslateText(originalText, upgradePathRemovedPattern);
}
else if(Regex.IsMatch(originalText, "当前全部基础植物:(.*)"))
{
@@ -316,17 +325,14 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
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))
+ if (Utils.plantIndiceString.ContainsKey(groups[1].Value) && Utils.plantIndiceString.ContainsKey(groups[2].Value))
{
- firstLine = TranslatePlantNameParts(firstLine, lockedPlantPattern);
+ firstLine = StringStore.TranslateText(firstLine, lockedPlantPattern);
List translatedLines = new List() { firstLine };
for(int i = 1; i < lines.Length; i++)
{
string nextLine = lines[i];
- Log.LogDebug(nextLine);
- string translatedNextLine = TranslatePlantNameParts(nextLine, multiLockedPlantPattern);
+ string translatedNextLine = StringStore.TranslateText(nextLine, multiLockedPlantPattern);
translatedLines.Add(translatedNextLine);
}
res = string.Join("\n", translatedLines);
@@ -343,9 +349,9 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
{
Match match = lockedPlantRegex.Match(originalText);
GroupCollection groups = match.Groups;
- if (Utils.plantIndiceStrings.ContainsKey(groups[1].Value) && Utils.plantIndiceStrings.ContainsKey(groups[2].Value))
+ if (Utils.plantIndiceString.ContainsKey(groups[1].Value) && Utils.plantIndiceString.ContainsKey(groups[2].Value))
{
- res = TranslatePlantNameParts(originalText, lockedPlantPattern);
+ res = StringStore.TranslateText(originalText, lockedPlantPattern);
}
else
{
@@ -371,5 +377,17 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
}
return res;
}
+
+ public static string CheckQualityUpgrade(string originalText)
+ {
+ string res = "";
+
+ if(Regex.IsMatch(originalText, qualityChangePattern))
+ {
+ res = StringStore.TranslateText(originalText, qualityChangePattern);
+ }
+
+ return res;
+ }
}
}
\ No newline at end of file
diff --git a/MelonLoader/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs b/MelonLoader/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs
index fbfd521..e7444ca 100644
--- a/MelonLoader/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs
+++ b/MelonLoader/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs
@@ -17,6 +17,10 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
{
if (!string.IsNullOrEmpty(__instance.text))
{
+ __instance.font = FontStore.LoadTMPFont(Utils.Language.ToString());
+
+ if (!Utils.CheckForUntranslatedText(__instance.text) && !(__instance.text).Contains("_")) return;
+
if(__instance.transform.parent != null)
{
if(__instance.transform.parent.name.Contains("DrawCardsText"))
diff --git a/MelonLoader/Patches/GameObjects/AlmanacBuffMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacBuffMenu_Patch.cs
new file mode 100644
index 0000000..b32868f
--- /dev/null
+++ b/MelonLoader/Patches/GameObjects/AlmanacBuffMenu_Patch.cs
@@ -0,0 +1,91 @@
+using HarmonyLib;
+using Il2Cpp;
+using Il2CppAlmanacData;
+using Il2CppTMPro;
+using PvZ_Fusion_Translator.AssetStore;
+using UnityEngine;
+using System.Drawing;
+using static Il2Cpp.AlmanacBuffMenu;
+using static PvZ_Fusion_Translator.FileLoader;
+using static PvZ_Fusion_Translator.Patches.Modes.Odyssey.TravelMgr_Patch;
+using static PvZ_Fusion_Translator.Utils;
+
+namespace PvZ_Fusion_Translator.Patches.GameObjects
+{
+ [HarmonyPatch(typeof(AlmanacBuffMenu))]
+ public static class AlmanacBuffMenu_Patch
+ {
+ public static Dictionary modifierNameDict = new Dictionary()
+ {
+ { "advancedBuffs", "COMMON_MODIFIER_TAG" },
+ { "ultimateBuffs", "EPIC_MODIFIER_TAG" },
+ { "debuffs", "ZOMBIE_MODIFIER_TAG" },
+ { "unlocks", "UNLOCK_MODIFIER_TAG" },
+ { "investmentBuffs", "INVEST_MODIFIER_TAG" }
+ };
+
+ public static Dictionary fallbackNameDict = new Dictionary()
+ {
+ { "COMMON_MODIFIER_TAG", "Common Modifier" },
+ { "EPIC_MODIFIER_TAG", "Epic Modifier" },
+ { "ZOMBIE_MODIFIER_TAG", "Zombie Modifier" },
+ { "UNLOCK_MODIFIER_TAG", "Unlock Modifier" },
+ { "INVEST_MODIFIER_TAG", "Investment Modifier" }
+ };
+
+ public static string TranslateNameTag(string originalText)
+ {
+ string res = originalText;
+
+ string nameTag = modifierNameDict[originalText];
+ res = StringStore.translationString.ContainsKey(nameTag) ? StringStore.TranslateText(nameTag) : fallbackNameDict[nameTag];
+
+ return res;
+ }
+
+ [HarmonyPatch(nameof(AlmanacBuffMenu.Awake))]
+ [HarmonyPostfix]
+ public static void Post_Awake(AlmanacBuffMenu __instance)
+ {
+ foreach(AlmanacCardUI cardUI in __instance.cards)
+ {
+ AlmanacBuffMenu.CardInfo cardInfo = __instance.cardInfos[cardUI];
+ var buffData = FindBuffData(cardInfo.description);
+
+ if (buffData.Item1 == null || buffData.Item3 == null) continue;
+
+ string nameTag = TranslateNameTag(buffData.Item1);
+ cardUI.cost.text = $"{nameTag} #{buffData.Item2}";
+ }
+
+ Post_OnCardClick(__instance);
+ }
+
+ [HarmonyPatch(nameof(AlmanacBuffMenu.OnCardClick))]
+ [HarmonyPostfix]
+ public static void Post_OnCardClick(AlmanacBuffMenu __instance)
+ {
+ var buffData = FindBuffData(__instance.buffDescription.text);
+
+ if (buffData.Item1 == null || buffData.Item3 == null) return;
+
+ string nameTag = TranslateNameTag(buffData.Item1);
+ __instance.buffTitle.text = $"{nameTag} #{buffData.Item2}";
+ __instance.buffTitle.font = FontStore.LoadTMPFont(Utils.Language.ToString());
+ __instance.buffDescription.text = buffData.Item3 + "\n\n";
+ __instance.buffDescription.font = FontStore.LoadTMPFont(Utils.Language.ToString());
+ string colorHex = StringStore.translationString.ContainsKey("MOD_ALMANAC_COL") ? StringStore.TranslateText("MOD_ALMANAC_COL") : "#000000";
+ System.Drawing.Color descriptionColor = ColorTranslator.FromHtml(colorHex);
+ __instance.buffDescription.color = new UnityEngine.Color(descriptionColor.R / 255.0f, descriptionColor.G / 255.0f, descriptionColor.B / 255.0f);
+
+ __instance.buffDescription.fontSizeMax = 18;
+ __instance.buffDescription.margin = new Vector4(8, 4, 25, 0);
+
+ __instance.buffDescription.enableWordWrapping = true;
+ __instance.buffDescription.overflowMode = TextOverflowModes.ScrollRect;
+
+ Canvas.ForceUpdateCanvases();
+ __instance.buffDescription.ForceMeshUpdate();
+ }
+ }
+}
diff --git a/MelonLoader/Patches/GameObjects/AlmanacCardUI_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacCardUI_Patch.cs
index 8f6527c..9cdf33e 100644
--- a/MelonLoader/Patches/GameObjects/AlmanacCardUI_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/AlmanacCardUI_Patch.cs
@@ -1,10 +1,6 @@
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
{
@@ -19,14 +15,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
__instance.cost.text = StringStore.TranslateText(__instance.cost.text);
}
- [HarmonyPatch(nameof(AlmanacCardUI.OnPointerDown))]
+ /*[HarmonyPatch(nameof(AlmanacCardUI.OnPointerDown))]
[HarmonyPostfix]
public static void OnPointerDown(AlmanacCardUI __instance)
{
- foreach(AlmanacCardUI almanacCardUI in __instance.menu.GetComponentsInChildren())
+ foreach (AlmanacCardUI almanacCardUI in __instance.menu.GetComponentsInChildren())
{
AlmanacCardUI_Patch.Awake(almanacCardUI);
}
- }
+ }*/
}
}
diff --git a/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs
index 837aa7e..39a454d 100644
--- a/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/AlmanacPlantMenu_Patch.cs
@@ -2,7 +2,9 @@
using Il2Cpp;
using Il2CppAlmanacData;
using Il2CppTMPro;
+using MelonLoader.TinyJSON;
using PvZ_Fusion_Translator.AssetStore;
+using System.Text.Json;
using System.Text.RegularExpressions;
using Unity.Collections;
using Unity.VisualScripting;
@@ -18,6 +20,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
public static class AlmanacPlantMenu_Patch
{
public static string almanacJson = "";
+ public static Dictionary plantInfoDict = new();
[HarmonyPatch(nameof(AlmanacPlantMenu.Awake))]
[HarmonyPostfix]
@@ -35,7 +38,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
}
}
- foreach(AlmanacCardUI almanacCardUI in __instance.GetComponentsInChildren())
+ foreach (AlmanacCardUI almanacCardUI in __instance.GetComponentsInChildren())
{
AlmanacCardUI_Patch.Awake(almanacCardUI);
}
@@ -44,10 +47,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
AlmanacPlantWindow window = __instance.window;
GameObject skinButton = window.skinButton;
- GameObject skinTextObj = skinButton.transform.GetChild(0).gameObject;
- GameObject skinShadowTextObj = skinTextObj.transform.GetChild(0).gameObject;
- TextMeshProUGUI skinShadowText = skinShadowTextObj.GetComponent();
- skinShadowText.text = StringStore.TranslateText("换肤_S");
+ GameObject skinTextObj = skinButton.transform.Find("text_1").gameObject;
skinButton.transform.localScale /= 1.75f;
skinButton.transform.localPosition = new Vector3(0.0f, 111.345f, 0.0f);
skinButton.transform.GetChild(1).Translate(new Vector3(-0.35f, 0));
@@ -79,6 +79,10 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
{
searchedPlants.Add((PlantType)plantInfo.seedType);
}
+ else if ($"{plantInfo.seedType}".ToLower().StartsWith(search.ToLower()))
+ {
+ searchedPlants.Add((PlantType)plantInfo.seedType);
+ }
}
__instance.ShowPlants(searchedPlants);
@@ -88,5 +92,46 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
return true;
}
+
+ [HarmonyPatch(nameof(AlmanacPlantMenu.ShowPlants), argumentTypes: [typeof(Il2CppSystem.Func)])]
+ [HarmonyPostfix]
+ public static void ShowPlants(AlmanacPlantMenu __instance, ref Func condition)
+ {
+ foreach (AlmanacCardUI cardUI in __instance.cards)
+ {
+ AlmanacCardUI_Patch.Awake(cardUI);
+ }
+ }
+
+ [HarmonyPatch(nameof(AlmanacPlantMenu.ClassicMix))]
+ [HarmonyPostfix]
+ public static void ClassicMix(AlmanacPlantMenu __instance)
+ {
+ foreach (AlmanacCardUI cardUI in __instance.cards)
+ {
+ AlmanacCardUI_Patch.Awake(cardUI);
+ }
+ }
+
+ public static void LoadPlantAlmanacData(string json)
+ {
+ if (json == null) return;
+
+ almanacJson = json;
+
+ var plantData = JsonUtility.FromJson(almanacJson);
+
+ foreach (Il2CppAlmanacData.PlantInfo plantInfo in plantData.plants)
+ {
+ if(plantInfoDict.ContainsKey(plantInfo.seedType))
+ {
+ plantInfoDict[plantInfo.seedType] = plantInfo;
+ }
+ else
+ {
+ plantInfoDict.Add(plantInfo.seedType, plantInfo);
+ }
+ }
+ }
}
}
diff --git a/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs b/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs
index c0ae83a..239c747 100644
--- a/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/AlmanacPlantWindow_Patch.cs
@@ -1,5 +1,6 @@
using HarmonyLib;
using Il2Cpp;
+using Il2CppAlmanacData;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using System.Text.RegularExpressions;
@@ -34,35 +35,34 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
TMP_FontAsset fontAsset = (hasAlmanacFont) ? FontStore.LoadTMPFontAlmanac(Utils.Language.ToString()) : FontStore.LoadTMPFont(Utils.Language.ToString());
- Il2CppAlmanacData.AlmanacData plantData = JsonUtility.FromJson(json);
+ AlmanacData plantData = JsonUtility.FromJson(json);
- foreach (Il2CppAlmanacData.PlantInfo plantInfo in plantData.plants)
+ if(AlmanacPlantMenu_Patch.plantInfoDict.ContainsKey((int)__instance.currentPlantType))
{
- if (plantInfo.seedType == (int)__instance.currentPlantType)
+ PlantInfo plantInfo = AlmanacPlantMenu_Patch.plantInfoDict[(int)__instance.currentPlantType];
+
+ foreach (TextMeshProUGUI text in __instance.showedPlantName)
{
- foreach (TextMeshProUGUI text in __instance.showedPlantName)
- {
- text.autoSizeTextContainer = false;
- text.text = $"{Utils.RemoveSizeTags(plantInfo.name)} ({plantInfo.seedType})";
- text.font = fontAsset;
- text.fontSizeMax = 21;
- }
-
- char[] toTrim = Environment.NewLine.ToCharArray();
- __instance.showedPlantIntroduce.text = Utils.RemoveSizeTags(plantInfo.info) + "\n\n" + Utils.RemoveSizeTags(plantInfo.introduce) + "\n\n" + Utils.RemoveSizeTags(plantInfo.cost).TrimStart(toTrim) + "\n\n";
- __instance.showedPlantIntroduce.font = fontAsset;
- __instance.showedPlantIntroduce.fontSizeMax = 21;
- __instance.showedPlantIntroduce.margin = new Vector4(6, 2, 12, 0);
-
- __instance.showedPlantIntroduce.enableWordWrapping = true;
- __instance.showedPlantIntroduce.overflowMode = TextOverflowModes.ScrollRect;
-
- Canvas.ForceUpdateCanvases();
- __instance.showedPlantIntroduce.ForceMeshUpdate();
-
- float textHeight = __instance.showedPlantIntroduce.preferredHeight;
- __instance.plantTextContent.sizeDelta = new Vector2(__instance.plantTextContent.sizeDelta.x, textHeight);
+ text.autoSizeTextContainer = false;
+ text.text = $"{Utils.RemoveSizeTags(plantInfo.name)} ({plantInfo.seedType})";
+ text.font = fontAsset;
+ text.fontSizeMax = 21;
}
+
+ char[] toTrim = Environment.NewLine.ToCharArray();
+ __instance.showedPlantIntroduce.text = Utils.RemoveSizeTags(plantInfo.info) + "\n\n" + Utils.RemoveSizeTags(plantInfo.introduce) + "\n\n" + Utils.RemoveSizeTags(plantInfo.cost).TrimStart(toTrim) + "\n\n";
+ __instance.showedPlantIntroduce.font = fontAsset;
+ __instance.showedPlantIntroduce.fontSizeMax = 21;
+ __instance.showedPlantIntroduce.margin = new Vector4(6, 2, 12, 0);
+
+ __instance.showedPlantIntroduce.enableWordWrapping = true;
+ __instance.showedPlantIntroduce.overflowMode = TextOverflowModes.ScrollRect;
+
+ Canvas.ForceUpdateCanvases();
+ __instance.showedPlantIntroduce.ForceMeshUpdate();
+
+ float textHeight = __instance.showedPlantIntroduce.preferredHeight;
+ __instance.plantTextContent.sizeDelta = new Vector2(__instance.plantTextContent.sizeDelta.x, textHeight);
}
}
}
diff --git a/MelonLoader/Patches/GameObjects/Almanac_Patch.cs b/MelonLoader/Patches/GameObjects/Almanac_Patch.cs
index be6b547..d1e2885 100644
--- a/MelonLoader/Patches/GameObjects/Almanac_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/Almanac_Patch.cs
@@ -18,12 +18,12 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
TranslateAlmanacMenu(__instance);
}
- [HarmonyPatch(nameof(Almanac.OldAlmanac))]
+ /*[HarmonyPatch(nameof(Almanac.OldAlmanac))]
[HarmonyPostfix]
private static void OldAlmanac(Almanac __instance)
{
TranslateAlmanacMenu(__instance);
- }
+ }*/
[HarmonyPatch(nameof(Almanac.AnimSwitch))]
[HarmonyPostfix]
diff --git a/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs b/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs
index f528ec6..49c2fa3 100644
--- a/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs
@@ -35,6 +35,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
MainMenu_Patch.AnimOver(__instance);
}
+ if(__instance.name.StartsWith("PlantDamageMenu"))
+ {
+ PlantDamageMenu_Patch.Awake(__instance);
+ }
+
TranslateBaseMenuTransform(__instance, "Level");
TranslateBaseMenuTransform(__instance, "Levels");
TranslateBaseMenuTransform(__instance, "CustomLevel");
diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/LevelSaveEnter_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/LevelSaveEnter_Patch.cs
new file mode 100644
index 0000000..86a42f0
--- /dev/null
+++ b/MelonLoader/Patches/GameObjects/ButtonObjects/LevelSaveEnter_Patch.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using HarmonyLib;
+using Il2Cpp;
+using Il2CppTMPro;
+using PvZ_Fusion_Translator.AssetStore;
+using UnityEngine;
+
+namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
+{
+ public static class LevelSaveEnter_Patch
+ {
+ public static void TranslateEnter(LevelSaveEnter __instance)
+ {
+ TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
+
+ __instance.text.text = StringStore.TranslateText(__instance.text.text);
+ __instance.text.font = fontAsset;
+ }
+ }
+}
diff --git a/MelonLoader/Patches/GameObjects/LevelResultMenu_Patch.cs b/MelonLoader/Patches/GameObjects/LevelResultMenu_Patch.cs
index 8b2071e..3f52c2c 100644
--- a/MelonLoader/Patches/GameObjects/LevelResultMenu_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/LevelResultMenu_Patch.cs
@@ -14,7 +14,6 @@ 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]
@@ -26,4 +25,4 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
}
}
}
-}
+}
\ No newline at end of file
diff --git a/MelonLoader/Patches/GameObjects/MainMenu_Patch.cs b/MelonLoader/Patches/GameObjects/MainMenu_Patch.cs
index f6c1024..f1792c5 100644
--- a/MelonLoader/Patches/GameObjects/MainMenu_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/MainMenu_Patch.cs
@@ -45,12 +45,13 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
}
}
- OptionBtn templateButton = newOptionsMenu.transform.Find("F").GetComponent();
+ OptionBtn templateButton = newOptionsMenu.transform.Find("Buttons/F").GetComponent();
OptLanguageBtn_Patch.OptLangBtn_Patch.Awake(templateButton);
UIButton goBackButton = newOptionsMenu.transform.Find("Goback").GetComponent();
- newOptionsMenu.transform.Find("F").gameObject.SetActive(false);
+ newOptionsMenu.transform.Find("Buttons/F").gameObject.SetActive(false);
+ newOptionsMenu.transform.Find("Buttons").gameObject.SetActive(true);
foreach (TextMeshProUGUI text in newOptionsMenu.transform.Find("Background").GetComponentsInChildren())
{
diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/GameLose_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/GameLose_Patch.cs
index 340fd95..e55957f 100644
--- a/MelonLoader/Patches/GameObjects/MinorObjects/GameLose_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/MinorObjects/GameLose_Patch.cs
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using HarmonyLib;
using UnityEngine;
using Il2Cpp;
+using Il2CppCore;
using PvZ_Fusion_Translator.Patches.BaseTextObjects;
namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/HealthSlider_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/HealthSlider_Patch.cs
new file mode 100644
index 0000000..370d592
--- /dev/null
+++ b/MelonLoader/Patches/GameObjects/MinorObjects/HealthSlider_Patch.cs
@@ -0,0 +1,45 @@
+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;
+using Unity.VisualScripting;
+
+namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
+{
+ [HarmonyPatch(typeof(HealthSlider))]
+ public static class HealthSlider_Patch
+ {
+ public static TMP_FontAsset fontAsset = null;
+
+ [HarmonyPatch(nameof(HealthSlider.Start))]
+ [HarmonyPostfix]
+ public static void Post_Start(HealthSlider __instance)
+ {
+ if(!fontAsset)
+ {
+ fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
+ }
+ }
+
+ [HarmonyPatch(nameof(HealthSlider.UpdateText))]
+ [HarmonyPostfix]
+ public static void Post_UpdateText(HealthSlider __instance)
+ {
+ if(!fontAsset) fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
+
+ if (__instance.healthText.font != fontAsset) __instance.healthText.font = fontAsset;
+
+ foreach(TextMeshProUGUI txt in __instance.healthTextContainer.GetComponentsInChildren(true))
+ {
+ txt.text = StringStore.TranslateText(txt.text);
+ txt.font = fontAsset;
+ }
+ }
+ }
+}
diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/LanternUmbrella_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/LanternUmbrella_Patch.cs
index d751354..d4a1c82 100644
--- a/MelonLoader/Patches/GameObjects/MinorObjects/LanternUmbrella_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/MinorObjects/LanternUmbrella_Patch.cs
@@ -4,7 +4,7 @@ using PvZ_Fusion_Translator.AssetStore;
namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
{
-[HarmonyPatch(typeof(LanternUmbrella))]
+ /*[HarmonyPatch(typeof(LanternUmbrella))]
public class LanternUmbrella_Patch
{
[HarmonyPostfix]
@@ -14,5 +14,5 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
__instance.energyText = StringStore.TranslateText(__instance.energyText);
__instance.energyTextShadow = StringStore.TranslateText(__instance.energyTextShadow);
}
- }
+ }*/
}
\ No newline at end of file
diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/PumpinerChestMenu_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/PumpinerChestMenu_Patch.cs
new file mode 100644
index 0000000..4a54d10
--- /dev/null
+++ b/MelonLoader/Patches/GameObjects/MinorObjects/PumpinerChestMenu_Patch.cs
@@ -0,0 +1,26 @@
+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.MinorObjects
+{
+ [HarmonyPatch(typeof(PumpinerChestMenu))]
+ public static class PumpinerChestMenu_Patch
+ {
+ [HarmonyPatch(nameof(PumpinerChestMenu.InitPlants))]
+ [HarmonyPostfix]
+ public static void Post_InitPlants(PumpinerChestMenu __instance)
+ {
+ Transform closeBtnTransform = __instance.transform.Find("SampleButton");
+ TextMeshProUGUI txt = closeBtnTransform.GetComponentInChildren();
+ txt.text = StringStore.TranslateText("合上");
+ }
+ }
+}
diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/SpecialCard_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/SpecialCard_Patch.cs
new file mode 100644
index 0000000..875809e
--- /dev/null
+++ b/MelonLoader/Patches/GameObjects/MinorObjects/SpecialCard_Patch.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using HarmonyLib;
+using Il2Cpp;
+using Il2CppTMPro;
+using PvZ_Fusion_Translator.AssetStore;
+using UnityEngine;
+
+namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
+{
+ [HarmonyPatch(typeof(SpecialCard))]
+ public static class SpecialCard_Patch
+ {
+ [HarmonyPatch(nameof(SpecialCard.Awake))]
+ [HarmonyPatch(nameof(SpecialCard.Start))]
+ [HarmonyPatch(nameof(SpecialCard.ClickedEvent))]
+ [HarmonyPostfix]
+ public static void Post_Awake(SpecialCard __instance)
+ {
+ TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
+
+ foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren())
+ {
+ txt.text = StringStore.TranslateText(txt.text);
+ txt.font = fontAsset;
+ }
+ }
+ }
+}
diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/TrainingDummy_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/TrainingDummy_Patch.cs
index f2bb0d5..8128ccc 100644
--- a/MelonLoader/Patches/GameObjects/MinorObjects/TrainingDummy_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/MinorObjects/TrainingDummy_Patch.cs
@@ -10,7 +10,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
public static void UpdateHealthText(TrainingDummy __instance)
{
Zombie_Patch.TranslateHpUI_T(__instance.healthText, __instance);
- Zombie_Patch.TranslateHpUI_T(__instance.healthTextShadow, __instance);
+ //Zombie_Patch.TranslateHpUI_T(__instance.healthTextShadow, __instance);
}
}
}
\ No newline at end of file
diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/UltimateChomper_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/UltimateChomper_Patch.cs
index d04c947..9443605 100644
--- a/MelonLoader/Patches/GameObjects/MinorObjects/UltimateChomper_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/MinorObjects/UltimateChomper_Patch.cs
@@ -4,7 +4,7 @@ using PvZ_Fusion_Translator.AssetStore;
namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
{
- [HarmonyPatch(typeof(UltimateChomper), nameof(UltimateChomper.UpdateText))]
+ /*[HarmonyPatch(typeof(UltimateChomper), nameof(UltimateChomper.UpdateText))]
public static class UltimateChomper_Patch
{
[HarmonyPostfix]
@@ -13,5 +13,5 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
StringStore.TranslateText(__instance.killingText);
StringStore.TranslateText(__instance.killingTextShadow);
}
- }
+ }*/
}
\ No newline at end of file
diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/Zombie_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/Zombie_Patch.cs
index 5a67517..6dd850a 100644
--- a/MelonLoader/Patches/GameObjects/MinorObjects/Zombie_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/MinorObjects/Zombie_Patch.cs
@@ -32,7 +32,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
public static void Start(Zombie __instance)
{
TranslateHpUI(__instance.healthText, __instance);
- TranslateHpUI(__instance.healthTextShadow, __instance);
+ //TranslateHpUI(__instance.healthTextShadow, __instance);
if (__instance.healthText.transform.rotation != Quaternion.Euler(0, 0, 0))
__instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
@@ -45,10 +45,10 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
if (__instance.theZombieType == ZombieType.TrainingDummy || !Board.Instance.showZombieHealth)
return;
- if (__instance.healthText == null || __instance.healthTextShadow == null) return;
+ if (__instance.healthText == null) return;
TranslateHpUI(__instance.healthText, __instance);
- TranslateHpUI(__instance.healthTextShadow, __instance);
+ //TranslateHpUI(__instance.healthTextShadow, __instance);
if (__instance.healthText.transform.rotation != Quaternion.Euler(0f, 0f, 0f))
__instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
diff --git a/MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs b/MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs
index c5e3bb1..f29c099 100644
--- a/MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs
@@ -10,26 +10,27 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
[HarmonyPatch(typeof(PlantDamageMenu))]
public static class PlantDamageMenu_Patch
{
- [HarmonyPatch(nameof(PlantDamageMenu.Awake))]
- [HarmonyPostfix]
- private static void Awake(PlantDamageMenu __instance)
+ public static void Awake(BaseMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren())
{
- text.text = StringStore.TranslateText(text.text);
+ string originalKey = StringStore.translationString.FirstOrDefault(x => x.Value == text.text).Key;
+ text.text = StringStore.translationString.ContainsKey(originalKey + "_RM") ? StringStore.TranslateText(originalKey + "_RM") : StringStore.TranslateText(text.text);
text.font = fontAsset;
}
}
+ [HarmonyPatch(nameof(PlantDamageMenu.Awake))]
[HarmonyPatch(nameof(PlantDamageMenu.InitCards))]
[HarmonyPostfix]
- private static void InitCards(PlantDamageMenu __instance)
+ public static void InitCards(PlantDamageMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren())
{
- text.text = StringStore.TranslateText(text.text);
+ string originalKey = StringStore.translationString.FirstOrDefault(x => x.Value == text.text).Key;
+ text.text = StringStore.translationString.ContainsKey(originalKey + "_RM") ? StringStore.TranslateText(originalKey + "_RM") : StringStore.TranslateText(text.text);
text.font = fontAsset;
}
}
diff --git a/MelonLoader/Patches/GameObjects/PlantDataMenu_Patch.cs b/MelonLoader/Patches/GameObjects/PlantDataMenu_Patch.cs
index 52669ed..1643d0d 100644
--- a/MelonLoader/Patches/GameObjects/PlantDataMenu_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/PlantDataMenu_Patch.cs
@@ -21,12 +21,12 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
TranslatePlantDataMenu(__instance);
}
- [HarmonyPatch(nameof(PlantDataMenu.Update))]
+ /*[HarmonyPatch(nameof(PlantDataMenu.Update))]
[HarmonyPostfix]
public static void Post_Update(PlantDataMenu __instance)
{
TranslatePlantDataMenu(__instance);
- }
+ }*/
[HarmonyPatch(nameof(PlantDataMenu.InitDataFromPlant))]
[HarmonyPostfix]
@@ -37,6 +37,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
public static void TranslatePlantDataMenu(PlantDataMenu __instance)
{
+ if (!__instance) return;
+
PlantType thePlantType = __instance.plant.thePlantType;
string plantName = Utils.GetPlantNameFromAlmanac(thePlantType);
diff --git a/MelonLoader/Patches/GameObjects/PlayerSaveMenu_Patch.cs b/MelonLoader/Patches/GameObjects/PlayerSaveMenu_Patch.cs
index f8e702d..d550ff9 100644
--- a/MelonLoader/Patches/GameObjects/PlayerSaveMenu_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/PlayerSaveMenu_Patch.cs
@@ -26,10 +26,10 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
public static void TranslateCreatePlayerSaveMenu()
{
- Transform createPlayerSaveMenuTransform = GameAPP.canvasUp.Find("CreatePlayerSaveMenu(Clone)");
- if(createPlayerSaveMenuTransform.TryGetComponent(out CreatePlayerSaveMenu createPlayerSaveMenu))
+ Transform reNameMenuTransform = GameAPP.canvasUp.Find("ReNameMenu(Clone)");
+ if(reNameMenuTransform.TryGetComponent(out ReNameMenu reNameMenu))
{
- createPlayerSaveMenu.title.text = StringStore.TranslateText(createPlayerSaveMenu.title.text);
+ reNameMenu.title.text = StringStore.TranslateText(reNameMenu.title.text);
}
}
}
diff --git a/MelonLoader/Patches/GameObjects/ReNameMenu_Patch.cs b/MelonLoader/Patches/GameObjects/ReNameMenu_Patch.cs
new file mode 100644
index 0000000..5a1ce8e
--- /dev/null
+++ b/MelonLoader/Patches/GameObjects/ReNameMenu_Patch.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using HarmonyLib;
+using UnityEngine;
+using Il2Cpp;
+using PvZ_Fusion_Translator.AssetStore;
+
+namespace PvZ_Fusion_Translator.Patches.GameObjects
+{
+ [HarmonyPatch(typeof(ReNameMenu))]
+ public static class ReNameMenu_Patch
+ {
+ [HarmonyPatch(nameof(ReNameMenu.SetTitle))]
+ [HarmonyPostfix]
+ public static void SetTitle(ReNameMenu __instance)
+ {
+ __instance.title.text = StringStore.TranslateText(__instance.title.text);
+ }
+
+ [HarmonyPatch(nameof(ReNameMenu.SetInputText))]
+ [HarmonyPostfix]
+ public static void SetInputText(ReNameMenu __instance)
+ {
+ __instance.input.text = StringStore.TranslateText(__instance.input.text);
+ }
+ }
+}
diff --git a/MelonLoader/Patches/GameObjects/ShootingMenu_Patch.cs b/MelonLoader/Patches/GameObjects/ShootingMenu_Patch.cs
index 069ee0e..7735106 100644
--- a/MelonLoader/Patches/GameObjects/ShootingMenu_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/ShootingMenu_Patch.cs
@@ -6,7 +6,7 @@ using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
- [HarmonyPatch(typeof(ShootingMenu))]
+ /*[HarmonyPatch(typeof(ShootingMenu))]
public static class ShootingMenu_Patch
{
[HarmonyPatch(nameof(ShootingMenu.Update))]
@@ -21,5 +21,5 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
txt.font = fontAsset;
}
}
- }
+ }*/
}
\ No newline at end of file
diff --git a/MelonLoader/Patches/GameObjects/ShootingSelectWindow_Patch.cs b/MelonLoader/Patches/GameObjects/ShootingSelectWindow_Patch.cs
index 2e49428..79580b5 100644
--- a/MelonLoader/Patches/GameObjects/ShootingSelectWindow_Patch.cs
+++ b/MelonLoader/Patches/GameObjects/ShootingSelectWindow_Patch.cs
@@ -7,7 +7,7 @@ using System.Text.RegularExpressions;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
- [HarmonyPatch(typeof(ShootingSelectWindow))]
+ /*[HarmonyPatch(typeof(ShootingSelectWindow))]
public static class ShootingSelectWindow_Patch
{
[HarmonyPatch(nameof(ShootingSelectWindow.InitPlantType))]
@@ -69,5 +69,5 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
introduceText.text = StringStore.TranslateText(introduceText.text);
introduceText.font = fontAsset;
}
- }
+ }*/
}
diff --git a/MelonLoader/Patches/Managers/SaveMenu_Patch.cs b/MelonLoader/Patches/Managers/SaveMenu_Patch.cs
index 2a36d90..0f5ae09 100644
--- a/MelonLoader/Patches/Managers/SaveMenu_Patch.cs
+++ b/MelonLoader/Patches/Managers/SaveMenu_Patch.cs
@@ -2,6 +2,8 @@
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
+using PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects;
+using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.Managers
{
@@ -9,20 +11,27 @@ namespace PvZ_Fusion_Translator.Patches.Managers
public static class SaveMenu_Patch
{
[HarmonyPatch(nameof(SaveMenu.Start))]
+ [HarmonyPatch(nameof(SaveMenu.CreateLevelEnter))]
+ [HarmonyPatch(nameof(SaveMenu.InitLevelSaveEnters))]
[HarmonyPostfix]
private static void Start(SaveMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
- __instance.title.text = StringStore.TranslateText(__instance.title.text);
- __instance.title.font = fontAsset;
- __instance.title_shadow.text = StringStore.TranslateText(__instance.title_shadow.text);
- __instance.title_shadow.font = fontAsset;
+ __instance.menuTitle.text = StringStore.TranslateText(__instance.menuTitle.text);
+ __instance.menuTitle.font = fontAsset;
- foreach(SaveMenuBtn level in __instance.levels)
+ foreach(LevelSaveEnter enter in __instance.GetComponentsInChildren())
{
- level.theName.text = StringStore.TranslateText(level.theName.text);
+ LevelSaveEnter_Patch.TranslateEnter(enter);
}
}
+
+ [HarmonyPatch(nameof(SaveMenu.OnEditSelectedButtonClicked))]
+ [HarmonyPostfix]
+ private static void OnEditSelectedButtonClicked(SaveMenu __instance)
+ {
+
+ }
}
}
diff --git a/MelonLoader/Patches/Modes/Odyssey/MultipleChoiceMenu_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/MultipleChoiceMenu_Patch.cs
index acd06b3..9540207 100644
--- a/MelonLoader/Patches/Modes/Odyssey/MultipleChoiceMenu_Patch.cs
+++ b/MelonLoader/Patches/Modes/Odyssey/MultipleChoiceMenu_Patch.cs
@@ -1,42 +1,61 @@
-using System;
+using HarmonyLib;
+using Il2Cpp;
+using Il2CppTMPro;
+using PvZ_Fusion_Translator.AssetStore;
+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;
+using UnityEngine.TextCore.Text;
namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
{
[HarmonyPatch(typeof(MultipleChoiceMenu))]
public static class MultipleChoiceMenu_Patch
{
+ public static TMP_FontAsset fontAsset => FontStore.LoadTMPFont(Utils.Language.ToString());
+
[HarmonyPatch(nameof(MultipleChoiceMenu.Awake))]
- [HarmonyPatch(nameof(MultipleChoiceMenu.UpdateWindow))]
- [HarmonyPatch(nameof(MultipleChoiceMenu.Refresh))]
[HarmonyPatch(nameof(MultipleChoiceMenu.Cancel))]
+ [HarmonyPatch(nameof(MultipleChoiceMenu.Refresh))]
+ [HarmonyPatch(nameof(MultipleChoiceMenu.UpdateWindow))]
+ [HarmonyPatch(nameof(MultipleChoiceMenu.UpdateWindows))]
[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())
+ TranslateWindowText(window.title);
+ TranslateWindowText(window.introduce);
+ }
+
+ foreach(TheButton button in __instance.GetComponentsInChildren())
+ {
+ foreach(TextMeshProUGUI txt in button.GetComponentsInChildren())
{
+ txt.text = StringStore.translationString.ContainsKey(txt.text + "_MC") ? StringStore.TranslateText(txt.text + "_MC") : StringStore.TranslateText(txt.text);
txt.font = fontAsset;
- if(StringStore.customLevelString.ContainsKey(txt.text))
- {
- txt.text = StringStore.customLevelString[txt.text];
- }
- else
- {
- txt.text = StringStore.translationString.ContainsKey(txt.text + "_MC") ? StringStore.TranslateText(txt.text + "_MC") : StringStore.TranslateText(txt.text);
- }
}
}
}
+
+ public static void TranslateWindowText(TextMeshProUGUI txt)
+ {
+ txt.font = fontAsset;
+ if(StringStore.customLevelString.ContainsKey(txt.text))
+ {
+ txt.text = StringStore.customLevelString[txt.text];
+ }
+ else if(Utils.GetPlantNameFromAlmanac(txt.text) != "")
+ {
+ txt.text = Utils.GetPlantNameFromAlmanac(txt.text);
+ }
+ else
+ {
+ txt.text = StringStore.translationString.ContainsKey(txt.text + "_MC") ? StringStore.TranslateText(txt.text + "_MC") : StringStore.TranslateText(txt.text);
+ }
+ }
}
}
diff --git a/MelonLoader/Patches/Modes/Odyssey/OppositeBuffManager_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/OppositeBuffManager_Patch.cs
index ef299fa..a29838f 100644
--- a/MelonLoader/Patches/Modes/Odyssey/OppositeBuffManager_Patch.cs
+++ b/MelonLoader/Patches/Modes/Odyssey/OppositeBuffManager_Patch.cs
@@ -7,7 +7,7 @@ using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
{
- [HarmonyPatch(typeof(OppositeBuffManager))]
+ /*[HarmonyPatch(typeof(OppositeBuffManager))]
public static class OppositeBuffManager_Patch
{
public static Dictionary buffLinks = TravelMgr_Patch.buffLinks;
@@ -20,14 +20,14 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
[HarmonyPostfix]
private static void SetText(OppositeBuffManager __instance)
{
- /*if (TravelMgr_Patch.travelBuffString.ContainsKey(__result))
+ *//*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 textList, Il2CppSystem.Object buff, bool isBad = false)
@@ -48,5 +48,5 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
text.font = fontAsset;
}
}
- }
+ }*/
}
diff --git a/MelonLoader/Patches/Modes/Odyssey/ShootingManager_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/ShootingManager_Patch.cs
new file mode 100644
index 0000000..b20146b
--- /dev/null
+++ b/MelonLoader/Patches/Modes/Odyssey/ShootingManager_Patch.cs
@@ -0,0 +1,19 @@
+using HarmonyLib;
+using Il2CppGameLevel;
+using Il2Cpp;
+using UnityEngine;
+using Il2CppGameLevel.RogueShooting;
+
+namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
+{
+ [HarmonyPatch(typeof(ShootingManager))]
+ public static class ShootingManager_Patch
+ {
+ [HarmonyPatch(nameof(ShootingManager.UpgradeBuff))]
+ [HarmonyPostfix]
+ public static void UpgradeBuff(ShootingManager __instance, ref MultipleChoiceMenu menu)
+ {
+ MultipleChoiceMenu_Patch.Awake(menu);
+ }
+ }
+}
diff --git a/MelonLoader/Patches/Modes/Odyssey/SynergyDisplay_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/SynergyDisplay_Patch.cs
index cd944ff..2ec60a3 100644
--- a/MelonLoader/Patches/Modes/Odyssey/SynergyDisplay_Patch.cs
+++ b/MelonLoader/Patches/Modes/Odyssey/SynergyDisplay_Patch.cs
@@ -15,8 +15,7 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
[HarmonyPostfix]
public static void Start(SynergyDisplay __instance)
{
- __instance.text1.text = TranslateInvestDisplay(__instance.text1.text);
- __instance.text_shadow.text = Utils.RemoveColorTags(__instance.text1.text);
+ __instance.text.text = TranslateInvestDisplay(__instance.text.text);
}
public static string TranslateInvestDisplay(string originalText)
diff --git a/MelonLoader/Patches/Modes/Odyssey/TravelAdvantureMenu_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/TravelAdvantureMenu_Patch.cs
index f2a38f4..4411728 100644
--- a/MelonLoader/Patches/Modes/Odyssey/TravelAdvantureMenu_Patch.cs
+++ b/MelonLoader/Patches/Modes/Odyssey/TravelAdvantureMenu_Patch.cs
@@ -20,7 +20,14 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
foreach(CustomButton_enterGame button in __instance.GetComponentsInChildren())
{
string plantName = Utils.GetPlantNameFromAlmanac(button.levelName.text);
- button.levelName.text = (plantName != "") ? plantName : StringStore.TranslateText(button.levelName.text);
+ if(Utils.Language == Utils.LanguageEnum.Arabic)
+ {
+ button.levelName.text = StringStore.TranslateText(button.levelName.text);
+ }
+ else
+ {
+ button.levelName.text = (plantName != "") ? plantName : StringStore.TranslateText(button.levelName.text);
+ }
}
}
diff --git a/MelonLoader/Patches/Modes/Odyssey/TravelMgr_Patch.cs b/MelonLoader/Patches/Modes/Odyssey/TravelMgr_Patch.cs
index 407880f..de356eb 100644
--- a/MelonLoader/Patches/Modes/Odyssey/TravelMgr_Patch.cs
+++ b/MelonLoader/Patches/Modes/Odyssey/TravelMgr_Patch.cs
@@ -17,6 +17,15 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
[HarmonyPatch(typeof(TravelMgr))]
public static class TravelMgr_Patch
{
+ public static readonly Dictionary> templateTravelBuffs = new()
+ {
+ { "advancedBuffs", new SortedDictionary() },
+ { "ultimateBuffs", new SortedDictionary() },
+ { "debuffs", new SortedDictionary() },
+ { "unlocks", new SortedDictionary() },
+ { "investmentBuffs", new SortedDictionary() }
+ };
+
public static Dictionary> dumpedTravelBuffs = new()
{
{ "advancedBuffs", new SortedDictionary() },
@@ -70,35 +79,37 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
public static void DumpTravelBuffs()
{
TravelMgr.Instance.GetPlantBuffUnlockCount(PlantType.DoomGatling);
+ dumpedTravelBuffs = new(templateTravelBuffs);
+ travelBuffString.Clear();
foreach (var pair in TravelDictionary.advancedBuffsText)
{
- dumpedTravelBuffs["advancedBuffs"].Add((int)pair.Key, pair.Value);
- travelBuffString.Add(pair.Value, pair.Value);
+ Utils.TryAdd(dumpedTravelBuffs["advancedBuffs"], (int)pair.Key, pair.Value);
+ Utils.TryAdd(travelBuffString, pair.Value, pair.Value);
}
foreach (var pair in TravelDictionary.ultimateBuffsText)
{
- dumpedTravelBuffs["ultimateBuffs"].Add((int)pair.Key, pair.Value);
- travelBuffString.Add(pair.Value, pair.Value);
+ Utils.TryAdd(dumpedTravelBuffs["ultimateBuffs"], (int)pair.Key, pair.Value);
+ Utils.TryAdd(travelBuffString, 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);
+ Utils.TryAdd(dumpedTravelBuffs["debuffs"], (int)pair.Key, pair.Value.Item1);
+ Utils.TryAdd(travelBuffString, 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);
+ Utils.TryAdd(dumpedTravelBuffs["unlocks"], (int)pair.Key, pair.Value);
+ Utils.TryAdd(travelBuffString, 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());
+ Utils.TryAdd(dumpedTravelBuffs["investmentBuffs"], (int)pair.Key, pair.Value.GetDescription());
+ Utils.TryAdd(travelBuffString, pair.Value.GetDescription(), pair.Value.GetDescription());
}
File.WriteAllText(Path.Combine(GetAssetDir(AssetType.Dumps), "travel_buffs.json"), JsonSerializer.Serialize(dumpedTravelBuffs, new JsonSerializerOptions
@@ -121,17 +132,15 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
}
//System.Text.Json.JsonSerializer.Deserialize>>(travelBuffsContent);
- public static Dictionary> GenerateTranslatedTravelBuffs(string travelBuffsContent)
+ public static void GenerateTranslatedTravelBuffs(string travelBuffsContent)
{
- TravelMgr_Patch.DumpTravelBuffs();
+ if (!Core.isInitialized) return;
+
+ DumpTravelBuffs();
- Dictionary> travelBuffs = System.Text.Json.JsonSerializer.Deserialize>>(travelBuffsContent);
-
- // save travel buffs
-
- string travelBuffsToSave = SerializeWithIndentation(travelBuffs);
- string stringDir = GetAssetDir(AssetType.Strings, Utils.Language);
- File.WriteAllText(Path.Combine(stringDir, "travel_buffs.json"), travelBuffsToSave);
+ Dictionary> travelBuffs = JsonSerializer.Deserialize>>(travelBuffsContent);
+ translatedTravelBuffs = travelBuffs;
+ travelBuffString.Clear();
foreach(var i in travelBuffs)
{
@@ -145,28 +154,14 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
{
if (translatedBuffSet.ContainsKey(j.Key))
{
- if(travelBuffString.ContainsKey(originalBuff))
- {
- travelBuffString[originalBuff] = translatedBuffSet[j.Key];
- }
- else
- {
- travelBuffString.Add(originalBuff, translatedBuffSet[j.Key]);
- }
+ Utils.TryAdd(travelBuffString, 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]);
- }
+ Utils.TryAdd(travelBuffString, originalBuff, translatedBuffSet[j.Key]);
}
}
@@ -179,7 +174,9 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
}
}
- return travelBuffs;
+ string travelBuffsToSave = SerializeWithIndentation(TravelMgr_Patch.translatedTravelBuffs);
+ string stringDir = GetAssetDir(AssetType.Strings, Utils.Language);
+ File.WriteAllText(Path.Combine(stringDir, "travel_buffs.json"), travelBuffsToSave);
}
public static string MatchTravelBuff(string originalText)
@@ -217,5 +214,46 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Odyssey
}
return res;
}
+
+ public static ValueTuple FindBuffData(string buffText)
+ {
+ ValueTuple res = new();
+ foreach(var pair1 in translatedTravelBuffs)
+ {
+ foreach(var pair2 in pair1.Value)
+ {
+ if(buffText == pair2.Value)
+ {
+ res.Item1 = pair1.Key;
+ res.Item2 = pair2.Key;
+ }
+ }
+ }
+
+ foreach(var pair1 in dumpedTravelBuffs)
+ {
+ foreach(var pair2 in pair1.Value)
+ {
+ if(buffText == pair2.Value)
+ {
+ res.Item1 = pair1.Key;
+ res.Item2 = pair2.Key;
+ }
+ }
+ }
+
+ string finalBuffText = buffText;
+ if(travelBuffString.ContainsKey(buffText))
+ {
+ finalBuffText = travelBuffString[buffText];
+ }
+ else
+ {
+ finalBuffText = StringStore.TranslateText(buffText);
+ }
+ res.Item3 = finalBuffText;
+
+ return res;
+ }
}
}
diff --git a/MelonLoader/Patches/Modes/Super Editor/CustomMenuPage_event_Patch_B.cs b/MelonLoader/Patches/Modes/Super Editor/CustomMenuPage_event_Patch_B.cs
new file mode 100644
index 0000000..b0cd093
--- /dev/null
+++ b/MelonLoader/Patches/Modes/Super Editor/CustomMenuPage_event_Patch_B.cs
@@ -0,0 +1,29 @@
+/*using MelonLoader;
+using HarmonyLib;
+using UnityEngine;
+using Il2Cpp;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Il2CppTMPro;
+using PvZ_Fusion_Translator.AssetStore;
+using Il2CppGameLevel;
+using PvZ_Fusion_Translator.Patches.Modes.Super_Editor.GameLevel.EventNodes;
+
+namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor
+{
+ [HarmonyPatch(typeof(CustomMenuPage_event))]
+ public static class CustomMenuPage_event_Patch
+ {
+ [HarmonyPatch(nameof(CustomMenuPage_event.InitializeNodeEditor))]
+ [HarmonyPostfix]
+ public static void InitializeNodeEditor(CustomMenuPage_event __instance)
+ {
+ RuntimeEventNodeEditor_Patch.Update(__instance.nodeEditor);
+ NodeInfoPanel_Patch.UpdatePanelContent(__instance.nodeInfoPanel);
+ }
+ }
+}
+*/
\ No newline at end of file
diff --git a/MelonLoader/Patches/Modes/Super Editor/GameLevel/EventNodes/RuntimeEventNodeEditor_Patch.cs b/MelonLoader/Patches/Modes/Super Editor/GameLevel/EventNodes/RuntimeEventNodeEditor_Patch.cs
index 97278d9..91d43fc 100644
--- a/MelonLoader/Patches/Modes/Super Editor/GameLevel/EventNodes/RuntimeEventNodeEditor_Patch.cs
+++ b/MelonLoader/Patches/Modes/Super Editor/GameLevel/EventNodes/RuntimeEventNodeEditor_Patch.cs
@@ -1,96 +1,47 @@
-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 HarmonyLib;
using Il2CppGameLevel.EventNodes;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
+using PvZ_Fusion_Translator.Patches.BaseTextObjects;
+using UnityEngine;
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())
- {
- txt.text = StringStore.translationString.ContainsKey(txt.text + "_code") ? StringStore.TranslateText(txt.text + "_code") : StringStore.TranslateText(txt.text);
- txt.font = fontAsset;
- }
- }
- }
+ public static TMP_FontAsset fontAsset => FontStore.LoadTMPFont(Utils.Language.ToString());
[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)
+ // translate the new screens (3.7)
+ TranslateFullTransform(__instance.nodeInfoPanel.transform);
+ TranslateFullTransform(__instance.attributePanel.transform);
+ TranslateFullTransform(__instance.canvas.transform);
+ if(__instance.TryGetComponent(out EventNodeContextMenu eventNodeContextMenu))
{
- RuntimeNodeUI nodeUI = node.value;
+ TranslateFullTransform(eventNodeContextMenu.transform);
+ }
+ }
+
+ public static void TranslateFullTransform(Transform transform)
+ {
+ if (transform == null) return;
- if(nodeUI.Node.nodeType == "PlantTypeValueNode" || nodeUI.Node.nodeType == "SinglePlantTypeListNode")
+ foreach(TextMeshProUGUI txt in transform.GetComponentsInChildren())
+ {
+ txt.text = RuntimeNodeUI_Patch.TranslateCodeText(txt.text);
+ txt.font = fontAsset;
+ }
+
+ foreach(TMP_InputField inputField in transform.GetComponentsInChildren())
+ {
+ TMP_InputField_Patch.OnEnable(inputField);
+ foreach(TextMeshProUGUI txt in inputField.GetComponentsInChildren(true))
{
- Transform buttonTransform = nodeUI.transform.Find("Header/ValueEditContainer/Button(Clone)/Label");
- TextMeshProUGUI txt = buttonTransform.GetComponent();
-
- if (!txt.gameObject.name.Contains("Label")) continue;
- if (!Utils.CheckForUntranslatedText(txt.text)) continue;
-
- string plantName = "";
- if(nodeUI.Node.nodeType == "PlantTypeValueNode")
- {
- plantName = Utils.GetPlantNameFromAlmanac(nodeUI.Node.GetPortValue(nodeUI.Node.GetOutputPorts()[0].portName, PlantType.Nothing));
- }
- else if(nodeUI.Node.nodeType == "SinglePlantTypeListNode")
- {
- SinglePlantTypeListNode tempNode = nodeUI.Node.TryCast();
- plantName = Utils.GetPlantNameFromAlmanac(tempNode.plantType);
- }
- 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();
-
- if (!txt.gameObject.name.Contains("Label")) continue;
- if (!Utils.CheckForUntranslatedText(txt.text)) continue;
-
- string zombieName = Utils.GetZombieNameFromAlmanac(nodeUI.Node.GetPortValue(nodeUI.Node.GetOutputPorts()[0].portName, ZombieType.Nothing));
- txt.text = (zombieName != "") ? zombieName : StringStore.TranslateText(txt.text);
- txt.font = fontAsset;
- }
- else if(nodeUI.Node.nodeType == "PlantTypeListStorageNode")
- {
- Transform dropdownTransform = nodeUI.transform.Find("Header/ValueEditContainer/Dropdown(Clone)");
-
- if (!dropdownTransform) continue;
-
- foreach(TextMeshProUGUI txt in dropdownTransform.GetComponentsInChildren())
- {
- if (!Utils.CheckForUntranslatedText(txt.text)) continue;
-
- txt.text = StringStore.TranslateText(txt.text);
- txt.font = fontAsset;
- }
+ txt.text = RuntimeNodeUI_Patch.TranslateCodeText(txt.text);
}
}
}
diff --git a/MelonLoader/Patches/Modes/Super Editor/GameLevel/EventNodes/RuntimeNodeUI_Patch.cs b/MelonLoader/Patches/Modes/Super Editor/GameLevel/EventNodes/RuntimeNodeUI_Patch.cs
index fc31045..540f243 100644
--- a/MelonLoader/Patches/Modes/Super Editor/GameLevel/EventNodes/RuntimeNodeUI_Patch.cs
+++ b/MelonLoader/Patches/Modes/Super Editor/GameLevel/EventNodes/RuntimeNodeUI_Patch.cs
@@ -1,12 +1,4 @@
-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 HarmonyLib;
using Il2CppGameLevel.EventNodes;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
@@ -18,99 +10,134 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Super_Editor.GameLevel.EventNodes
public static class RuntimeNodeUI_Patch
{
[HarmonyPatch(nameof(RuntimeNodeUI.Awake))]
- [HarmonyPatch(nameof(RuntimeNodeUI.Initialize))]
- [HarmonyPatch(nameof(RuntimeNodeUI.CreatePorts))]
- [HarmonyPatch(nameof(RuntimeNodeUI.CreateTravelEntryEditUI), argumentTypes: [typeof(RectTransform), typeof(GetTravelEntryNode)])]
- [HarmonyPatch(nameof(RuntimeNodeUI.CreateStringInputField))]
[HarmonyPatch(nameof(RuntimeNodeUI.CreatePorts))]
+ [HarmonyPatch(nameof(RuntimeNodeUI.CreateValueEditUI))]
+ [HarmonyPatch(nameof(RuntimeNodeUI.GetPortUI))]
+ [HarmonyPatch(nameof(RuntimeNodeUI.UpdateDisplay))]
+ [HarmonyPatch(nameof(RuntimeNodeUI.UpdateSelectionVisual))]
+ [HarmonyPatch(nameof(RuntimeNodeUI.UpdateVisable))]
[HarmonyPostfix]
- public static void Awake(RuntimeNodeUI __instance)
+ public static void Post_UpdateDisplay(RuntimeNodeUI __instance)
{
if (!__instance.isActiveAndEnabled) return;
+ if (__instance.Node == null) return;
+
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
- if(__instance.dropdownPrefab)
- {
- if(__instance.dropdownPrefab.TryGetComponent(out TMP_Dropdown dropdown))
- {
- TMP_Dropdown_Patch.CreateDropdownList(dropdown);
- }
- }
+ __instance.titleText.text = TranslateCodeText(__instance.titleText.text);
+ __instance.titleText.font = fontAsset;
- if(__instance.valueInputField)
+ foreach(TextMeshProUGUI txt in __instance.inputPortsContainer.GetComponentsInChildren())
{
- TMP_InputField_Patch.OnEnable(__instance.valueInputField);
- foreach(TextMeshProUGUI txt in __instance.valueInputField.GetComponentsInChildren(true))
- {
- txt.text = StringStore.translationString.ContainsKey(txt.text + "_code") ? StringStore.TranslateText(txt.text + "_code") : StringStore.TranslateText(txt.text);
- }
- }
-
- foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren())
- {
- txt.text = StringStore.translationString.ContainsKey(txt.text + "_code") ? StringStore.TranslateText(txt.text + "_code") : StringStore.TranslateText(txt.text);
+ txt.text = TranslateCodeText(txt.text);
txt.font = fontAsset;
}
- }
- [HarmonyPatch(nameof(RuntimeNodeUI.UpdateDisplay))]
- [HarmonyPostfix]
- public static void UpdateDisplay(RuntimeNodeUI __instance)
- {
- if (!__instance.isActiveAndEnabled) return;
-
- TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
-
- if(__instance.Node.nodeType == "PlantTypeValueNode" || __instance.Node.nodeType == "SinglePlantTypeListNode")
+ foreach(TextMeshProUGUI txt in __instance.outputPortsContainer.GetComponentsInChildren())
{
- foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren())
+ txt.text = TranslateCodeText(txt.text);
+ txt.font = fontAsset;
+ }
+
+ if (
+ __instance.GetComponentsInChildren().Count == 0
+ && __instance.GetComponentsInChildren().Count == 0
+ && __instance.Node.nodeType != "PlantTypeValueNode"
+ && __instance.Node.nodeType != "SinglePlantTypeListNode"
+ && __instance.Node.nodeType != "ZombieTypeValueNode"
+ ) return;
+
+ if (__instance.Node != null)
+ {
+ if(__instance.Node.nodeType == "PlantTypeValueNode")
{
- if(txt.gameObject.name.Contains("Label"))
+ foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren())
{
- string plantName = Utils.GetPlantNameFromAlmanac(__instance.Node.GetPortValue(__instance.Node.nodeName, PlantType.Nothing));
- txt.text = (plantName != "") ? plantName : StringStore.TranslateText(txt.text);
- txt.font = fontAsset;
+ if(txt.gameObject.name.Contains("Label"))
+ {
+ if (Utils.CheckForUntranslatedText(txt.text))
+ {
+ PlantTypeValueNode castedNode = __instance.Node.TryCast();
+ if (castedNode != null)
+ {
+ string portName = castedNode.value_PortName;
+ string plantName = Utils.GetPlantNameFromAlmanac(castedNode.value, removeTags: true);
+ txt.text = (plantName != "") ? plantName : StringStore.TranslateText(txt.text);
+ txt.font = fontAsset;
+ }
+ }
+ }
+ }
+ }
+
+ if(__instance.Node.nodeType == "SinglePlantTypeListNode")
+ {
+ foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren())
+ {
+ if (txt.gameObject.name.Contains("Label"))
+ {
+ if (Utils.CheckForUntranslatedText(txt.text))
+ {
+ SinglePlantTypeListNode castedNode = __instance.Node.TryCast();
+ if (castedNode != null)
+ {
+ string portName = castedNode.plantTypeList_PortName;
+ string plantName = Utils.GetPlantNameFromAlmanac(castedNode.plantType, removeTags: true);
+ txt.text = (plantName != "") ? plantName : StringStore.TranslateText(txt.text);
+ txt.font = fontAsset;
+ }
+ }
+ }
+ }
+ }
+
+ if(__instance.Node.nodeType == "ZombieTypeValueNode")
+ {
+ foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren())
+ {
+ if(txt.gameObject.name.Contains("Label"))
+ {
+ if(Utils.CheckForUntranslatedText(txt.text))
+ {
+ ZombieTypeValueNode castedNode = __instance.Node.TryCast();
+ if(castedNode != null)
+ {
+ string portName = castedNode.value_PortName;
+ string zombieName = Utils.GetZombieNameFromAlmanac(castedNode.value, removeTags: true);
+ txt.text = (zombieName != "") ? zombieName : StringStore.TranslateText(txt.text);
+ txt.font = fontAsset;
+ }
+ }
+ }
}
}
}
- if(__instance.Node.nodeType == "ZombieTypeValueNode")
+ if(__instance.GetComponentsInChildren().Count > 0)
{
- foreach(TextMeshProUGUI txt in __instance.GetComponentsInChildren())
- {
- if(txt.gameObject.name.Contains("Label"))
- {
- string zombieName = Utils.GetZombieNameFromAlmanac(__instance.Node.GetPortValue(__instance.Node.nodeName, ZombieType.Nothing));
- txt.text = (zombieName != "") ? zombieName : StringStore.TranslateText(txt.text);
- txt.font = fontAsset;
- }
- }
- }
-
- if(__instance.dropdownPrefab)
- {
- if(__instance.dropdownPrefab.TryGetComponent(out TMP_Dropdown dropdown))
+ foreach(TMP_Dropdown dropdown in __instance.GetComponentsInChildren())
{
TMP_Dropdown_Patch.CreateDropdownList(dropdown);
}
}
- if(__instance.valueInputField)
+ if(__instance.GetComponentsInChildren().Count > 0)
{
- TMP_InputField_Patch.OnEnable(__instance.valueInputField);
- foreach(TextMeshProUGUI txt in __instance.valueInputField.GetComponentsInChildren(true))
+ foreach(TMP_InputField inputField in __instance.GetComponentsInChildren())
{
- txt.text = StringStore.translationString.ContainsKey(txt.text + "_code") ? StringStore.TranslateText(txt.text + "_code") : StringStore.TranslateText(txt.text);
+ TMP_InputField_Patch.OnEnable(inputField);
+ foreach(TextMeshProUGUI txt in inputField.GetComponentsInChildren(true))
+ {
+ txt.text = TranslateCodeText(txt.text);
+ }
}
}
}
-
- [HarmonyPatch(nameof(RuntimeNodeUI.UpdateSelectionVisual))]
- [HarmonyPostfix]
- public static void UpdateSelectionVisual(RuntimeNodeUI __instance)
+
+ public static string TranslateCodeText(string originalText)
{
- UpdateDisplay(__instance);
+ return StringStore.translationString.ContainsKey(originalText + "_code") ? StringStore.TranslateText(originalText + "_code") : StringStore.TranslateText(originalText);
}
}
}
diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj
index 642359a..8eb8423 100644
--- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj
+++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj
@@ -13,7 +13,7 @@
latest
enable
Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate
- C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.6.1
+ C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.7
AnyCPU;ARM64;x64
@@ -31,7 +31,6 @@
-
@@ -305,6 +304,9 @@
$(GamePath)\MelonLoader\net6\Il2CppInterop.Common.dll
+
+ $(GamePath)\MelonLoader\Il2CppAssemblies\Il2CppCore.dll
+
@@ -404,19 +406,26 @@
+
+
+
+
+
+
+
@@ -515,13 +524,14 @@
+
-
+
@@ -565,11 +575,11 @@
-
+
-
+
diff --git a/MelonLoader/Resources/ModUpdateUtil.exe b/MelonLoader/Resources/ModUpdateUtil.exe
deleted file mode 100644
index fa4a746..0000000
Binary files a/MelonLoader/Resources/ModUpdateUtil.exe and /dev/null differ
diff --git a/MelonLoader/Utils.cs b/MelonLoader/Utils.cs
index b47ae57..375a205 100644
--- a/MelonLoader/Utils.cs
+++ b/MelonLoader/Utils.cs
@@ -10,6 +10,7 @@ using PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects;
using PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects;
using PvZ_Fusion_Translator.Patches.Modes.Super_Editor;
using System.Diagnostics;
+using System.Reflection;
using System.Text.RegularExpressions;
using Unity.Burst.Intrinsics;
using UnityEngine;
@@ -115,13 +116,34 @@ namespace PvZ_Fusion_Translator
if (string.IsNullOrEmpty(text))
return text ?? string.Empty;
- // Remove opening color tags like
+ // Remove opening size tags like
string withoutOpenTags = Regex.Replace(text, @"]+>", string.Empty, RegexOptions.IgnoreCase);
- // Remove closing color tags like
+ // Remove closing size tags like
string withoutCloseTags = Regex.Replace(withoutOpenTags, @"", string.Empty, RegexOptions.IgnoreCase);
return withoutCloseTags;
}
+ public static string RemoveFormatTags(string text)
+ {
+ if (string.IsNullOrEmpty(text))
+ return text ?? string.Empty;
+
+ string withoutUnderlineTags = Regex.Replace(text, @"", string.Empty, RegexOptions.IgnoreCase);
+ string withoutUnderlineCloseTags = Regex.Replace(withoutUnderlineTags, @"", string.Empty, RegexOptions.IgnoreCase);
+ string withoutItalicTags = Regex.Replace(withoutUnderlineCloseTags, @"", string.Empty, RegexOptions.IgnoreCase);
+ string withoutItalicCloseTags = Regex.Replace(withoutItalicTags, @"", string.Empty, RegexOptions.IgnoreCase);
+
+ return withoutItalicCloseTags;
+ }
+
+ public static string RemoveAllTags(string text)
+ {
+ if (string.IsNullOrEmpty(text))
+ return text ?? string.Empty;
+
+ return RemoveColorTags(RemoveSizeTags(RemoveFormatTags(text)));
+ }
+
public static GameObject ConvertToTextMeshProUGUI(GameObject originalText, Transform parent, string name)
{
GameObject newObj = new GameObject(name);
@@ -152,7 +174,7 @@ namespace PvZ_Fusion_Translator
newGoBackText.color = color;
}
- public static string GetPlantNameFromAlmanac(PlantType thePlantType, bool log = false)
+ public static string GetPlantNameFromAlmanac(PlantType thePlantType, bool removeTags = false, bool log = false)
{
bool foundPlantName = false;
string thePlantName = "";
@@ -172,18 +194,20 @@ namespace PvZ_Fusion_Translator
thePlantName = "";
}
+ thePlantName = (removeTags) ? RemoveAllTags(thePlantName) : thePlantName;
+
return thePlantName;
}
- public static string GetPlantNameFromAlmanac(string theOriginalPlantName, bool log = false)
+ public static string GetPlantNameFromAlmanac(string theOriginalPlantName, bool removeTags = false, bool log = false)
{
bool foundPlantName = false;
string thePlantName = "";
- if(plantIndiceStrings.ContainsKey(theOriginalPlantName))
+ if(plantIndiceString.ContainsKey(theOriginalPlantName))
{
foundPlantName = true;
- thePlantName = plantIndiceStrings[theOriginalPlantName];
+ thePlantName = plantIndiceString[theOriginalPlantName];
}
if (!foundPlantName)
@@ -195,10 +219,12 @@ namespace PvZ_Fusion_Translator
thePlantName = "";
}
+ thePlantName = (removeTags) ? RemoveAllTags(thePlantName) : thePlantName;
+
return thePlantName;
}
- public static string GetZombieNameFromAlmanac(ZombieType theZombieType)
+ public static string GetZombieNameFromAlmanac(ZombieType theZombieType, bool removeTags = false)
{
string json;
string theZombieName = "";
@@ -216,16 +242,18 @@ namespace PvZ_Fusion_Translator
}
}
+ theZombieName = (removeTags) ? RemoveAllTags(theZombieName) : theZombieName;
+
return theZombieName;
}
public static Dictionary> plantIndices = new Dictionary>();
- public static Dictionary plantIndiceStrings = new Dictionary();
+ public static Dictionary plantIndiceString = new Dictionary();
public static void RegisterPlantIndices()
{
plantIndices = new Dictionary>();
- plantIndiceStrings = new Dictionary();
+ plantIndiceString = new Dictionary();
string originalJson;
string translatedJson;
@@ -241,37 +269,110 @@ namespace PvZ_Fusion_Translator
}
else
{
- originalJson = File.ReadAllText(originalPath);
- translatedJson = AlmanacPlantMenu_Patch.almanacJson;
- Il2CppAlmanacData.AlmanacData originalPlantData = JsonUtility.FromJson(originalJson);
- Il2CppAlmanacData.AlmanacData translatedPlantData = JsonUtility.FromJson(translatedJson);
-
- for (int i = 0; i < originalPlantData.plants.Count; i++)
+ try
{
- Il2CppAlmanacData.PlantInfo originalPlantInfo = originalPlantData.plants[i];
- if(!plantIndiceStrings.ContainsKey(originalPlantInfo.name))
- {
- plantIndiceStrings.Add(originalPlantInfo.name, originalPlantInfo.name);
- }
- Il2CppAlmanacData.PlantInfo translatedPlantInfo = null;
+ originalJson = File.ReadAllText(originalPath);
+ translatedJson = AlmanacPlantMenu_Patch.almanacJson;
+ Il2CppAlmanacData.AlmanacData originalPlantData = JsonUtility.FromJson(originalJson);
+ Il2CppAlmanacData.AlmanacData translatedPlantData = JsonUtility.FromJson(translatedJson);
- foreach (Il2CppAlmanacData.PlantInfo info in translatedPlantData.plants)
+ foreach (Il2CppAlmanacData.PlantInfo originalPlantInfo in originalPlantData.plants)
{
- if (info.seedType == originalPlantInfo.seedType)
+ if(!plantIndiceString.ContainsKey(originalPlantInfo.name))
{
- translatedPlantInfo = info;
+ plantIndiceString.Add(originalPlantInfo.name, originalPlantInfo.name);
+ }
+ Il2CppAlmanacData.PlantInfo translatedPlantInfo = null;
+
+ foreach (Il2CppAlmanacData.PlantInfo info in translatedPlantData.plants)
+ {
+ if (info.seedType == originalPlantInfo.seedType)
+ {
+ translatedPlantInfo = info;
+ }
+ }
+
+ if (translatedPlantInfo != null)
+ {
+ if(translatedPlantInfo.name != null)
+ {
+ KeyValuePair temp = new KeyValuePair(translatedPlantInfo.seedType, translatedPlantInfo.name);
+ plantIndices.Add(originalPlantInfo.seedType, temp);
+ plantIndiceString[originalPlantInfo.name] = translatedPlantInfo.name;
+ }
}
}
-
- if (translatedPlantInfo != null)
- {
- KeyValuePair temp = new KeyValuePair(translatedPlantInfo.seedType, translatedPlantInfo.name);
- plantIndices.Add(originalPlantInfo.seedType, temp);
- plantIndiceStrings[originalPlantInfo.name] = translatedPlantInfo.name;
- }
+ }
+ catch (Exception e)
+ {
+ Log.LogError(e);
}
}
}
+
+ public static void TryAdd(Dictionary dict, A key, B val)
+ {
+ if (dict.ContainsKey(key))
+ {
+ dict[key] = val;
+ }
+ else
+ {
+ dict.Add(key, val);
+ }
+ }
+
+ public static void TryAdd(SortedDictionary dict, A key, B val)
+ {
+ if (dict.ContainsKey(key))
+ {
+ dict[key] = val;
+ }
+ else
+ {
+ dict.Add(key, val);
+ }
+ }
+
+ public static AssetBundle GetAssetBundle(Assembly assembly, string assetBundlePath, bool log = false)
+ {
+ try
+ {
+ if (assembly != null)
+ {
+ Stream manifestResourceStream = assembly.GetManifestResourceStream($"PvZ_Fusion_Translator.Resources.{assetBundlePath}");
+ using (manifestResourceStream)
+ {
+ if (manifestResourceStream == null)
+ {
+ throw new Exception("Stream was null.");
+ }
+
+ byte[] array = new byte[manifestResourceStream.Length];
+ manifestResourceStream.Read(array, 0, array.Length);
+ AssetBundle assetBundle = AssetBundle.LoadFromMemory(array);
+ ArgumentNullException.ThrowIfNull(assetBundle, "assetBundle");
+ if(log)
+ {
+ Log.LogDebug($"AssetBundle {assetBundlePath} has successfully been loaded.");
+ }
+ return assetBundle;
+ }
+ }
+
+ throw new Exception($"AssetBundle {assetBundlePath} was null.");
+ }
+ catch (Exception value)
+ {
+ throw new ArgumentException($"Failed to load {assetBundlePath}. \n{value}");
+ }
+ }
+
+ public static AssetBundle GetAssetBundle(string path)
+ {
+ AssetBundle assetBundle = AssetBundle.LoadFromFile(path);
+ return assetBundle;
+ }
/*public static Dictionary> recipeLinks = new Dictionary>();
@@ -316,12 +417,13 @@ namespace PvZ_Fusion_Translator
}
}*/
+ public static Regex untranslatedRegex = new("\\p{IsCJKUnifiedIdeographs}+");
+
public static bool CheckForUntranslatedText(string text)
{
- Regex regex = new("\\p{IsCJKUnifiedIdeographs}+");
- try
+ try
{
- Match match = regex.Match(text);
+ Match match = untranslatedRegex.Match(text);
return match.Success;
}
catch(Exception e)
@@ -346,6 +448,7 @@ namespace PvZ_Fusion_Translator
confirmButton.clickEvent = new UnityEvent();
confirmButton.clickEvent.AddListener(new Action(() => SwapLocalData()));
+ confirmButton.clickEvent.AddListener(new Action(() => CursorChange.SetDefaultCursor()));
confirmButton.clickEvent.AddListener(new Action(() => GameAPP.UIManager.Pop()));
}
@@ -356,6 +459,7 @@ namespace PvZ_Fusion_Translator
ChangeLanguage(Utils.Language.ToString());
string sourceMsg = "" + (!(Utils.useLocal) ? "Translation Source:\nOnline" : "Translation Source:\nLocal");
OptLanguageBtn_Patch.FlashMessage(OptLanguageBtn_Patch.toggleSlots[2], sourceMsg, 0.1f, false);
+ CursorChange.SetDefaultCursor();
}
public static async Task GetDataFromWeb(string url, bool isLog = true)
@@ -560,8 +664,8 @@ namespace PvZ_Fusion_Translator
// Slovak,
//Polish,
//Turkish,
- //Arabic,
- Romanian,
+ Arabic,
+ Romanian,
LANG_END
}
@@ -578,6 +682,7 @@ namespace PvZ_Fusion_Translator
{ LanguageEnum.Japanese, "日本語"},
{ LanguageEnum.Korean, "한국어"},
{ LanguageEnum.Ukrainian, "українська"},
+ { LanguageEnum.Arabic, "ﺔﻴﺑﺮﻌﻟا"},
{ LanguageEnum.Romanian, "Română"}
};
diff --git a/PvZ Fusion Translator.sln b/PvZ Fusion Translator.sln
index b7a6813..7b38d36 100644
--- a/PvZ Fusion Translator.sln
+++ b/PvZ Fusion Translator.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 17
-VisualStudioVersion = 17.10.35122.118
+# Visual Studio Version 18
+VisualStudioVersion = 18.7.11911.148 stable
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
ProjectSection(SolutionItems) = preProject