2021-10-20 22:22:19 +02:00

58 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.IO;
namespace AnotherReplayReader.ReplayFile
{
internal sealed class CommandChunk
{
public byte CommandId { get; private set; }
public int PlayerIndex { get; private set; }
public static List<CommandChunk> Parse(ReplayChunk chunk)
{
if (chunk.Type != 1)
{
throw new NotImplementedException();
}
static int ManglePlayerId(byte id)
{
return id / 8 - 2;
}
using var reader = chunk.GetReader();
if (reader.ReadByte() != 1)
{
throw new InvalidDataException("Payload first byte not 1");
}
var list = new List<CommandChunk>();
var numberOfCommands = reader.ReadInt32();
for (var i = 0; i < numberOfCommands; ++i)
{
var commandId = reader.ReadByte();
var playerId = reader.ReadByte();
reader.ReadCommandData(commandId);
list.Add(new CommandChunk
{
CommandId = commandId,
PlayerIndex = ManglePlayerId(playerId)
});
}
if (reader.BaseStream.Position != reader.BaseStream.Length)
{
throw new InvalidDataException("Payload not fully parsed");
}
return list;
}
public override string ToString()
{
return $"[玩家 {PlayerIndex}{RA3Commands.GetCommandName(CommandId)}]";
}
}
}