WAD
WAD (short for Where's All the Data) is the file extension for Half-Life texture packages. WAD files first originated in id Software's Doom as a general purpose file archive to help facilitate game mods. A format of the same name was later used in id Software's Quake engine as a texture package (referred to in its header as WAD2), then consequentially adapted by Half-Life 1's GoldSrc engine, which was based off the heavily modified version of Quake engine. GoldSrc specifically uses version 3 of the format, referred to in its header as WAD3. WAD files typically contain standard texture sets, custom texture sets for individual levels, and sprays. HUD elements typically use SPR, and fonts typically use TTF.
Contents
Technical specifications
WAD3 can store 3 types of data (the WAD format itself allows up to 256 types, but GoldSrc uses only 3).
The following types are supported:
- miptex (0x43)
- Primary format. Multiple-of-16-sized world textures with 4 mipmaps.
- qpic (0x42)
- Simple image with any size.
typedef struct { int width, height; char data[height][width]; //Image is stored as 8-bit numbers of colors in palette short colors_used; //Number of colors in palette (can't be more than 256) char lbmpalette[numcolors][3]; //8-bit RGB palette data } qpic_t;
- font (0x45)
- Fixed-height font. Contains an image and font data (row, X offset and width of a character) for 256 ASCII characters.
typedef struct { short startoffset; //Offset to the character in data short charwidth; } charinfo; typedef struct { int width, height; //Width is always 256 pixels int rowcount; //Number of fixed-height character rows int rowheight; //Height of a row charinfo fontinfo[256]; //Info about each character char data[height][width]; //Same as in qpic_t short colors_used; //Same as in qpic_t char lbmpalette[numcolors][3]; //Same as in qpic_t }
All numbers in WAD files are unsigned and little-endian.
Overview
This file spec uses constructs from the C programming language to describe the different data structures used in the WAD file format. Architecture dependent datatypes like integers are replaced by exact-width integer types of the C99 standard in the stdint.h header file, to provide more flexibillity when using x64 platforms. Basic knowledge about textures in the BSP file is recommended.
#include <stdint.h>
Directory entries
The directory of a WAD file is basically an array of structures. Every archived file has an associated entry in this directory:
#define MAXTEXTURENAME 16
typedef struct _WADDIRENTRY
{
int32_t nFilePos; // offset in WAD
int32_t nDiskSize; // size in file
int32_t nSize; // uncompressed size
int8_t nType; // type of entry
bool bCompression; // 0 if none
int16_t nDummy; // not used
char szName[MAXTEXTURENAME]; // must be null terminated
} WADDIRENTRY;
The first value is the offset of the raw data of the archived file within the WAD file followed by the size of data used by the it in its current form. Additionally nSize stores the size of original file, if it has been compressed. This is indicated by the bCompression boolean value. If it is false, no compression is used which is mostly the case. The nType member would give as information about the type of file, that is associated with this entry. As WAD files usually contain only textures, this information may be ignored. The nDummy short integer is not used when loading textures and i have not found any information about this member. Finally the entry contains a name for the file which can be a string of maximum 16 chars including the zero termination. In case of textures, this is the name referred by the BSPMIPTEX structs of the BSP file.
Files in a WAD File - Textures
The actual files in the WAD archive, the textures, also start with a file header which may look familiar:
#define MAXTEXTURENAME 16
#define MIPLEVELS 4
typedef struct _BSPMIPTEX
{
char szName[MAXTEXTURENAME]; // Name of texture
uint32_t nWidth, nHeight; // Extends of the texture
uint32_t nOffsets[MIPLEVELS]; // Offsets to texture mipmaps BSPMIPTEX;
} BSPMIPTEX;
This struct equals the one of the BSP file exactly. The name of the texture as not needed actually, as it equals the file name in the directory entry. The next members are of particular interest. They give the size of the texture in pixel as well as the offsets into the raw texture data. The first value of the offset array points to the beginning of the original texture relativly to the local header (the BSPMIPTEX struct). From this point follows a nWidth * nHeight bytes long array of indexes (0-255) pointing to colors in a color table. The other three offsets are used the same way, but with the diference that the width and height of the image are cut in half with every further offset. These represent the so-called mipmap levels of the original image. After the last byte of the fourth mipmap there are two dummy bytes followed by the actual color table consisting of an array of triples of bytes (RGB values) with 256 elements. The indexes of the image are plugged into the color table array to receive the corresponding RGB color value for the pixel.
Links
- CStrike Planet
- A collection of official and custom Counter-Strike WAD files.
- The Wadfather
- A large collection of WAD files.
Utilities
- GCFScape
- Views and extracts WAD files as BMP files.
- Half-Life Texture Tools
- Modern GUI tool for creating, viewing and extracting WAD files and sprites.
- Download
- HLExtract from HLLib
- command-line utility written in C that can browse, extract, validate and defragment all supported packages...
- Qlumpy
- Half-Life SDK tool for compiling WAD files.
- VTFEdit
- 3rd party tool for converting WAD files to Source materials.
- WadMaker and SpriteMaker
- Modern CLI tool for creating, updating and extracting WAD files and sprites.
- Download
- Wally
- The de facto WAD editing suite (supports only miptex).
- Download
- Xwad
- Source SDK tool for converting WAD files to Source materials.
- XBLAH's Modding Tool
- Can view, edit and create WAD files (more info).
See also
- WAD to VMT conversion in Hammer
- GoldSrc WAD Lists for some games
External links
- Specification: WAD3 on the TWHL wiki
- WAD3 Specifications at Source Forge