MESSY bepinex stuff + some melonloader

This commit is contained in:
SillyStar-Github 2025-05-11 15:51:58 -04:00
parent 0df5c96f4c
commit 7216014ac2
33 changed files with 958 additions and 572 deletions

View file

@ -147,6 +147,8 @@ namespace PvZ_Fusion_Translator__BepInEx_
public class AudioSource_Patch
{
public static void Prefix(UnityEngine.AudioSource __instance)
{
if(Utils.customAudio)
{
if (__instance.clip == null)
return;
@ -161,4 +163,5 @@ namespace PvZ_Fusion_Translator__BepInEx_
}
}
}
}
}

View file

@ -17,7 +17,6 @@ namespace PvZ_Fusion_Translator__BepInEx_.AssetStore
#if MULTI_LANGUAGE
RestoreTextures();
#endif
FileLoader.LoadDefaultTextures();
FileLoader.LoadTextures();
}

View file

@ -67,7 +67,6 @@ public class Core : BasePlugin
public void InitCoroutine()
{
replaceTextureRoutine = MonoInstance.StartCoroutine(TextureStore.ReplaceTexturesCoroutine());
Log.LogDebug("Coroutine Started");
}
public static void ShowToast(string message)
{
@ -111,9 +110,24 @@ public class Core : BasePlugin
private void LoadConfig()
{
string mainCategory = "PvZ_Fusion_Translator";
if(Config.TryGetEntry<bool>(new ConfigDefinition(mainCategory, "DefaultTextures"), out configDefaultTextures) == false)
{
configDefaultTextures = Config.Bind(new ConfigDefinition(mainCategory, "DefaultTextures"), false, new ConfigDescription("Use Default Textures + Translation Textures", new AcceptableValueList<bool>(true, false)));
}
bool defaultTextures = Config.TryGetEntry<bool>(new ConfigDefinition("PvZ_Fusion_Translator", "DefaultTextures"), out configDefaultTextures);
if (Config.TryGetEntry<bool>(new ConfigDefinition(mainCategory, "DefaultAudio"), out configDefaultAudio) == false)
{
configDefaultAudio = Config.Bind(new ConfigDefinition(mainCategory, "DefaultAudio"), false, new ConfigDescription("Use Default Audio", new AcceptableValueList<bool>(true, false)));
}
bool defaultAudio = Config.TryGetEntry<bool>(new ConfigDefinition("PvZ_Fusion_Translator", "DefaultAudio"), out configDefaultAudio);
if (Config.TryGetEntry<string>(new ConfigDefinition(mainCategory, "Language"), out configLanguage) == false)
{
configLanguage = Config.Bind(new ConfigDefinition(mainCategory, "Language"), "English", new ConfigDescription("Load the Game in this Language", new AcceptableValueList<string>("English", "French", "Italian", "German", "Spanish", "Portuguese", "Indonesian", "Vietnamese", "Javanese", "Russian", "Japanese", "Korean")));
}
bool language = Config.TryGetEntry<string>(new ConfigDefinition("PvZ_Fusion_Translator", "Language"), out configLanguage);
}
}

View file

