diff --git a/LuteBot/Config/PropertyItem.cs b/LuteBot/Config/PropertyItem.cs index ffd0f63..1a879ec 100644 --- a/LuteBot/Config/PropertyItem.cs +++ b/LuteBot/Config/PropertyItem.cs @@ -23,7 +23,7 @@ public enum PropertyItem NoteCooldown, DebugMode, ZeroingOnPlay, - PauseWhenRequired, + DontPlayNoteWhenRequired, //keybinds Play, diff --git a/LuteBot/IO/KB/ActionManager.cs b/LuteBot/IO/KB/ActionManager.cs index 5080f10..cfefeff 100644 --- a/LuteBot/IO/KB/ActionManager.cs +++ b/LuteBot/IO/KB/ActionManager.cs @@ -117,10 +117,12 @@ struct CURSORINFO private static extern IntPtr GetForegroundWindow(); #endregion - public static event EventHandler PauseFromGameEvent = delegate { }; + + private static void InputCommand(int noteId) { + Process[] processes = Process.GetProcessesByName("Mordhau-Win64-Shipping"); // i refresh it on each call because it may get closed or rebooted etc if (processes.Length != 1) // if there is no game detected then fuck off return; @@ -128,46 +130,25 @@ private static void InputCommand(int noteId) if (winhandle != GetForegroundWindow()) // if the game has no focus, then fuck off return; - /* - * If the cursor is showing, it has 2 possibilities: - * - * 1. Console is still up from previously sent note - * 2. User initiated action (e.g., typing, menu) - * - * To avoid case 1, we check again after brief timeout to give console enough time to close; - * if the cursor is still up, we know with high confidence it's case 2. - */ - CURSORINFO pci = new CURSORINFO(); pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO)); GetCursorInfo(ref pci); // it stores the cursordata to the struct - if (pci.flags == CURSOR_SHOWING) + + + /* + * If the cursor is showing, it means the user is typing or doesn't have the required state to play lute. + */ + + if (ConfigManager.GetBooleanProperty(PropertyItem.DontPlayNoteWhenRequired) == true) { - Thread.Sleep(20); - // refetch cursor info - CURSORINFO pci_1 = new CURSORINFO(); - pci_1.cbSize = Marshal.SizeOf(typeof(CURSORINFO)); - GetCursorInfo(ref pci_1); - if (pci_1.flags == CURSOR_SHOWING) - { - if (ConfigManager.GetBooleanProperty(PropertyItem.PauseWhenRequired) == true) - { - PauseFromGameEvent(null, EventArgs.Empty); - } + if (pci.flags == CURSOR_SHOWING) return; - } - } - if (((Control.ModifierKeys & Keys.Control) == Keys.Control) || - ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) || - (Control.ModifierKeys & Keys.Alt) == Keys.Alt) - { - if (ConfigManager.GetBooleanProperty(PropertyItem.PauseWhenRequired) == true) - { - PauseFromGameEvent(null, EventArgs.Empty); - } - return; + if (((Control.ModifierKeys & Keys.Control) == Keys.Control) || + ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) || + (Control.ModifierKeys & Keys.Alt) == Keys.Alt) + return; } diff --git a/LuteBot/Resources/DefaultConfig.txt b/LuteBot/Resources/DefaultConfig.txt index 487df5a..7a72006 100644 --- a/LuteBot/Resources/DefaultConfig.txt +++ b/LuteBot/Resources/DefaultConfig.txt @@ -129,7 +129,7 @@ "Value": "false" }, { - "Item": "PauseWhenRequired", + "Item": "DontPlayNoteWhenRequired", "Value": "true" } ] diff --git a/LuteBot/UI/LuteBotForm.cs b/LuteBot/UI/LuteBotForm.cs index 7e921a8..3e74a70 100644 --- a/LuteBot/UI/LuteBotForm.cs +++ b/LuteBot/UI/LuteBotForm.cs @@ -86,7 +86,6 @@ public LuteBotForm() trackSelectionManager.ToggleTrackRequest += new EventHandler(ToggleTrack); liveMidiManager = new LiveMidiManager(); hotkeyManager.LiveInputManager = liveMidiManager; - ActionManager.PauseFromGameEvent += PauseFromGame; PlayButton.Enabled = false; StopButton.Enabled = false; @@ -407,11 +406,7 @@ private void Play() { ActionManager.ToggleConsole(true); } - // needs to be wrapped to avoid cross-thread issue - PlayButton.BeginInvoke(new MethodInvoker(() => - { - PlayButton.Text = playButtonStopString; - })); + PlayButton.Text = playButtonStopString; player.Play(); timer1.Start(); playButtonIsPlaying = true; @@ -423,11 +418,7 @@ private void Pause() { ActionManager.ToggleConsole(false); } - // needs to be wrapped to avoid cross-thread issue - PlayButton.BeginInvoke(new MethodInvoker(() => - { - PlayButton.Text = playButtonStartString; - })); + PlayButton.Text = playButtonStartString; player.Pause(); timer1.Stop(); playButtonIsPlaying = false; @@ -519,12 +510,6 @@ private void TrackFilteringToolStripMenuItem_Click(object sender, EventArgs e) } } - private void PauseFromGame(object sender, EventArgs e) - { - Pause(); - } - - private static IntPtr SetHook(LowLevelKeyboardProc proc) { using (Process curProcess = Process.GetCurrentProcess()) diff --git a/LuteBot/UI/SettingsForm.Designer.cs b/LuteBot/UI/SettingsForm.Designer.cs index a916134..b4ecd07 100644 --- a/LuteBot/UI/SettingsForm.Designer.cs +++ b/LuteBot/UI/SettingsForm.Designer.cs @@ -54,7 +54,7 @@ private void InitializeComponent() this.NoteCountLabel = new System.Windows.Forms.Label(); this.LowestNoteLabel = new System.Windows.Forms.Label(); this.LowestNoteNumeric = new System.Windows.Forms.NumericUpDown(); - this.PauseWhenRequiredCheckbox = new System.Windows.Forms.CheckBox(); + this.DontPlayWhenRequiredCheckbox = new System.Windows.Forms.CheckBox(); this.SettingsGroupBox.SuspendLayout(); this.AdvancedGroupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.NoteCooldownNumeric)).BeginInit(); @@ -182,7 +182,7 @@ private void InitializeComponent() // // SettingsGroupBox // - this.SettingsGroupBox.Controls.Add(this.PauseWhenRequiredCheckbox); + this.SettingsGroupBox.Controls.Add(this.DontPlayWhenRequiredCheckbox); this.SettingsGroupBox.Controls.Add(this.ZeroingCheckBox); this.SettingsGroupBox.Controls.Add(this.LiveMidiCheckBox); this.SettingsGroupBox.Controls.Add(this.OffAutoConsoleRadio); @@ -354,16 +354,16 @@ private void InitializeComponent() this.LowestNoteNumeric.TabIndex = 13; this.LowestNoteNumeric.ValueChanged += new System.EventHandler(this.LowestNoteNumeric_ValueChanged); // - // PauseWhenRequiredCheckbox + // DontPlayWhenRequiredCheckbox // - this.PauseWhenRequiredCheckbox.AutoSize = true; - this.PauseWhenRequiredCheckbox.Location = new System.Drawing.Point(6, 157); - this.PauseWhenRequiredCheckbox.Name = "PauseWhenRequiredCheckbox"; - this.PauseWhenRequiredCheckbox.Size = new System.Drawing.Size(378, 17); - this.PauseWhenRequiredCheckbox.TabIndex = 8; - this.PauseWhenRequiredCheckbox.Text = "Pause when a modifier key is pressed or when player is in a menu"; - this.PauseWhenRequiredCheckbox.UseVisualStyleBackColor = true; - this.PauseWhenRequiredCheckbox.CheckedChanged += new System.EventHandler(this.PauseWhenRequiredCheckbox_CheckedChanged); + this.DontPlayWhenRequiredCheckbox.AutoSize = true; + this.DontPlayWhenRequiredCheckbox.Location = new System.Drawing.Point(6, 157); + this.DontPlayWhenRequiredCheckbox.Name = "DontPlayWhenRequiredCheckbox"; + this.DontPlayWhenRequiredCheckbox.Size = new System.Drawing.Size(378, 17); + this.DontPlayWhenRequiredCheckbox.TabIndex = 8; + this.DontPlayWhenRequiredCheckbox.Text = "Dont play notes when a modifier key is pressed or when player is in a menu"; + this.DontPlayWhenRequiredCheckbox.UseVisualStyleBackColor = true; + this.DontPlayWhenRequiredCheckbox.CheckedChanged += new System.EventHandler(this.DontPlayWhenRequiredCheckbox_CheckedChanged); // // SettingsForm // @@ -421,6 +421,6 @@ private void InitializeComponent() private System.Windows.Forms.RadioButton OffAutoConsoleRadio; private System.Windows.Forms.CheckBox LiveMidiCheckBox; private System.Windows.Forms.CheckBox ZeroingCheckBox; - private System.Windows.Forms.CheckBox PauseWhenRequiredCheckbox; + private System.Windows.Forms.CheckBox DontPlayWhenRequiredCheckbox; } } \ No newline at end of file diff --git a/LuteBot/UI/SettingsForm.cs b/LuteBot/UI/SettingsForm.cs index 578cb8e..cc0bfbd 100644 --- a/LuteBot/UI/SettingsForm.cs +++ b/LuteBot/UI/SettingsForm.cs @@ -120,7 +120,7 @@ private void InitSettings() OnlineSyncCheckBox.Checked = ConfigManager.GetBooleanProperty(PropertyItem.OnlineSync); SoundEffectsCheckBox.Checked = ConfigManager.GetBooleanProperty(PropertyItem.SoundEffects); ZeroingCheckBox.Checked = ConfigManager.GetBooleanProperty(PropertyItem.ZeroingOnPlay); - PauseWhenRequiredCheckbox.Checked = ConfigManager.GetBooleanProperty(PropertyItem.PauseWhenRequired); + DontPlayWhenRequiredCheckbox.Checked = ConfigManager.GetBooleanProperty(PropertyItem.DontPlayNoteWhenRequired); InitRadioButtons(); NoteConversionMode.SelectedIndex = ConfigManager.GetIntegerProperty(PropertyItem.NoteConversionMode); @@ -256,9 +256,9 @@ private void ZeroingCheckBox_CheckedChanged(object sender, EventArgs e) ConfigManager.SetProperty(PropertyItem.ZeroingOnPlay, (ZeroingCheckBox.Checked.ToString())); } - private void PauseWhenRequiredCheckbox_CheckedChanged(object sender, EventArgs e) + private void DontPlayWhenRequiredCheckbox_CheckedChanged(object sender, EventArgs e) { - ConfigManager.SetProperty(PropertyItem.PauseWhenRequired, (PauseWhenRequiredCheckbox.Checked.ToString())); + ConfigManager.SetProperty(PropertyItem.DontPlayNoteWhenRequired, (DontPlayWhenRequiredCheckbox.Checked.ToString())); } } }