KMP (File Format)

From MK7
Revision as of 18:54, 22 October 2019 by Yosh (talk | contribs) (added object reference)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

KMP files are used in Mario Kart 7 aswell as in Mario Kart Wii. This article describes the KMP file format used in Mario Kart 7.

KMP files contain information about how the course is played, such as start positions, check points and the CPU routes. The file is written in little endian.

File Header

This is the general layout for a KMP header:

File header of a KMP file
Offset Type Description
0x00 String File magic.
0x04 UInt32 Length of the file in bytes.
0x08 UInt16 N = Number of sections in the file.
0x0A UInt16 Header length.
0x0C UInt32 Unknown meaning, perhaps something like a revision number. The value of MK7 KMP files is 0x1C0C (le) = 3100.
0x10 UInt32[N] N section offsets. The type of each section can be detected by analysing the first 4 bytes of the section; it's always the section name. The offset is relative to the end of this header.
N * 0x04 + 0x10 End of this file header

Typical File Header

This is specific file header for Mario Kart 7 tracks. It is a structure with 0x58 (=88) bytes.

File header of a MK7 KMP file
Offset Type Description
0x00 String File magic. Always DMDC in ASCII.
0x04 UInt32 Length of the file in bytes.
0x08 UInt16 Number of sections in the file (0x12).
0x0A UInt16 Header length.
0x0C UInt32 Probably a revision number. The value of MK7 KMP files is 0xC1C = 3100.
0x10 UInt32 TPTK section offset.
0x14 UInt32 TPNE section offset.
0x18 UInt32 HPNE section offset.
0x1C UInt32 TPTI section offset.
0x20 UInt32 HPTI section offset.
0x24 UInt32 TPKC section offset.
0x28 UInt32 HPKC section offset.
0x2C UInt32 JBOG section offset.
0x30 UInt32 ITOP section offset.
0x34 UInt32 AERA section offset.
0x38 UInt32 EMAC section offset.
0x3C UInt32 TPGJ section offset.
0x40 UInt32 TPNC section offset.
0x44 UInt32 TPSM section offset.
0x48 UInt32 IGTS section offset.
0x4C UInt32 SROC section offset.
0x50 UInt32 TPLG section offset.
0x54 UInt32 HPLG section offset.
0x58 End of this file header

All offsets are relative to the end of the header.

Sections

Every section starts with this section header. The section header is a 0x08 byte structure as follows:

Section header for all KMP sections
Offset Type Description
0x00 String The section name in ASCII. Compared with Mario Kart Wii, the section names are written in reversed order.
0x04 UInt16 Number of entries.
0x06 UInt16 Additional value. The POTI section stores the total number of points of all routes. The CAME section stores 0xFFFF. All other values 0x0000 (padding).
0x08 End of header & start of first entry

TPTK

The TPTK (kart point) section describes kart points; the starting positions of racers. Each entry is a 0x1A byte structure as follows:

Offset Type Description
0x00 Float[3] A 3D position vector of the start position.
0x0C Float[3] A 3D rotation vector of the start position.
0x18 UInt16 Player index.
0x1A UInt16 Padding?

This section is only used in battle tracks. The start point is written as an object in the JBOG section in the regular tracks.

TPNE

The TPNE (enemy point) section describes enemy points; the routes of CPU racers. The CPU racers attempt to follow the path described by each group of points (as determined by HPNE). Each entry is a 0x18 byte structure as follows:

Offset Type Description
0x00 Float[3] A 3D position vector of the enemy position.
0x0C Float This value controls, how much the enemies leave the direct point-to-point line to the left and right side.
0x10 UInt32 Unknown.
0x14 UInt32 Unknown.

HPNE

The HPNE (enemy path) section describes enemy points grouping; how the routes of CPU racers link together. Each entry is a 0x48 byte structure as follows:

Offset Type Description
0x00 UInt16 Point start. The index of the first TPNE entry in this group.
0x02 UInt16 Point length. The number of TPNE entries in this group.
0x04 UInt16[16] Previous group. The indicies of up to 16 the previous TPNE groups entries may have followed. Unneeded slots are set to value 0xFFFF.
0x24 UInt16[16] Next group. The indicies of up to 16 next TPNE group entries to follow. Unneeded slots are set to value 0xFFFF.
0x44 UInt32 Unknown.

TPTI

The TPTI (item point) section describes item points; the routes of items such as red shells. The items attempt to follow the path described by each group of points (as determined by HPTI). Each entry is a 0x14 byte structure as follows:

Offset Type Description
0x00 Float[3] A 3D position vector of the item position.
0x0C Float Bullet Bill can be controlled a little bit by left and right. And this value defines the range.
0x10 UInt32 Unknown.

HPTI

The HPTI (item path) section describes item point grouping; how the routes of items link together. Each entry is a 0x1C byte structure as follows:

Offset Type Description
0x00 UInt16 Point start. The index of the first TPTI entry in this group.
0x02 UInt16 Point length. The number of TPTI entries in this group.
0x04 UInt16[6] Previous group. The indicies of up to 6 the previous TPTI groups entries may have followed. Unneeded slots are set to value 0xFFFF.
0x10 UInt16[6] Next group. The indicies of up to 6 next TPTI group entries to follow. Unneeded slots are set to value 0xFFFF.

TPKC

The TPKC (checkpoint) section describes check points; the routes players must follow to count laps. The racers must follow the path described by each group of points (as determined by HPKC). Each entry is a 0x18 byte structure as follows:

