add a version tag to waterbox states

we're not building any sort of back compat, no.  but if things change, better to bail early to decrease the chance i get bug reports for things i'm not going to fix.
This commit is contained in:
nattthebear 2020-06-03 07:23:06 -04:00
parent d06ed05929
commit 46bfcbc47d
1 changed files with 9 additions and 0 deletions

View File

@ -361,8 +361,13 @@ namespace BizHawk.Emulation.Cores.Waterbox
return _syscalls.RemoveTransientFile(name);
}
private const ulong MAGIC = 0x736b776162727477;
private const ulong WATERBOXSTATEVERSION = 1;
public void SaveStateBinary(BinaryWriter bw)
{
bw.Write(MAGIC);
bw.Write(WATERBOXSTATEVERSION);
bw.Write(_createstamp);
bw.Write(_savestateComponents.Count);
using (this.EnterExit())
@ -376,6 +381,10 @@ namespace BizHawk.Emulation.Cores.Waterbox
public void LoadStateBinary(BinaryReader br)
{
if (br.ReadUInt64() != MAGIC)
throw new InvalidOperationException("Internal savestate error");
if (br.ReadUInt64() != WATERBOXSTATEVERSION)
throw new InvalidOperationException("Waterbox savestate version mismatch");
var differentCore = br.ReadInt64() != _createstamp; // true if a different core instance created the state
if (br.ReadInt32() != _savestateComponents.Count)
throw new InvalidOperationException("Internal savestate error");