mirror of
https://github.com/libretro/Mesen.git
synced 2025-01-21 00:04:24 +00:00
Savestates: Added header/versioning in file format
This commit is contained in:
parent
9e9c3b4f29
commit
baded7ae25
@ -80,6 +80,16 @@ private:
|
||||
static uint32_t _videoScale;
|
||||
|
||||
public:
|
||||
static uint32_t GetMesenVersion()
|
||||
{
|
||||
//Version 0.1.0
|
||||
uint16_t major = 0;
|
||||
uint8_t minor = 1;
|
||||
uint8_t revision = 0;
|
||||
|
||||
return (major << 16) | (minor << 8) | revision;
|
||||
}
|
||||
|
||||
static void SetFlags(EmulationFlags flags)
|
||||
{
|
||||
_flags |= flags;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "MessageManager.h"
|
||||
#include "Console.h"
|
||||
#include "../Utilities/FolderUtilities.h"
|
||||
#include "EmulationSettings.h"
|
||||
|
||||
string SaveStateManager::GetStateFilepath(int stateIndex)
|
||||
{
|
||||
@ -31,6 +32,12 @@ void SaveStateManager::SaveState(int stateIndex)
|
||||
|
||||
if(file) {
|
||||
Console::Pause();
|
||||
|
||||
uint32_t emuVersion = EmulationSettings::GetMesenVersion();
|
||||
file.write("MST", 3);
|
||||
file.write((char*)&emuVersion, sizeof(emuVersion));
|
||||
file.write((char*)&SaveStateManager::FileFormatVersion, sizeof(uint32_t));
|
||||
|
||||
Console::SaveState(file);
|
||||
Console::Resume();
|
||||
file.close();
|
||||
@ -42,16 +49,34 @@ bool SaveStateManager::LoadState(int stateIndex)
|
||||
{
|
||||
string filepath = SaveStateManager::GetStateFilepath(stateIndex);
|
||||
ifstream file(filepath, ios::in | ios::binary);
|
||||
bool result = false;
|
||||
|
||||
if(file) {
|
||||
Console::Pause();
|
||||
Console::LoadState(file);
|
||||
Console::Resume();
|
||||
char header[3];
|
||||
file.read(header, 3);
|
||||
if(memcmp(header, "MST", 3) == 0) {
|
||||
Console::Pause();
|
||||
|
||||
uint32_t emuVersion, fileFormatVersion;
|
||||
file.read((char*)&emuVersion, sizeof(emuVersion));
|
||||
file.read((char*)&fileFormatVersion, sizeof(fileFormatVersion));
|
||||
|
||||
if(emuVersion != EmulationSettings::GetMesenVersion() || fileFormatVersion != SaveStateManager::FileFormatVersion) {
|
||||
MessageManager::DisplayMessage("Game States", "State #" + std::to_string(stateIndex) + " does not match emulator version.");
|
||||
}
|
||||
|
||||
Console::LoadState(file);
|
||||
Console::Resume();
|
||||
|
||||
MessageManager::DisplayMessage("Game States", "State #" + std::to_string(stateIndex) + " loaded.");
|
||||
result = true;
|
||||
}
|
||||
file.close();
|
||||
MessageManager::DisplayMessage("Game States", "State #" + std::to_string(stateIndex) + " loaded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!result) {
|
||||
MessageManager::DisplayMessage("Game States", "Slot is empty.");
|
||||
}
|
||||
|
||||
MessageManager::DisplayMessage("Game States", "Slot is empty.");
|
||||
return false;
|
||||
return result;
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
class SaveStateManager
|
||||
{
|
||||
private:
|
||||
static const uint32_t FileFormatVersion = 1;
|
||||
static string GetStateFilepath(int stateIndex);
|
||||
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user