Specification: WAD3 Last edited 3 weeks ago2024-11-24 06:42:00 UTC

You are viewing an older revision of this wiki page. The current revision may be more detailed and up-to-date. Click here to see the current revision of this page.

WAD3 Format Specification

Derived from Quake's WAD2 format.
All data types uses little endian byte order.

After the format's header there are num_dirs directory entries that contains data about all the files within the WAD3 archive, as well as their position within the file.
typedef struct {
    char[4] magic;     // File format magic number
    int num_dirs;      // Number of Directory entries
    int dir_offset;    // Offset from the WAD3 data's beginning for first Directory entry
} Header;
The magic number is 4 bytes represented by the string WAD3 in ASCII.

Directory Entry

typedef struct {
    int entry_offset;           // Offset from the beginning of the WAD3 data
    int disk_size;              // The entry's size in the archive in bytes
    int entry_size;             // The entry's uncompressed size
    char file_type;             // File type of the entry
    _Bool compressed;           // Whether the file was compressed
    short padding;
    nt_string[16] texture_name  // Null-terminated texture name
} DirEntry;
The file entries archived in the WAD3's directory are described using an array of DirEntry structures.

File types

The WAD3 format can store up to 256 different entry types, but only four are used in GoldSrc:

File Entry

The description of the files within the WAD3 archive varies depending on its file type:
qlumpy always align entries to the DWORD (=4 bytes) boundary (i.e. next integer multiples of 4 offset from start of file)

Qpic Image

A simple image of any size. Specific images of this format can be found in these wad files:
typedef struct {
    int width, height;
    char[height][width] data;
    short colors_used;
    char[colors_used][3] palette;
} QpicT;

Miptex Image

This is the file type used by world textures and is the typical type of file you find in WAD3 archives.
The structure is similar to what's used to describe textures in the BSP format.
// Image structure used by each mip level
typedef struct {
    char[width][height] data;           // Raw image data. Each byte points to an index in the palette
} MipMap;

// Texture structure
typedef struct {
    nt_string[16] texture_name;         // Null-terminated texture name
    u_int width, height;                // Dimensions of the texture (must be divisible by 16)
    u_int[4] mip_offsets;               // Offset from start of this struct to each mipmap level's image
    MipMap[4] mip_images;               // One MipMap for each mipmap level
    short colors_used;                  // Number of colors used in the palette (always 256 for GoldSrc)
    char[colors_used][3] palette        // The color palette for the mipmaps (always 256 * 3 = 768 for GoldSrc)
} MipTex;
For the MipMap images, the first image (level 0) is the texture image in its original dimensions.
All following levels have dimensions that are a quarter the size of the previous level. For example, for a 16x16 texture:

Font

Fixed-height font, laid out as a font sheet: one image with glyphs following the codepoint order in rows across the image. The width of the font sheet is always 256 pixels, and the apparent max size is 256x256 (perhaps slightly taller). Only 255 characters (i.e. 8-bit character sets) are supported and are locale-dependent.
typedef struct {
    char offset_y, offset_x;       // offset from the top and left of the fontsheet
    short charwidth;               // width of glyph (0 for non-printing codepoints)
} CharInfo;

typedef struct {
    int unknown;                   // instead of width preceding height, an unknown value that's always identical to row_height
    int height;                    // height of fontsheet
    int row_count;                 // number of rows of glyphs
    int row_height;                // height of glyph row
    CharInfo[256] font_info;       // glyph data for codepoints 0 to 255
    char[height*256] data;         // note that the size is always 256 multiplied by height
    short colors_used;
    char[colors_used][3] palette;
} Font;
To author a font sheet requires both the use of qlumpy + ls script and a specially crafted source image where the boundaries of each glyph is denoted with pixels on palette index #254 (second to last).

Sources

See also

Comments

You must log in to post a comment. You can login or register a new account.