MREA (Metroid Prime 2)

See MREA (File Format) for the other revisions of this format.

The MREA format defines areas (rooms) in Metroid Prime 2. It serves the same purpose as the MREA files from Prime 1, but in Echoes it was updated with new features, including some new data sections and the ability to compress most of the data in the file.

Format
Like CMDL, MREA files are split up into a number of 32-byte aligned sections. Every section both starts and ends on a 32-byte boundary. These are used to separate different parts of the file; different types of sections typically indicate different sets of data. The header declares the section count and the size of each one; using these is the only way to navigate the file.

Compressed Blocks
The MREA format contains compressed blocks that can each contain a number of regular file sections within them. The data defining these blocks is at the end of the MREA header; the beginning and end of the compressed block list is padded to 32 bytes. The decompressed size of a block is capped at 0x20000 bytes; each section contains as many MREA sections as it can fit under that size limit. There are two exceptions:


 * If a single section's uncompressed size is larger than 0x20000, then its corresponding compressed block can exceed the size limit.
 * Each SCLY and SCGN layer is always in its own block, regardless of how close to the limit it is.

This is the structure of each block definition:

The actual data contained in these blocks is padded to 32 bytes, but their padding is located at the beginning of the block rather than the end, so it's required to account for the padding before you start decompressing. Thee data is compressed using segmented LZO1X-999; the "segmented" part means there's multiple segments of data that are compressed/decompressed separately. Each segment starts with a 16-bit size value. The size value is signed; a negative value indicates the segment is not compressed (this is done when compressing a segment doesn't reduce its size). Each segment is 0x4000 bytes large when decompressed (except the last one).

World Geometry
See MREA (Metroid Prime), Materials (Metroid Prime) and Geometry (Metroid Prime)

Largely the same as Prime 1. There are two new sections to watch out for on each world model (described on the Geometry (Metroid Prime) page). There's two sections that are now grouped under the same section number as world geometry.

The first is the area octree section, which is back from Prime 1 but no longer has its own section number.

The second section is an array of a structure that provides the bounding box for every surface group. The first entry in the array has the combined bounding box for all of the world geometry in the entire area, then each surface group is listed in order.

Unknown Section 1
This section appears to be related to world geometry.

Path
This section only contains a single PATH asset ID.

Portal Area
This section only contains a single PATH asset ID.

Static Geometry Map
This section only contains a single EGMC asset ID.