Bioware HAK file format v1.0
Please send all errata/further info to: smokeserpent@psnw.com
This is the format of Bioware .hak files as used in NeverWinter Nights. I determined what I know from hex listings of many test files I made. It may well be that there are aspects of this format which did not present themselves in these test cases.
The structure of a .hak file is:
HEADER
DESCRIPTION TEXT
FILE NAME/TYPE LIST
FILE OFFSET/LENGTH LIST
FILE DATA
There don't seem to be any alignment requirements, except that the header file appears padded to 159 bytes of all things.
HEADER
| OFFSET | BYTES | TYPE | Description |
| 0x00 | 4 | CHAR | "HAK " |
| 0x04 | 4 | CHAR | "V1.0" |
| 0x08 | 4 | DWORD | Show description = 0x00000001? |
| 0x0c | 4 | DWORD | Unknown data, 0x00000000 seems fine. |
| 0x10 | 4 | DWORD | # of files in HAK |
| 0x14 | 4 | DWORD | Offset to Description text from start of file |
| 0x18 | 4 | DWORD | Offset to File Name/Type list |
| 0x1c | 4 | DWORD | Offset to File Offset/Size list |
| 0x20-0x9f | 127 | ??? | Unknown data, 0x00 seems fine. |
Description Text
| OFFSET | BYTES | TYPE | Description |
| 0x00 | 4 | DWORD | Unknown data, 0x00000000 works, one with 0xc0c0c0c0 didn't display descr. In nwhak |
| 0x04 | 4 | DWORD | Description length |
| 0x08-?* | ? | CHAR | Name, URL, Description, delimited by 0x0a |
*There are limits for lines and chars, don't know what those limits are, just be reasonable
File Name Entry
| OFFSET | BYTES | TYPE | Description |
| 0x00 | 16 | CHAR[16] | File name |
| 0x04 | 4 | DWORD | File Number, 0-based index, haven't seen any that aren't in order yet... *shrugs* |
| 0x08 | 4 | DWORD | File Type (list follows format description) |
File Offset Entry
| OFFSET | BYTES | TYPE | Description |
| 0x00 | 4 | DWORD | File offset, from start of HAK file |
| 0x04 | 4 | DWORD | File length |
File data is simply run together bytes of all
the files.
File Type Table
| CODE | EXTENSION |
| 0x0000 | res |
| 0x0001 | bmp |
| 0x0002 | mve |
| 0x0003 | tga |
| 0x0004 | wav |
| 0x0006 | plt |
| 0x0007 | ini |
| 0x0008 | mp3 |
| 0x000a | txt |
| 0x07d2 | mdl |
| 0x07d9 | nss |
| 0x07da | ncs |
| 0x07db | mod |
| 0x07dc | are |
| 0x07dd | set |
| 0x07de | ifo |
| 0x07df | bic |
| 0x07e0 | wok |
| 0x07e1 | 2da |
| 0x07ed | dlg |
| 0x07e6 | txi |
| 0x07e7 | git |
| 0x07e9 | uti |
| 0x07ea | bti |
| 0x07eb | utc |
| 0x07ee | itp |
| 0x07f0 | utt |
| 0x07f1 | dds |
| 0x07f3 | uts |
| 0x07f4 | ltr |
| 0x07f5 | gff |
| 0x07f6 | fac |
| 0x07f7 | bte |
| 0x07f8 | ute |
| 0x07f9 | btd |
| 0x07fa | utd |
| 0x07fb | btp |
| 0x07fc | utp |
| 0x07fd | dft |
| 0x07fe | gic |
| 0x07ff | gui |
| 0x0800 | css |
| 0x0801 | ccs |
| 0x0802 | btm |
| 0x0803 | utm |
| 0x0804 | dwk |
| 0x0805 | pwk |
| 0x0806 | btg |
| 0x0807 | utg |
| 0x0808 | jrl |
| 0x0809 | sav |
| 0x080a | utw |
| 0x080b | 4pc |
Thanks to Artur Biesiadowski and Paul Byrne from the NWN Java3D utility team for providing most of this in a nice big switch/case, and for putting the code in the Public Domain.