From 03077daf7147c23b81d274bd2f8c5a7469023112 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Wed, 25 Jan 2023 22:43:57 -0800 Subject: [PATCH] fix a crash when loading a quicksave right after shutting down retroachievements --- .../RetroAchievements/RAIntegration.cs | 17 ++++++++++------- .../RetroAchievements/RCheevos.cs | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegration.cs b/src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegration.cs index 3a8ff6e3be..7e1abcfc76 100644 --- a/src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegration.cs +++ b/src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegration.cs @@ -133,6 +133,7 @@ namespace BizHawk.Client.EmuHawk { RA?.Shutdown(); _memGuard.Dispose(); + _mainForm.EmuClient.BeforeQuickLoad -= QuickLoadCallback; } public override void OnSaveState(string path) @@ -147,6 +148,14 @@ namespace BizHawk.Client.EmuHawk RA.OnLoadState(path); } + + private static void QuickLoadCallback(object _, BeforeQuickLoadEventArgs e) + { + if (RA.HardcoreModeIsActive()) + { + e.Handled = !RA.WarnDisableHardcore("load a quicksave"); + } + } public override void Stop() { @@ -214,13 +223,7 @@ namespace BizHawk.Client.EmuHawk _mainForm.UpdateWindowTitle(); // note: this can only catch quicksaves (probably only case of accidential use from hotkeys) - _mainForm.EmuClient.BeforeQuickLoad += (_, e) => - { - if (RA.HardcoreModeIsActive()) - { - e.Handled = !RA.WarnDisableHardcore("load a quicksave"); - } - }; + _mainForm.EmuClient.BeforeQuickLoad += QuickLoadCallback; } public override void Update() diff --git a/src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.cs b/src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.cs index f179b303a4..1b04a79bc2 100644 --- a/src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.cs +++ b/src/BizHawk.Client.EmuHawk/RetroAchievements/RCheevos.cs @@ -213,6 +213,7 @@ namespace BizHawk.Client.EmuHawk _gameInfoForm.Dispose(); _cheevoListForm.Dispose(); _lboardListForm.Dispose(); + _mainForm.EmuClient.BeforeQuickLoad -= QuickLoadCallback; } public override void OnSaveState(string path) @@ -252,6 +253,14 @@ namespace BizHawk.Client.EmuHawk var buffer = file.ReadAllBytes(); _lib.rc_runtime_deserialize_progress(ref _runtime, buffer, IntPtr.Zero); } + + private void QuickLoadCallback(object _, BeforeQuickLoadEventArgs e) + { + if (HardcoreMode) + { + e.Handled = _mainForm.ShowMessageBox2(null, "Loading a quicksave is not allowed in hardcode mode. Abort loading state?", "Warning", EMsgBoxIcon.Warning); + } + } // not sure if we really need to do anything here... // nice way to ensure config is written back every so often (and on close) @@ -385,13 +394,7 @@ namespace BizHawk.Client.EmuHawk Update(); // note: this can only catch quicksaves (probably only case of accidential use from hotkeys) - _mainForm.EmuClient.BeforeQuickLoad += (_, e) => - { - if (HardcoreMode) - { - e.Handled = _mainForm.ShowMessageBox2(null, "Loading a quicksave is not allowed in hardcode mode. Abort loading state?", "Warning", EMsgBoxIcon.Warning); - } - }; + _mainForm.EmuClient.BeforeQuickLoad += QuickLoadCallback; } public override void Update()