[+] Mark supported game versions with attributes
Build AquaMai / build (push) Has been cancelled Details

pull/78/head
Clansty 2024-10-27 23:34:41 +08:00
parent 6bb2685e03
commit ff2ed50dea
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134
9 changed files with 54 additions and 23 deletions

View File

@ -49,7 +49,7 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: AquaMai
path: AquaMai\Output\AquaMai.dll
path: AquaMai\Output\Upload
- name: Send to Telegram
if: github.event_name != 'pull_request'

View File

@ -0,0 +1,9 @@
using System;
namespace AquaMai.Attributes;
public class GameVersionAttribute(uint minVersion = 0, uint maxVersion = 0) : Attribute
{
public uint MinVersion { get; } = minVersion;
public uint MaxVersion { get; } = maxVersion;
}

View File

@ -1,9 +1,11 @@
using HarmonyLib;
using AquaMai.Attributes;
using HarmonyLib;
using MAI2System;
using Manager;
namespace AquaMai.Cheat
{
[GameVersion(24000)]
public class UnlockUtage
{
[HarmonyPrefix]

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using AquaMai.Attributes;
using HarmonyLib;
using MAI2.Util;
using Manager;
@ -9,6 +10,7 @@ using UnityEngine;
namespace AquaMai.Fix;
[GameVersion(23000)]
public class ExtendNotesPool
{
[HarmonyPostfix]

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Reflection;
using AquaMai.Attributes;
using HarmonyLib;
using Manager;
using MelonLoader;
@ -7,6 +8,7 @@ using Monitor;
namespace AquaMai.Fix;
[GameVersion(23000)]
public class FixConnSlide
{
/* Patch bug:

View File

@ -1,4 +1,5 @@
using HarmonyLib;
using AquaMai.Attributes;
using HarmonyLib;
using MAI2.Util;
using Manager;
using Monitor;
@ -7,6 +8,7 @@ using UnityEngine;
namespace AquaMai.Fix;
[GameVersion(24000)]
public class FixLevelDisplay
{
[HarmonyPostfix]

View File

@ -3,6 +3,7 @@ using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using AquaMai.Attributes;
using AquaMai.Fix;
using AquaMai.Helpers;
using AquaMai.Resources;
@ -29,15 +30,33 @@ namespace AquaMai
public static Config AppConfig { get; private set; }
private static bool _hasErrors;
private void Patch(Type type)
private void Patch(Type type, bool isNested = false)
{
var versionAttr = type.GetCustomAttribute<GameVersionAttribute>();
var compatible = true;
if (versionAttr != null)
{
if (versionAttr.MinVersion > 0 && versionAttr.MinVersion > GameInfo.GameVersion) compatible = false;
if (versionAttr.MaxVersion > 0 && versionAttr.MaxVersion < GameInfo.GameVersion) compatible = false;
}
if (!compatible)
{
if (!isNested)
{
MelonLogger.Warning($"> Skipping incompatible patch: {type}");
}
return;
}
MelonLogger.Msg($"> Patching {type}");
try
{
HarmonyInstance.PatchAll(type);
foreach (var nested in type.GetNestedTypes())
{
Patch(nested);
Patch(nested, true);
}
var customMethod = type.GetMethod("DoCustomPatch", BindingFlags.Public | BindingFlags.Static);
@ -143,15 +162,12 @@ namespace AquaMai
Patch(typeof(FixCharaCrash));
Patch(typeof(BasicFix));
Patch(typeof(DisableReboot));
if (GameInfo.GameVersion >= 23000)
Patch(typeof(ExtendNotesPool));
Patch(typeof(ExtendNotesPool));
Patch(typeof(FixCheckAuth));
Patch(typeof(DebugFeature));
if (GameInfo.GameVersion >= 23000)
Patch(typeof(FixConnSlide));
Patch(typeof(FixConnSlide));
Patch(typeof(FixSlideAutoPlay)); // Rename: SlideAutoPlayTweak -> FixSlideAutoPlay, 不过这个应该无副作用所以不需要改配置文件
if (GameInfo.GameVersion >= 24000)
Patch(typeof(FixLevelDisplay));
Patch(typeof(FixLevelDisplay));
// UX
Patch(typeof(CustomVersionString));
Patch(typeof(CustomPlaceName));

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using AquaMai.Attributes;
using AquaMai.Helpers;
using HarmonyLib;
using Mai2.Mai2Cue;
@ -86,13 +87,8 @@ public class QuickSkip
}
}
public static void DoCustomPatch(HarmonyLib.Harmony h)
{
if (GameInfo.GameVersion < 23000) return;
h.PatchAll(typeof(FestivalAndLaterQuickRetryPatch));
}
private class FestivalAndLaterQuickRetryPatch
[GameVersion(23000)]
public class FestivalAndLaterQuickRetryPatch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(QuickRetry), "IsQuickRetryEnable")]

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using AquaMai.Attributes;
using AquaMai.Helpers;
using AquaMai.Resources;
using HarmonyLib;
@ -13,6 +14,7 @@ using UnityEngine;
namespace AquaMai.Utils;
[GameVersion(23500)]
public class SelectionDetail
{
private static readonly Window[] window = new Window[2];