@ -1,4 +1,5 @@
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using BepInEx.Configuration;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using PvZ_Fusion_Translator__BepInEx_.Patches.OtherManagers;
using System;
using System.Collections.Generic;
@ -24,11 +25,21 @@ namespace PvZ_Fusion_Translator__BepInEx_
string languagePath = language.HasValue ? ("Localization" + Path.DirectorySeparatorChar + language.ToString()) : string.Empty;
return Path.Combine(Core.Instance.modsDirectory, languagePath, assetType.ToString());
}
// private static string GetAssetDir(AssetType assetType) => Path.Combine(Core.Instance.modsDirectory, assetType.ToString());
#if MULTI_LANGUAGE
internal static void LoadStrings() => LoadStrings(Utils.Language);
internal static void LoadStrings(Utils.LanguageEnum language)
#else
internal static void LoadStrings(bool isLog = false)
#endif
{
#if MULTI_LANGUAGE
string stringDir = GetAssetDir(AssetType.Strings, Utils.Language);
#else
string stringDir = GetAssetDir(AssetType.Strings);
#endif
if (!Directory.Exists(stringDir))
{
Directory.CreateDirectory(stringDir);
@ -38,23 +49,23 @@ namespace PvZ_Fusion_Translator__BepInEx_
foreach (string filepath in Directory.EnumerateFiles(stringDir, "*.json", SearchOption.AllDirectories))
{
#if OBFUSCATE
#if OBFUSCATE
if (CheckSumStore.IsModified(filepath))
{
Log.LogError("File {0} was modified!" , filepath);
continue;
}
#endif
#endif
string fileName = Path.GetFileNameWithoutExtension(filepath);
StringStore.stringsDict[fileName] = filepath;
#if DEBUG
#if DEBUG
Log.LogInfo("Loading File : " + filepath);
#endif
#endif
string jsonString = File.ReadAllText(filepath);
if (fileName.EndsWith("_strings"))
{
Dictionary<string, string> dictionary = JsonSerializer.Deserialize<Dictionary<string, string>>(jsonString);
Dictionary<string, string> dictionary = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, string>>(jsonString);
foreach (var (key, value) in dictionary)
{
StringStore.translationString[key] = value;
@ -62,7 +73,7 @@ namespace PvZ_Fusion_Translator__BepInEx_
}
else if (fileName.EndsWith("_regexs"))
{
Dictionary<string, string> dictionary = JsonSerializer.Deserialize<Dictionary<string, string>>(jsonString);
Dictionary<string, string> dictionary = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, string>>(jsonString);
foreach (var (key, value) in dictionary)
{
StringStore.translationStringRegex[key] = value;
@ -70,9 +81,7 @@ namespace PvZ_Fusion_Translator__BepInEx_
}
}
SaveStrings();
#if DEBUG
DumpJson();
#endif
}
catch (Exception e)
{
@ -82,17 +91,16 @@ namespace PvZ_Fusion_Translator__BepInEx_
Log.LogInfo("Strings loaded successfully.");
}
public static bool loadDefaultTextures = Core.Instance.configDefaultTextures.Value;
internal static void LoadTextures()
{
ConfigEntry<bool> defaultTextureEntry;
Core.Instance.Config.TryGetEntry<bool>(new ConfigDefinition("PvZ_Fusion_Translator", "DefaultTextures"), out defaultTextureEntry);
// Default or Custom Texturse -> English Textures -> Localized Textures
try
{
if (loadDefaultTextures == true)
{
LoadDefaultTextures();
}
else
if (!defaultTextureEntry.Value)
{
LoadCustomTextures();
}
@ -103,17 +111,24 @@ namespace PvZ_Fusion_Translator__BepInEx_
Log.LogError($"{e.GetType()} {e.Message}");
}
#if MULTI_LANGUAGE
if (Utils.Language != Utils.LanguageEnum.English)
{
LoadLocalizedTextures(Utils.LanguageEnum.English);
}
LoadLocalizedTextures(Utils.Language);
#else
LoadLocalizedTextures();
#endif
Log.LogInfo("Textures loaded successfully.");
}
internal static void LoadLocalizedTextures(Utils.LanguageEnum? language = null)
{
ConfigEntry<bool> defaultTextureEntry;
Core.Instance.Config.TryGetEntry<bool>(new ConfigDefinition("PvZ_Fusion_Translator", "DefaultTextures"), out defaultTextureEntry);
string textureDir = GetAssetDir(AssetType.Textures, language);
if (!Directory.Exists(textureDir))
@ -124,22 +139,22 @@ namespace PvZ_Fusion_Translator__BepInEx_
{
foreach (string filepath in Directory.EnumerateFiles(textureDir, "*.png", SearchOption.AllDirectories))
{
if (filepath.Contains("[Custom Textures]", StringComparison.OrdinalIgnoreCase) && loadDefaultTextures)
if (filepath.Contains("[Custom Textures]", StringComparison.OrdinalIgnoreCase) && defaultTextureEntry.Value)
{
continue;
}
#if OBFUSCATE
#if OBFUSCATE
if (CheckSumStore.IsModified(filepath))
{
Log.LogError("File {0} was modified!" , filepath);
continue;
}
#endif
#endif
#if DEBUG
#if DEBUG
Log.LogDebug("Loading File : " + filepath);
#endif
#endif
Texture2D texture2D = Utils.LoadImage(filepath);
TextureStore.textureDict[Path.GetFileNameWithoutExtension(filepath)] = filepath;
@ -154,6 +169,8 @@ namespace PvZ_Fusion_Translator__BepInEx_
}
internal static void LoadDefaultTextures()
{
if (Core.Instance.configDefaultTextures.Value)
{
string textureDefaultDir = Path.Combine(Core.Instance.modsDirectory, AssetType.Dumps.ToString(), "Default Textures [Do Not Remove]");
if (!Directory.Exists(textureDefaultDir))
@ -164,6 +181,7 @@ namespace PvZ_Fusion_Translator__BepInEx_
{
foreach (string filepath in Directory.EnumerateFiles(textureDefaultDir, "*.png", SearchOption.AllDirectories))
{
#if OBFUSCATE
if (CheckSumStore.IsModified(filepath))
{
@ -183,6 +201,7 @@ namespace PvZ_Fusion_Translator__BepInEx_
Log.LogError(e.GetType() + " " + e.Message);
}
}
}
internal static void LoadCustomTextures()
{
@ -196,13 +215,13 @@ namespace PvZ_Fusion_Translator__BepInEx_
{
foreach (string filepath in Directory.EnumerateFiles(texturePackDir, "*.png", SearchOption.AllDirectories))
{
#if OBFUSCATE
#if OBFUSCATE
if (CheckSumStore.IsModified(filepath))
{
Log.LogError("File {0} was modified!" , filepath);
continue;
}
#endif
#endif
Texture2D texture2D = Utils.LoadImage(filepath);
TextureStore.textureDict[Path.GetFileNameWithoutExtension(filepath)] = filepath;
@ -218,13 +237,17 @@ namespace PvZ_Fusion_Translator__BepInEx_
internal static void SaveStrings()
{
#if MULTI_LANGUAGE
string stringDir = GetAssetDir(AssetType.Strings, Utils.Language);
#else
string stringDir = GetAssetDir(AssetType.Strings);
#endif
if (!Directory.Exists(stringDir))
{
Directory.CreateDirectory(stringDir);
}
string translationStringRegex = JsonSerializer.Serialize(StringStore.translationStringRegex, new JsonSerializerOptions
string translationStringRegex = System.Text.Json.JsonSerializer.Serialize(StringStore.translationStringRegex, new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
@ -232,7 +255,7 @@ namespace PvZ_Fusion_Translator__BepInEx_
File.WriteAllText(Path.Combine(stringDir, "translation_regexs.json"), translationStringRegex);
string translationString = JsonSerializer.Serialize(StringStore.translationString, new JsonSerializerOptions
string translationString = System.Text.Json.JsonSerializer.Serialize(StringStore.translationString, new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
@ -241,7 +264,6 @@ namespace PvZ_Fusion_Translator__BepInEx_
File.WriteAllText(Path.Combine(stringDir, "translation_strings.json"), translationString);
}
#if DEBUG
public static void DumpJson()
{
string dumpDir = GetAssetDir(AssetType.Dumps);
@ -266,9 +288,8 @@ namespace PvZ_Fusion_Translator__BepInEx_
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
}));
}
#endif
#if DEBUG && MELON
#if DEBUG
public static void DumpUntranslatedStrings(string text)
{
string dumpDir = GetAssetDir(AssetType.Dumps);
@ -285,22 +306,30 @@ namespace PvZ_Fusion_Translator__BepInEx_
}
string json = File.ReadAllText(jsonFile);
JObject untranslatedStrings = JObject.Parse(json);
var untranslatedStrings = JsonSerializer.Deserialize<Dictionary<string, string>>(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
#endif
#if MULTI_LANGUAGE
internal static void LoadLanguage()
{
try
{
// Load the language preference as a string and parse it into the enum
string languageName = Core.Instance.configLanguage.Value;
ConfigEntry<string> languageEntry;
Core.Instance.Config.TryGetEntry<string>(new ConfigDefinition("PvZ_Fusion_Translator", "Language"), out languageEntry);
string languageName = languageEntry.Value;
if (Enum.TryParse(languageName, out Utils.LanguageEnum loadedLanguage))
{
Utils.Language = loadedLanguage;
@ -325,10 +354,10 @@ namespace PvZ_Fusion_Translator__BepInEx_
try
{
// Save the current language as a string
if (Core.Instance.Config.TryGetEntry<string>("PvZ_Fusion_Translator", "Language", out var languageEntry))
{
ConfigEntry<string> languageEntry;
Core.Instance.Config.TryGetEntry<string>(new ConfigDefinition("PvZ_Fusion_Translator", "Language"), out languageEntry);
languageEntry.Value = Utils.Language.ToString();
}
Core.Instance.Config.Save();
// Ensure changes are written to the config file
// MelonPreferences.Save();
@ -340,5 +369,6 @@ namespace PvZ_Fusion_Translator__BepInEx_
}
// Log.LogInfo($"Language has been saved: {Utils.Language}");
}
#endif
}
}

View file

@ -1,8 +1,7 @@
using HarmonyLib;
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using System;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.BaseTextObjects
{

View file

@ -1,6 +1,7 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
using UnityEngine.TextCore.Text;

View file

@ -1,6 +1,7 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
using UnityEngine.TextCore.Text;

View file

@ -1,7 +1,6 @@
using System.Text.RegularExpressions;
using System.Collections.Generic;
using HarmonyLib;
using System.Collections.Generic;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine.TextCore.Text;
@ -22,7 +21,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
TextMeshProUGUI upgradeCostText = __instance.transform.FindChild("UpgradeCost").GetComponent<TextMeshProUGUI>();
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
string regexStr = "【([^\\s]+)】\n当前等级:([^\\s]+)\n\n升级条件:\n([^\\s]+)\n\n升级消耗:([^\\s]+)";
string regexStr = "([^\\s]+)\n当前等级:([^\\s]+)\n\n升级条件:\n([^\\s]+)\n\n升级消耗:([^\\s]+)";
Regex regex = new Regex(regexStr);

View file

@ -1,6 +1,7 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
using UnityEngine.TextCore.Text;

View file

@ -1,13 +1,15 @@
using HarmonyLib;
using TMPro;
using System;
using System.Collections.Generic;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using Unity.VisualScripting;
using UnityEngine;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using UnityEngine.UI;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(AbyssMenu))]

View file

@ -1,11 +1,10 @@
using HarmonyLib;
using TMPro;
using System.Collections.Generic;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using Unity.VisualScripting;
using UnityEngine;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
@ -19,15 +18,22 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
string regexStr1 = "第(\\d+)关\n通关用时:(\\d+)分(\\d+)秒\n杀敌数量:(\\d+)\n关卡叶绿素产出:(\\d+)\n极限模式产出:(\\d+)\n非首胜无额外产出\n产出叶绿素总计:(\\d+)\n";
string regexStr2 = "第(\\d+)关\n通关用时:(\\d+)分(\\d+)秒\n杀敌数量:(\\d+)\n关卡叶绿素产出:(\\d+)\n极限模式产出:(\\d+)\n首胜产出:(\\d+)\n剩余小推车数量:(\\d+),获得叶绿素:(\\d+)\n产出叶绿素总计:(\\d+)";
string[] regexStrList = [
"第(\\d+)关\n通关用时:(\\d+)分(\\d+)秒\n杀敌数量:(\\d+)\n关卡叶绿素产出:(\\d+)\n极限模式产出:(\\d+)\n非首胜无额外产出\n产出叶绿素总计:(\\d+)",
"第(\\d+)关\n通关用时:(\\d+)分(\\d+)秒\n杀敌数量:(\\d+)\n关卡叶绿素产出:(\\d+)\n极限模式产出:(\\d+)\n首胜产出:(\\d+)\n剩余小推车数量:(\\d+),获得叶绿素:(\\d+)\n产出叶绿素总计:(\\d+)",
"第(\\d+)关\n通关用时:(\\d+)分(\\d+)秒\n杀敌数量:(\\d+)\n关卡叶绿素产出:(\\d+)\n首胜产出:(\\d+)\n剩余小推车数量:(\\d+),获得叶绿素:(\\d+)\n产出叶绿素总计:(\\d+)",
"第(\\d+)关\n通关用时:(\\d+)分(\\d+)秒\n杀敌数量:(\\d+)\n关卡叶绿素产出:(\\d+)\n困难模式产出:(\\d+)\n首胜产出:(\\d+)\n剩余小推车数量:(\\d+),获得叶绿素:(\\d+)\n产出叶绿素总计:(\\d+)",
"第(\\d+)关\n通关用时:(\\d+)分(\\d+)秒\n杀敌数量:(\\d+)\n关卡叶绿素产出:(\\d+)\n非首胜无额外产出\n产出叶绿素总计:(\\d+)",
"第(\\d+)关\n通关用时:(\\d+)分(\\d+)秒\n杀敌数量:(\\d+)\n关卡叶绿素产出:(\\d+)\n困难模式产出:(\\d+)\n非首胜无额外产出\n产出叶绿素总计:(\\d+)"
];
Regex regex1 = new Regex(regexStr1);
Regex regex2 = new Regex(regexStr2);
if (regex1.IsMatch(__instance.settleInfo.text))
foreach(string regexStr in regexStrList)
{
Match match = regex1.Match(__instance.settleInfo.text);
Regex regex = new Regex(regexStr);
if (regex.IsMatch(__instance.settleInfo.text))
{
Match match = regex.Match(__instance.settleInfo.text);
int groupCount = match.Groups.Count;
List<string> dynamicParts = [];
@ -39,25 +45,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
dynamicParts.Add(translatedValue);
}
__instance.settleInfo.text = string.Format(StringStore.translationStringRegex[regexStr1], [.. dynamicParts]);
__instance.settleInfo.text = string.Format(StringStore.translationStringRegex[regexStr], [.. dynamicParts]);
__instance.settleInfo.font = fontAsset;
}
else if (regex2.IsMatch(__instance.settleInfo.text))
{
Match match = regex2.Match(__instance.settleInfo.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);
}
__instance.settleInfo.text = string.Format(StringStore.translationStringRegex[regexStr2], [.. dynamicParts]);
__instance.settleInfo.font = fontAsset;
}
}
}

View file

@ -5,7 +5,7 @@ using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
using MelonLoader;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
{

View file

@ -1,6 +1,7 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;

View file

@ -1,6 +1,7 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
@ -30,6 +31,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
}
}
}
foreach(TextMeshProUGUI text in __instance.transform.GetComponentsInChildren<TextMeshProUGUI>())
{
text.text = StringStore.TranslateText(text.text);
}
}
}
}

View file

@ -1,22 +1,30 @@
#if MULTI_LANGUAGE
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using HarmonyLib;
using System.Collections.Generic;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;
using BepInEx.Configuration;
using BepInEx;
using UnityEngine.Experimental.Rendering.RenderGraphModule;
using BepInEx.Unity.IL2CPP.Utils;
using Unity.VisualScripting.FullSerializer;
public class OptionButtonData
{
public OptionBtn Button { get; set; }
public Vector3 Position { get; set; }
public Utils.LanguageEnum? Language { get; set; } // Null if it's the "Next" button
public Utils.ToggleEnum? Toggle { get; set; } // Null if it's the "Next" button
public bool IsNextButton { get; set; }
public bool shifted = false;
}
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
@ -24,17 +32,25 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
internal class OptLanguageBtn_Patch
{
public static Dictionary<int, OptionButtonData> LanguageBtnDict = new();
public static Dictionary<int, OptionButtonData> ToggleBtnDict = new();
private static bool buttonsCreated = false;
private static bool togglesCreated = false;
private static OptionBtn cachedTemplateButton;
private static OptionBtn cachedTemplateToggleButton;
private const float startX = 4.3241f + 2.56f;
private const float startY = 2.7769f;
private const float ySpacing = 1.2505f;
private const float toggleStartX = 4.3241f;
private const float toggleStartY = -2.2251f;
private static List<Utils.LanguageEnum> AvailableLanguages;
private static List<Utils.ToggleEnum> AvailableToggles;
private const int LanguagesPerPage = 5;
private static int currentPage = 0;
private static OptionBtn[] buttonSlots = new OptionBtn[6]; // 5 language buttons + 1 next button
private static OptionBtn[] toggleSlots = new OptionBtn[2];
public static void CreateLanguageButtons(OptionBtn templateButton)
{
@ -68,10 +84,43 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
UpdatePage();
}
public static void CreateToggleButtons(OptionBtn templateButton)
{
if (togglesCreated) return;
togglesCreated = true;
cachedTemplateToggleButton = templateButton;
AvailableToggles = Enum.GetValues(typeof(Utils.ToggleEnum))
.Cast<Utils.ToggleEnum>()
.Where(lang => lang != Utils.ToggleEnum.TOGGLE_END)
.ToList();
for (int i = 0; i < 2; i++)
{
var newButton = Object.Instantiate(templateButton, templateButton.transform.parent);
newButton.optionType = 100 + i;
float yPos = toggleStartY - i * ySpacing;
Vector3 pos = new(toggleStartX, yPos);
newButton.transform.position = pos;
toggleSlots[i] = newButton;
ToggleBtnDict[newButton.GetInstanceID()] = new OptionButtonData
{
Button = newButton,
Position = pos
};
}
UpdatePage();
}
private static void UpdatePage()
{
int startIndex = currentPage * LanguagesPerPage;
int langCount = AvailableLanguages.Count;
int toggleCount = (togglesCreated) ? AvailableToggles.Count : 0;
for (int i = 0; i < 5; i++)
{
@ -94,6 +143,30 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
}
}
if (togglesCreated)
{
for (int i = 0; i < 2; i++)
{
var btn = toggleSlots[i];
var data = ToggleBtnDict[btn.GetInstanceID()];
if (i < toggleCount)
{
var toggle = AvailableToggles[i];
data.Toggle = toggle;
data.IsNextButton = false;
btn.gameObject.SetActive(true);
UpdateButtonText(btn, toggle.ToString());
}
else
{
data.Language = null;
data.IsNextButton = false;
btn.gameObject.SetActive(false);
}
}
}
// "Next" button always visible at index 5
var nextBtn = buttonSlots[5];
var nextData = LanguageBtnDict[nextBtn.GetInstanceID()];
@ -134,7 +207,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
}
}
private static void FlashMessage(OptionBtn button, string message)
private static void FlashMessage(OptionBtn button, string message, float yShift = 0.0f)
{
var child = button.transform.GetChild(0);
if (child != null)
@ -143,6 +216,19 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
if (text != null)
{
text.text = message;
OptionButtonData data;
bool isToggle = ToggleBtnDict.TryGetValue(button.GetInstanceID(), out data);
if(isToggle)
{
text.transform.position = new Vector3(text.transform.position.x, text.transform.position.y + (ToggleBtnDict[button.GetInstanceID()].shifted ? 0.0f : yShift), text.transform.position.z);
ToggleBtnDict[button.GetInstanceID()].shifted = true;
}
else
{
text.transform.position = new Vector3(text.transform.position.x, text.transform.position.y + (LanguageBtnDict[button.GetInstanceID()].shifted ? 0.0f : yShift), text.transform.position.z);
LanguageBtnDict[button.GetInstanceID()].shifted = true;
}
}
child.gameObject.SetActive(true);
@ -156,6 +242,30 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
}
}
private static void ToggleCustomAssets(string type)
{
if (type != "Textures" && type != "Audio") return;
if(type == "Textures")
{
Utils.customTextures = !Utils.customTextures;
ConfigEntry<bool> customTexturesEntry;
Core.Instance.Config.TryGetEntry<bool>(new ConfigDefinition("PvZ_Fusion_Translator", "DefaultTextures"), out customTexturesEntry);
customTexturesEntry.BoxedValue = !Utils.customTextures;
TextureStore.Reload();
Coroutine replaceTextureRoutine = Core.MonoInstance.StartCoroutine(TextureStore.ReplaceTexturesCoroutine());
}
if (type == "Audio")
{
Utils.customAudio = !Utils.customAudio;
ConfigEntry<bool> customAudioEntry;
Core.Instance.Config.TryGetEntry<bool>(new ConfigDefinition("PvZ_Fusion_Translator", "DefaultAudio"), out customAudioEntry);
customAudioEntry.BoxedValue = !Utils.customAudio;
}
Core.Instance.Config.Save();
}
[HarmonyPatch(typeof(OptionBtn))]
public static class OptLangBtn_Patch
{
@ -166,7 +276,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
if (!buttonsCreated || cachedTemplateButton == null)
{
buttonsCreated = false;
togglesCreated = false;
CreateLanguageButtons(__instance);
CreateToggleButtons(__instance);
}
}
@ -199,6 +311,20 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
}
}
}
if (ToggleBtnDict.TryGetValue(__instance.GetInstanceID(), out var toggleData))
{
string toggleType = toggleData.Toggle.ToString();
ToggleCustomAssets(toggleType);
if (toggleType == "Textures")
{
FlashMessage(toggleData.Button, "<size=10>Toggled custom textures!", 0.1f);
}
else if (toggleType == "Audio")
{
FlashMessage(toggleData.Button, "<size=10>Toggled custom audio!", 0.1f);
}
}
}
[HarmonyPatch(nameof(OptionBtn.Update))]
@ -209,6 +335,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
{
btnData.Button.transform.position = btnData.Position;
}
if (ToggleBtnDict.TryGetValue(__instance.GetInstanceID(), out var toggleData))
{
toggleData.Button.transform.position = toggleData.Position;
}
}
}
}

