Neverwinter Nights:Key File Format

From TBotR Wiki

Introduction

A Key file is an index of all the resources contained within a set of BIF files. The key file contains information as to which BIFs it indexes for and what resources are contained in those BIFs.

Structure

Header
File Table
Filename Table
Key Table

Header

(size 64 bytes)

Keyfile Header

Offset Value Type Description
0 FileType CHAR [4] "KEY "
4 FileVersion CHAR [4] "V1 "
8 BIFCount INT32 Number of BIF files that this KEY file controls
12 KeyCount INT32 Number of Resources in all BIF files linked to this keyfile
16 OffsetToFileTable INT32 Byte offset of File Table from beginning of this file
20 OffsetToKeyTable INT32 Byte offset of Key Entry Table from beginning of this file
24 Build Year INT32 Number of years since 1900
28 Build Day INT32 Number of days since January 1
32 Reserved BYTE [32] Reserved for future use

File Table

(size 12 bytes * BIFCount)

The File Table is a list of all the BIF files that are associated with the key file.

The number of elements in the File Table is equal to the BIFCount specified in the Header.

Each element in the File Table is a File Entry, and describes a single BIF file.

File Entry

Offset Value Type Description
0 FileSize INT32 File size of the BIF
4 FilenameOffset INT32 Byte position of the BIF file's filename in this file. Points to a location in the Filename Table
8 FilenameSize INT16 Number of characters in the BIF's filename
10 Drives INT16 A number that represents which drives the BIF file is located in. Currently each bit represents a drive letter, e.g., bit 0 = HD0, which is the directory where the application was installed

Filename Table

(size varies * BIFCount)

The Filename Table lists the filenames of all the BIF files associated with the key file.

Each File Entry in the File Table has a FilenameOffset that indexes into a Filename Entry in the Filename Table.

Filename Entry

Offset Value Type Description
0 Filename variable Filename of the BIF as a non-terminated character string.

This filename is relative to the "drive" where the BIF is located (as specified in the Drives portion of the BIF File Entry). Each Filename must be unique. e.g., "data\2da.bif"

Key Table

(size 22 bytes * KeyCount)

The Key Table is a list of all the resources in all the BIFs associated with this key file.

The number of elements in the Key Table is equal to the KeyCount specified in the the Header.

Each element in the Key Table is a Key Entry, and describes a single resource. A resource may be a Variable Resource, or it may be a Fixed Resource (at this time, all resources are Variable).

Key Entry

Offset Value Type Description
0 ResRef CHAR [16] The filename of the resource item without it's extension. The game uses this name to access the resource. Each ResRef must be unique.
16 ResourceType INT16 Resource Type of the Resource
18 ResID INT32 A unique ID number. It is generated as follows:
Variable: ID = (x << 20) + y
Fixed: ID = (x << 20) + (y << 14)

x = [index into File Table to specify a BIF]
y = [index into Variable or Fixed Resource Table in BIF]
(<< means bit shift left)

Note: This ID must match the ID in the BIF.

Personal tools