From be4089eb08d839c8eeb520084ba820259340337e Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Mon, 6 Jun 2022 10:17:08 -0700 Subject: [PATCH] fix possible InvalidOperationException for a7800 settings (GetSettingsAdapterForLoadedCore to GetSettingsAdapterFor) allow old bsnes and bsnes main settings to be edited without the core loaded --- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 40 +++++++++---------- .../config/SNES/BSNESOptions.cs | 7 ++-- .../config/SNES/SNESOptions.cs | 7 ++-- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 366802b90f..69a8757248 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -1731,18 +1731,18 @@ namespace BizHawk.Client.EmuHawk Tools.Load(); } - private DialogResult OpenOldBSNESSettingsDialog(ISettingsAdapter settable, LibsnesCore bsnes) - => SNESOptions.DoSettingsDialog(this, settable, bsnes); + private DialogResult OpenOldBSNESSettingsDialog() + => SNESOptions.DoSettingsDialog(this, GetSettingsAdapterFor()); - private DialogResult OpenBSNESSettingsDialog(ISettingsAdapter settable, BsnesCore bsnes) - => BSNESOptions.DoSettingsDialog(this, settable, bsnes); + private DialogResult OpenBSNESSettingsDialog() + => BSNESOptions.DoSettingsDialog(this, GetSettingsAdapterFor()); private void SnesOptionsMenuItem_Click(object sender, EventArgs e) { _ = Emulator switch { - LibsnesCore oldBSNES => OpenOldBSNESSettingsDialog(GetSettingsAdapterForLoadedCore(), oldBSNES), - BsnesCore bsnes => OpenBSNESSettingsDialog(GetSettingsAdapterForLoadedCore(), bsnes), + LibsnesCore => OpenOldBSNESSettingsDialog(), + BsnesCore => OpenBSNESSettingsDialog(), _ => DialogResult.None }; } @@ -2763,26 +2763,24 @@ namespace BizHawk.Client.EmuHawk items.Add(CreateCoreSubmenu(VSystemCategory.Consoles, CoreNames.Atari2600Hawk, CreateGenericCoreConfigItem(CoreNames.Atari2600Hawk))); // BSNES - var bsnesGamepadSettingsItem = CreateSettingsItem("Controller Configuration...", (_, _) => OpenOldBSNESGamepadSettingsDialog(GetSettingsAdapterFor())); - var bsnesSettingsItem = CreateSettingsItem("Options...", SnesOptionsMenuItem_Click); - var bsnesSubmenu = CreateCoreSubmenu(VSystemCategory.Consoles, CoreNames.Bsnes, bsnesGamepadSettingsItem, bsnesSettingsItem); - bsnesSubmenu.DropDownOpened += (_, _) => + var oldBSNESGamepadSettingsItem = CreateSettingsItem("Controller Configuration...", (_, _) => OpenOldBSNESGamepadSettingsDialog(GetSettingsAdapterFor())); + var oldBSNESSettingsItem = CreateSettingsItem("Options...", (_, _) => OpenOldBSNESSettingsDialog()); + var oldBSNESSubmenu = CreateCoreSubmenu(VSystemCategory.Consoles, CoreNames.Bsnes, oldBSNESGamepadSettingsItem, oldBSNESSettingsItem); + oldBSNESSubmenu.DropDownOpened += (_, _) => { - var loadedCoreIsBSNES = Emulator is LibsnesCore; - bsnesGamepadSettingsItem.Enabled = !loadedCoreIsBSNES || MovieSession.Movie.NotActive(); - bsnesSettingsItem.Enabled = loadedCoreIsBSNES; + var loadedCoreIsOldBSNES = Emulator is LibsnesCore; + oldBSNESGamepadSettingsItem.Enabled = !loadedCoreIsOldBSNES || MovieSession.Movie.NotActive(); }; - items.Add(bsnesSubmenu); + items.Add(oldBSNESSubmenu); // BSNESv115+ - var oldBSNESGamepadSettingsItem = CreateSettingsItem("Controller Configuration...", (_, _) => OpenBSNESGamepadSettingsDialog(GetSettingsAdapterFor())); - var oldBSNESSettingsItem = CreateSettingsItem("Options...", SnesOptionsMenuItem_Click); - var oldBSNESSubmenu = CreateCoreSubmenu(VSystemCategory.Consoles, CoreNames.Bsnes115, oldBSNESGamepadSettingsItem, oldBSNESSettingsItem); + var bsnesGamepadSettingsItem = CreateSettingsItem("Controller Configuration...", (_, _) => OpenBSNESGamepadSettingsDialog(GetSettingsAdapterFor())); + var bsnesSettingsItem = CreateSettingsItem("Options...", (_, _) => OpenBSNESSettingsDialog()); + var bsnesSubmenu = CreateCoreSubmenu(VSystemCategory.Consoles, CoreNames.Bsnes115, bsnesGamepadSettingsItem, bsnesSettingsItem); oldBSNESSubmenu.DropDownOpened += (_, _) => { var loadedCoreIsBSNES = Emulator is BsnesCore; - oldBSNESGamepadSettingsItem.Enabled = !loadedCoreIsBSNES || MovieSession.Movie.NotActive(); - oldBSNESSettingsItem.Enabled = loadedCoreIsBSNES; + bsnesGamepadSettingsItem.Enabled = !loadedCoreIsBSNES || MovieSession.Movie.NotActive(); }; items.Add(oldBSNESSubmenu); @@ -2796,8 +2794,8 @@ namespace BizHawk.Client.EmuHawk // ColecoHawk var colecoHawkGamepadSettingsItem = CreateSettingsItem("Controller Settings...", (_, _) => OpenColecoHawkGamepadSettingsDialog(GetSettingsAdapterFor())); - var colecoHawkSkipBIOSItem = CreateSettingsItem("Skip BIOS intro (When Applicable)", (sender, _) => ColecoHawkSetSkipBIOSIntro(!((ToolStripMenuItem) sender).Checked, GetSettingsAdapterForLoadedCore())); - var colecoHawkUseSGMItem = CreateSettingsItem("Use the Super Game Module", (sender, _) => ColecoHawkSetSuperGameModule(!((ToolStripMenuItem)sender).Checked, GetSettingsAdapterForLoadedCore())); + var colecoHawkSkipBIOSItem = CreateSettingsItem("Skip BIOS intro (When Applicable)", (sender, _) => ColecoHawkSetSkipBIOSIntro(!((ToolStripMenuItem) sender).Checked, GetSettingsAdapterFor())); + var colecoHawkUseSGMItem = CreateSettingsItem("Use the Super Game Module", (sender, _) => ColecoHawkSetSuperGameModule(!((ToolStripMenuItem)sender).Checked, GetSettingsAdapterFor())); var colecoHawkSubmenu = CreateCoreSubmenu(VSystemCategory.Consoles, CoreNames.ColecoHawk, colecoHawkGamepadSettingsItem, colecoHawkSkipBIOSItem, colecoHawkUseSGMItem); colecoHawkSubmenu.DropDownOpened += (_, _) => { diff --git a/src/BizHawk.Client.EmuHawk/config/SNES/BSNESOptions.cs b/src/BizHawk.Client.EmuHawk/config/SNES/BSNESOptions.cs index 1a3859da78..83a1b24926 100644 --- a/src/BizHawk.Client.EmuHawk/config/SNES/BSNESOptions.cs +++ b/src/BizHawk.Client.EmuHawk/config/SNES/BSNESOptions.cs @@ -14,11 +14,10 @@ namespace BizHawk.Client.EmuHawk InitializeComponent(); } - /// TODO only use - public static DialogResult DoSettingsDialog(IDialogParent dialogParent, ISettingsAdapter settable, BsnesCore bsnes) + public static DialogResult DoSettingsDialog(IDialogParent dialogParent, ISettingsAdapter settable) { - var s = bsnes.GetSettings(); - var ss = bsnes.GetSyncSettings(); + var s = settable.GetSettings() as BsnesCore.SnesSettings; + var ss = settable.GetSyncSettings() as BsnesCore.SnesSyncSettings; using var dlg = new BSNESOptions { AlwaysDoubleSize = s.AlwaysDoubleSize, diff --git a/src/BizHawk.Client.EmuHawk/config/SNES/SNESOptions.cs b/src/BizHawk.Client.EmuHawk/config/SNES/SNESOptions.cs index 52b71796cd..cdf64d3afc 100644 --- a/src/BizHawk.Client.EmuHawk/config/SNES/SNESOptions.cs +++ b/src/BizHawk.Client.EmuHawk/config/SNES/SNESOptions.cs @@ -17,11 +17,10 @@ namespace BizHawk.Client.EmuHawk private bool _suppressDoubleSize; private bool _userDoubleSizeOption; - /// TODO only use - public static DialogResult DoSettingsDialog(IDialogParent dialogParent, ISettingsAdapter settable, LibsnesCore bsnes) + public static DialogResult DoSettingsDialog(IDialogParent dialogParent, ISettingsAdapter settable) { - var s = bsnes.GetSettings(); - var ss = bsnes.GetSyncSettings(); + var s = settable.GetSettings() as LibsnesCore.SnesSettings; + var ss = settable.GetSyncSettings() as LibsnesCore.SnesSyncSettings; using var dlg = new SNESOptions { RandomizedInitialState = ss.RandomizedInitialState,