AquaDX/AquaMai/Main.cs
2025-02-04 21:52:32 +08:00

53 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Reflection;
using System.Runtime.InteropServices;
using MelonLoader;
namespace AquaMai;
public class AquaMai : MelonMod
{
public const string AQUAMAI_SAY = """
dnSpy / ILSpy resources DLLs
If you see this line in dnSpy / ILSpy, please unpack the DLLs from resources.
""";
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleOutputCP(uint wCodePageID);
private void SetCoreBuildInfo(Assembly coreAssembly)
{
var coreBuildInfo = coreAssembly.GetType("AquaMai.Core.BuildInfo");
var buildInfo = typeof(BuildInfo);
foreach (var field in buildInfo.GetFields())
{
coreBuildInfo.GetField(field.Name)?.SetValue(null, field.GetValue(null));
}
coreBuildInfo.GetField("ModAssembly")?.SetValue(null, MelonAssembly);
}
private static MethodInfo onGUIMethod;
public override void OnInitializeMelon()
{
// Prevent Chinese characters from being garbled
SetConsoleOutputCP(65001);
AssemblyLoader.LoadAssemblies();
var modsAssembly = AssemblyLoader.GetAssembly(AssemblyLoader.AssemblyName.Mods);
var coreAssembly = AssemblyLoader.GetAssembly(AssemblyLoader.AssemblyName.Core);
SetCoreBuildInfo(coreAssembly);
coreAssembly.GetType("AquaMai.Core.Startup")
.GetMethod("Initialize", BindingFlags.Public | BindingFlags.Static)
.Invoke(null, [modsAssembly, HarmonyInstance]);
onGUIMethod = coreAssembly.GetType("AquaMai.Core.Startup")
.GetMethod("OnGUI", BindingFlags.Public | BindingFlags.Static);
}
public override void OnGUI()
{
base.OnGUI();
onGUIMethod?.Invoke(null, []);
}
}