Split into multiple files

This commit is contained in:
Emik 2026-10-21 20:39:06 +02:00
parent c6851be43e
commit 1bea15968d
Signed by: emik
GPG key ID: 6B0CD72A5E503BDF
4 changed files with 191 additions and 131 deletions

View file

@ -1,25 +1,4 @@
global using UnityEngine;
#if MELONLOADER
global using MelonLoader;
global using MelonLoader.Logging;
global using MelonLoader.Utils;
global using Il2Cpp;
global using Il2CppAlmanacData;
global using Il2CppCore;
global using Il2CppGameLevel; // ReSharper disable once RedundantUsingDirective.Global
global using Il2CppGameLevel.Abyss;
global using Il2CppGameLevel.EventNodes;
global using Il2CppGameLevel.RogueShooting;
global using Il2CppPVPScaryPot;
global using Il2CppRhythmGame;
global using Il2CppRhythmGameEditor;
global using Il2CppTMPro;
global using Il2CppZenGarden;
global using AudioImportLibAPI = AudioImportLib.API;
global using Il2CppAlmanacDataClass = Il2CppAlmanacData.AlmanacData;
global using Il2CppLevelData = Il2Cpp.LevelData;
global using Il2CppPlantInfo = Il2CppAlmanacData.PlantInfo;
#elif BEPINEX
#if BEPINEX
global using AlmanacData;
global using BepInEx;
global using BepInEx.Configuration;
@ -27,7 +6,7 @@ global using BepInEx.Logging;
global using BepInEx.Unity.IL2CPP;
global using BepInEx.Unity.IL2CPP.Utils;
global using Core;
global using GameLevel;
global using GameLevel; // ReSharper disable once RedundantUsingDirective.Global
global using GameLevel.Abyss;
global using GameLevel.EventNodes;
global using GameLevel.RogueShooting;
@ -35,37 +14,21 @@ global using PVPScaryPot;
global using RhythmGame;
global using RhythmGameEditor;
global using TMPro;
global using UnityEngine;
global using ZenGarden;
global using AudioImportLibAPI = AudioImportLib.BepInEx.API;
global using Il2CppAlmanacDataClass = AlmanacData.AlmanacData;
global using Il2CppLevelData = LevelData;
global using Il2CppPlantInfo = AlmanacData.PlantInfo;
#endif
using PvZ_Fusion_Translator.AssetStore;
using PvZ_Fusion_Translator.Patches.Managers;
using PvZ_Fusion_Translator.Patches.Modes.Super_Editor;
#if MELONLOADER
[assembly:
MelonGame("LanPiaoPiao", "PlantsVsZombiesRH"),
MelonInfo(
typeof(PvZ_Fusion_Translator.Core),
"PvZ Fusion Translator",
"231.0.0",
"dynaslash / arifrios1st / lancerx0 / JustNull / Dakosha / Mamoru-kun / cassidy / Teyliu / Emik"
)]
#endif
namespace PvZ_Fusion_Translator;
#pragma warning disable CA1822 // ReSharper disable once ClassNeverInstantiated.Global
#if MELONLOADER
public class Core : MelonMod
#elif BEPINEX
[BepInPlugin("PVZFusionTranslator_BepInEx", "PvZ Fusion Translator", "3.1.1"), BepInProcess("PlantsVsZombiesRH.exe")]
public class Core : BasePlugin
#endif
{
#if BEPINEX
public sealed class UnityCoroutineHelper : MonoBehaviour
{
// ReSharper disable once MemberHidesStaticFromOuterClass
@ -73,23 +36,13 @@ public class Core : BasePlugin
public void Awake() => Instance = this;
}
#endif
public static string ModDirectory =>
#if MELONLOADER
Path.Combine(MelonEnvironment.ModsDirectory, "PvZ_Fusion_Translator");
#elif BEPINEX
Path.Combine(Paths.PluginPath, "PvZ_Fusion_Translator");
#endif
public static string ModDirectory => Path.Combine(Paths.PluginPath, "PvZ_Fusion_Translator");
public static bool IsInitialized { get; set; }
public static Core Instance { get; private set; }
#if MELONLOADER
public MelonPreferences_Entry<bool> ConfigDefaultAudio, ConfigDefaultTextures, ConfigUseLocal;
public MelonPreferences_Entry<string> ConfigLanguage;
private object _replaceTextureRoutine;
#elif BEPINEX
public static MonoBehaviour MonoInstance { get; private set; }
public ConfigEntry<bool> ConfigDefaultAudio, ConfigDefaultTextures, ConfigUseLocal;
@ -99,22 +52,15 @@ public class Core : BasePlugin
public new static ManualLogSource Log { get; private set; }
private Coroutine _replaceTextureRoutine;
#endif
private static DateTime? s_dtStartToast;
private static string s_toastText;
#if MELONLOADER
public static object Coroutine(System.Collections.IEnumerator enumerator) =>
MelonCoroutines.Start(enumerator);
#elif BEPINEX
public static Coroutine Coroutine(System.Collections.IEnumerator enumerator) =>
MonoInstance.StartCoroutine(enumerator);
#endif
#if MELONLOADER
public override void OnInitializeMelon()
#elif BEPINEX
public override void Load()
#endif
{
Instance = this;
LoadConfig();
@ -127,31 +73,13 @@ public class Core : BasePlugin
StringStore.Init();
AudioStore.Init();
FontStore.Init();
#if MELONLOADER
base.OnInitializeMelon();
#elif BEPINEX
Log = base.Log;
Utils.RegisterPlantIndices();
MonoInstance = AddComponent<UnityCoroutineHelper>();
HarmonyLib.Harmony.CreateAndPatchAll(System.Reflection.Assembly.GetExecutingAssembly());
#endif
IsInitialized = true;
}
#if MELONLOADER
public override void OnLateInitializeMelon()
{
FileLoader.LoadTravelBuffs();
Utils.RegisterPlantIndices();
}
public override void OnDeinitializeMelon()
{
MelonCoroutines.Stop(_replaceTextureRoutine);
if (ModFeatures.IsMultiLanguage)
FileLoader.SaveLanguage();
}
#elif BEPINEX
public override bool Unload()
{
if (_replaceTextureRoutine != null)
@ -163,17 +91,14 @@ public class Core : BasePlugin
FileLoader.SaveLanguage();
return true;
}
#endif
public static void ShowToast(string message)
{
s_toastText = message;
s_dtStartToast = new(DateTime.Now.Ticks);
}
#if MELONLOADER
public override void OnLateUpdate()
#elif BEPINEX
public void OnUpdate()
#endif
{
if (ModFeatures.IsDebug)
ModFeatures.OnLateUpdate();
@ -194,11 +119,8 @@ public class Core : BasePlugin
if (CustomLevelMenu_Patch.RequestTimer < 0)
CustomLevelMenu_Patch.RequestTimer = 0;
}
#if MELONLOADER
public override void OnGUI()
#elif BEPINEX
public void OnGUI()
#endif
{
if (!ModFeatures.IsDebug)
return;
@ -213,19 +135,7 @@ public class Core : BasePlugin
if (timeSpan > t)
s_dtStartToast = null;
}
#if MELONLOADER
private void LoadConfig()
{
var category = MelonPreferences.CreateCategory("PvZ_Fusion_Translator", "Fusion Translator Settings");
ConfigDefaultTextures = category.CreateEntry("DefaultTextures", false);
ConfigDefaultAudio = category.CreateEntry("DefaultAudio", false);
ConfigUseLocal = category.CreateEntry("UseLocal", false);
ConfigLanguage = category.CreateEntry("Language", "English");
MelonPreferences.Save();
}
#elif BEPINEX
private void LoadConfig()
{
const string MainCategory = "PvZ_Fusion_Translator";
@ -272,5 +182,5 @@ public class Core : BasePlugin
Debug.Assert(Config.TryGetEntry(new(MainCategory, "Language"), out ConfigLanguage));
}
#endif
}
#endif

