fix zipstate internals that caused movies that started from savestate to explode

This commit is contained in:
goyuken 2014-07-25 16:51:27 +00:00
parent 3618cbde81
commit 7ac1d58a51
3 changed files with 34 additions and 16 deletions

View File

@ -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. // 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 _ver = new Version(1, 0, 0); // except for the first release, which doesn't
} }
@ -160,7 +160,7 @@ namespace BizHawk.Client.Common
/// <param name="abort">true to throw exception on failure</param> /// <param name="abort">true to throw exception on failure</param>
/// <param name="callback">function to call with the desired stream</param> /// <param name="callback">function to call with the desired stream</param>
/// <returns>true if callback was called and stream was loaded</returns> /// <returns>true if callback was called and stream was loaded</returns>
public bool GetLump(BinaryStateLump lump, bool abort, Action<Stream> callback) public bool GetLump(BinaryStateLump lump, bool abort, Action<Stream, long> callback)
{ {
var name = BinaryStateFileNames.Get(lump); var name = BinaryStateFileNames.Get(lump);
var e = _zip.GetEntry(name); var e = _zip.GetEntry(name);
@ -168,7 +168,7 @@ namespace BizHawk.Client.Common
{ {
using (var zs = _zip.GetInputStream(e)) using (var zs = _zip.GetInputStream(e))
{ {
callback(zs); callback(zs, e.Size);
} }
return true; return true;
@ -184,26 +184,45 @@ namespace BizHawk.Client.Common
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader> callback) public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader> callback)
{ {
return GetLump(lump, abort, delegate(Stream s) return GetLump(lump, abort, delegate(Stream s, long unused)
{ {
var br = new BinaryReader(s); var br = new BinaryReader(s);
callback(br); callback(br);
}); });
} }
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader, long> 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<TextReader> callback) public bool GetLump(BinaryStateLump lump, bool abort, Action<TextReader> callback)
{ {
return GetLump(lump, abort, delegate(Stream s) return GetLump(lump, abort, delegate(Stream s, long unused)
{ {
var tr = new StreamReader(s); var tr = new StreamReader(s);
callback(tr); callback(tr);
}); });
} }
/*
/// <summary> /// <summary>
/// load binary state, or text state if binary state lump doesn't exist /// load binary state, or text state if binary state lump doesn't exist
/// </summary> /// </summary>
public void GetCoreState(Action<Stream> callbackBinary, Action<Stream> callbackText) public void GetCoreState(Action<Stream> callbackBinary, Action<Stream> 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<BinaryReader, long> callbackBinary, Action<TextReader> callbackText)
{ {
if (!GetLump(BinaryStateLump.Corestate, false, callbackBinary) if (!GetLump(BinaryStateLump.Corestate, false, callbackBinary)
&& !GetLump(BinaryStateLump.CorestateText, false, callbackText)) && !GetLump(BinaryStateLump.CorestateText, false, callbackText))
@ -215,7 +234,7 @@ namespace BizHawk.Client.Common
public void GetCoreState(Action<BinaryReader> callbackBinary, Action<TextReader> callbackText) public void GetCoreState(Action<BinaryReader> callbackBinary, Action<TextReader> callbackText)
{ {
if (!GetLump(BinaryStateLump.Corestate, false, callbackBinary) 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"); throw new Exception("Couldn't find Binary or Text savestate");
} }

View File

@ -111,9 +111,9 @@ namespace BizHawk.Client.Common
if (StartsFromSavestate) if (StartsFromSavestate)
{ {
bl.GetCoreState( 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) delegate(TextReader tr)
{ {

View File

@ -134,9 +134,9 @@ namespace BizHawk.Client.Common
if (StartsFromSavestate) if (StartsFromSavestate)
{ {
bl.GetCoreState( 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) delegate(TextReader tr)
{ {
@ -145,10 +145,9 @@ namespace BizHawk.Client.Common
} }
// TasMovie enhanced information // 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 = br.ReadBytes((int)length).ToBools().ToList();
LagLog = bytes.ToBools().ToList();
}); });
bl.GetLump(BinaryStateLump.GreenzoneSettings, false, delegate(TextReader tr) bl.GetLump(BinaryStateLump.GreenzoneSettings, false, delegate(TextReader tr)
@ -158,9 +157,9 @@ namespace BizHawk.Client.Common
if (StateManager.Settings.SaveGreenzone) 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));
}); });
} }