diff --git a/CelesteTAS-EverestInterop/Source/EverestInterop/Hotkeys.cs b/CelesteTAS-EverestInterop/Source/EverestInterop/Hotkeys.cs index 699489ab0..ed2da2f18 100644 --- a/CelesteTAS-EverestInterop/Source/EverestInterop/Hotkeys.cs +++ b/CelesteTAS-EverestInterop/Source/EverestInterop/Hotkeys.cs @@ -232,9 +232,6 @@ private static void ReleaseAllKeys() { [Load] private static void Load() { On.Celeste.Input.Initialize += InputOnInitialize; - typeof(ModuleSettingsKeyboardConfigUI) - .GetMethodInfo(nameof(ModuleSettingsKeyboardConfigUI.Reset)) - .IlHook(ModReload); } [Unload] @@ -247,36 +244,6 @@ private static void InputOnInitialize(On.Celeste.Input.orig_Initialize orig) { CommunicationWrapper.SendCurrentBindings(); } - private static void ModReload(ILContext il) { - bindingProperties = typeof(CelesteTasSettings) - .GetProperties(BindingFlags.Instance | BindingFlags.Public) - .Where(info => info.PropertyType == typeof(ButtonBinding) && - info.GetCustomAttribute() is { } extraDefaultKeyAttribute && - extraDefaultKeyAttribute.ExtraKey != Keys.None); - - ILCursor ilCursor = new(il); - if (ilCursor.TryGotoNext( - MoveType.After, - ins => ins.OpCode == OpCodes.Callvirt && ins.Operand.ToString().Contains("::Add(T)") - )) { - ilCursor.Emit(OpCodes.Ldloc_1).EmitDelegate>(AddExtraDefaultKey); - } - } - - private static void AddExtraDefaultKey(object bindingEntry) { - if (bindingFieldInfo == null) { - bindingFieldInfo = bindingEntry.GetType().GetFieldInfo("Binding"); - } - - if (bindingFieldInfo?.GetValue(bindingEntry) is not ButtonBinding binding) { - return; - } - - if (bindingProperties.FirstOrDefault(info => info.GetValue(TasSettings) == binding) is { } propertyInfo) { - binding.Keys.Add(propertyInfo.GetCustomAttribute().ExtraKey); - } - } - public class Hotkey { private static readonly Regex keysNameFixRegex = new(@"^D(\d)$", RegexOptions.Compiled); @@ -433,11 +400,3 @@ public void Update(ButtonState buttonState) { } } } - -public class DefaultButtonBinding2Attribute : DefaultButtonBindingAttribute { - public readonly XNAKeys ExtraKey; - - public DefaultButtonBinding2Attribute(Buttons button, params XNAKeys[] keys) : base(button, keys.IsEmpty() ? XNAKeys.None : keys[0]) { - ExtraKey = keys.Length > 1 ? keys[1] : XNAKeys.None; - } -} diff --git a/CelesteTAS-EverestInterop/Source/Module/CelesteTasSettings.cs b/CelesteTAS-EverestInterop/Source/Module/CelesteTasSettings.cs index 6de1ff2cb..e6a78042c 100644 --- a/CelesteTAS-EverestInterop/Source/Module/CelesteTasSettings.cs +++ b/CelesteTAS-EverestInterop/Source/Module/CelesteTasSettings.cs @@ -95,68 +95,68 @@ public ActualCollideHitboxType ShowActualCollideHitboxes { #region HotKey [SettingName("TAS_KEY_START_STOP")] - [DefaultButtonBinding2(0, Keys.RightControl)] - public ButtonBinding KeyStart { get; set; } = new(0, Keys.RightControl); + [DefaultButtonBinding([0], [Keys.RightControl])] + public ButtonBinding KeyStart { get; set; } = null!; [SettingName("TAS_KEY_RESTART")] - [DefaultButtonBinding2(0, Keys.OemPlus)] - public ButtonBinding KeyRestart { get; set; } = new(0, Keys.OemPlus); + [DefaultButtonBinding([0], [Keys.OemPlus])] + public ButtonBinding KeyRestart { get; set; } = null!; [SettingName("TAS_KEY_FAST_FORWARD")] - [DefaultButtonBinding2(0, Keys.RightShift)] - public ButtonBinding KeyFastForward { get; set; } = new(0, Keys.RightShift); + [DefaultButtonBinding([0], [Keys.RightShift])] + public ButtonBinding KeyFastForward { get; set; } = null!; [SettingName("TAS_KEY_FAST_FORWARD_COMMENT")] - [DefaultButtonBinding2(0, Keys.RightAlt, Keys.RightShift)] - public ButtonBinding KeyFastForwardComment { get; set; } = new(0, Keys.RightAlt, Keys.RightShift); + [DefaultButtonBinding([0], [Keys.RightAlt, Keys.RightShift])] + public ButtonBinding KeyFastForwardComment { get; set; } = null!; [SettingName("TAS_KEY_SLOW_FORWARD")] - [DefaultButtonBinding2(0, Keys.OemPipe)] - public ButtonBinding KeySlowForward { get; set; } = new(0, Keys.OemPipe); + [DefaultButtonBinding([0], [Keys.OemPipe])] + public ButtonBinding KeySlowForward { get; set; } = null!; [SettingName("TAS_KEY_FRAME_ADVANCE")] - [DefaultButtonBinding2(0, Keys.OemOpenBrackets)] - public ButtonBinding KeyFrameAdvance { get; set; } = new(0, Keys.OemOpenBrackets); + [DefaultButtonBinding([0], [Keys.OemOpenBrackets])] + public ButtonBinding KeyFrameAdvance { get; set; } = null!; [SettingName("TAS_KEY_PAUSE_RESUME")] - [DefaultButtonBinding2(0, Keys.OemCloseBrackets)] - public ButtonBinding KeyPause { get; set; } = new(0, Keys.OemCloseBrackets); + [DefaultButtonBinding([0], [Keys.OemCloseBrackets])] + public ButtonBinding KeyPause { get; set; } = null!; [SettingName("TAS_KEY_HITBOXES")] - [DefaultButtonBinding2(0, Keys.LeftControl, Keys.B)] - public ButtonBinding KeyHitboxes { get; set; } = new(0, Keys.LeftControl, Keys.B); + [DefaultButtonBinding([0], [Keys.LeftControl, Keys.B])] + public ButtonBinding KeyHitboxes { get; set; } = null!; [SettingName("TAS_KEY_TRIGGER_HITBOXES")] - [DefaultButtonBinding2(0, Keys.LeftAlt, Keys.T)] - public ButtonBinding KeyTriggerHitboxes { get; set; } = new(0, Keys.LeftAlt, Keys.T); + [DefaultButtonBinding([0], [Keys.LeftAlt, Keys.T])] + public ButtonBinding KeyTriggerHitboxes { get; set; } = null!; [SettingName("TAS_KEY_SIMPLIFIED_GRAPHICS")] - [DefaultButtonBinding2(0, Keys.LeftControl, Keys.N)] - public ButtonBinding KeyGraphics { get; set; } = new(0, Keys.LeftControl, Keys.N); + [DefaultButtonBinding([0], [Keys.LeftControl, Keys.N])] + public ButtonBinding KeyGraphics { get; set; } = null!; [SettingName("TAS_KEY_CENTER_CAMERA")] - [DefaultButtonBinding2(0, Keys.LeftControl, Keys.M)] - public ButtonBinding KeyCamera { get; set; } = new(0, Keys.LeftControl, Keys.M); + [DefaultButtonBinding([0], [Keys.LeftControl, Keys.M])] + public ButtonBinding KeyCamera { get; set; } = null!; [SettingName("TAS_KEY_LOCK_CAMERA")] - [DefaultButtonBinding2(0, Keys.LeftControl, Keys.H)] - public ButtonBinding KeyLockCamera { get; set; } = new(0, Keys.LeftControl, Keys.H); + [DefaultButtonBinding([0], [Keys.LeftControl, Keys.H])] + public ButtonBinding KeyLockCamera { get; set; } = null!; [SettingName("TAS_KEY_SAVE_STATE")] - [DefaultButtonBinding2(0, Keys.RightAlt, Keys.OemMinus)] - public ButtonBinding KeySaveState { get; set; } = new(0, Keys.RightAlt, Keys.OemMinus); + [DefaultButtonBinding([0], [Keys.RightAlt, Keys.OemMinus])] + public ButtonBinding KeySaveState { get; set; } = null!; [SettingName("TAS_KEY_CLEAR_STATE")] - [DefaultButtonBinding2(0, Keys.RightAlt, Keys.Back)] - public ButtonBinding KeyClearState { get; set; } = new(0, Keys.RightAlt, Keys.Back); + [DefaultButtonBinding([0], [Keys.RightAlt, Keys.Back])] + public ButtonBinding KeyClearState { get; set; } = null!; [SettingName("TAS_KEY_INFO_HUD")] - [DefaultButtonBinding2(0, Keys.LeftControl)] - public ButtonBinding KeyInfoHud { get; set; } = new(0, Keys.LeftControl); + [DefaultButtonBinding([0], [Keys.LeftControl])] + public ButtonBinding KeyInfoHud { get; set; } = null!; [SettingName("TAS_KEY_FREE_CAMERA")] - [DefaultButtonBinding2(0, Keys.LeftAlt)] - public ButtonBinding KeyFreeCamera { get; set; } = new(0, Keys.LeftAlt); + [DefaultButtonBinding([0], [Keys.LeftAlt])] + public ButtonBinding KeyFreeCamera { get; set; } = null!; #endregion