Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:HL2DEMO (Source demo)

From ReverseEngineering.wiki
Format
Developer Valve
Versions demo protocol 3 (DEMO_PROTOCOL)
Magic 48 4C 32 44 45 4D 4F 00 ("HL2DEMO\0") at offset 0
Extensions .dem
Endianness little
On this wiki Facts · Code · Notes · Topics

Source engine demo recording (.dem): the 8-byte id HL2DEMO, a 1072-byte header (demo and network protocol, server, client, map, game directory, playback time, ticks, frames, signon length) and a stream of commands dem_signon to dem_stringtables.

Identification

The file starts with the 8-byte string HL2DEMO (NUL padded, DEMO_HEADER_ID) and DEMO_PROTOCOL is 3 in the SDK 2013. GoldSrc demos are a different format. Unverified: Source 2 demos start with PBDEMS2.

Header

demoheader_t: char demofilestamp[8]; int demoprotocol; int networkprotocol; char servername[260]; char clientname[260]; char mapname[260]; char gamedirectory[260]; float playback_time; int playback_ticks; int playback_frames; int signonlength; = 8 + 4 + 4 + 4*260 + 16 = 1072 bytes (computed from the types; MAX_OSPATH is 260). networkprotocol is the game's PROTOCOL_VERSION.

Commands

After the header the file is a stream of commands (dem_signon 1, dem_packet 2, dem_synctick 3, dem_consolecmd 4, dem_usercmd 5, dem_datatables 6, dem_stop 7, dem_stringtables 8; dem_lastcmd = 8). The header file defines only the ids and the view info struct democmdinfo_t (flags FDEMO_USE_ORIGIN2 1, FDEMO_USE_ANGLES2 2, FDEMO_NOINTERP 4, then viewOrigin, viewAngles, localViewAngles and their resampled copies).

Code & repositories

  • https://github.com/ValveSoftware/source-sdk-2013 @ be57e3d01ac7d7aa6a2cacbfef187c0b46616db0 · license: LicenseRef-Source-SDK (declared by the contributor; GitHub's detector did not recognize LICENSE)
    Source SDK 2013: src/public/demofile/demoformat.h (demo header and commands). Proprietary Source SDK license.
    Tested on: source read, not run · checked 2026-10-18; last activity 2026-10-10

Pitfalls

Unverified: each command is a 1-byte id and a 4-byte tick (and, in newer protocols, a player-slot byte), followed by a payload whose length prefix depends on the command (dem_packet starts with a democmdinfo_t, a sequence in/out pair and a length-prefixed network message); dem_stop has no payload. This is not in demoformat.h and comes from community readers; confirm in the engine's demo reader or by parsing a public demo.

Evidence & references

ValveSoftware/source-sdk-2013 src/public/demofile/demoformat.h lines 17-61, 73-76 at commit be57e3d01ac7d7aa6a2cacbfef187c0b46616db0.