fix some edge cases with new zip compression
This commit is contained in:
parent
0ff4aca182
commit
31c7f59e86
|
@ -229,22 +229,20 @@ namespace BizHawk.Client.Common
|
||||||
if (StartsFromSavestate)
|
if (StartsFromSavestate)
|
||||||
{
|
{
|
||||||
bl.GetCoreState(
|
bl.GetCoreState(
|
||||||
(br, length) => BinarySavestate = br.ReadBytes((int) length),
|
br => BinarySavestate = br.ReadAllBytes(),
|
||||||
tr => TextSavestate = tr.ReadToEnd());
|
tr => TextSavestate = tr.ReadToEnd());
|
||||||
bl.GetLump(BinaryStateLump.Framebuffer, false,
|
bl.GetLump(BinaryStateLump.Framebuffer, false,
|
||||||
(br, length) =>
|
br =>
|
||||||
{
|
{
|
||||||
SavestateFramebuffer = new int[length / sizeof(int)];
|
var fb = br.ReadAllBytes();
|
||||||
for (int i = 0; i < SavestateFramebuffer.Length; i++)
|
SavestateFramebuffer = new int[fb.Length / sizeof(int)];
|
||||||
{
|
Buffer.BlockCopy(fb, 0, SavestateFramebuffer, 0, fb.Length);
|
||||||
SavestateFramebuffer[i] = br.ReadInt32();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (StartsFromSaveRam)
|
else if (StartsFromSaveRam)
|
||||||
{
|
{
|
||||||
bl.GetLump(BinaryStateLump.MovieSaveRam, false,
|
bl.GetLump(BinaryStateLump.MovieSaveRam, false,
|
||||||
(br, length) => SaveRam = br.ReadBytes((int) length));
|
br => SaveRam = br.ReadAllBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using BizHawk.Bizware.BizwareGL;
|
using BizHawk.Bizware.BizwareGL;
|
||||||
|
using BizHawk.Common.IOExtensions;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
|
@ -223,10 +224,9 @@ namespace BizHawk.Client.Common
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bl.GetLump(ncore, abort: true, (Stream s, long length) =>
|
bl.GetLump(ncore, abort: true, (s, _) =>
|
||||||
{
|
{
|
||||||
b.CoreData = new byte[length];
|
b.CoreData = s.ReadAllBytes();
|
||||||
s.Read(b.CoreData, 0, b.CoreData.Length);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bl.GetLump(ninput, abort: true, tr =>
|
bl.GetLump(ninput, abort: true, tr =>
|
||||||
|
|
|
@ -163,7 +163,7 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bl.GetLump(BinaryStateLump.StateHistory, abort: false, (br, _) =>
|
bl.GetLump(BinaryStateLump.StateHistory, abort: false, br =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -149,22 +149,9 @@ namespace BizHawk.Client.Common
|
||||||
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader> callback)
|
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader> callback)
|
||||||
=> GetLump(lump, abort, (s, _) => callback(new(s)));
|
=> GetLump(lump, abort, (s, _) => callback(new(s)));
|
||||||
|
|
||||||
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader, long> callback)
|
|
||||||
=> GetLump(lump, abort, (s, length) => callback(new(s), length));
|
|
||||||
|
|
||||||
public bool GetLump(BinaryStateLump lump, bool abort, Action<TextReader> callback)
|
public bool GetLump(BinaryStateLump lump, bool abort, Action<TextReader> callback)
|
||||||
=> GetLump(lump, abort, (s, _) => callback(new StreamReader(s)), false);
|
=> GetLump(lump, abort, (s, _) => callback(new StreamReader(s)), false);
|
||||||
|
|
||||||
/// <exception cref="Exception">couldn't find Binary or Text savestate</exception>
|
|
||||||
public void GetCoreState(Action<BinaryReader, long> callbackBinary, Action<TextReader> callbackText)
|
|
||||||
{
|
|
||||||
if (!GetLump(BinaryStateLump.Corestate, false, callbackBinary)
|
|
||||||
&& !GetLump(BinaryStateLump.CorestateText, false, callbackText))
|
|
||||||
{
|
|
||||||
throw new Exception("Couldn't find Binary or Text savestate");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <exception cref="Exception">couldn't find Binary or Text savestate</exception>
|
/// <exception cref="Exception">couldn't find Binary or Text savestate</exception>
|
||||||
public void GetCoreState(Action<BinaryReader> callbackBinary, Action<TextReader> callbackText)
|
public void GetCoreState(Action<BinaryReader> callbackBinary, Action<TextReader> callbackText)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,22 @@ namespace BizHawk.Common.IOExtensions
|
||||||
return outStream.ToArray();
|
return outStream.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] ReadAllBytes(this BinaryReader br)
|
||||||
|
{
|
||||||
|
const int BUFF_SIZE = 4096;
|
||||||
|
var buffer = new byte[BUFF_SIZE];
|
||||||
|
|
||||||
|
int bytesRead;
|
||||||
|
var outStream = new MemoryStream();
|
||||||
|
|
||||||
|
while ((bytesRead = br.Read(buffer, 0, BUFF_SIZE)) > 0)
|
||||||
|
{
|
||||||
|
outStream.Write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
return outStream.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read a string from a binary reader using utf8 encoding and known byte length
|
/// Read a string from a binary reader using utf8 encoding and known byte length
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue