Module key

Module key 

Source
Expand description

KEY index support. KEY binary reader and writer.

KEY files are global resource indexes that map (resref, type) pairs to a packed resource_id that identifies both:

  • which BIF file contains the resource, and
  • which entry inside that BIF file to load.

§Format Layout

+------------------------------+ 0x0000
| Header (64 bytes)            |
+------------------------------+ file_table_offset
| BIF file table               |
| 12 bytes * bif_count         |
+------------------------------+ filename table (from file entries)
| BIF filenames                |
| variable-size strings        |
+------------------------------+ key_table_offset
| Resource key table           |
| 22 bytes * key_count         |
+------------------------------+

§BIF File Entry (12 bytes)

0x00..0x04  file_size       (u32)
0x04..0x08  filename_offset (u32)
0x08..0x0A  filename_size   (u16)
0x0A..0x0C  drives          (u16)

§Key Entry (22 bytes)

0x00..0x10  resref[16]      (null padded)
0x10..0x12  type_id         (u16)
0x12..0x16  resource_id     (u32)

§Header (64 bytes)

0x00..0x04  magic             ("KEY ")
0x04..0x08  version           ("V1  " or "V1.1")
0x08..0x0C  bif_count         (u32)
0x0C..0x10  key_count         (u32)
0x10..0x14  file_table_offset (u32)
0x14..0x18  key_table_offset  (u32)
0x18..0x1C  build_year        (u32, years since 1900)
0x1C..0x20  build_day         (u32, day of year)
0x20..0x40  reserved          (32 bytes, preserved verbatim)

resource_id bit layout:

  • bits 31..20: BIF index
  • bits 19..0: resource index within that BIF

Structs§

Key
In-memory KEY container.
KeyBifEntry
One BIF file-table entry in a KEY index.
KeyReadOptions
KEY reader option set.
KeyResourceEntry
One resource entry in the KEY key table.

Enums§

KeyBinaryError
Errors produced while parsing or serializing KEY binary data.
KeyReadMode
KEY reader input policy.

Functions§

pack_resource_id
Packs (bif_index, resource_index) into KEY resource_id format.
read_key
Reads a KEY index from a reader.
read_key_from_bytes
Reads a KEY index from bytes.
read_key_from_bytes_with_options
Reads a KEY index from bytes with explicit options.
read_key_with_options
Reads a KEY index from a reader with explicit options.
write_key
Writes a KEY index to a writer.
write_key_to_vec
Serializes a KEY index to bytes.