38 lines
980 B
C#
38 lines
980 B
C#
using System.IO;
|
|
|
|
namespace AnotherReplayReader.ReplayFile
|
|
{
|
|
internal sealed class ReplayChunk
|
|
{
|
|
private readonly byte[] _data;
|
|
|
|
public uint TimeCode { get; }
|
|
public byte Type { get; }
|
|
|
|
public ReplayChunk(uint timeCode, BinaryReader reader)
|
|
{
|
|
TimeCode = timeCode; // reader.ReadUInt32();
|
|
Type = reader.ReadByte();
|
|
var chunkSize = reader.ReadInt32();
|
|
_data = reader.ReadBytes(chunkSize);
|
|
if (reader.ReadInt32() != 0)
|
|
{
|
|
throw new InvalidDataException("Replay Chunk not ended with zero");
|
|
}
|
|
}
|
|
|
|
public BinaryReader GetReader() => new(new MemoryStream(_data, false));
|
|
|
|
public void WriteTo(BinaryWriter writer)
|
|
{
|
|
writer.Write(TimeCode);
|
|
writer.Write(Type);
|
|
writer.Write(_data.Length);
|
|
writer.Write(_data);
|
|
writer.Write(0);
|
|
}
|
|
}
|
|
|
|
|
|
}
|