diff --git a/BizHawk.Client.Common/BinarySaveStates.cs b/BizHawk.Client.Common/BinarySaveStates.cs index c0731e358a..bab7932b91 100644 --- a/BizHawk.Client.Common/BinarySaveStates.cs +++ b/BizHawk.Client.Common/BinarySaveStates.cs @@ -100,10 +100,10 @@ namespace BizHawk.Client.Common } } - private void ReadVersion(Stream s) + private void ReadVersion(Stream s, long length) { // the "BizState 1.0" tag contains an integer in it describing the sub version. - if (s.Length == 0) + if (length == 0) { _ver = new Version(1, 0, 0); // except for the first release, which doesn't } @@ -160,7 +160,7 @@ namespace BizHawk.Client.Common /// true to throw exception on failure /// function to call with the desired stream /// true if callback was called and stream was loaded - public bool GetLump(BinaryStateLump lump, bool abort, Action callback) + public bool GetLump(BinaryStateLump lump, bool abort, Action callback) { var name = BinaryStateFileNames.Get(lump); var e = _zip.GetEntry(name); @@ -168,7 +168,7 @@ namespace BizHawk.Client.Common { using (var zs = _zip.GetInputStream(e)) { - callback(zs); + callback(zs, e.Size); } return true; @@ -184,26 +184,45 @@ namespace BizHawk.Client.Common public bool GetLump(BinaryStateLump lump, bool abort, Action callback) { - return GetLump(lump, abort, delegate(Stream s) + return GetLump(lump, abort, delegate(Stream s, long unused) { var br = new BinaryReader(s); callback(br); }); } + public bool GetLump(BinaryStateLump lump, bool abort, Action callback) + { + return GetLump(lump, abort, delegate(Stream s, long length) + { + var br = new BinaryReader(s); + callback(br, length); + }); + } + public bool GetLump(BinaryStateLump lump, bool abort, Action callback) { - return GetLump(lump, abort, delegate(Stream s) + return GetLump(lump, abort, delegate(Stream s, long unused) { var tr = new StreamReader(s); callback(tr); }); } + /* /// /// load binary state, or text state if binary state lump doesn't exist /// public void GetCoreState(Action callbackBinary, Action callbackText) + { + if (!GetLump(BinaryStateLump.Corestate, false, callbackBinary) + && !GetLump(BinaryStateLump.CorestateText, false, callbackText)) + { + throw new Exception("Couldn't find Binary or Text savestate"); + } + }*/ + + public void GetCoreState(Action callbackBinary, Action callbackText) { if (!GetLump(BinaryStateLump.Corestate, false, callbackBinary) && !GetLump(BinaryStateLump.CorestateText, false, callbackText)) @@ -215,7 +234,7 @@ namespace BizHawk.Client.Common public void GetCoreState(Action callbackBinary, Action callbackText) { if (!GetLump(BinaryStateLump.Corestate, false, callbackBinary) - && !GetLump(BinaryStateLump.CorestateText, false, callbackText)) + && !GetLump(BinaryStateLump.CorestateText, false, callbackText)) { throw new Exception("Couldn't find Binary or Text savestate"); } diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs index 9a84811428..eaf136748b 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs @@ -111,9 +111,9 @@ namespace BizHawk.Client.Common if (StartsFromSavestate) { bl.GetCoreState( - delegate(BinaryReader br) + delegate(BinaryReader br, long length) { - BinarySavestate = br.ReadBytes((int)br.BaseStream.Length); + BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs index 938a0375fd..77f7e67b3c 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs @@ -134,9 +134,9 @@ namespace BizHawk.Client.Common if (StartsFromSavestate) { bl.GetCoreState( - delegate(BinaryReader br) + delegate(BinaryReader br, long length) { - BinarySavestate = br.ReadBytes((int)br.BaseStream.Length); + BinarySavestate = br.ReadBytes((int)length); }, delegate(TextReader tr) { @@ -145,10 +145,9 @@ namespace BizHawk.Client.Common } // TasMovie enhanced information - bl.GetLump(BinaryStateLump.LagLog, false, delegate(BinaryReader br) + bl.GetLump(BinaryStateLump.LagLog, false, delegate(BinaryReader br, long length) { - var bytes = br.BaseStream.ReadAllBytes(); - LagLog = bytes.ToBools().ToList(); + LagLog = br.ReadBytes((int)length).ToBools().ToList(); }); bl.GetLump(BinaryStateLump.GreenzoneSettings, false, delegate(TextReader tr) @@ -158,9 +157,9 @@ namespace BizHawk.Client.Common if (StateManager.Settings.SaveGreenzone) { - bl.GetLump(BinaryStateLump.Greenzone, false, delegate(BinaryReader br) + bl.GetLump(BinaryStateLump.Greenzone, false, delegate(BinaryReader br, long length) { - StateManager.FromArray(br.BaseStream.ReadAllBytes()); + StateManager.FromArray(br.ReadBytes((int)length)); }); }