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 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(); 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)}]"; } } }