146
Source/Core.MelonLoader.cs Normal file
View file

@ -0,0 +1,146 @@
#if MELONLOADER
global using MelonLoader;
global using MelonLoader.Logging;
global using MelonLoader.Utils;
global using Il2Cpp;
global using Il2CppAlmanacData;
global using Il2CppCore;
global using Il2CppGameLevel; // ReSharper disable once RedundantUsingDirective.Global
global using Il2CppGameLevel.Abyss;
global using Il2CppGameLevel.EventNodes;
global using Il2CppGameLevel.RogueShooting;
global using Il2CppPVPScaryPot;
global using Il2CppRhythmGame;
global using Il2CppRhythmGameEditor;
global using Il2CppTMPro;
global using Il2CppZenGarden;
global using AudioImportLibAPI = AudioImportLib.API;
global using Il2CppAlmanacDataClass = Il2CppAlmanacData.AlmanacData;
global using Il2CppLevelData = Il2Cpp.LevelData;
global using Il2CppPlantInfo = Il2CppAlmanacData.PlantInfo;
global using UnityEngine;
using PvZ_Fusion_Translator.AssetStore;
using PvZ_Fusion_Translator.Patches.Managers;
using PvZ_Fusion_Translator.Patches.Modes.Super_Editor;
[assembly:
MelonGame("LanPiaoPiao", "PlantsVsZombiesRH"),
MelonInfo(
typeof(PvZ_Fusion_Translator.Core),
"PvZ Fusion Translator",
"231.0.0",
"dynaslash / arifrios1st / lancerx0 / JustNull / Dakosha / Mamoru-kun / cassidy / Teyliu / Emik"
)]
namespace PvZ_Fusion_Translator;
#pragma warning disable CA1822 // ReSharper disable once ClassNeverInstantiated.Global
public class Core : MelonMod
{
public static string ModDirectory =>
Path.Combine(MelonEnvironment.ModsDirectory, "PvZ_Fusion_Translator");
public static bool IsInitialized { get; set; }
public static Core Instance { get; private set; }
public MelonPreferences_Entry<bool> ConfigDefaultAudio, ConfigDefaultTextures, ConfigUseLocal;
public MelonPreferences_Entry<string> ConfigLanguage;
private object _replaceTextureRoutine;
private static DateTime? s_dtStartToast;
private static string s_toastText;
public static object Coroutine(System.Collections.IEnumerator enumerator) =>
MelonCoroutines.Start(enumerator);
public override void OnInitializeMelon()
{
Instance = this;
LoadConfig();
if (ModFeatures.IsMultiLanguage)
FileLoader.LoadLanguage();
_replaceTextureRoutine = Coroutine(TextureStore.ReplaceTexturesCoroutine());
TextureStore.Init();
StringStore.Init();
AudioStore.Init();
FontStore.Init();
base.OnInitializeMelon();
IsInitialized = true;
}
public override void OnLateInitializeMelon()
{
FileLoader.LoadTravelBuffs();
Utils.RegisterPlantIndices();
}
public override void OnDeinitializeMelon()
{
MelonCoroutines.Stop(_replaceTextureRoutine);
if (ModFeatures.IsMultiLanguage)
FileLoader.SaveLanguage();
}
public static void ShowToast(string message)
{
s_toastText = message;
s_dtStartToast = new(DateTime.Now.Ticks);
}
public override void OnLateUpdate()
{
if (ModFeatures.IsDebug)
ModFeatures.OnLateUpdate();
if (Input.GetKeyDown(KeyCode.Insert))
Utils.OpenSaveDirectory();
if (Input.GetKeyDown(KeyCode.PageUp))
Utils.OpenOnlineAlmanac();
TowerManager_Patch.UpdateText();
if (CustomLevelMenu_Patch.RequestTimer <= 0)
return;
CustomLevelMenu_Patch.RequestTimer -= Time.deltaTime;
if (CustomLevelMenu_Patch.RequestTimer < 0)
CustomLevelMenu_Patch.RequestTimer = 0;
}
public override void OnGUI()
{
if (!ModFeatures.IsDebug)
return;
if (s_dtStartToast is null)
return;
GUI.Button(new(10, 10, 200, 20), $"\n{s_toastText}\n");
var timeSpan = DateTime.Now - s_dtStartToast;
TimeSpan t = new(0, 0, 0, 2);
if (timeSpan > t)
s_dtStartToast = null;
}
private void LoadConfig()
{
var category = MelonPreferences.CreateCategory("PvZ_Fusion_Translator", "Fusion Translator Settings");
ConfigDefaultTextures = category.CreateEntry("DefaultTextures", false);
ConfigDefaultAudio = category.CreateEntry("DefaultAudio", false);
ConfigUseLocal = category.CreateEntry("UseLocal", false);
ConfigLanguage = category.CreateEntry("Language", "English");
MelonPreferences.Save();
}
}
#endif