View file

@ -1,6 +1,5 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
@ -9,12 +8,17 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
[HarmonyPatch(typeof(MainMenu))]
public class MainMenu_Patch
{
private static bool _warningShown = false;
[HarmonyPostfix]
[HarmonyPatch(nameof(MainMenu.FixedUpdate))]
private static void FixedUpdate(MainMenu __instance)
{
NoticeMenu noticeMenu = NoticeMenu.Instance;
WarningStore.WarningReload(Utils.Language, noticeMenu);
if (_warningShown || NoticeMenu.Instance == null)
return;
WarningStore.WarningReload(Utils.Language, NoticeMenu.Instance);
_warningShown = true;
}
}
}

View file

@ -1,6 +1,5 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects

View file

@ -0,0 +1,20 @@
using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(OtherMenu))]
public static class OtherMenu_Patch
{
[HarmonyPatch(nameof(OtherMenu.UpdateText))]
[HarmonyPostfix]
private static void UpdateText(OtherMenu __instance)
{
__instance.text1 = StringStore.TranslateText(__instance.text1);
__instance.text2 = StringStore.TranslateText(__instance.text2);
}
}
}

View file

@ -14,6 +14,27 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
__instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
}
[HarmonyPatch(nameof(TravelBuffOptionButton.Awake))]
[HarmonyPostfix]
private static void Awake(TravelBuffOptionButton __instance)
{
__instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
}
[HarmonyPatch(nameof(TravelBuffOptionButton.OnAnimOver))]
[HarmonyPostfix]
private static void OnAnimOver(TravelBuffOptionButton __instance)
{
__instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
}
[HarmonyPatch(nameof(TravelBuffOptionButton.SetBackground))]
[HarmonyPostfix]
private static void SetBackground(TravelBuffOptionButton __instance)
{
__instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
}
//[HarmonyPatch(nameof(TravelMenuMgr.SetText))]
//[HarmonyPostfix]
//private static void SetText(TravelMenuMgr __instance)

