PAK File Format

By Ben Owen, 16/08/2009
Revision 1

.PAK files use a simple archive format to store the majority of the resource files used by the Dune II game engine.

The structure of a .PAK file is very straightforward - a header containing a list of all the files contained within the archive, and a data block containing said files.


The header is made up of a series of short structures:

header {
   Int32  offset;
   char[] filename;
   byte   terminator = 0;

The offset of a contained file is given by a 32-bit, little endian integer, followed by the filename, and finished by a null byte in the format:

SS = File offset
NN = File name
TT = Null byte

For example, the first two file entries in HARK.PAK:

The header is terminated by four null bytes, ie:

00000290:SS NN NN NN NN NN NN NN NN NN NN TT 00 00 00 00 .HNEXT2.VOC.....

Where TT is the null byte terminating the last entry in the header, with the following four null bytes terminating the header itself.


The data block immediately follows the header.

To read a file from the .PAK archive, you should parse the header to find the offset of the file you wish to extract. Subtract this from the offset of the following file (or if this is the last file in the archive, subtract the offset from the archive size) to obtain the file size. You can then perform a binary read operation on the .PAK file starting at the offset and using a buffer of size equal to the file size.


File Formats:

Compression PAK
Copyright © 2009 Ben Owen
Dune 2 and derived graphics © Virgin Interactive