[RF] AquaMai configuration refactor (#82)

更新了配置文件格式,原有的配置文件将被自动无缝迁移,详情请见新的配置文件中的注释(例外:`SlideJudgeTweak` 不再默认启用)
旧配置文件将被重命名备份,如果更新到此版本遇到 Bug 请联系我们

Updated configuration file schema. The old config file will be migrated automatically and seamlessly. See the comments in the new configuration file for details. (Except for `SlideJudgeTweak` is no longer enabled by default)
Your old configuration file will be renamed as a backup. If you encounter any bug with this version, please contact us.
This commit is contained in:
Menci
2024-11-25 01:25:19 +08:00
committed by GitHub
parent e9ee31b22a
commit 37044dae01
217 changed files with 6051 additions and 3040 deletions

View File

@@ -0,0 +1,74 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{788BC472-59F7-46F6-B760-65C18BA74389}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>AquaMai</RootNamespace>
<AssemblyName>AquaMai</AssemblyName>
<TargetFramework>net472</TargetFramework>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<LangVersion>12</LangVersion>
<NoWarn>414</NoWarn>
<AssemblySearchPaths>$(ProjectDir)../Libs/;$(AssemblySearchPaths)</AssemblySearchPaths>
<OutputPath>$(ProjectDir)../Output/</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>true</Optimize>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>DEBUG</DefineConstants>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../AquaMai.Config.Interfaces/AquaMai.Config.Interfaces.csproj" />
<ProjectReference Include="../AquaMai.Config/AquaMai.Config.csproj" />
<ProjectReference Include="../AquaMai.Core/AquaMai.Core.csproj" />
<ProjectReference Include="../AquaMai.Mods/AquaMai.Mods.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="0Harmony" />
<Reference Include="MelonLoader" />
</ItemGroup>
<UsingTask TaskName="PostBuildPatch" AssemblyFile="$(OutputPath)AquaMai.Build.dll" />
<Target Name="PostBuildPatch" AfterTargets="AfterBuild" Condition=" '$(Configuration)' == 'Release' ">
<PostBuildPatch DllPath="$(OutputPath)$(AssemblyName).dll" />
</Target>
<UsingTask TaskName="GenerateExampleConfig" AssemblyFile="$(OutputPath)AquaMai.Build.dll" />
<Target Name="GenerateExampleConfig" AfterTargets="AfterBuild">
<GenerateExampleConfig DllPath="$(OutputPath)$(AssemblyName).dll" OutputPath="$(OutputPath)" />
</Target>
<ItemGroup>
<EmbeddedResource Include="$(OutputPath)AquaMai.Config.Interfaces.dll">
<LogicalName>AquaMai.Config.Interfaces.dll</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="$(OutputPath)AquaMai.Config.dll">
<LogicalName>AquaMai.Config.dll</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="$(OutputPath)AquaMai.Core.dll">
<LogicalName>AquaMai.Core.dll</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="$(OutputPath)AquaMai.Mods.dll">
<LogicalName>AquaMai.Mods.dll</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Reflection;
namespace AquaMai;
public static class AssemblyLoader
{
public enum AssemblyName
{
ConfigInterfaces,
Config,
Core,
Mods,
}
private static readonly Dictionary<AssemblyName, string> Assemblies = new()
{
[AssemblyName.ConfigInterfaces] = "AquaMai.Config.Interfaces.dll",
[AssemblyName.Config] = "AquaMai.Config.dll",
[AssemblyName.Core] = "AquaMai.Core.dll",
[AssemblyName.Mods] = "AquaMai.Mods.dll",
};
private static readonly Dictionary<AssemblyName, Assembly> LoadedAssemblies = [];
public static Assembly GetAssembly(AssemblyName assemblyName) => LoadedAssemblies[assemblyName];
public static void LoadAssemblies()
{
foreach (var (assemblyName, assemblyFileName) in Assemblies)
{
# if DEBUG
MelonLoader.MelonLogger.Msg($"Loading assembly \"{assemblyFileName}\"...");
# endif
LoadedAssemblies[assemblyName] = LoadAssemblyFromResource(assemblyFileName);
}
}
private static Assembly LoadAssemblyFromResource(string assemblyName)
{
var executingAssembly = Assembly.GetExecutingAssembly();
using var decompressedStream = executingAssembly.GetManifestResourceStream(assemblyName);
if (decompressedStream != null)
{
return AppDomain.CurrentDomain.Load(StreamToBytes(decompressedStream));
}
using var compressedStream = executingAssembly.GetManifestResourceStream($"{assemblyName}.compressed");
if (compressedStream != null)
{
return AppDomain.CurrentDomain.Load(DecompressToBytes(compressedStream));
}
throw new Exception($"Embedded assembly \"{assemblyName}\" not found.");
}
private static byte[] StreamToBytes(Stream stream)
{
if (stream == null)
{
return [];
}
using var memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
private static byte[] DecompressToBytes(Stream stream) => StreamToBytes(new DeflateStream(stream, CompressionMode.Decompress));
}

View File

@@ -0,0 +1,12 @@
namespace AquaMai;
public static class BuildInfo
{
public const string Name = "AquaMai";
public const string Description = "Mod for Sinmai";
public const string Author = "Aza ft. Clansty ft. Menci";
public const string Company = null;
public const string Version = "1.2.2";
public const string DownloadLink = null;
}

39
AquaMai/AquaMai/Main.cs Normal file
View File

@@ -0,0 +1,39 @@
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);
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);
coreAssembly.GetType("AquaMai.Core.Startup")
.GetMethod("Initialize", BindingFlags.Public | BindingFlags.Static)
.Invoke(null, [modsAssembly, HarmonyInstance]);
}
public override void OnGUI()
{
var coreAssembly = AssemblyLoader.GetAssembly(AssemblyLoader.AssemblyName.Core);
coreAssembly.GetType("AquaMai.Core.Startup")
.GetMethod("OnGUI", BindingFlags.Public | BindingFlags.Static)
.Invoke(null, []);
base.OnGUI();
}
}

View File

@@ -0,0 +1,19 @@
using System.Reflection;
using MelonLoader;
[assembly: AssemblyTitle(AquaMai.BuildInfo.Description)]
[assembly: AssemblyDescription(AquaMai.BuildInfo.Description)]
[assembly: AssemblyCompany(AquaMai.BuildInfo.Company)]
[assembly: AssemblyProduct(AquaMai.BuildInfo.Name)]
[assembly: AssemblyCopyright("Created by " + AquaMai.BuildInfo.Author)]
[assembly: AssemblyTrademark(AquaMai.BuildInfo.Company)]
[assembly: AssemblyVersion(AquaMai.BuildInfo.Version)]
[assembly: AssemblyFileVersion(AquaMai.BuildInfo.Version)]
[assembly: MelonInfo(typeof(AquaMai.AquaMai), AquaMai.BuildInfo.Name, AquaMai.BuildInfo.Version, AquaMai.BuildInfo.Author, AquaMai.BuildInfo.DownloadLink)]
[assembly: MelonColor()]
[assembly: HarmonyDontPatchAll]
// Create and Setup a MelonGame Attribute to mark a Melon as Universal or Compatible with specific Games.
// If no MelonGame Attribute is found or any of the Values for any MelonGame Attribute on the Melon is null or empty it will be assumed the Melon is Universal.
// Values for MelonGame Attribute can be found in the Game's app.info file or printed at the top of every log directly beneath the Unity version.
[assembly: MelonGame(null, null)]