View file

@ -1,9 +1,8 @@
using HarmonyLib;
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
using System;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
@ -24,6 +23,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
StringStore.TranslateTextTransform(moneyTransform);
}
foreach (TextMeshProUGUI text in __instance.points)
{
text.text = StringStore.TranslateText(text.text);
}
}
[HarmonyPatch(nameof(TravelStore.SetText), new Type[] { typeof(string)})]
@ -34,6 +38,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
text.text = StringStore.TranslateText(text.text);
}
foreach (TextMeshProUGUI text in __instance.points)
{
text.text = StringStore.TranslateText(text.text);
}
}
}
}

View file

@ -15,8 +15,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
#if MULTI_LANGUAGE
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
string difficultyText = StringStore.patchesStore["Difficulty"][Utils.Language.ToString()];
__instance.t.text = string.Format(difficultyText + " {0}", GameAPP.difficulty);
__instance.t.text = StringStore.TranslateText(__instance.t.text);
#else
TMP_FontAsset fontAsset = FontStore.LoadTMPFont();
string difficultyText = StringStore.patchesStore["Difficulty"]["Spanish"];

View file

@ -15,8 +15,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
#if MULTI_LANGUAGE
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
string zombieText = StringStore.patchesStore["Zombies"][Utils.Language.ToString()];
__instance.t.text = string.Format(zombieText + " {0}", Board.Instance.enermyCount);
string zombieText = StringStore.TranslateText(__instance.t.text);
__instance.t.text = zombieText;
#else
TMP_FontAsset fontAsset = FontStore.LoadTMPFont();
string zombieText = StringStore.patchesStore["Zombies"]["Spanish"];

