diff --git a/BepInEx/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs b/BepInEx/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs index a4db226..04ac110 100644 --- a/BepInEx/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs +++ b/BepInEx/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs @@ -94,6 +94,14 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects StringStore.TranslateTextTransform(pageScaryPotTransform.Find("Nextpage")); StringStore.TranslateTextTransform(pageScaryPotTransform.Find("LastPage")); } + + Transform pageNewAdvantureLevelTransform = levelTransform.transform.Find("PageNewAdvantureLevel"); + if (pageNewAdvantureLevelTransform != null) + { + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("BackToIndex")); + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("Nextpage")); + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("LastPage")); + } } StringStore.TranslateTextTransform(parentTransform.Find("CameraSize")); diff --git a/MelonLoader/FileLoader.cs b/MelonLoader/FileLoader.cs index 7209d3f..84956b7 100644 --- a/MelonLoader/FileLoader.cs +++ b/MelonLoader/FileLoader.cs @@ -1,6 +1,5 @@ using Il2Cpp; using MelonLoader; -using Newtonsoft.Json.Linq; using PvZ_Fusion_Translator.AssetStore; using PvZ_Fusion_Translator.Patches.OtherManagers; using System.Text.Encodings.Web; @@ -301,12 +300,17 @@ namespace PvZ_Fusion_Translator } string json = File.ReadAllText(jsonFile); - JObject untranslatedStrings = JObject.Parse(json); + var untranslatedStrings = JsonSerializer.Deserialize>(json); if (!untranslatedStrings.ContainsKey(text)) { untranslatedStrings[text] = text; - File.WriteAllText(jsonFile, untranslatedStrings.ToString()); + var options = new JsonSerializerOptions + { + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, + WriteIndented = true + }; + File.WriteAllText(jsonFile, JsonSerializer.Serialize(untranslatedStrings, options)); } } #endif diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs index a0a4216..c7dfb52 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/Advanture_Btn_Patch.cs @@ -94,6 +94,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects StringStore.TranslateTextTransform(pageScaryPotTransform.Find("Nextpage")); StringStore.TranslateTextTransform(pageScaryPotTransform.Find("LastPage")); } + + Transform pageNewAdvantureLevelTransform = levelTransform.transform.Find("PageNewAdvantureLevel"); + if (pageNewAdvantureLevelTransform != null) + { + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("BackToIndex")); + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("Nextpage")); + StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("LastPage")); + } } StringStore.TranslateTextTransform(parentTransform.Find("CameraSize")); diff --git a/MelonLoader/Patches/Managers/AlmanacMgrZombie_Patch.cs b/MelonLoader/Patches/Managers/AlmanacMgrZombie_Patch.cs index 2f1fcdf..4d28793 100644 --- a/MelonLoader/Patches/Managers/AlmanacMgrZombie_Patch.cs +++ b/MelonLoader/Patches/Managers/AlmanacMgrZombie_Patch.cs @@ -2,8 +2,8 @@ using Il2Cpp; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; -using static PvZ_Fusion_Translator.FileLoader; using UnityEngine; +using static PvZ_Fusion_Translator.FileLoader; namespace PvZ_Fusion_Translator.Patches.Managers { @@ -11,8 +11,8 @@ namespace PvZ_Fusion_Translator.Patches.Managers public static partial class AlmanacMgrZombie_Patch { [HarmonyPatch(nameof(AlmanacMgrZombie.InitNameAndInfoFromJson))] - [HarmonyPrefix] - private static bool InitNameAndInfoFromJson(AlmanacMgrZombie __instance) + [HarmonyPostfix] + private static void InitNameAndInfoFromJson(AlmanacMgrZombie __instance) { #if MULTI_LANGUAGE string currentLanguage = Utils.Language.ToString(); @@ -22,11 +22,12 @@ namespace PvZ_Fusion_Translator.Patches.Managers string currentLanguage = "English"; #endif string path = Path.Combine(almanacDir, "ZombieStringsTranslate.json"); + string moddedPath = Path.Combine(almanacDir, "ModdedZombiesTranslate.json"); if (!File.Exists(path)) { Log.LogError($"ZombieStringsTranslate.json file not found at path: {path}"); - return true; + return; } #if OBFUSCATE @@ -77,12 +78,38 @@ namespace PvZ_Fusion_Translator.Patches.Managers component.font = fontAsset; component2.font = fontAsset; component3.font = fontAsset; - - return false; } } - return true; + if (File.Exists(moddedPath)) + { + string moddedJson; + moddedJson = File.ReadAllText(moddedPath); + + AlmanacMgrZombie.ZombieAlmanacData moddedZombieData = JsonUtility.FromJson(moddedJson); + + foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in moddedZombieData.zombies) + { + if (zombieInfo.theZombieType == __instance.theZombieType) + { + component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce; + component.overflowMode = TextOverflowModes.Page; + component2.text = zombieInfo.name; + component2.autoSizeTextContainer = true; + component3.text = Utils.RemoveColorTags(zombieInfo.name); + component3.autoSizeTextContainer = true; + + if (hasAlmanacFont) + component.font = almanacFontAsset; + else + component.font = fontAsset; + component2.font = fontAsset; + component3.font = fontAsset; + } + } + } + + return; } [HarmonyPatch(nameof(AlmanacMgrZombie.OnMouseDown))] diff --git a/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs b/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs index eeb6350..cb26802 100644 --- a/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs +++ b/MelonLoader/Patches/Managers/AlmanacPlantBank_Patch.cs @@ -1,8 +1,6 @@ using HarmonyLib; using Il2Cpp; using Il2CppTMPro; -using MelonLoader; -using MelonLoader.TinyJSON; using PvZ_Fusion_Translator.AssetStore; using UnityEngine; using static PvZ_Fusion_Translator.FileLoader; @@ -24,6 +22,7 @@ namespace PvZ_Fusion_Translator.Patches.Managers string currentLanguage = "English"; #endif string path = Path.Combine(almanacDir, "LawnStringsTranslate.json"); + string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json"); if (!File.Exists(path)) { @@ -61,23 +60,24 @@ namespace PvZ_Fusion_Translator.Patches.Managers TextMeshPro component3 = __instance.plantName.transform.GetChild(0).GetComponent(); TextMeshPro component4 = __instance.cost.GetComponent(); - Il2Cpp.AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); + AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); - foreach (Il2Cpp.AlmanacPlantBank.PlantInfo plantInfo in plantData.plants) + foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants) { if (plantInfo.seedType == __instance.theSeedType) { - component.autoSizeTextContainer = false; - component.text = plantInfo.info + "\n\n" + plantInfo.introduce; + component.autoSizeTextContainer = false; + component.text = plantInfo.info + "\n\n" + plantInfo.introduce; component.overflowMode = TextOverflowModes.Page; - //fix dimensions for cost text - component.rectTransform.offsetMax = new Vector2(component.rectTransform.offsetMax.x, 27.3839f); + // fix dimensions for cost text + component.rectTransform.offsetMax = new Vector2(component.rectTransform.offsetMax.x, 27.3839f); component.rectTransform.offsetMin = new Vector2(component.rectTransform.offsetMin.x, -29.3079f); - component.rectTransform.sizeDelta = new Vector2(component.rectTransform.sizeDelta.x, 50.917f); + component.rectTransform.sizeDelta = new Vector2(component.rectTransform.sizeDelta.x, 50.917f); component.transform.localPosition = new Vector3(component.transform.localPosition.x, component.transform.localPosition.y + 0.15f, component.transform.localPosition.z); + - component2.text = plantInfo.name; + component2.text = plantInfo.name; component2.autoSizeTextContainer = true; component3.text = Utils.RemoveColorTags(plantInfo.name); @@ -85,7 +85,7 @@ namespace PvZ_Fusion_Translator.Patches.Managers component4.text = plantInfo.cost; - if (hasAlmanacFont) + if (hasAlmanacFont) { component.font = almanacFontAsset; component4.font = almanacFontAsset; @@ -100,12 +100,58 @@ namespace PvZ_Fusion_Translator.Patches.Managers } } + if (File.Exists(moddedPath)) + { + string moddedJson; + moddedJson = File.ReadAllText(moddedPath); + + AlmanacPlantBank.PlantData moddedPlantData = JsonUtility.FromJson(moddedJson); + + foreach (AlmanacPlantBank.PlantInfo plantInfo in moddedPlantData.plants) + { + if (plantInfo.seedType == __instance.theSeedType) + { + component.autoSizeTextContainer = false; + component.text = plantInfo.info + "\n\n" + plantInfo.introduce; + component.overflowMode = TextOverflowModes.Page; + + // fix dimensions for cost text + component.rectTransform.offsetMax = new Vector2(component.rectTransform.offsetMax.x, 27.3839f); + component.rectTransform.offsetMin = new Vector2(component.rectTransform.offsetMin.x, -29.3079f); + component.rectTransform.sizeDelta = new Vector2(component.rectTransform.sizeDelta.x, 50.917f); + component.transform.localPosition = new Vector3(component.transform.localPosition.x, component.transform.localPosition.y + 0.15f, component.transform.localPosition.z); + + + component2.text = plantInfo.name; + component2.autoSizeTextContainer = true; + + component3.text = Utils.RemoveColorTags(plantInfo.name); + component3.autoSizeTextContainer = true; + + component4.text = plantInfo.cost; + + if (hasAlmanacFont) + { + component.font = almanacFontAsset; + component4.font = almanacFontAsset; + } + else + { + component.font = fontAsset; + component4.font = fontAsset; + } + component2.font = fontAsset; + component3.font = fontAsset; + } + } + } + return; } - [HarmonyPatch(nameof(AlmanacPlantBank.OnMouseDown))] + [HarmonyPatch(nameof(AlmanacPlantBank.OnMouseDown))] [HarmonyPrefix] - private static bool OnMouseDown(Il2Cpp.AlmanacPlantBank __instance) + private static bool OnMouseDown(AlmanacPlantBank __instance) { TextMeshPro component = __instance.introduce.GetComponent(); if (component != null) @@ -116,15 +162,15 @@ namespace PvZ_Fusion_Translator.Patches.Managers return true; } - [HarmonyPatch(nameof(AlmanacPlantBank.PVPInit))] - [HarmonyPostfix] - private static void PVPInit(Il2Cpp.AlmanacPlantBank __instance) - { - TextMeshPro component = __instance.introduce.GetComponent(); - if (component != null) - { + [HarmonyPatch(nameof(AlmanacPlantBank.PVPInit))] + [HarmonyPostfix] + private static void PVPInit(Il2Cpp.AlmanacPlantBank __instance) + { + TextMeshPro component = __instance.introduce.GetComponent(); + if (component != null) + { component.autoSizeTextContainer = false; - } - } - } + } + } + } } \ No newline at end of file