This commit is contained in:
2026-06-21 14:42:04 +02:00
parent 22cfb1f0a9
commit a3b4cc530d
15 changed files with 2437 additions and 403 deletions

View File

@@ -1,13 +1,41 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
namespace AnotherReplayReader.ReplayFile
{
internal sealed class CommandChunk
public enum CommandArgumentType
{
public byte CommandId { get; private set; }
Int32 = 0,
Float32 = 1,
Bool = 2,
AssetId = 3,
ObjectId = 4,
ObjectId_2 = 5,
UInt32 = 6,
Vector3 = 7,
UInt32_2 = 8,
UInt16 = 9,
AsciiString = 10,
UnicodeString = 11,
}
public record struct CommandArgumentEntry(CommandArgumentType Type, object Value, int Count);
public record struct Vector3(float X, float Y, float Z)
{
public override readonly string ToString() => $"(X={Math.Round(X)},Y={Math.Round(Y)},Z={Math.Round(Z)})";
}
public record struct AssetId(uint TypeId, uint InstanceId)
{
public override readonly string ToString() => $"(TypeId={TypeId:X},InstanceId={InstanceId:X})";
}
public sealed class CommandChunk
{
public int CommandId { get; private set; }
public int PlayerIndex { get; private set; }
public ImmutableArray<CommandArgumentEntry> Data { get; private set; }
public static List<CommandChunk> Parse(ReplayChunk chunk)
{
@@ -16,11 +44,6 @@ namespace AnotherReplayReader.ReplayFile
throw new NotImplementedException();
}
static int ManglePlayerId(byte id)
{
return id / 8 - 2;
}
using var reader = chunk.GetReader();
if (reader.ReadByte() != 1)
{
@@ -31,13 +54,15 @@ namespace AnotherReplayReader.ReplayFile
var numberOfCommands = reader.ReadInt32();
for (var i = 0; i < numberOfCommands; ++i)
{
var commandId = reader.ReadByte();
var playerId = reader.ReadByte();
reader.ReadCommandData(commandId);
var commandIdAndPlayerId = reader.ReadUInt16();
var commandId = commandIdAndPlayerId & 0x7FF;
var playerId = commandIdAndPlayerId >> 11;
var data = reader.ReadCommandData();
list.Add(new CommandChunk
{
CommandId = commandId,
PlayerIndex = ManglePlayerId(playerId)
PlayerIndex = playerId,
Data = data.ToImmutableArray(),
});
}
@@ -54,4 +79,5 @@ namespace AnotherReplayReader.ReplayFile
return $"[玩家 {PlayerIndex}{RA3Commands.GetCommandName(CommandId)}]";
}
}
}