This page describes the data structure used to store and transmit replays. The high level structure of replays is fairly simple and can be understood just by looking at the template below. The structure of the replay key frames is a little more complex.
Key frames are 0x10 bytes long and contain all the position and animation data used during demo replay. Replays can contain a variable number of key frames, the average is about 27. The playback rate is about 3fps.
The first 8 byte of a key frame contain compressed position data, compression and decompression functions are given below. The remaining two DWORDs contain two categories of animation data which are referred to as UP and MV. The UP DWORD generally contains “active” animations triggered by the player, like attacking, jumping, running etc. The MV DWORD contains “passive” animations like flailing while falling, automatic rolls after a jump or recovering after falling from great heights. How exactly the animations are encoded depends on the last byte in each DWORD so lets talk about this byte first.
The last byte in each DWORD is a cyclic counter usually ranging from 0x00 to 0x70. It’s incremented by 0x10 every time an animation change takes place. If the counter is 0x20 for example and the player backsteps, it will get incremented to 0x30 and incremented again when the player returns to the idle animation. Movement animations are not explicitly contained in replay frames. Walking, running and turning animations are reconstructed from changes in position data. You will for example never see a ghost running again a wall and the counter is not incremented when walking, running or when players change between the two.
If the counter is between 0x00 and 0x70 then the first two bytes contain a WORD that defines the animation. These animation IDs don’t seem to match up with the animation IDs used in other parts of the game. A few examples of animation IDs used are:
The third byte contains a bit-field that’s not entirely understood. Bits 4-6(7?) define the characters weight, all animations are modified according to this weight modifier (examples: 000 - ninja flip, 010 - mid roll, 110 - fat roll…). The lower bits are very rarely set and setting them manually doesn’t make any visual difference.
There are situations when the counter byte will have values between 0x80 and 0xF0. For example while throwing( backstabbing, .. ), picking up items or while sitting at a bonfire. In those cases the first 3 bytes are interpreted as regular animation IDs.
Replays can be fully modded. Replay ghosts can be created online and offline. Sending ghosts to other players is also possible.