AquaDX/AquaMai/AquaMai.Mods/GameSystem/TestProof.cs

70 lines
2.5 KiB
C#
Raw Normal View History

using System.Diagnostics;
using System.Linq;
using AquaMai.Config.Attributes;
using AquaMai.Config.Types;
using AquaMai.Core;
using AquaMai.Core.Attributes;
using AquaMai.Core.Helpers;
using AquaMai.Mods.UX;
using AquaMai.Mods.UX.PracticeMode;
using HarmonyLib;
using Manager;
namespace AquaMai.Mods.GameSystem;
[ConfigSection(
en: """
When enabled, test button must be long pressed to enter game test mode.
When test button is bound to other features, this option is enabled automatically.
""",
zh: """
""")]
[EnableImplicitlyIf(nameof(ShouldEnableImplicitly))]
public class TestProof
{
public static bool ShouldEnableImplicitly
{
get
{
(System.Type section, KeyCodeOrName key)[] featureKeys =
[
(typeof(OneKeyEntryEnd), OneKeyEntryEnd.key),
(typeof(OneKeyRetrySkip), OneKeyRetrySkip.retryKey),
(typeof(OneKeyRetrySkip), OneKeyRetrySkip.skipKey),
(typeof(HideSelfMadeCharts), HideSelfMadeCharts.key),
(typeof(PracticeMode), PracticeMode.key),
];
var keyMapEnabled = ConfigLoader.Config.GetSectionState(typeof(KeyMap)).Enabled;
return featureKeys.Any(it =>
// The feature is enabled and...
ConfigLoader.Config.GetSectionState(it.section).Enabled &&
(
// and the key is test, or...
it.key == KeyCodeOrName.Test ||
// or the key have been mapped to the same key as test.
(keyMapEnabled && it.key.ToString() == KeyMap.Test.ToString())));
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(InputManager), "GetSystemInputDown")]
public static bool GetSystemInputDown(ref bool __result, InputManager.SystemButtonSetting button, bool[] ___SystemButtonDown)
{
__result = ___SystemButtonDown[(int)button];
if (button != InputManager.SystemButtonSetting.ButtonTest)
return false;
var stackTrace = new StackTrace(); // get call stack
var stackFrames = stackTrace.GetFrames(); // get method calls (frames)
if (stackFrames.Any(it => it.GetMethod().Name == "DMD<Main.GameMainObject::Update>"))
{
__result = KeyListener.GetKeyDownOrLongPress(KeyCodeOrName.Test, true);
}
return false;
}
}