DPK format is a game archive data format. Current DPK format version is 5, but there were many games in the past that used version 4 of the format. A couple of unofficial DPK utilities can be found on the Internet, but none of them works perfectly.
This document describes the minimal requirements for creating and decompressing a DPK archive.
A DPK file consists of three main parts, a header, a directory and a compressed file data. In cases where an integer is written to a file the information is stored with the low order byte followed by the high order byte, ie: little endian.
The header structure might be defined as follows in C++:struct DpkHeader { char id[4]; uint32_t fileSize; uint32_t directorySize; uint32_t nDirectoryEntries; };
The header is always 16 bytes long. The id field is always 'D', 'P', 'K', '4' in DPK version 4 file. The fileSize is length of the DPK archive file in bytes. The directorySize is the size in bytes of the directory block. The last field nDirectoryEntries contains the number of files in the archive.
The directory block starts right after the header and consist of entries defined as follows:struct DpkEntry { uint32_t next; uint32_t unpackedSize; uint32_t packedSize; uint32_t offset; };
Right after every DpkEntry struct there is a file path encoded as zero-terminated ASCII string (char[] in C/C++). The relative path can not only contains a filename but also a directory name(s). The valid path separator character is a backslash (\).
The next is offset in bytes from the beginning of current entry to the beginning of the next entry. The next is also the size of the directory entry and must contain a valid value even in the last entry. The size should be aligned to the multiply of 4 and the entry should be padded with zeros right after the file path. The packedSize of the file can not excess the unpackedSize. In case when packedSize is equal to unpackedSize, the file is not compressed and is stored in the archive as is. If packedSize is less than unpackedSize, the file is compressed by zlib's compress() function (deflate method). And finally, offset is the offset from the beginning of the DPK archive to (possibly compressed) file data of the entry.