nwge-docs

Nwge Bundle Format Specification, Version 1

This document shall serve as the specification of the bundle file format used by the nwge engine. It contains both the formal definition and C-like pseudo-code.

File Structure

The file consists of the following:

Magic Value

The first eight bytes of a bundle file consist of a magic number, where:

//N  W  G  E  B  N  D\x01
0x4E'57'47'45'42'4E'44'01

The bundle header consists of two fields:

struct Header {  // always at offset 8
  u32 treeOffset;
  u32 padding;
};

File Tree

The file tree consists of:

struct FileTree {  // offset determined by Header's treeOffset
  u32 fileCount;
  FileInfo files[fileCount];
};

File Info

The file info consists of:

struct FileInfo {
  char name[12];
  char extension[4];
  u32 size;
  u32 offset;
};

File Data

The raw data of each file stored in the bundle. The official nwgebndl tool simply stores all files after each other between the Header and the File Tree. It is permissible to store file data after the File Tree. It is permissible to store file data in both locations at once. It is permissible for file data to overlap. It is permissible for file data to extend into the bundle file structures, as bundle files are inherently immutable. It is permissible for the files’ data to not be stored contiguously – i.e. with padding added between files. The official libnwge_bndl implementation adds padding between files to ensure data is aligned to 16-byte boundaries.

Example File

Below is a commented hex dump of the BUNDLEv1EXAMPLE.BNDL file.

/* Magic at offset 0 */
0x4E'57'47'45'42'4E'44'01 // "NWGEBND\x01" or 0x01444E424547574E

/* Header at offset 8 */
0x16'00'00'00 // File Tree Offset: 0x16
0x6E'77'67'54 // Padding: "nwge" or 0x6567776E

/* File Data */
0x48'65'6C'6C'6F'2E // PLAIN.TXT data: "Hello."

/* File Tree at offset 0x16 */
0x01'00'00'00 // File Count: 1

  /* File #1 */
  0x50'4C'41'49'4E'00'00'00'00'00'00'00 // Name: "PLAIN"
  0x54'58'54'00 // Extension: "TXT"
  0x06'00'00'00 // Size: 0x06
  0x10'00'00'00 // Offset: 0x10