30
Source/Log.BepInEx.cs Normal file
View file

@ -0,0 +1,30 @@
#if BEPINEX
namespace PvZ_Fusion_Translator;
internal static class Log
{
public static void LogDebug(object txt) => Core.Log.LogDebug(txt);
public static void LogDebug(string txt) => Core.Log.LogDebug(txt);
public static void LogDebug(string txt, params object[] args) => Core.Log.LogDebug(string.Format(txt, args));
public static void LogInfo(object txt) => Core.Log.LogInfo(txt);
public static void LogInfo(string txt) => Core.Log.LogInfo(txt);
public static void LogInfo(string txt, params object[] args) => Core.Log.LogInfo(string.Format(txt, args));
public static void LogWarning(object txt) => Core.Log.LogWarning(txt);
public static void LogWarning(string txt) => Core.Log.LogWarning(txt);
public static void LogWarning(string txt, params object[] args) => Core.Log.LogWarning(string.Format(txt, args));
public static void LogError(object txt) => Core.Log.LogError(txt);
public static void LogError(string txt) => Core.Log.LogError(txt);
public static void LogError(string txt, params object[] args) => Core.Log.LogError(string.Format(txt, args));
}
#endif

View file

@ -1,11 +1,10 @@
// ReSharper disable once RedundantUsingDirective
#if MELONLOADER
using System.Drawing;
namespace PvZ_Fusion_Translator;
internal static class Log
{
#if MELONLOADER
public static void LogDebug(object txt) => Melon<Core>.Logger.Msg(ColorARGB.Gray, txt);
public static void LogDebug(string txt) => Melon<Core>.Logger.Msg(ColorARGB.Gray, txt);
@ -31,30 +30,5 @@ internal static class Log
public static void LogError(string txt) => Melon<Core>.Logger.Error(txt);
public static void LogError(string txt, params object[] args) => Melon<Core>.Logger.Error(txt, args);
#elif BEPINEX
public static void LogDebug(object txt) => Core.Log.LogDebug(txt);
public static void LogDebug(string txt) => Core.Log.LogDebug(txt);
public static void LogDebug(string txt, params object[] args) => Core.Log.LogDebug(string.Format(txt, args));
public static void LogInfo(object txt) => Core.Log.LogInfo(txt);
public static void LogInfo(string txt) => Core.Log.LogInfo(txt);
public static void LogInfo(string txt, params object[] args) => Core.Log.LogInfo(string.Format(txt, args));
public static void LogWarning(object txt) => Core.Log.LogWarning(txt);
public static void LogWarning(string txt) => Core.Log.LogWarning(txt);
public static void LogWarning(string txt, params object[] args) => Core.Log.LogWarning(string.Format(txt, args));
public static void LogError(object txt) => Core.Log.LogError(txt);
public static void LogError(string txt) => Core.Log.LogError(txt);
public static void LogError(string txt, params object[] args) => Core.Log.LogError(string.Format(txt, args));
#endif
}
#endif