odyssey id system fixes + file protection added
This commit is contained in:
parent
14a1681ea9
commit
ba7c713a37
5 changed files with 75 additions and 80 deletions
|
|
@ -41,28 +41,9 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
|
|
||||||
foreach (TextMeshProUGUI txt in __instance.levelInfo)
|
foreach (TextMeshProUGUI txt in __instance.levelInfo)
|
||||||
{
|
{
|
||||||
string regexStr = "第(\\d+)关\n场景:([^\\s]+)\n总波数:(\\d+)波\n特殊环境:([^\\s:]+)\n减伤强度:(\\d+)";
|
txt.text = StringStore.TranslateText(txt.text);
|
||||||
|
|
||||||
Regex regex = new Regex(regexStr);
|
|
||||||
|
|
||||||
if(regex.IsMatch(txt.text))
|
|
||||||
{
|
|
||||||
Match match = regex.Match(txt.text);
|
|
||||||
int groupCount = match.Groups.Count;
|
|
||||||
|
|
||||||
List<string> dynamicParts = [];
|
|
||||||
|
|
||||||
for (int i = 1; i < groupCount; i++)
|
|
||||||
{
|
|
||||||
string groupValue = match.Groups[i].Value;
|
|
||||||
string translatedValue = StringStore.translationString.ContainsKey(groupValue) ? StringStore.translationString[groupValue] : groupValue;
|
|
||||||
dynamicParts.Add(translatedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
txt.text = string.Format(StringStore.translationStringRegex[regexStr], [.. dynamicParts]);
|
|
||||||
txt.font = fontAsset;
|
txt.font = fontAsset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,8 @@
|
||||||
using Il2Cpp;
|
using Il2Cpp;
|
||||||
using Il2CppTMPro;
|
using Il2CppTMPro;
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
using System.Text.Json;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using UnityEngine.UIElements;
|
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
{
|
{
|
||||||
|
|
@ -20,6 +18,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
|
|
||||||
TextMeshProUGUI contentText = contentObject.GetComponent<TextMeshProUGUI>();
|
TextMeshProUGUI contentText = contentObject.GetComponent<TextMeshProUGUI>();
|
||||||
File.WriteAllText(Path.Combine(FileLoader.GetAssetDir(FileLoader.AssetType.Dumps), "changelog.txt"), contentText.text);
|
File.WriteAllText(Path.Combine(FileLoader.GetAssetDir(FileLoader.AssetType.Dumps), "changelog.txt"), contentText.text);
|
||||||
|
|
||||||
|
string stringDir = FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language);
|
||||||
|
string changelogDir = Path.Combine(stringDir, "changelog.txt");
|
||||||
|
|
||||||
|
if (!File.Exists(changelogDir))
|
||||||
|
{
|
||||||
|
File.WriteAllText(changelogDir, contentText.text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
|
|
@ -27,7 +33,10 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
private static void Post_Awake(NoticeMenu __instance)
|
private static void Post_Awake(NoticeMenu __instance)
|
||||||
{
|
{
|
||||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||||
string changelogText = File.ReadAllText(Path.Combine(FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language), "changelog.txt"));
|
string stringDir = FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language);
|
||||||
|
string changelogDir = Path.Combine(stringDir, "changelog.txt");
|
||||||
|
|
||||||
|
string changelogText = File.ReadAllText(changelogDir);
|
||||||
|
|
||||||
GameObject contentObject = __instance.transform.FindChild("Scroll View").GetChild(0).GetChild(0).gameObject; //bc normal Find or FindChild didn't work
|
GameObject contentObject = __instance.transform.FindChild("Scroll View").GetChild(0).GetChild(0).gameObject; //bc normal Find or FindChild didn't work
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,35 +6,35 @@ using static PvZ_Fusion_Translator.Patches.Managers.TravelMgr_Patch;
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
{
|
{
|
||||||
[HarmonyPatch(typeof(TravelBuffOptionButton))]
|
//[HarmonyPatch(typeof(TravelBuffOptionButton))]
|
||||||
public static class TravelBuffOptionButton_Patch
|
//public static class TravelBuffOptionButton_Patch
|
||||||
{
|
//{
|
||||||
[HarmonyPatch(nameof(TravelBuffOptionButton.SetBuff))]
|
// [HarmonyPatch(nameof(TravelBuffOptionButton.SetBuff))]
|
||||||
[HarmonyPostfix]
|
// [HarmonyPostfix]
|
||||||
private static void SetBuff(TravelBuffOptionButton __instance)
|
// private static void SetBuff(TravelBuffOptionButton __instance)
|
||||||
{
|
// {
|
||||||
__instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex];
|
// __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex];
|
||||||
}
|
// }
|
||||||
|
|
||||||
[HarmonyPatch(nameof(TravelBuffOptionButton.Awake))]
|
// [HarmonyPatch(nameof(TravelBuffOptionButton.Awake))]
|
||||||
[HarmonyPostfix]
|
// [HarmonyPostfix]
|
||||||
private static void Awake(TravelBuffOptionButton __instance)
|
// private static void Awake(TravelBuffOptionButton __instance)
|
||||||
{
|
// {
|
||||||
__instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex];
|
// __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex];
|
||||||
}
|
// }
|
||||||
|
|
||||||
[HarmonyPatch(nameof(TravelBuffOptionButton.OnAnimOver))]
|
// [HarmonyPatch(nameof(TravelBuffOptionButton.OnAnimOver))]
|
||||||
[HarmonyPostfix]
|
// [HarmonyPostfix]
|
||||||
private static void OnAnimOver(TravelBuffOptionButton __instance)
|
// private static void OnAnimOver(TravelBuffOptionButton __instance)
|
||||||
{
|
// {
|
||||||
__instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex];
|
// __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex];
|
||||||
}
|
// }
|
||||||
|
|
||||||
[HarmonyPatch(nameof(TravelBuffOptionButton.SetBackground))]
|
// [HarmonyPatch(nameof(TravelBuffOptionButton.SetBackground))]
|
||||||
[HarmonyPostfix]
|
// [HarmonyPostfix]
|
||||||
private static void SetBackground(TravelBuffOptionButton __instance)
|
// private static void SetBackground(TravelBuffOptionButton __instance)
|
||||||
{
|
// {
|
||||||
__instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex];
|
// __instance.introduce.text = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex];
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,44 +4,42 @@ using Il2CppTMPro;
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
using static PvZ_Fusion_Translator.Patches.Managers.TravelMgr_Patch;
|
using static PvZ_Fusion_Translator.Patches.Managers.TravelMgr_Patch;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using MelonLoader;
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
{
|
{
|
||||||
[HarmonyPatch(typeof(TravelLookBuff))]
|
[HarmonyPatch(typeof(TravelLookBuff))]
|
||||||
public static class TravelLookBuff_Patch
|
public static class TravelLookBuff_Patch
|
||||||
{
|
{
|
||||||
private static void TranslateTexts(TravelLookBuff __instance)
|
[HarmonyPatch(nameof(TravelLookBuff.Clear))]
|
||||||
|
[HarmonyPostfix]
|
||||||
|
public static void Post_Clear(TravelLookBuff __instance)
|
||||||
{
|
{
|
||||||
string buffText = translatedTravelBuffs[buffLinks[__instance.buffType]][__instance.buffIndex];
|
__instance.introduce.text = StringStore.TranslateText("无");
|
||||||
|
__instance.set = false;
|
||||||
|
}
|
||||||
|
|
||||||
__instance.introduce.text = buffText;
|
[HarmonyPatch(nameof(TravelLookBuff.OnMouseUpAsButton))]
|
||||||
|
[HarmonyPostfix]
|
||||||
Transform transform = __instance.rectTransform.transform;
|
public static void Post_OnMouseUpAsButton(TravelLookBuff __instance)
|
||||||
var component1 = transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
{
|
||||||
var component2 = transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
foreach (TextMeshProUGUI text in __instance.transform.FindChild("Images").FindChild("Button").GetComponentsInChildren<TextMeshProUGUI>())
|
||||||
|
{
|
||||||
if (component1 != null) component1.text = StringStore.TranslateText(component1.text);
|
text.text = StringStore.TranslateText(text.text);
|
||||||
if (component2 != null) component2.text = StringStore.TranslateText(component2.text);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(nameof(TravelLookBuff.SetBuff))]
|
[HarmonyPatch(nameof(TravelLookBuff.SetBuff))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
private static void SetBuff(TravelLookBuff __instance) => TranslateTexts(__instance);
|
public static void Post_SetBuff(TravelLookBuff __instance)
|
||||||
|
{
|
||||||
|
List<string> buffSet = translatedTravelBuffs[buffLinks[__instance.buffType]];
|
||||||
|
string buffText = (__instance.buffIndex < buffSet.Count) ? buffSet[__instance.buffIndex] : StringStore.TranslateText(__instance.introduce.text);
|
||||||
|
|
||||||
[HarmonyPatch(nameof(TravelLookBuff.OnMouseUpAsButton))]
|
foreach (TextMeshProUGUI text in __instance.transform.FindChild("Images").FindChild("Button").GetComponentsInChildren<TextMeshProUGUI>())
|
||||||
[HarmonyPostfix]
|
{
|
||||||
private static void OnMouseUpAsButton(TravelLookBuff __instance) => TranslateTexts(__instance);
|
text.text = StringStore.TranslateText(text.text);
|
||||||
|
}
|
||||||
[HarmonyPatch(nameof(TravelLookBuff.Clear))]
|
}
|
||||||
[HarmonyPostfix]
|
|
||||||
private static void Clear(TravelLookBuff __instance) => TranslateTexts(__instance);
|
|
||||||
|
|
||||||
[HarmonyPatch(nameof(TravelLookBuff.SetText), new Type[] { typeof(string) })]
|
|
||||||
[HarmonyPostfix]
|
|
||||||
private static void SetText_String(TravelLookBuff __instance) => TranslateTexts(__instance);
|
|
||||||
|
|
||||||
[HarmonyPatch(nameof(TravelLookBuff.SetText), new Type[] { typeof(bool), typeof(int) })]
|
|
||||||
[HarmonyPostfix]
|
|
||||||
private static void SetText_Bool(TravelLookBuff __instance) => TranslateTexts(__instance);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -63,6 +63,13 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
||||||
File.WriteAllText(Path.Combine(dumpDir, "travel_buffs.json"), JsonSerializer.Serialize(dumpedTravelBuffs, options));
|
File.WriteAllText(Path.Combine(dumpDir, "travel_buffs.json"), JsonSerializer.Serialize(dumpedTravelBuffs, options));
|
||||||
|
|
||||||
string stringDir = FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language);
|
string stringDir = FileLoader.GetAssetDir(FileLoader.AssetType.Strings, Utils.Language);
|
||||||
|
string travelBuffDir = Path.Combine(stringDir, "travel_buffs.json");
|
||||||
|
|
||||||
|
if(!File.Exists(travelBuffDir))
|
||||||
|
{
|
||||||
|
File.WriteAllText(travelBuffDir, JsonSerializer.Serialize(dumpedTravelBuffs, options));
|
||||||
|
}
|
||||||
|
|
||||||
string travelBuffs = File.ReadAllText(Path.Combine(stringDir, "travel_buffs.json"));
|
string travelBuffs = File.ReadAllText(Path.Combine(stringDir, "travel_buffs.json"));
|
||||||
|
|
||||||
translatedTravelBuffs = JsonSerializer.Deserialize<Dictionary<string, List<string>>>(travelBuffs);
|
translatedTravelBuffs = JsonSerializer.Deserialize<Dictionary<string, List<string>>>(travelBuffs);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue