TAStudio - saving/loading of greenzone
This commit is contained in:
parent
f3af2821bb
commit
4c9c8e3cb1
|
@ -28,6 +28,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog()));
|
||||
|
||||
bs.PutLump(BinaryStateLump.Greenzone, (BinaryWriter bw) => bw.Write(StateManager.ToArray()));
|
||||
bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => bw.Write(LagLog.ToByteArray()));
|
||||
bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));
|
||||
|
||||
|
@ -124,24 +125,6 @@ namespace BizHawk.Client.Common
|
|||
ExtractInputLog(tr, out errorMessage);
|
||||
});
|
||||
|
||||
bl.GetLump(BinaryStateLump.LagLog, true, delegate(BinaryReader br)
|
||||
{
|
||||
var bytes = br.BaseStream.ReadAllBytes();
|
||||
LagLog = bytes.ToBools().ToList();
|
||||
});
|
||||
|
||||
bl.GetLump(BinaryStateLump.Markers, true, delegate(TextReader tr)
|
||||
{
|
||||
string line;
|
||||
while ((line = tr.ReadLine()) != null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
Markers.Add(new TasMovieMarker(line));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (StartsFromSavestate)
|
||||
{
|
||||
bl.GetCoreState(
|
||||
|
@ -154,6 +137,30 @@ namespace BizHawk.Client.Common
|
|||
TextSavestate = tr.ReadToEnd();
|
||||
});
|
||||
}
|
||||
|
||||
// TasMovie enhanced information
|
||||
bl.GetLump(BinaryStateLump.LagLog, false, delegate(BinaryReader br)
|
||||
{
|
||||
var bytes = br.BaseStream.ReadAllBytes();
|
||||
LagLog = bytes.ToBools().ToList();
|
||||
});
|
||||
|
||||
bl.GetLump(BinaryStateLump.Greenzone, false, delegate(BinaryReader br)
|
||||
{
|
||||
StateManager.FromArray(br.BaseStream.ReadAllBytes());
|
||||
});
|
||||
|
||||
bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr)
|
||||
{
|
||||
string line;
|
||||
while ((line = tr.ReadLine()) != null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
Markers.Add(new TasMovieMarker(line));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
|
@ -76,5 +78,50 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
States.Clear();
|
||||
}
|
||||
|
||||
public byte[] ToArray()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
var bytes = BitConverter.GetBytes(States.Count);
|
||||
ms.Write(bytes, 0, bytes.Length);
|
||||
foreach (var kvp in States.OrderBy(s => s.Key))
|
||||
{
|
||||
var frame = BitConverter.GetBytes(kvp.Key);
|
||||
ms.Write(frame, 0, frame.Length);
|
||||
|
||||
var stateLen = BitConverter.GetBytes(kvp.Value.Length);
|
||||
ms.Write(stateLen, 0, stateLen.Length);
|
||||
ms.Write(kvp.Value, 0, kvp.Value.Length);
|
||||
}
|
||||
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
// Map:
|
||||
// 4 bytes - total savestate count
|
||||
//[Foreach state]
|
||||
// 4 bytes - frame
|
||||
// 4 bytes - length of savestate
|
||||
// 0 - n savestate
|
||||
public void FromArray(byte[] bytes)
|
||||
{
|
||||
var position = 0;
|
||||
var stateCount = BitConverter.ToInt32(bytes, 0);
|
||||
position += 4;
|
||||
for (int i = 0; i < stateCount; i++)
|
||||
{
|
||||
var frame = BitConverter.ToInt32(bytes, position);
|
||||
position += 4;
|
||||
var stateLen = BitConverter.ToInt32(bytes, position);
|
||||
position += 4;
|
||||
var state = bytes
|
||||
.Skip(position)
|
||||
.Take(stateLen)
|
||||
.ToArray();
|
||||
|
||||
position += stateLen;
|
||||
States.Add(frame, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue