From 49c7767ed4fcbd78086d91a14e1c730e56db3266 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 22 Feb 2020 17:16:45 +0900 Subject: [PATCH] System: Check save state version when loading Fixes #34. --- src/core/save_state_version.h | 5 +++-- src/core/system.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/core/save_state_version.h b/src/core/save_state_version.h index a347dc760..12bc78ac0 100644 --- a/src/core/save_state_version.h +++ b/src/core/save_state_version.h @@ -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; diff --git a/src/core/system.cpp b/src/core/system.cpp index be7ce9574..4afeec216 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -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;