diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json deleted file mode 100644 index b6554f30..00000000 --- a/.config/dotnet-tools.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": 1, - "isRoot": true, - "tools": { - "cake.tool": { - "version": "5.0.0", - "commands": [ - "dotnet-cake" - ], - "rollForward": false - } - } -} \ No newline at end of file diff --git a/AquaMai.Config/Migration/ConfigMigrationManager.cs b/AquaMai.Config/Migration/ConfigMigrationManager.cs index 3d5480a8..95a069e1 100644 --- a/AquaMai.Config/Migration/ConfigMigrationManager.cs +++ b/AquaMai.Config/Migration/ConfigMigrationManager.cs @@ -16,6 +16,7 @@ public class ConfigMigrationManager : IConfigMigrationManager new ConfigMigration_V2_0_V2_1(), new ConfigMigration_V2_1_V2_2(), new ConfigMigration_V2_2_V2_3(), + new ConfigMigration_V2_3_V2_4(), }.ToDictionary(m => m.FromVersion); public string LatestVersion { get; } diff --git a/AquaMai.Config/Migration/ConfigMigration_V2_3_V2_4.cs b/AquaMai.Config/Migration/ConfigMigration_V2_3_V2_4.cs new file mode 100644 index 00000000..93f4ee2f --- /dev/null +++ b/AquaMai.Config/Migration/ConfigMigration_V2_3_V2_4.cs @@ -0,0 +1,27 @@ +using AquaMai.Config.Interfaces; +using Tomlet.Models; + +namespace AquaMai.Config.Migration; + +public class ConfigMigration_V2_3_V2_4 : IConfigMigration +{ + public string FromVersion => "2.3"; + public string ToVersion => "2.4"; + + public ConfigView Migrate(ConfigView src) + { + var dst = (ConfigView)src.Clone(); + dst.SetValue("Version", ToVersion); + + if (src.TryGetValue("GameSystem.KeyMap.DisableIO4", out var disableIO4)) + { + dst.SetValue("GameSystem.KeyMap.DisableIO4_1P", disableIO4); + dst.SetValue("GameSystem.KeyMap.DisableIO4_2P", disableIO4); + dst.SetValue("GameSystem.KeyMap.DisableIO4System", disableIO4); + dst.Remove("GameSystem.KeyMap.DisableIO4"); + } + + return dst; + } +} + diff --git a/AquaMai.Mods/GameSystem/KeyMap.cs b/AquaMai.Mods/GameSystem/KeyMap.cs index a501c304..9f5c1a3b 100644 --- a/AquaMai.Mods/GameSystem/KeyMap.cs +++ b/AquaMai.Mods/GameSystem/KeyMap.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Reflection; using AMDaemon; using AquaMai.Config.Attributes; @@ -24,7 +25,7 @@ namespace AquaMai.Mods.GameSystem; public class KeyMap { [ConfigEntry( - name: "禁用 IO4", + name: "禁用 IO4(1P)", en: """ Disable IO4 (IO4-compatible board / segatools IO4 emulation) input. With IO4 input disabled, your IO4-compatible board or segatools IO4 emulation is ignored. @@ -33,7 +34,19 @@ public class KeyMap 禁用 IO4(兼容 IO4 板 / segatools IO4 模拟)输入。 在禁用 IO4 输入后,你的兼容 IO4 板或 segatools IO4 模拟将被忽略。 """)] - private static readonly bool disableIO4 = false; + private static readonly bool disableIO4_1P = false; + [ConfigEntry("禁用 IO4(2P)")] + private static readonly bool disableIO4_2P = false; + + [ConfigEntry( + name: "禁用 IO4(系统按键)", + en: """ + System buttons (test, service) input. + """, + zh: """ + 禁用系统按键的 IO4 输入,输入源同上。 + """)] + private static readonly bool disableIO4System = false; [ConfigEntry( name: "禁用 DebugInput", @@ -59,30 +72,45 @@ public class KeyMap """)] public static readonly bool disableDebugFeatureHotkeys = false; // Implemented in DebugFeature - [EnableIf(nameof(disableIO4))] + private static bool DisableIO4 => disableIO4_1P || disableIO4_2P || disableIO4System; + private static List disabledSwitchInputs = []; + + [EnableIf(nameof(DisableIO4))] [HarmonyPatch("IO.Jvs+JvsSwitch", ".ctor", MethodType.Constructor, [typeof(int), typeof(string), typeof(KeyCode), typeof(bool), typeof(bool)])] - [HarmonyPrefix] - public static void PreJvsSwitchConstructor(ref bool invert) + [HarmonyPostfix] + public static void PostJvsSwitchConstructor(ref bool ____invert, int playerNo, bool systemButton, SwitchInput ____switchInput) { - invert = false; + if ((systemButton && disableIO4System) || (playerNo == 0 && disableIO4_1P) || (playerNo == 1 && disableIO4_2P)) + { + ____invert = false; + disabledSwitchInputs.Add(____switchInput); + } } - [EnableIf(nameof(disableIO4))] - [HarmonyPatch(typeof(SwitchInput), "get_IsOn")] + [EnableIf(nameof(DisableIO4))] + [HarmonyPatch(typeof(SwitchInput), nameof(SwitchInput.IsOn), MethodType.Getter)] [HarmonyPrefix] - public static bool PreGetIsOn(ref bool __result) + public static bool PreGetIsOn(ref bool __result, SwitchInput __instance) { - __result = false; - return false; + if (disabledSwitchInputs.Contains(__instance)) + { + __result = false; + return false; + } + return true; } - [EnableIf(nameof(disableIO4))] - [HarmonyPatch(typeof(SwitchInput), "get_HasOnNow")] + [EnableIf(nameof(DisableIO4))] + [HarmonyPatch(typeof(SwitchInput), nameof(SwitchInput.HasOnNow), MethodType.Getter)] [HarmonyPrefix] - public static bool PreGetHasOnNow(ref bool __result) + public static bool PreGetHasOnNow(ref bool __result, SwitchInput __instance) { - __result = false; - return false; + if (disabledSwitchInputs.Contains(__instance)) + { + __result = false; + return false; + } + return true; } [ConfigEntry]