Introduction
WAD2 is the lump archive of id Software’s Quake. The game
keeps its status bar and menu pictures in gfx.wad, and map makers keep wall textures in
texture WADs, which the map compiler reads and copies into the level. A file holds lumps, each with
a name of up to 16 bytes and a type code, and a directory that says where they are. It is not the
Doom engine WAD, whose header starts IWAD or
PWAD and whose directory entries are different.
Header
All numbers are little-endian. The writer in id’s tools puts the first lump at offset 12 and the directory after the last lump; the header gives its place, so a reader should not assume it.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | identification | The letters WAD2 (57 41 44 32) |
| 4 | 4 | numlumps | Signed 32-bit count of directory entries |
| 8 | 4 | infotableofs | Signed 32-bit offset of the directory from the start of the file |
A comment in the game’s source also mentions the identifier 2DAW, for a big-endian
file. The released game accepts only WAD2, and the released writer writes
WAD2 whichever byte order it is asked for.
Directory
The directory is numlumps entries of 32 bytes each.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | filepos | Offset of the lump’s data from the start of the file |
| 4 | 4 | disksize | Bytes the lump takes in the file |
| 8 | 4 | size | Bytes after decompression; the same as disksize for an uncompressed lump |
| 12 | 1 | type | Lump type, see below |
| 13 | 1 | compression | 0 = none (CMP_NONE), 1 = LZSS (CMP_LZSS) |
| 14 | 1 | pad1 | Padding; the writer leaves it 0 |
| 15 | 1 | pad2 | Padding; the writer leaves it 0 |
| 16 | 16 | name | Name, ended by a NUL, so at most 15 characters; the rest is zero |
Names are matched without regard to case. The game lower-cases both the stored name and the name it looks for; the command-line tools upper-case both. The released writer stores names in upper case. Lumps are found by name, in directory order.
LZSS compression is declared, but the released writer marks it “FIXME: do compression” and the released game reads every lump as stored.
Lump types
type 0 is TYP_NONE and 1 is TYP_LABEL. Codes from 64
(TYP_LUMPY) come from the lump builder, qlumpy, as 64 plus the number of the command that
made the lump. id’s two lists of those numbers do not agree:
| Code | Letter | Game header (wad.h) | Released qlumpy command |
|---|---|---|---|
| 64 | @ | TYP_PALETTE | palette |
| 65 | A | TYP_QTEX | colormap |
| 66 | B | TYP_QPIC | qpic |
| 67 | C | TYP_SOUND | miptex |
| 68 | D | TYP_MIPTEX | raw |
| 69 | E | not defined | colormap2 |
So a reader should not trust the code alone. The map compiler finds textures by name and ignores the type; the game looks up its pictures by name and uses the type only to byte-swap the width and height of type 66 lumps. The lump’s layout can be checked against its size, as below.
The released lump builder pads each lump with zero bytes to a multiple of 4 and counts the padding in both sizes.
Picture (qpic)
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | Width in pixels, signed 32-bit |
| 4 | 4 | Height in pixels, signed 32-bit |
| 8 | width × height | One palette index per pixel, row by row from the top |
When a picture is drawn with transparency, index 255 is the transparent colour. The palette is not in the lump: it is the game’s 256-colour palette.
Texture (miptex)
A wall texture with four sizes: full, half, quarter and eighth. The same block is what the map compiler copies into a Quake BSP file.
| Offset | Size | Field |
|---|---|---|
| 0 | 16 | Texture name, NUL ended |
| 16 | 4 | Width, unsigned; a multiple of 16 |
| 20 | 4 | Height, unsigned; a multiple of 16 |
| 24 | 16 | Four unsigned 32-bit offsets of the mip levels, counted from the start of this block |
| 40 | width × height | Level 0, one palette index per pixel, rows from the top (where the released builder puts it) |
| offset 1 | width/2 × height/2 | Level 1 |
| offset 2 | width/4 × height/4 | Level 2 |
| offset 3 | width/8 × height/8 | Level 3 |
The four levels together take width × height × 85 / 64 bytes. The game rejects a texture whose width or height is not a multiple of 16, and copies that many bytes from straight after the 40-byte header, so the levels must follow one another in order. The released builder replaces index 255 with 0 in level 0.
Names with a meaning
+starts an animation frame. The second character is the frame number,0to9, orAtoJfor the frames of the alternate animation; the rest of the name is shared. No frame number may be missing.*marks a liquid, drawn with a moving distortion.skyat the start of the name marks the sky texture.
Animation
The frames of one set are shown in order at 5 a second, going round. The set 0 to
9 is the ordinary one; an object whose own frame is not 0 shows the set A to
J instead, if there is one.
Liquids
Time is in seconds, and s and t are positions on the surface in texels.
| Renderer | Texel drawn |
|---|---|
| Software | The texture is taken as 64 × 64. Let p be the whole part of time × 20 and o(n) = 8 + 8 sin(2π n / 128), with n taken modulo 128. The texel is at s + o(p + (t mod 128)) across and t + o(p + (s mod 128)) down, each modulo 64. The pattern repeats every 6.4 seconds. |
| GLQuake | s + 8 sin(t / 8 + time) across and t + 8 sin(s / 8 + time) down; the texture repeats every 64 units. The pattern repeats every 2π seconds. |
Sky
A sky texture is 256 × 128 and holds two layers of 128 × 128: the right half is the back layer, and the left half the front layer, in which index 0 is clear. Both repeat and drift diagonally, the back layer 8 texels a second and the front layer 16.
Palette
Three bytes (red, green, blue) for each colour, with no header. The command takes an optional first and last colour; without them the lump holds colours 0 to 255, 768 bytes.
Colour map
Light-level tables: levels tables of 256 bytes, each mapping a palette index to another,
followed by one byte that gives the number of full-bright colours at the top of the palette. In a
colormap lump the first table maps every index to itself and the later ones grow darker,
while the full-bright colours stay as they are. colormap2, which the source calls
experimental and unused by Quake, has the same shape without the identity table: its tables run from a
chosen brightness down to black.
Raw block
Width × height palette indexes with no header: the size is not stored. The console font
conchars in gfx.wad is used this way by the game: a 128 × 128 block holding
256 characters of 8 × 8 pixels, 16 to a row, in which index 0 is transparent.
In the explorer
A dropped .wad file that starts WAD2 opens as a Quake WAD2.
- Structure and tables: the header, every lump and the directory in a tree, and a paged table of all lumps; open a row for the lump’s fields and pictures. Animation frames are gathered into a table of their own.
- Moving textures, in animated views with Play and a time slider:
+sets at 5 frames a second, liquids as the software renderer (64 × 64 textures) and as GLQuake draw them, and the two layers of a 256 × 128 sky. - Pictures: every level of a texture, pictures with index 255 transparent (except
conback), palettes, colour maps, the console font, and any raw block as palette indexes at a choice of widths. Pictures more than 4,096 pixels wide or high are shown in tiles. A lump is laid out as its type code says only when its size allows it, and otherwise by its size. - Palette: a 768-byte palette lump of the file itself, else a
palette.lmpsupplied beside the file. With neither, indexes are drawn as shades of grey: the game’s palette is not built in. - Checks: lumps outside the file or sharing bytes, names without a zero byte, sizes that differ in an uncompressed lump, type codes that the size does not allow, mip levels out of order and missing animation frames.
Not described
Known, not yet covered
- Viewer: compressed lumps are listed and not decompressed, because their layout is not known; the game’s own palette must come with the file.
Unknown
- Reference: the byte layout of an LZSS-compressed lump (
compression1). It is named in the headers, but the released tools never write it and the released game never reads it. Directory - Reference: the contents of the
TYP_SOUNDandTYP_QTEXtypes of the game header. The released game never tests for either code, and the released lump builder writes codes 67 and 65 formiptexandcolormaplumps instead. Lump types
Also used for
- Doom engine WAD – Doom engine game data: maps, pictures, sounds and music as named lumps in one file.
- Half-Life WAD3 – Half-Life’s textures, pictures and fonts, each with its own palette.
Variants
- Quake WAD2 – Quake’s pictures and wall textures, drawn with the game’s palette
- Half-Life WAD3 – Half-Life’s textures, pictures and fonts, each with its own palette
Links
Software
- TrenchBroom – map editor for Quake engine games that takes its textures from WAD files (Windows, macOS, Linux)
- Wally – texture editor for Quake engine games (Windows)
Developers
- Quake tools – id Software’s source for qlumpy, which builds WAD2 files, and for the map compiler that reads them (C)
- Quake source code – the game’s WAD loader and picture drawing (C)
Reference
- wad.h and wad.c – the structures and the loader in the Quake source, with
draw.candmodel.cfor pictures and texture names, andr_surf.c,d_scan.c,r_sky.candgl_warp.cfor animation, liquids and the sky - qutils –
WADLIB.C,QLUMPY.C,QUAKEGRB.Cand the map compiler’sWRITEBSP.C, which define how lumps are written and read