File StructureΒΆ
A Deadlock demo file uses the PBDEMS2 (Protobuf Demo Source 2) format. The file is a sequential stream of commands, each carrying a protobuf-encoded payload.
HeaderΒΆ
The first 16 bytes of the file are fixed:
Offset |
Size |
Contents |
|---|---|---|
0 |
8 bytes |
Magic: |
8 |
4 bytes |
Offset to |
12 |
4 bytes |
Offset to spawn groups |
The magic bytes are checked during construction to reject non-demo files. The
DEM_FileInfo offset is used by the parser to jump directly to the file info command
at the end of the file, avoiding a full sequential scan. The spawn groups offset is
currently unused.
Command StreamΒΆ
After the 16-byte header, the rest of the file is a sequence of commands. Each command has a small header followed by a protobuf body:
[Raw CMD] varint32 β command type + compression flag
[Tick] varint32 β game tick when this command was recorded
[Body Size] varint32 β size of the body in bytes
[Body] bytes β protobuf message, optionally Snappy-compressed
The raw command value encodes two pieces of information:
Command type: the lower bits, after masking out the compression flag
Compression flag:
DEM_IsCompressedβ when set, the body is Snappy-compressed and must be decompressed before protobuf decoding
Command TypesΒΆ
Command |
Description |
|---|---|
|
File metadata (build number, map name, game directory) |
|
Serializer definitions (field schemas for all entity classes) |
|
Maps numeric class IDs to network class names |
|
Initialization packets (string tables, server info, initial entities) |
|
Per-tick game state updates |
|
Complete state snapshot (string tables + all entities) |
|
Marks the end of initialization β game ticks begin after this |
|
End of demo |
|
Footer metadata (playback ticks, playback time, game info) |
Two PhasesΒΆ
Parsing happens in two phases, split by DEM_SyncTick:
Initialization (
DEM_FileHeaderthroughDEM_SyncTick): the file header, send tables, class info, and signon packets are processed to build up the serializer registry, class mapping, string tables, and initial entity state.Playback (after
DEM_SyncTickthroughDEM_Stop):DEM_Packetcommands carry per-tick entity deltas. PeriodicDEM_FullPacketcommands provide complete state snapshots that allow the parser to jump ahead without replaying every tick.