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:Progs.dat (QuakeC)

From ReverseEngineering.wiki
Format
Developer id Software
Versions 6 (Quake, QuakeWorld); FTEQCC extended version 7 is not covered
Magic 06 00 00 00 (int32 version 6) at offset 0
Extensions .dat
Endianness little
On this wiki Facts · Code · Notes · Topics

Compiled QuakeC bytecode loaded by the Software:Quake engine (`progs.dat`, QuakeWorld `qwprogs.dat`): a 60-byte header (version 6, CRC of the engine-shared definitions, then offset/count pairs) for statements, global and field definitions, functions, a string table and the global variables. Statements are 8 bytes (opcode and three 16-bit operands addressing the globals); functions with a negative first statement are engine builtins.

Identification

Offset 0 is the int32 version 6 and offset 4 the int32 header CRC: 5927 for Quake (NetQuake) progs, 54730 for QuakeWorld. The engine rejects files whose version or CRC differs from its compiled-in values. The CRC is a CRC-16 of the shared definitions header (progdefs.h) generated by the compiler, so it identifies the system globals and entity fields the progs expect, not the file contents.

Structure

The header is 15 int32: version, crc, then offset and count for statements, global definitions, field definitions, functions, strings (byte size) and globals, and finally entityfields (entity size in 4-byte words). All offsets are from the start of the file.

  • Statements (8 bytes): uint16 opcode, three int16 operands a, b, c. Operands are indices into the globals array (4-byte slots), not registers. Statement 0 is unused.
  • Definitions (8 bytes): uint16 type (etype_t 0-7: void, string, float, vector, entity, field, function, pointer; bit 15 = save in savegames), uint16 global or field offset, int32 name string offset.
  • Functions (36 bytes): first statement, first local slot, local slot count, a runtime profile counter, name and source file string offsets, parameter count and 8 parameter sizes (1 or 3 slots).
  • Strings: one block of NUL-terminated strings; a string value is a byte offset into it, and offset 0 is the empty string.
  • Globals: the initial value of every global slot. Slot 1 holds return values and slots 4, 7, ... 25 the eight parameters (3 slots each so vectors fit).

Execution model

  • OP_CALLn (n = argument count 0-8) calls the function whose index is in global a; if its first_statement is negative, -first_statement is a builtin number dispatched to the engine (pr_builtins[], e.g. spawning, tracing, sound).
  • Jumps are relative: OP_GOTO adds a to the current statement index, OP_IF/OP_IFNOT add b when the condition in a holds.
  • OP_STATE sets self.frame to a, self.think to b and self.nextthink to time + 0.1: the compiled form of QuakeC's [frame, nextfunction] animation syntax.
  • The interpreter aborts after 100000 statements in one call ("runaway loop error").

Tools that read/write it

  • Engine loader PR_LoadProgs (pr_edict.c) and interpreter PR_ExecuteProgram (pr_exec.c); compilers qcc (id), FTEQCC, GMQCC. Community decompilers exist; they work well because function, global and field names are kept in the file.

Code & repositories

  • https://github.com/id-Software/Quake @ bf4ac424ce754894ac8f1dae6a3981954bc9852d · license: GPL-2.0-or-later (declared by the contributor; GitHub's detector did not recognize a license file)
    GPL release of the Quake source (WinQuake/bspfile.h, common.c, pr_comp.h, modelgen.h, spritegn.h).
    Tested on: source read, not run: source read · checked 2026-10-18; last activity 2024-06-15

Pitfalls

  • Field definitions give offsets into the entity's field block, global definitions offsets into the globals array; both are in 4-byte slots, not bytes.
  • A vector occupies three consecutive slots, and the compiler also emits name_x, name_y, name_z definitions for its components.
  • Names are usually present, unlike in native code, but not always all of them. In LibreQuake's FTEQCC-built progs.dat and qwprogs.dat, ordinary functions and fields keep their names (bprint, logfrag, modelindex, ...), but builtin functions and their global definitions have empty names and every function's source file name is empty, so builtins must be mapped by number. Unverified: this comes from FTEQCC's name-stripping optimisations; test by recompiling with optimisations off. The compiler can be recognised by its FTEQCC: version string in the string table.

Evidence & references

  • id Software Quake source, WinQuake/pr_comp.h (shared by engine and compiler: opcodes, dstatement_t, ddef_t, dfunction_t, dprograms_t, PROG_VERSION), progdefs.q1 and QW/server/progdefs.h (PROGHEADER_CRC), pr_edict.c, pr_exec.c at commit bf4ac42.
  • Runtime test: LibreQuake v0.09-beta progs.dat (version 6, CRC 5927, 22216 statements, 2152 functions of which 67 are builtins) and qwprogs.dat (version 6, CRC 54730, 12326 statements, 540 functions, 70 builtins); every statement opcode is at most 65 and string offset 0 is the empty string.

Open questions

  • Which builtin numbers does each engine assign (Quake vs. QuakeWorld lists differ)? A table from pr_cmds.c and QW/server/pr_cmds.c would make decompiled progs readable.