View file

@ -1,10 +1,9 @@
using HarmonyLib;
using System.IO;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using static PvZ_Fusion_Translator__BepInEx_.FileLoader;
using UnityEngine;
using System.IO;
using static PvZ_Fusion_Translator__BepInEx_.FileLoader;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
{
@ -12,8 +11,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.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();
@ -23,18 +22,19 @@ namespace PvZ_Fusion_Translator__BepInEx_.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
if (CheckSumStore.IsModified(path))
{
Log.LogError("File {0} was modified!", path);
return true;
return;
}
#endif
@ -78,12 +78,38 @@ namespace PvZ_Fusion_Translator__BepInEx_.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<AlmanacMgrZombie.ZombieAlmanacData>(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))]

View file

@ -1,7 +1,6 @@
using HarmonyLib;
using TMPro;
using System.IO;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using UnityEngine;
using static PvZ_Fusion_Translator__BepInEx_.FileLoader;
@ -23,6 +22,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
string currentLanguage = "English";
#endif
string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json");
if (!File.Exists(path))
{
@ -70,12 +70,13 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
component.text = plantInfo.info + "\n\n" + plantInfo.introduce;
component.overflowMode = TextOverflowModes.Page;
//fix dimensions for cost text
// 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;
@ -99,6 +100,52 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
}
}
if (File.Exists(moddedPath))
{
string moddedJson;
moddedJson = File.ReadAllText(moddedPath);
AlmanacPlantBank.PlantData moddedPlantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(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;
}

View file

@ -1,8 +1,7 @@
using HarmonyLib;
using System;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using System;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
{

View file

@ -1,5 +1,4 @@
using HarmonyLib;
using System;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers

View file

@ -1,7 +1,6 @@
using System.IO;
using HarmonyLib;
using System.IO;
using System.Collections.Generic;
using HarmonyLib;
using TMPro;
using Newtonsoft.Json;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;

View file

@ -23,6 +23,12 @@
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.*" />
</ItemGroup>
<PropertyGroup>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>$(DefineConstants);MULTI_LANGUAGE;CHEAT;DEBUG</DefineConstants>
</PropertyGroup>
@ -75,26 +81,14 @@
<DefineConstants>$(DefineConstants);MULTI_LANGUAGE;OBFUSCATE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugMulti|AnyCPU'">
<DefineConstants>$(DefineConstants);MULTI_LANGUAGE;OBFUSCATE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseMulti|x64'">
<DefineConstants>$(DefineConstants);MULTI_LANGUAGE;OBFUSCATE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugMulti|x64'">
<DefineConstants>$(DefineConstants);MULTI_LANGUAGE;OBFUSCATE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseMulti|ARM64'">
<DefineConstants>$(DefineConstants);MULTI_LANGUAGE;OBFUSCATE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugMulti|ARM64'">
<DefineConstants>$(DefineConstants);MULTI_LANGUAGE;OBFUSCATE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseOther|AnyCPU'">
<DefineConstants>$(DefineConstants);OTHER;OBFUSCATE</DefineConstants>
</PropertyGroup>
@ -111,6 +105,83 @@
<DefineConstants>$(DefineConstants);MULTI_LANGUAGE;OBFUSCATE;RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssetStore\CheckSumStore.cs" />
<Compile Include="AssetStore\FontStore.cs" />
<Compile Include="AssetStore\StringStore.cs" />
<Compile Include="AssetStore\TextureStore.cs" />
<Compile Include="AssetStore\WarningStore.cs" />
<Compile Include="Core.cs" />
<Compile Include="FileLoader.cs" />
<Compile Include="FontHandler.cs" />
<Compile Include="Log.cs" />
<Compile Include="ModFeatures.cs" />
<Compile Include="AssetStore\AudioStore.cs" />
<Compile Include="Patches\GameObjects\AbyssBagMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\AbyssCheckInBag_Patch.cs" />
<Compile Include="Patches\GameObjects\AbyssStoreMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\AbyssSettlementMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\OtherMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssCheckSellMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssBuffButton_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssLevelEnter_Patch.cs" />
<Compile Include="Patches\GameObjects\BaseMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\CustomLevelEnter_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\SaveMenuBtn_Patch.cs" />
<Compile Include="Patches\GameObjects\MainMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\AbyssGoods_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\DY_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\LanternUmbrella_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\MagnetBox_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\MagnetInterface_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\Money_Patch.cs" />
<Compile Include="Patches\GameObjects\AbyssDevelopMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\AbyssMenu2_Patch.cs" />
<Compile Include="Patches\GameObjects\AbyssMenu_Patch.cs" />
<Compile Include="Patches\Managers\CustomLevelShower_Patch.cs" />
<Compile Include="Patches\Managers\SaveMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TravelBuffOptionButton_Patch.cs" />
<Compile Include="Patches\OtherManagers\AchievementClip_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\Advanture_Btn_Patch.cs" />
<Compile Include="Patches\Managers\AlmanacMgrZombie_Patch.cs" />
<Compile Include="Patches\Managers\AlmanacPlantBank_Patch.cs" />
<Compile Include="Patches\Managers\DifficultyMgr_Patch.cs" />
<Compile Include="Patches\Managers\EndlessMgr_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\EveBtn_Patch.cs" />
<Compile Include="Patches\GameObjects\GardenPlant_Patch.cs" />
<Compile Include="Patches\GameObjects\Close_Patch.cs" />
<Compile Include="Patches\GameObjects\CustomSettings_Patch.cs" />
<Compile Include="Patches\GameObjects\CustomSun_Patch.cs" />
<Compile Include="Patches\OtherManagers\GardenUI_Patch.cs" />
<Compile Include="Patches\GameObjects\NoticePauseMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\InGameBtn_Patch.cs" />
<Compile Include="Patches\BaseTextObjects\InGameText_Patch.cs" />
<Compile Include="Patches\Managers\InGameUIMgr_Patch.cs" />
<Compile Include="Patches\Managers\IZEMgr_Patch.cs" />
<Compile Include="Patches\OtherManagers\MenuText_Patch.cs" />
<Compile Include="Patches\Managers\OppositeBuffManager_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\OptionBtn_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\OptLanguageBtn_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\PauseMenu_Btn_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\PVPPotBtn_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\SelectYourPlants_Patch.cs" />
<Compile Include="Patches\BaseTextObjects\TextMeshPro_Patch.cs" />
<Compile Include="Patches\BaseTextObjects\TextMeshProUGUI_Patch.cs" />
<Compile Include="Patches\BaseTextObjects\TMP_InputField_Patch.cs" />
<Compile Include="Patches\Managers\TravelBuffMgr_Patch.cs" />
<Compile Include="Patches\GameObjects\TravelBuff_Patch.cs" />
<Compile Include="Patches\GameObjects\TravelRefresh_Patch.cs" />
<Compile Include="Patches\GameObjects\TravelStore_Patch.cs" />
<Compile Include="Patches\GameObjects\UIDifficulty_Patch.cs" />
<Compile Include="Patches\GameObjects\UIZombieNum_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\Plant_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\PlayerName_Patch.cs" />
<Compile Include="Patches\OtherManagers\ThanksMenu_Patch.cs" />
<Compile Include="Patches\Managers\UIMgr_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\Zombie_Patch.cs" />
<Compile Include="Utils.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>$(GamePath)\BepInEx\core\0Harmony.dll</HintPath>

View file

@ -1,8 +1,11 @@
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using BepInEx;
using BepInEx.Configuration;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using Unity.VisualScripting.FullSerializer;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
@ -20,7 +23,7 @@ namespace PvZ_Fusion_Translator__BepInEx_
{
ImageConversion.LoadImage(ogTexture, File.ReadAllBytes(texturePath));
Log.LogDebug("OK! Replaced Texture " + ogTexture.name);
Core.Log.LogDebug("OK! Replaced Texture " + ogTexture.name);
ogTexture.name = "replaced_" + ogTexture.name;
return true;
@ -77,6 +80,7 @@ namespace PvZ_Fusion_Translator__BepInEx_
return Regex.Replace(text, @"<color=[^>]+>", "");
}
#if MULTI_LANGUAGE
internal static void ChangeLanguage(string language)
{
OldLanguage = Language;
@ -97,9 +101,19 @@ namespace PvZ_Fusion_Translator__BepInEx_
TextureStore.Reload();
FileLoader.SaveLanguage();
}
#endif
#if MULTI_LANGUAGE
public static Utils.LanguageEnum OldLanguage;
#endif
public static Utils.LanguageEnum Language;
public static string mainCategory = "PvZ_Fusion_Translator";
public static bool customTextures = !Core.Instance.configDefaultTextures.Value;
public static bool customAudio = !Core.Instance.configDefaultAudio.Value;
public enum LanguageEnum
{
// first column
@ -121,8 +135,18 @@ namespace PvZ_Fusion_Translator__BepInEx_
// third column
// Ukrainian,
// Slovak,
Polish,
Hungarian,
Arabic,
LANG_END
}
public enum ToggleEnum
{
Textures,
Audio,
TOGGLE_END
}
}
}

