From 6d2d07428e781cae3e944373ce0b7963ad0102a4 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 28 Nov 2024 07:40:14 +1000 Subject: [PATCH] Make the Basic Bot fail more gracefully --- .../tools/BasicBot/BasicBot.cs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index 1c74d610344..661ce4034fb 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -146,6 +146,7 @@ private void BasicBot_Load(object sender, EventArgs e) _previousInvisibleEmulation = InvisibleEmulationCheckBox.Checked = Settings.InvisibleEmulation; _previousDisplayMessage = Config.DisplayMessages; + Closing += (_, _) => StopBot(); } private Dictionary ControlProbabilities => @@ -1073,6 +1074,12 @@ private string CanStart() return null; } + protected override void Dispose(bool disposing) + { + if (_isBotting) RestoreConfigFlags(); // disposed while running? least we can do is not clobber config + base.Dispose(disposing: disposing); + } + private void StopBot() { RunBtn.Visible = true; @@ -1084,20 +1091,21 @@ private void StopBot() _targetFrame = 0; reset_curent(0); GoalGroupBox.Enabled = true; - - if (MovieSession.Movie.IsRecording()) - { - MovieSession.Movie.IsCountingRerecords = _oldCountingSetting; - } - - Config.DisplayMessages = _previousDisplayMessage; - MainForm.InvisibleEmulation = _previousInvisibleEmulation; + RestoreConfigFlags(); MainForm.PauseEmulator(); SetNormalSpeed(); UpdateBotStatusIcon(); MessageLabel.Text = "Bot stopped"; } + private void RestoreConfigFlags() + { + Config.DisplayMessages = _previousDisplayMessage; + MainForm.InvisibleEmulation = _previousInvisibleEmulation; + var movie = MovieSession.Movie; + if (movie.IsRecording()) movie.IsCountingRerecords = _oldCountingSetting; + } + private void UpdateBotStatusIcon() { if (_replayMode)