nwnrs-key
nwnrs-key reads and writes KEY/BIF resource sets, which form the canonical
indexed storage layout for base-game content.
Scope
- parse KEY files and their BIF index tables
- expose the result as a typed [
KeyTable] - implement
nwnrs-resmancontainer behavior for KEY/BIF-backed content - write KEY/BIF output from typed archive state
The main entry points are [read_key_table], [read_key_table_from_file], and
[write_key_and_bif].
Public Surface
KeyTableKeyBifEntryKeyBifContentsKeyBifVersionVariableResourceBifResolverResIdKeyErrorKeyResultread_key_tableread_key_table_from_filewrite_key_and_bifwrite_key_table_archive
Core Model
ResIdis a packedu32- upper bits identify the owning BIF
- lower bits identify the variable resource within that BIF
KeyTablepreserves:- version
- label
- build year and day
- BIF handles
- resource-to-id lookup
- optional OID metadata
VariableResourcepreserves:- packed id
- I/O offset
- stored size
- compression type
- uncompressed size
KEY Layout
Header size: 64 bytes.
Known KEY versions:
V1E1
Header shape:
0x00 "KEY "
0x04 version
0x08 bif_count u32
0x0C key_count u32
0x10 offset_to_file_table u32
0x14 offset_to_key_table u32
0x18 build_year u32
0x1C build_day u32
0x20 remaining header / OID area
Body:
+----------------------+
| KEY header |
+----------------------+
| file table | one row per BIF
+----------------------+
| filename strings |
+----------------------+
| key table | one row per resource
+----------------------+
BIF Layout
Known BIF magic:
"BIFF"
Known BIF versions:
V1E1
Conceptually:
+----------------------+
| BIF header |
+----------------------+
| variable table |
+----------------------+
| payload 0 |
+----------------------+
| payload 1 |
+----------------------+
| ... |
+----------------------+
Each variable-resource row records:
- packed resource id
- byte offset
- stored size
- resource type
- optional
E1compression metadata
Invariants
- resource references remain typed rather than stringly indexed
- the mapping from KEY entries to BIF-backed payload locations remains explicit
- the same typed value may be inspected structurally and used as a
ResContainer - KEY indexing and BIF payload storage are separate concepts
BifResolverexists because the KEY file references BIFs by filename and the actual stream-opening policy belongs to the caller
See also
nwnrs-resman, which consumesKeyTableas a resource containernwnrs-install, which uses KEY/BIF data to assemble a conventional install-backed resource stack
Why This Crate Exists
If you only think in terms of "resource name to bytes," the KEY/BIF design looks more complicated than it needs to be. If you think in terms of indexed archival storage, it becomes clear:
- KEY is the index
- BIF is the payload store
ResIdis the join key
The crate makes that split explicit rather than hiding it behind opaque lookup machinery.