View file

@ -23,17 +23,9 @@ namespace PvZ_Fusion_Translator.AssetStore
#endif
public static void Init()
{
bool loadCustomAudio = MelonPreferences.GetEntryValue<bool>("PvZ_Fusion_Translator", "DefaultAudio");
if (loadCustomAudio)
{
return;
}
else
{
LoadAudios();
}
}
public static void LoadAudios()
{
if (!Directory.Exists(customAudioPath))
@ -157,6 +149,8 @@ namespace PvZ_Fusion_Translator.AssetStore
public static void AudioPlayPatch(AudioSource __instance)
{
if(Utils.customAudio)
{
if (__instance.clip == null)
return;
@ -178,4 +172,5 @@ namespace PvZ_Fusion_Translator.AssetStore
#endif
}
}
}
}

View file

@ -16,7 +16,6 @@ namespace PvZ_Fusion_Translator.AssetStore
#if MULTI_LANGUAGE
RestoreTextures();
#endif
FileLoader.LoadDefaultTextures();
FileLoader.LoadTextures();
}

View file

@ -96,11 +96,7 @@ namespace PvZ_Fusion_Translator
try
{
if (loadDefaultTextures == true)
{
LoadDefaultTextures();
}
else
if (Utils.customTextures)
{
LoadCustomTextures();
}
@ -167,7 +163,7 @@ namespace PvZ_Fusion_Translator
internal static void LoadDefaultTextures()
{
if(Utils.customTextures)
if(Utils.customTextures == false)
{
string textureDefaultDir = Path.Combine(Core.Instance.modsDirectory, AssetType.Dumps.ToString(), "Default Textures [Do Not Remove]");
if (!Directory.Exists(textureDefaultDir))

View file

@ -240,8 +240,10 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
if(type == "Textures")
{
Utils.customTextures = (Utils.customTextures) ? false : true;
Utils.customTextures = !Utils.customTextures;
MelonPreferences.SetEntryValue<bool>("PvZ_Fusion_Translator", "DefaultTextures", !Utils.customTextures);
TextureStore.Reload();
object replaceTextureRoutine = MelonCoroutines.Start(TextureStore.ReplaceTexturesCoroutine());
}
if (type == "Audio")
@ -304,11 +306,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
ToggleCustomAssets(toggleType);
if (toggleType == "Textures")
{
FlashMessage(toggleData.Button, "<size=10>Toggled custom textures! (Restart game to apply changes.)", 0.1f);
FlashMessage(toggleData.Button, "<size=10>Toggled custom textures!", 0.1f);
}
else if (toggleType == "Audio")
{
FlashMessage(toggleData.Button, "<size=10>Toggled custom audio! (Restart game to apply changes.)", 0.1f);
FlashMessage(toggleData.Button, "<size=10>Toggled custom audio!", 0.1f);
}
}
}