System: Check save state version when loading

Fixes #34.
This commit is contained in:
Connor McLaughlin 2020-02-22 17:16:45 +09:00
parent 959a555274
commit 49c7767ed4
2 changed files with 18 additions and 2 deletions

View File

@ -1,4 +1,5 @@
#pragma once
#include "pse/types.h"
#include "types.h"
constexpr u32 SAVE_STATE_VERSION = 1;
static constexpr u32 SAVE_STATE_MAGIC = 0x43435544;
static constexpr u32 SAVE_STATE_VERSION = 1;

View File

@ -16,6 +16,7 @@
#include "mdec.h"
#include "memory_card.h"
#include "pad.h"
#include "save_state_version.h"
#include "sio.h"
#include "spu.h"
#include "timers.h"
@ -271,6 +272,20 @@ bool System::CreateGPU(GPURenderer renderer)
bool System::DoState(StateWrapper& sw)
{
u32 magic = SAVE_STATE_MAGIC;
u32 version = SAVE_STATE_VERSION;
sw.Do(&magic);
if (magic != SAVE_STATE_MAGIC)
return false;
sw.Do(&version);
if (version != SAVE_STATE_VERSION)
{
m_host_interface->ReportFormattedError("Save state is incompatible: expecting version %u but state is version %u.",
SAVE_STATE_VERSION, version);
return false;
}
if (!sw.DoMarker("System"))
return false;