FF7/WorldMap Module

The following was originaly described by Tonberry, in qhimm's forum. It was
completed by Ficedula sometimes later, who reversed texture data.

Additions in *italics* by Aali

*MAP file follows the structure described below and is used to load single blocks on demand. BOT file contains the same blocks but arranged to speed up initial load time by storing each block and 3 of its neighboring blocks together. For instance, the data stored for the first 2 blocks is (numbers refer to the MAP layout below): 0,1,9,10 1,2,10,11. This pattern repeats up to block #62. Replacement blocks 63-68 are divided in groups for each replacement, i.e. block 64 and 65 are part of the same group since they both belong to the Ultima Weapon crater. These groups are then stored using the same algorithm as above, each 4-block group containing a replaced block is written out again. 1-block replacements thus add 4\*4 blocks to the .BOT file while 2-block replacements add 6\*4 blocks. Replacements are to be made **in order**, when writing the data for the Ultima Weapon crater the Temple of the Ancients should be gone and so on. All of this adds up to 63\*4 + 4\*4 + 6\*4 + 4\*4 + 6\*4 = 332 blocks.*

### Content

* WM0 is the above water map.
* WM2 is the underwater (submarine) map.
* WM3 is the snowstorm map.

## MAP Format

### File Structure

A worldmap file is divided in sections of 0xB800 bytes, each section
representing a square block of the map.

#### Map Block

Each block consists in 16 meshes, organized in a grid-like fashion:

Map Block mesh arrangement
 4
 8
 12

A block is recorded following the structure (all pointers are expressed in bytes
relative to offset 0 of block):

*Pointers have to be aligned to 4-byte boundaries, FF7 ignores the last two bits when reading the file.*

The data for each mesh is independently compressed using LZSS, so the
first 4 bytes are the size in bytes of the compressed data and the
rest is the compressed data itself.

#### WM0.MAP

wm0.map contains 68 blocks. The first 63 of them are arranged in a
grid-like fashion, made of 7 rows of 9 columns, like this:

The last 5 meshes 63, 64, 65, 66, 67 and 68 replaces meshes 50, 41,
42, 60, 47 and 48 (respectively), according to the story of the game.

#### Header

Header Structure
 2 bytes

```
typedef struct
{
  uint16 NumberOfTriangles;
  uint16 NumberOfVertices;
} WorldMeshHeader;

```

#### Triangle

```
typedef struct
{
 uint8 Vertex0Index;
 uint8 Vertex1Index;
 uint8 Vertex2Index;
 *uint8 WalkabilityInfo:5;*
 *uint8 Unknown:3;*
 uint8 uVertex0, vVertex0;
 uint8 uVertex1, vVertex1;
 uint8 uVertex2, vVertex2;
 *uint16 TextureInfo:9;*
 *uint16 Location:7;*
} WorldMeshTriangle;

```

#### Vertex

For each vertex v in *number of vertices*
 2 bytes
 2 bytes
 2 bytes

```
typedef struct
{
  int16 X, Y, Z;
  uint16 Unused; // fill to fit structure to 32bit boundry
} VertexType;

```

#### Normal

For each vertex v in *number of vertices*
 2 bytes
 2 bytes
 2 bytes

```
typedef struct
{
  int16 X, Y, Z;
  uint16 Unused; // fill to fit structure to 32bit boundry
} NormalType;

```

structures added by Cyberman 13:43, 10 Jan 2007 (CST)

### Walkmap

*Each triangle can have one of the 32 different walkmap types described below.*

### Texture

The lower 9 bits contain a texture number (0-511, but only 0-281
appear to be used). *Unfortunately, knowing which texture to use is not enough, the UV coordinates found in the mesh data are (presumably) the original PSX VRAM coordinates, so to get the real coordinates you must subtract a texture-specific offset from each of the UV pairs. A complete table with every texture, its original size and offsets can be found  here. Sometimes you will end up with negative values after subtracting the offsets, this is normal, the texture should be assumed to repeat itself indefinitely in all directions.*