Cheats: Fixed cheats not being saved properly when switching games with the cheat window opened, etc.

+ Compilation error fix on some compilers
This commit is contained in:
Sour 2019-10-14 10:59:06 -04:00
parent 2ed4f3603b
commit 52c61f00f9
5 changed files with 16 additions and 3 deletions

View file

@ -39,7 +39,10 @@ void CheatManager::SetCheats(uint32_t codes[], uint32_t length)
vector<CheatCode> cheats;
cheats.reserve(length);
for(uint32_t i = 0; i < length; i++) {
cheats.push_back({ codes[i] >> 8, codes[i] & 0xFF });
CheatCode code;
code.Address = codes[i] >> 8;
code.Value = codes[i] & 0xFF;
cheats.push_back(code);
}
SetCheats(cheats);
}

View file

@ -203,6 +203,8 @@ void Console::Stop(bool sendNotification)
_saveStateManager->SaveRecentGame(romInfo.RomFile.GetFileName(), romInfo.RomFile, romInfo.PatchFile);
}
_notificationManager->SendNotification(ConsoleNotificationType::BeforeGameUnload);
if(sendNotification) {
_notificationManager->SendNotification(ConsoleNotificationType::BeforeEmulationStop);
}

View file

@ -18,7 +18,8 @@ enum class ConsoleNotificationType
BeforeEmulationStop = 12,
ViewerRefresh = 13,
EventViewerRefresh = 14,
MissingFirmware = 15
MissingFirmware = 15,
BeforeGameUnload = 16,
};
class INotificationListener

View file

@ -61,6 +61,10 @@ namespace Mesen.GUI.Forms
private void OnNotification(NotificationEventArgs e)
{
switch(e.NotificationType) {
case ConsoleNotificationType.BeforeGameUnload:
(new CheatCodes() { Cheats = _cheats }).Save();
break;
case ConsoleNotificationType.GameLoaded:
this.BeginInvoke((Action)(() => {
InitCheatList();
@ -69,6 +73,8 @@ namespace Mesen.GUI.Forms
case ConsoleNotificationType.BeforeEmulationStop:
this.Invoke((Action)(() => {
//Close and save saves
DialogResult = DialogResult.OK;
Close();
}));
break;

View file

@ -62,6 +62,7 @@ namespace Mesen.GUI
BeforeEmulationStop = 12,
ViewerRefresh = 13,
EventViewerRefresh = 14,
MissingFirmware = 15
MissingFirmware = 15,
BeforeGameUnload = 16,
}
}