Module erf

Module erf 

Source
Expand description

ERF-family archive support. ERF/MOD/HAK binary reader and writer.

This module provides a strict, roundtrip-safe implementation of the KotOR ERF family container format. Compatibility mode can also parse legacy non-canonical variants (for example SAV headers).

§Format Layout

+------------------------------+ 0x0000
| Header (160 bytes)           |
+------------------------------+ localized_strings_offset
| Localized string block       |
| (variable size)              |
+------------------------------+ keys_offset
| Key table                    |
| 24 bytes * entry_count       |
+------------------------------+ resources_offset
| Resource table               |
| 8 bytes * entry_count        |
+------------------------------+ data offsets from resource table
| Resource payload blob        |
| (concatenated file data)     |
+------------------------------+

MOD archives may include an optional legacy blank block between key and resource tables. This implementation supports both tight and blank-block variants for compatibility.

§Header (160 bytes)

0x00..0x04  file_type                (fourcc: "ERF ", "MOD ", "HAK ", "SAV ")
0x04..0x08  version                  (fourcc: "V1.0" or "V1.1")
0x08..0x0C  localized_string_count   (u32)
0x0C..0x10  localized_string_size    (u32, total byte length of string block)
0x10..0x14  entry_count              (u32)
0x14..0x18  localized_strings_offset (u32)
0x18..0x1C  keys_offset              (u32)
0x1C..0x20  resources_offset         (u32)
0x20..0x24  build_year               (u32, years since 1900)
0x24..0x28  build_day                (u32, day of year)
0x28..0x2C  description_strref       (i32)
0x2C..0xA0  reserved                 (116 bytes, preserved verbatim)

§Key Entry (24 bytes)

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

§Resource Entry (8 bytes)

0x00..0x04  data_offset (u32)
0x04..0x08  data_size   (u32)

Structs§

Erf
In-memory ERF-family container.
ErfLocalizedString
One localized ERF description entry.
ErfReadOptions
Reader options for ERF/MOD/HAK parsing.
ErfResource
One resource entry stored in an ERF-family archive.
ErfWriteOptions
Writer options for ERF-family serialization.

Enums§

ErfBinaryError
Errors produced while parsing or serializing ERF binary data.
ErfFileType
Supported ERF-family container signatures.
ErfReadMode
Input-profile behavior for ERF-family readers.
ErfWriteMode
Output-profile behavior for ERF-family writers.
ModLayout
Layout mode for MOD key/resource table spacing during writes.

Functions§

read_erf
Reads an ERF/MOD/HAK archive from a reader.
read_erf_from_bytes
Reads an ERF/MOD/HAK archive from bytes.
read_erf_from_bytes_with_options
Reads an ERF-family archive from bytes with explicit read options.
read_erf_with_options
Reads an ERF-family archive from a reader with explicit read options.
read_save_archive
Reads a save archive from a reader.
read_save_archive_from_bytes
Reads a save archive directly from bytes.
write_erf
Writes an ERF/MOD/HAK archive to a writer.
write_erf_to_vec
Serializes an ERF/MOD/HAK archive to bytes.
write_erf_to_vec_with_options
Serializes an ERF/MOD/HAK archive to bytes with explicit layout options.
write_erf_with_options
Writes an ERF/MOD/HAK archive to a writer with explicit layout options.
write_save_archive
Writes a save archive to a writer.
write_save_archive_to_vec
Serializes a save archive to bytes.