Skip to content

Commit

Permalink
Merge pull request #2 from ExtReMLapin/revert-1-feature-autopause
Browse files Browse the repository at this point in the history
Revert "Feature autopause"
  • Loading branch information
ExtReMLapin authored Feb 8, 2020
2 parents 2640540 + 3daceaa commit 4a33baa
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 68 deletions.
2 changes: 1 addition & 1 deletion LuteBot/Config/PropertyItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum PropertyItem
NoteCooldown,
DebugMode,
ZeroingOnPlay,
PauseWhenRequired,
DontPlayNoteWhenRequired,

//keybinds
Play,
Expand Down
49 changes: 15 additions & 34 deletions LuteBot/IO/KB/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,57 +117,38 @@ 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;
IntPtr winhandle = processes[0].MainWindowHandle;
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;
}


Expand Down
2 changes: 1 addition & 1 deletion LuteBot/Resources/DefaultConfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"Value": "false"
},
{
"Item": "PauseWhenRequired",
"Item": "DontPlayNoteWhenRequired",
"Value": "true"
}
]
Expand Down
19 changes: 2 additions & 17 deletions LuteBot/UI/LuteBotForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public LuteBotForm()
trackSelectionManager.ToggleTrackRequest += new EventHandler<TrackItem>(ToggleTrack);
liveMidiManager = new LiveMidiManager();
hotkeyManager.LiveInputManager = liveMidiManager;
ActionManager.PauseFromGameEvent += PauseFromGame;

PlayButton.Enabled = false;
StopButton.Enabled = false;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
24 changes: 12 additions & 12 deletions LuteBot/UI/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions LuteBot/UI/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()));
}
}
}

0 comments on commit 4a33baa

Please sign in to comment.