MLVL (File Format)

The MLVL format defines worlds in the Metroid Prime trilogy and Donkey Kong Country Returns. While the MREA format defines individual areas, the MLVL is what links together all the areas to create a single cohesive world.

Format
The format largely defines properties related to each area in general and how they link together, as well as things that apply to the world on a global scale across all areas, such as the skybox.

Remember that all resource IDs are 32 bits in Prime 1/2, and 64 bits in Prime 3/DKCR.

Version
These are the known version numbers:

Memory Relays
This section is only present in Prime 1. It contains a list of all Memory Relay objects used in the world and what objects they're connected to. If a Memory Relay is connected to multiple objects, it will show up multiple times.

The section starts with a 32-bit count value, then each relay is structured as:

Areas
This section defines every area in the world and how they connect to other areas.

Attached Areas
This part contains a small table listing what areas within the world are attached (connected) to this one. This is done by using indices into the MLVL's area table; so an index if 0 indicates the first area listed in the MLVL, for example.

Dependency List
This section is only present in Prime 1 and 2. It starts with what's essentially an embedded DGRP file: a 32-bit count value followed by a list of resources used by the area.

Following that is a small array. The purpose of this array is to distinguish which resources are used by which layers, to avoid wasting time loading resources used by objects that aren't active. It's an array of offsets into the dependency table, each one marking the start of that layer's dependency list.

Docks
This section is only present in the Prime trilogy.

.rel List
This section is only present in Echoes. It contains a list of .rel files used by the area. Like the dependency list, this is split up by layer, and is followed by an offset that indicates which .rel files are used by which layers.

World Map
This section is only present in the Prime trilogy. It sets the MAPW file used for this world.

Audio Groups
This section is only present in Prime 1. It contains a list of audio groups (AGSC files) used in this world. It begins with a 32-bit count value, then each audio group is defined as:

There's two values following this, at the end of the AGSC table.

Layer Info
The final section of the file contains some metadata related to each layer.

Layer Flags
This part attaches a set of 64-bit flags to every area, where each bit corresponds to a layer; if the bit is set, then that indicates that the corresponding layer will be enabled by default (on a new save file). Since the flags are 64 bits, that means the maximum number of layers that can be present in one area is 64.

After a 32-bit area count, the following structure is repeated for each area:

Layer Names
This is a very simple list of layer name strings. For info on how each layer is actually attached to its corresponding area, check the Layer Name Offsets section.

Unknown Array
This array is only present in Prime 3 and DKCR.

Layer Name Offsets
The final layer info section provides one offset into the layer name table per area. This can be used to attach a layer's name to its corresponding data within the area.