WAD

WAD (acronym for "Where's All the Data?") is the file format used by Doom and all Doom-engine-based games for storing data. A WAD file consists of a header, a directory, and the data that makes up the resources stored within the file. WADs can be either IWADs or PWADs.

Header
A WAD file always starts with a 12-byte header. It contains three values: All integers are 4 bytes long in x86-style little-endian order. Their values can never exceed 231-1 since Doom reads them as signed ints.

Directory
The directory associates names of lumps with the data that belong to them. It consists of a number of entries, each with a length of 16 bytes. The length of the directory is determined by the number given in the WAD header. The structure of each entry is as follows:

Lump order
The majority of lumps have no restriction on where they must be located in WAD files. However, there are typically some guidelines to make the file easily readable by other people. For some lumps, however, the location is crucial.

Map data lumps
A map in Doom is made up of several lumps, each containing specific data required to construct and execute the map. The first lump gives the internal name of the map. In Doom, this had to be in the form ExMy or MAPxx, where x and y could not exceed 4 and 9 respectively (Ultimate Doom), and xx could not exceed 32 (Doom 2/Final Doom). Other than defining the name of the map, the lump is usually empty but can contain data. The level name marks the start of this map. In order to work properly, the following lumps must follow immediately after the the level name:


 * THINGS: A lump listing all the Things present in this map, their X, Y, and Z coordinates, starting angles, type, flags, special, and args. As with all of these lumps, this list will be generated by your level editor and should generally be left alone. Note: The standard Doom format does not contain Z and args.


 * LINEDEFS: A list of linedefs, defined by their starting and ending vertices, flags, type, tag, args and front and back sidedefs (if any). Note: The standard Doom format does not contain args.


 * SIDEDEFS: A list of the sidedefs that are linked to the linedefs. These contain the data for what textures appear where on the side of each line, their X and Y offsets, and what sector this side of the linedef belongs to.


 * VERTEXES: A list of each vertex in the map, using X and Y coordinates.


 * SEGS: A list of lines called "segs" that connect to form subsectors.


 * SSECTORS: A list of subsectors, created by your nodes builder.


 * NODES: The node tree which Doom uses to speed up the rendering process. Similar to a vismap in modern 3D games (such as Quake 3).  Created by your nodes builder.


 * SECTORS: Defines the floor and ceiling heights and textures, as well as light value, tag, and type of each sector in your map.


 * REJECT: Optionally compiled by the nodes builder, this lump contains data about which sectors are visible from which other sectors. Originally, Doom used this to optimize the game speed by skipping AI routines for enemies whose target was in a rejected sector.  Some modern source ports do not require this lump any more; ZDoom for example has been designed to work even without this lump present.  For compatibility purposes, an empty (0-filled) REJECT lump should be included if nothing else.  The REJECT lump can also be used to create certain special effects (sectors into which enemies cannot see, for example) if modified carefully.


 * BLOCKMAP: Collision-detection information which determines whether objects in a map are touching.


 * BEHAVIOR: Not originally a part of Doom, the BEHAVIOR lump was first used in Hexen and contains the compiled scripts that this map will use. Vanilla Doom and other ports designed for Doom only will crash when this lump is present because Hexen format levels are not compatible with Doom format levels.  This lump must be present for Hexen format levels since it is the only way to tell if a map is in Hexen or Doom format.

Flats, Sprites, and Patches
These three resources must be located between special marker lumps so that Doom knows what it is looking at. Other than defining the beginning and end of a graphics section, these lumps contain no data and are 0 bytes long.

The markers consist of names X_START and X_END, where X is the first 1 or 2 letters of the appropriate resource. For example, sprites should be located between S_START and S_END markers. SS_START and SS_END are usually used for user WAD files. Similarly Flats are F_START and F_END (again FF_START and FF_END in user WAD files). Patches are not required to have any markers. Some lump management utitilies require P_START and P_END.

Miscellaneous
Some lumps are known by their names and apply to the game as a whole. Some of these are:
 * Sound effects
 * Music
 * PLAYPAL: Color palettes for various situations.
 * COLORMAP: Map to adjust pixel values for reduced brightness.
 * ENDOOM: Text displayed when vanilla Doom exits.
 * TEXTURE1, TEXTURE2, PNAMES: Data defining the wall textures.
 * DEMOs: Recorded games, auto-played before any level is started.