41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace AnotherReplayReader.ReplayFile
|
|
{
|
|
internal sealed class ReplayChunk
|
|
{
|
|
private readonly byte[] _data;
|
|
|
|
public uint TimeCode { get; }
|
|
public byte Type { get; }
|
|
|
|
public TimeSpan Time => TimeSpan.FromSeconds(TimeCode / Replay.FrameRate);
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
}
|