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)
|
||||
{
|
||||
bl.GetCoreState(
|
||||
(br, length) => BinarySavestate = br.ReadBytes((int) length),
|
||||
br => BinarySavestate = br.ReadAllBytes(),
|
||||
tr => TextSavestate = tr.ReadToEnd());
|
||||
bl.GetLump(BinaryStateLump.Framebuffer, false,
|
||||
(br, length) =>
|
||||
br =>
|
||||
{
|
||||
SavestateFramebuffer = new int[length / sizeof(int)];
|
||||
for (int i = 0; i < SavestateFramebuffer.Length; i++)
|
||||
{
|
||||
SavestateFramebuffer[i] = br.ReadInt32();
|
||||
}
|
||||
var fb = br.ReadAllBytes();
|
||||
SavestateFramebuffer = new int[fb.Length / sizeof(int)];
|
||||
Buffer.BlockCopy(fb, 0, SavestateFramebuffer, 0, fb.Length);
|
||||
});
|
||||
}
|
||||
else if (StartsFromSaveRam)
|
||||
{
|
||||
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 Newtonsoft.Json;
|
||||
using BizHawk.Bizware.BizwareGL;
|
||||
using BizHawk.Common.IOExtensions;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -223,10 +224,9 @@ namespace BizHawk.Client.Common
|
|||
return;
|
||||
}
|
||||
|
||||
bl.GetLump(ncore, abort: true, (Stream s, long length) =>
|
||||
bl.GetLump(ncore, abort: true, (s, _) =>
|
||||
{
|
||||
b.CoreData = new byte[length];
|
||||
s.Read(b.CoreData, 0, b.CoreData.Length);
|
||||
b.CoreData = s.ReadAllBytes();
|
||||
});
|
||||
|
||||
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
|
||||
{
|
||||
|
|
|
@ -149,22 +149,9 @@ namespace BizHawk.Client.Common
|
|||
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader> callback)
|
||||
=> 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)
|
||||
=> 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>
|
||||
public void GetCoreState(Action<BinaryReader> callbackBinary, Action<TextReader> callbackText)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,22 @@ namespace BizHawk.Common.IOExtensions
|
|||
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>
|
||||
/// Read a string from a binary reader using utf8 encoding and known byte length
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue