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:PAK (Quake)

From ReverseEngineering.wiki
Format
Developer id Software
Versions one layout, no version field
Magic 50 41 43 4B ("PACK") at offset 0
Extensions .pak
Endianness little
On this wiki Facts · Code · Notes · Topics

Archive format of Software:Quake (`pak0.pak`, `pak1.pak`, ...): a 12-byte header ("PACK", directory offset, directory length) and a directory of 64-byte entries (56-byte path, offset, length) pointing at stored, uncompressed files. Also used, unchanged, by Quake II and many Quake-engine games.

Identification

Offset 0 holds the ASCII text PACK, followed by two little-endian int32: the file offset of the directory and its length in bytes. The number of files is the directory length divided by 64.

Structure

  • Header (12 bytes): id, dirofs, dirlen.
  • Directory: dirlen / 64 entries of a 56-byte NUL-terminated path (forward slashes, e.g. maps/start.bsp, progs/player.mdl) and two int32: offset of the file data and its length.
  • Data: stored files, no compression, no per-file header, no alignment. Tools write the directory after the data, but only dirofs is authoritative.

The Quake engine accepts at most 2048 files per pack (MAX_FILES_IN_PACK). There is no hash or index: the engine scans the directory linearly with a case-sensitive string compare.

Quake II reuses the same structures with the ident written as IDPAKHEADER ('P','A','C','K' packed into a little-endian int32, bytes 50 41 43 4B) and raises the limit to MAX_FILES_IN_PACK 4096 (Quake 1: 2048). Source: id-Software/Quake-2 qcommon/qfiles.h lines 34-49 at commit 372afde. Quake III dropped PAK for Format:PK3 (Quake III) (ZIP).

Integrity check

When loading each pack, the 1.09 source compares the entry count with 339 and a CRC-16 of the raw directory bytes with 32981 (0x80D5) and sets an internal "modified" flag if either differs; those constants describe the original id1/pak0.pak (see the identification fact on Software:Quake). The CRC is CRC-16/CCITT-FALSE over exactly dirlen bytes.

Tools that read/write it

  • The engine's COM_LoadPackFile in common.c (GPL-2.0) is the reference reader.
  • Any Quake source port and editors such as TrenchBroom read it; the format is simple enough to parse with a dozen lines of any language.

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

  • The 56-byte name is a C string: readers must stop at the first NUL, not strip trailing padding (some writers leave garbage after the NUL).
  • Quake's pak1.pak (registered episodes) is an ordinary second pack; nothing in the format links the two.

Evidence & references

  • id Software Quake source, WinQuake/common.c (dpackheader_t, dpackfile_t, COM_LoadPackFile, COM_AddGameDirectory) at commit bf4ac42.
  • Runtime test: LibreQuake v0.09-beta id1/pak0.pak (353 entries, SHA-256 0dd895a425e75d9908025dcfe340f75f5b8166ada68b2d7ee54d8d91d29378ff) and pak1.pak (60 entries) parse with these structures; in both the directory length is a multiple of 64 and the directory ends exactly at the end of the file. Directory CRCs are 34223 and 47719, so the engine treats them as modified, as expected for non-id data.