diff --git a/Core/Shared/Emulator.cpp b/Core/Shared/Emulator.cpp index baf5f3ce..1f5e1619 100644 --- a/Core/Shared/Emulator.cpp +++ b/Core/Shared/Emulator.cpp @@ -275,7 +275,7 @@ void Emulator::RunSingleFrame() _controlManager->UpdateControlDevices();*/ } -void Emulator::Stop(bool sendNotification) +void Emulator::Stop(bool sendNotification, bool preventRecentGameSave) { BlockDebuggerRequests(); @@ -290,7 +290,7 @@ void Emulator::Stop(bool sendNotification) _emuThread.release(); } - if(_console && !_settings->GetPreferences().DisableGameSelectionScreen && !_audioPlayerHud) { + if(!preventRecentGameSave && _console && !_settings->GetPreferences().DisableGameSelectionScreen && !_audioPlayerHud) { RomInfo romInfo = GetRomInfo(); _saveStateManager->SaveRecentGame(romInfo.RomFile.GetFileName(), romInfo.RomFile, romInfo.PatchFile); } @@ -425,7 +425,9 @@ bool Emulator::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom, } if(stopRom) { - Stop(false); + //Only update the recent game entry if the game that was loaded is a different game + bool gameChanged = (string)_rom.RomFile != (string)romFile || (string)_rom.PatchFile != (string)patchFile; + Stop(false, !gameChanged); //TODO PERF //KeyManager::UpdateDevices(); } @@ -435,9 +437,7 @@ bool Emulator::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom, //Cast VirtualFiles to string to ensure the original file data isn't kept in memory _rom.RomFile = (string)romFile; - if(patchFile.IsValid()) { - _rom.PatchFile = (string)patchFile; - } + _rom.PatchFile = (string)patchFile; _rom.Format = console->GetRomFormat(); if(_rom.Format == RomFormat::Spc || _rom.Format == RomFormat::Nsf || _rom.Format == RomFormat::Gbs) { diff --git a/Core/Shared/Emulator.h b/Core/Shared/Emulator.h index 8ea28d4a..21cf6f18 100644 --- a/Core/Shared/Emulator.h +++ b/Core/Shared/Emulator.h @@ -155,7 +155,7 @@ public: void Run(); void RunSingleFrame(); - void Stop(bool sendNotification); + void Stop(bool sendNotification, bool preventRecentGameSave = false); void OnBeforeSendFrame(); void ProcessEndOfFrame(); diff --git a/Core/Shared/SettingTypes.h b/Core/Shared/SettingTypes.h index 14b77d77..9073d37d 100644 --- a/Core/Shared/SettingTypes.h +++ b/Core/Shared/SettingTypes.h @@ -639,6 +639,7 @@ enum class EmulatorShortcut LoadStateSlotAuto, LoadStateFromFile, LoadStateDialog, + LoadLastSession, OpenFile, LoadRandomGame, diff --git a/Core/Shared/ShortcutKeyHandler.cpp b/Core/Shared/ShortcutKeyHandler.cpp index cf7ba0af..4ca343db 100644 --- a/Core/Shared/ShortcutKeyHandler.cpp +++ b/Core/Shared/ShortcutKeyHandler.cpp @@ -159,6 +159,7 @@ bool ShortcutKeyHandler::IsShortcutAllowed(EmulatorShortcut shortcut, uint32_t s case EmulatorShortcut::LoadStateDialog: case EmulatorShortcut::LoadStateFromFile: case EmulatorShortcut::LoadState: + case EmulatorShortcut::LoadLastSession: return isRunning && !isNetplayClient && !isMovieActive; } diff --git a/NewUI/Config/Shortcuts/EmulatorShortcut.cs b/NewUI/Config/Shortcuts/EmulatorShortcut.cs index 13d67eb6..bac01623 100644 --- a/NewUI/Config/Shortcuts/EmulatorShortcut.cs +++ b/NewUI/Config/Shortcuts/EmulatorShortcut.cs @@ -103,6 +103,7 @@ namespace Mesen.Config.Shortcuts LoadStateSlotAuto, LoadStateFromFile, LoadStateDialog, + LoadLastSession, OpenFile, LoadRandomGame, diff --git a/NewUI/Debugger/Utilities/ContextMenuAction.cs b/NewUI/Debugger/Utilities/ContextMenuAction.cs index 6be12ea5..0daba452 100644 --- a/NewUI/Debugger/Utilities/ContextMenuAction.cs +++ b/NewUI/Debugger/Utilities/ContextMenuAction.cs @@ -548,5 +548,6 @@ namespace Mesen.Debugger.Utilities LoadStateFromFile, RecentFiles, + LoadLastSession, } } diff --git a/NewUI/Utilities/ShortcutHandler.cs b/NewUI/Utilities/ShortcutHandler.cs index 4b625b22..2df17bb5 100644 --- a/NewUI/Utilities/ShortcutHandler.cs +++ b/NewUI/Utilities/ShortcutHandler.cs @@ -82,6 +82,16 @@ namespace Mesen.Utilities case EmulatorShortcut.LoadStateFromFile: LoadStateFromFile(); break; case EmulatorShortcut.SaveStateToFile: SaveStateToFile(); break; + case EmulatorShortcut.LoadLastSession: + string filename = Path.Combine(ConfigManager.RecentGamesFolder, MainWindowModel.RomInfo.GetRomName() + ".rgd"); + Task.Run(() => { + //Run in another thread to prevent deadlocks etc. when emulator notifications are processed UI-side + if(File.Exists(filename)) { + EmuApi.LoadRecentGame(filename, false); + } + }); + break; + case EmulatorShortcut.LoadStateDialog: //TODO /*if(_displayManager.ExclusiveFullscreen) { diff --git a/NewUI/ViewModels/MainMenuViewModel.cs b/NewUI/ViewModels/MainMenuViewModel.cs index d32d8957..826508c8 100644 --- a/NewUI/ViewModels/MainMenuViewModel.cs +++ b/NewUI/ViewModels/MainMenuViewModel.cs @@ -143,6 +143,12 @@ namespace Mesen.ViewModels new MainMenuAction(EmulatorShortcut.LoadStateFromFile) { ActionType = ActionType.LoadStateFromFile }, } }, + + new MainMenuAction(EmulatorShortcut.LoadLastSession) { + ActionType = ActionType.LoadLastSession, + IsEnabled = () => File.Exists(Path.Combine(ConfigManager.RecentGamesFolder, MainWindow.RomInfo.GetRomName() + ".rgd")) + }, + new ContextMenuSeparator(), new MainMenuAction() { ActionType = ActionType.RecentFiles, diff --git a/NewUI/ViewModels/PreferencesConfigViewModel.cs b/NewUI/ViewModels/PreferencesConfigViewModel.cs index 6e41f144..53f6445a 100644 --- a/NewUI/ViewModels/PreferencesConfigViewModel.cs +++ b/NewUI/ViewModels/PreferencesConfigViewModel.cs @@ -104,6 +104,7 @@ namespace Mesen.ViewModels EmulatorShortcut.LoadStateSlotAuto, EmulatorShortcut.LoadStateFromFile, EmulatorShortcut.LoadStateDialog, + EmulatorShortcut.LoadLastSession, EmulatorShortcut.SelectSaveSlot1, EmulatorShortcut.SelectSaveSlot2,