Skip to content

General Binary Format

satan6 edited this page Sep 18, 2014 · 13 revisions

General Binary Format

  • Each keyframe and chunk is a sequence of blocks.
  • Each block starts with a marker byte, which determines its structure.
  • A block encapsulates a game packet.
  • A chunk contains the S2C packets of the game during its timespan.
  • A keyframe contains a set of packets that will recreate the game state at that time.

Marker byte

Marker bits (high to low):

1 2 3 4
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
A 1 0 1 0
B 1 0 1 1
C 1 1 0 0
D 1 1 0 1
E 1 1 1 0
F 1 1 1 1
5 6 7 8 Channel
0 0 0 0 0 Handshake
1 0 0 0 1 C2S
2 0 0 1 0 Gameplay
3 0 0 1 1 S2C
4 0 1 0 0 Low priority
5 0 1 0 1 Communication
7 0 1 1 0 Loading screen

Bitflags

Bit 1: Time format

  • 0 => 4-bytes (float, absolute timestamp, in seconds)
  • 1 => 1 byte (uint8, milliseconds since last block)

Bit 2: Include type byte

  • 0 => yes
  • 1 => no (same as previous block)

Bit 3: Blockparam length

  • 0 => 4 bytes
  • 1 => 1 byte (relative to previous block)

Bit 4: Bytes reserved for the contentlength

  • 0 => 4 bytes
  • 1 => 1 byte

Bits 5-8: Channel

  • The enet channel in the normal game prototcol
  • Probably unimportant for our purposes

Block structure

marker + [time] + [contentlength] + (type) + [blockparam] + [blockcontent]

B3 [00] [C3] (4B) [00] ...
83 [00] [12 02 00 00] (29) [19 00 00 40] ...
A3 [00] [28 01 00 00] (45) [00] ...
F3 [00] [03] [00] ...
93 [00] [07] (FE) [00 00 00 00] ..
73 [XX XX XX XX] [03] [00] ...

Type

  • Specifies the kind of packet the block contains
  • Is the same as the packet type in the normal game protocol
  • The type 0xFE means that the real packet type is the first 2 bytes of the content, allowing types over 0xFF.

Time

  • In seconds of game time, specifies when the packet (like an event) occurred and should be replayed.
  • It does not (significantly) change in a keyframe.

Blockparam

  • The 8-bit values are, like with time, relative to the previous param.
  • Specifies the owner of the packet, usually in form of an entity ID.
  • If this kind of packet has no owner, it is set to 0

Example keyframe

Start spawn

03
D4 00 FF 44 // float: 2040.02 [time]
02 00 00 00 // [contentlength]
62 // [type]
00 00 00 00 // [blockparam]
00 00 // [blockcontent]

Spawn hero

B3
00 // [time]
C3 // [contentlength]
4C // [type]
00 // [blockparam]
[... 0xC3 bytes ...]

Summoner data

83
00 // [time]
12 02 00 00 // [contentlength]
2A // [type]
19 00 00 40 // EntityID [blockparam]
[... 0x212 bytes ...]

Set inventory

B3
00 // [time]
98 // [contentlength]
FE // [type]
00 // [blockparam]
[... 0x98 bytes ...]

Player stats

A3
00 // [time]
28 01 00 00 // [contentlength]
46 // [type]
00 // [blockparam]
[... 0x128 bytes ...]

Set ability levels

B3
00 // [time]
03 // [contentlength]
15 // [type]
00 // [blockparam]
00 05 00 // [blockcontent] 5 points in q
F3
00 // [time]
03 // [contentlength]
00 // [blockparam]
01 05 00 // [blockcontent] 5 points in w
[etc...]