From 46bfcbc47d734d7a2e1700c7f1f73086b45dbb73 Mon Sep 17 00:00:00 2001 From: nattthebear Date: Wed, 3 Jun 2020 07:23:06 -0400 Subject: [PATCH] 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. --- src/BizHawk.Emulation.Cores/Waterbox/WaterboxHost.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/BizHawk.Emulation.Cores/Waterbox/WaterboxHost.cs b/src/BizHawk.Emulation.Cores/Waterbox/WaterboxHost.cs index e92ba716b2..a86989c27c 100644 --- a/src/BizHawk.Emulation.Cores/Waterbox/WaterboxHost.cs +++ b/src/BizHawk.Emulation.Cores/Waterbox/WaterboxHost.cs @@ -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");