more disableio4

This commit is contained in:
Clansty 2025-12-21 01:33:48 +08:00
parent 73943bbfc3
commit a3cc26f2c8
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134
4 changed files with 72 additions and 29 deletions

View File

@ -1,13 +0,0 @@
{
"version": 1,
"isRoot": true,
"tools": {
"cake.tool": {
"version": "5.0.0",
"commands": [
"dotnet-cake"
],
"rollForward": false
}
}
}

View File

@ -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; }

View File

@ -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<bool>("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;
}
}

View File

@ -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: "禁用 IO41P",
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("禁用 IO42P")]
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<SwitchInput> 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]