Offset Type Description
0x00 Float[2] A 2D position vector (X and Z coordinate) of the left point of the check point line.
0x08 Float[2] A 2D position vector (X and Z coordinate) of the right point of the check point line.
0x10 Byte Respawn ID.
0x11 Byte Checkpoint type.
0x12 Byte Previous check point in this group's sequence; 0xFF for the first point of the group.
0x13 Byte Next check point in this group's sequence; 0xFF for the last point of the group.
0x14 Byte Unknown.
0x15 Byte Unknown.
0x16 Byte Unknown.
0x17 Byte Unknown.

HPKC

The HPKC (checkpoint path) section describes check point grouping; how the routes of check points link together. Each entry is a 0x10 byte structure as follows:

Offset Type Description
0x00 Byte Point start. The index of the first TPKC entry in this group.
0x01 Byte Point length. The number of TPKC entries in this group.
0x02 Byte[6] Previous group. The indicies of up to 6 the previous TPKC groups entries may have followed. Unneeded slots are set to value 0xFF.
0x08 Byte[6] Next group. The indicies of up to 6 next TPKC group entries to follow. Unneeded slots are set to value 0xFF.
0x0E UInt16 Unknown.

JBOG

The JBOG (game object) section describes objects; things on the course such as item boxes and coins. Each entry is a 0x40 byte structure as follows:

Offset Type Description
0x00 UInt16 Object ID to identify the Object. See »Object«
0x02 UInt16 Unknown.
0x04 Float[3] A 3D position vector of the object.
0x10 Float[3] A 3D rotation vector of the object.
0x1C Float[3] A 3D scale vector of the object's scale.
0x28 UInt16 Route used by the object. This is index link into the ITOP section. The value 0xFFFF means "no route".
0x2A UInt16[8] Up to 8 object specific settings.
0x3A UInt16 Object presence flags.
0x3C UInt16 Unknown.
0x3E UInt16 Unknown.

ITOP

The ITOP section describes routes; these are routes for many things including cameras and objects.

Each entry is a 0x04 byte structure as follows, which is followed by 0x10 byte structures:

Route Header
Offset Type Description
0x00 UInt16 Number of points in the route.
0x02 Byte Route setting 1.
0x03 Byte Route setting 2.

Each point in each entry is as follows:

Route Points
Offset Type Description
0x00 Float[3] A 3D position vector of the route position.
0x0C UInt16 Route point setting 1.
0x0E UInt16 Route point setting 2.

AERA

The AERA section describes areas; used to determine which camera to use for example. Each entry is a 0x30 byte structure as follows:

Offset Type Description
0x00 Byte Area mode. 0 = box, 1 = cylinder.
0x01 Byte Area type.
0x02 Byte Index of EMAC.
0x03 Byte Priority value. A higher number means a higher priority to choose which area activates if multiple areas intersected.
0x04 Float[3] A 3D position vector of the area.
0x10 Float[3] A 3D rotation vector of the area's rotation.
0x1C Float[3] A 3D scale vector of the area's scale.
0x28 UInt16 Unknown.
0x2A UInt16 Unknown.
0x2C UInt16 Unknown.
0x2E UInt16 Unknown.

EMAC

The EMAC section describes cameras; used to determine cameras for starting routes, time trial pans, etc. Each entry is a 0x48 byte structure as follows:

Offset Type Description
0x00 Byte Camera type.
0x01 Byte Next camera entry index. Value 0xFF means: no next camera.
0x02 Byte Unknown.
0x03 Byte Route used by the camera. This is index link into the ITPO section. The value 0xFF means "no route".
0x04 UInt16 Route speed.
0x06 UInt16 FOV speed.
0x08 UInt16 Viewpoint speed.
0x0A Byte Unknown.
0x0B Byte Unknown.
0x0C Float[3] A 3D position vector of the camera.
0x18 Float[3] A 3D rotation vector of the camera.
0x24 Float The angle of the FOV (start).
0x28 Float The angle of the FOV (end).
0x2C Float[3] Start vector of the view point.
0x38 Float[3] Destination vector of the view point.
0x44 Float The time how long this Camera is active.

TPGJ

The TPGJ section describes Jugem points; the respawn points. Each entry is a 0x1C byte structure as follows:

Offset Type Description
0x00 Float[3] A 3D position vector of the respawn position.
0x0C Float[3] A 3D rotation vector of the respawn position.
0x18 UInt16 The ID of this respawn position.
0x1A UInt16 Unknown.

TPNC

It seems that this section is usused.

TPSM

It seems that this section is usused.

IGTS

Offset Type Description
0x00 Byte Unknown.
0x01 Byte Unknown.
0x02 Byte Unknown.
0x03 Byte Unknown.
0x04 UInt32 Unknown.
0x08 UInt16 Unknown.
0x0A UInt16 Unknown.

SROC

It seems that this section is usused.

TPLG

Each entry is a 0x18 byte structure as follows:

Offset Type Description
0x00 Float[3] A 3D position vector of the point.
0x0C Float Point scale.
0x10 UInt32 Unknown.
0x14 UInt32 Unknown.

HPLG

Each entry is a 0x0C byte structure as follows:

Offset Type Description
0x00 Byte Point start. The index of the first TPLG entry in this group.
0x01 Byte Point length. The number of TPLG entries in this group.
0x02 Byte[6] Previous groups. The indicies of up to 6 the previous TPLG groups entries may have followed. Unneeded slots are set to value 0xFF.
0x08 Byte[6] Next groups. The indicies of up to 6 next TPLG group entries to follow. Unneeded slots are set to value 0xFF.
0x0C UInt32 Unknown.
0x10 UInt32 Unknown.

Notes

  • The rotation vector is written as radians in float.
  • Many sections are similar to the Mario Kart Wii KMP.

Tools

The following tools can handle Mario Kart 7 KMP files: