NKM (File Format)

From Custom Mario Kart
Jump to: navigation, search

Introduction

NKM is a file format that describes objects, routes, cameras and other information about a course in Mario Kart DS and is the equivalent to Mario Kart Wii's KMP. The file is written in little endian.

File Header

Offset Type Description
0x00 String File magic. Always NKMD in ASCII.
0x04 UInt16 Version number. Final tracks are always 3.7 (0x25 = 37). Beta tracks are 3.0 (0x1E = 30), 3.2 (0x20 = 32) or 3.4 (0x22 = 34). The files written with MKDS Course Modifier 4.0 beta 10 are 4.0 (0x28 = 40), because of the additional information section.
0x06 UInt16 Header length = H.
0x08 UInt32[(H - 8) / 4] Section offsets.
H End of file header

Typical File Header

A typical header is 0x4C long and has 17 sections.

Offset Type Description
0x00 String File magic. Always NKMD in ASCII.
0x04 UInt16 Version number.
0x06 UInt16 Header length = H.
0x08 UInt32 OBJI section offset.
0x0C UInt32 PATH section offset.
0x10 UInt32 POIT section offset.
0x14 UInt32 STAG section offset.
0x18 UInt32 KTPS section offset.
0x1C UInt32 KTPJ section offset.
0x20 UInt32 KTP2 section offset.
0x24 UInt32 KTPC section offset.
0x28 UInt32 KTPM section offset.
0x2C UInt32 CPOI section offset.
0x30 UInt32 CPAT section offset.
0x34 UInt32 IPOI section offset.
0x38 UInt32 IPAT section offset.
0x3C UInt32 EPOI section offset.
0x40 UInt32 EPAT section offset.
0x44 UInt32 AREA section offset.
0x48 UInt32 CAME section offset.
0x4C End of file header

Sections

Section Header

Every sections except the STAG section starts with the section header. The section header is a 0x08 byte structure as follows:

Offset Type Description
0x00 String Section magic.
0x04 UInt32 Number of entries in the section.

OBJI

The OBJI Section describes object used in tracks. Each entry is a 0x3C byte structure as follows:

Offset Type Description
0x00 Vector[1] 3D position vector
0x0C Vector 3D rotation vector.
0x18 Vector 3D scale vector.
0x24 UInt16 Object ID.[2]
0x26 UInt16 Route ID. 0xFFFF if none.
0x28 UInt32[4] 4 object-specific settings.
0x38 UInt32 Show in Time Trails. 1 if shown, 0 if not.

PATH

The PATH section describes paths used for objects and cameras. Each entry is a 0x04 byte structure as follows:

Offset Type Description
0x00 Byte Route ID.
0x01 Byte 1 if the route loops, 0 otherwise.
0x02 UInt16 Number of points. The points are stored in the POIT section.

POIT

The POIT section describes points that is used by the PATH section. Each entry is a 0x14 byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector.
0x0C Byte Point index in the route.
0x0D Byte Unknown.
0x0E Int16 Point duration. Not always used.
0x10 UInt32 Unknown.

STAG

The STAG section describes global information about the track. This is the only section that doesn't start with the section header. The section is a 0x2C byte structure as follows:

Offset Type Description
0x00 String Section magic. Always STAG in ASCII.
0x04 UInt16 Track ID.
0x06 UInt16 Amount of laps.
0x08 Byte Unknown.
0x09 Byte 1 = fog enabled, 0 = disabled.
0x0A Byte Fog table generation mode.
0x0B Byte Fog slope.
0x0C Byte[8] Unknown.
0x14 Fx32 Fog distance.
0x18 GXRgb[3] Fog color.
0x1A UInt16 Fog alpha (0-15).
0x1C GXRgb KCL color 1, the default color.
0x1E GXRgb KCL color 2.
0x20 GXRgb KCL color 3.
0x22 GXRgb KCL color 4.
0x24 Byte[8] Unknown.

KTPS

The KTPS section describes start positions of racers. Each entry is a 0x1C byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector.
0x0C Vector 3D rotation vector.
0x18 UInt16 Padding (0xFFFF).
0x1A UInt16 Start position index. Only used in battle stages and mission mode. For regular courses it is 0xFFFF.

KTPJ

The KTPJ section describes respawn positions. Each entry is a 0x20 byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector.
0x0C Vector 3D rotation vector.
0x18 UInt16 Enemy position ID (EPOI).
0x1A UInt16 Item position ID (IPOI).
0x1C UInt32 Respawn ID.

In tracks with version 0x1E, the Respawn ID does not exist. Tracks with version 0x1E, 0x20 and 0x22 (beta tracks) has a different rotation vector. The Y-rotation can be calculated by using:

Atan2(Rotation.X, Rotation.Z)

If the calculator uses radians, you need to convert it to degrees.

Atan2(Rotation.X, Rotation.Z) * 180 / PI

KTP2

The KTP2 section describes points you need to pass to let the lap count. Each entry is a 0x1C byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector.
0x0C Vector 3D rotation vector.
0x18 UInt16 Padding (0xFFFF).
0x1A UInt16 Index. Always 0xFFFF.

KTPC

The KTPC section describes cannons (or pipe) destination points. Pipes do only work in battle mode by default. Each entry is a 0x1C byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector.
0x0C Vector 3D rotation vector.
0x18 UInt16 Unknown.
0x1A UInt16 Cannon index. Used for the 'Cannon Activator' collision type.

KTPM

The KTPM sections describes points that you need to pass to let a mission succeed. Each entry is a 0x1C byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector.
0x0C Vector 3D rotation vector.
0x18 UInt16 Padding (0xFFFF).
0x1A UInt16 Index (last start position index + 1 is the first one).

CPOI

The CPOI section describes check points. Each entry is a 0x24 byte structure as follows:

Offset Type Description
0x00 Vector 2D position vector.
0x08 Vector 2D position vector 2.
0x10 Fx32 Sinus.[4]
0x14 Fx32 Cosinus.[4]
0x18 Fx32 Distance
0x1C Int16 Section data 1. Has to do with different sections and such, but it is still very unknown.[4]
0x1E Int16 Section data 2. Has to do with different sections and such, but it is still very unknown.[4]
0x20 UInt16 Key ID. 0x0000 = lap counter, 0x0001 – 0xFFFE = key, 0xFFFF = no key.
0x22 Byte Respawn ID.
0x23 Byte Unknown.

CPAT

The CPAT section describes CPOI grouping. Each entry is a 0x0C byte structure as follows:

Offset Type Description
0x00 UInt16 Point start.
0x02 UInt16 Point length.
0x04 Byte[3] Next group. The indicies of up to 3 the previous CPOI groups entries may have followed. Unneeded slots are set to value 0xFF.
0x07 Byte[3] Previous group. The indicies of up to 3 next CPOI group entries to follow. Unneeded slots are set to value 0xFF.
0x0A Int16 Section order.

IPOI

The IPOI section describes item points; the routes of items such as red shells. Each entry is a 0x14 byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector.
0x0C Fx32 Point scale.
0x10 UInt32 Unknown.

IPAT

The IPAT section describes IPOI grouping. Each entry is a 0x0C byte structure as follows:

Offset Type Description
0x00 UInt16 Point start.
0x02 UInt16 Point length.
0x04 Byte[3] Next group. The indicies of up to 3 the previous IPOI groups entries may have followed. Unneeded slots are set to value 0xFF.
0x07 Byte[3] Previous group. The indicies of up to 3 next IPOI group entries to follow. Unneeded slots are set to value 0xFF.
0x0A Int16 Section order.

EPOI

The EPOI section describes enemy points; the routes that the CPUs take. Each entry is a 0x18 byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector.
0x0C Fx32 Point scale.
0x10 Int16 Drifting.
0x12 UInt16 Unknown.
0x14 UInt32 Unknown.

EPAT

The EPAT section describes EPOI grouping. Each entry is a 0x0C byte structure as follows:

Offset Type Description
0x00 UInt16 Point start.
0x02 UInt16 Point length.
0x04 Byte[3] Next group. The indicies of up to 3 the previous EPOI groups entries may have followed. Unneeded slots are set to value 0xFF.
0x07 Byte[3] Previous group. The indicies of up to 3 next EPOI group entries to follow. Unneeded slots are set to value 0xFF.
0x0A Int16 Section order .

MEPO

The MEPO section describes enemy points used in minigames. Each entry is a 0x18 byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector.
0x0C Fx32 Point scale.
0x10 Int32 Drifting.
0x14 UInt32 Unknown.

MEPA

The MEPA section describes MEPO grouping used in minigames. Each entry is a 0x14 byte structure as follows:

Offset Type Description
0x00 UInt16 Point start.
0x02 UInt16 Point length.
0x04 Byte[8] Next group. The indicies of up to 8 the previous MEPO groups entries may have followed. Unneeded slots are set to value 0xFF.
0x0C Byte[8] Previous group. The indicies of up to 8 next MEPO group entries to follow. Unneeded slots are set to value 0xFF.

AREA

The AREA section describes areas, mosty used for determine which camera to use. Each entry is a 0x48 byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector.
0x0C Vector 3D length vector.
0x18 Vector X-vector?.
0x24 Vector Y-vector?.
0x30 Vector Z-vector?.
0x3C Int16 Unknown.
0x3E Int16 Unknown.
0x40 Int16 Unknown.
0x42 Byte Unknown.
0x43 Byte Camera ID.
0x44 Byte Area type.
Value Description
0x00 Unknown.
0x01 Camera.
0x02 Unknown.
0x03 Unknown.
0x04 Water fall sound area.
0x45 Int16 Unknown.
0x47 Byte Unknown.

CAME

The CAME section describes cameras used in tracks. Each entry is a 0x4C byte structure as follows:

Offset Type Description
0x00 Vector 3D position vector 1.
0x0C Vector 3D rotation vector.
0x18 Vector 3D position vector 2.
0x24 Vector 3D position vector 3.
0x30 Int16 FOV begin.
0x32 Fx16 FOV begin sine.
0x34 Fx16 FOV begin cosine.
0x36 Int16 FOV end.
0x38 Fx16 FOV end sine.
0x3A Fx16 FOV end cosine.
0x3C UInt16 Camera zoom.
0x3E UInt16 Camera type.
Value Description
0x00 After race camera
0x01 Unknown (with route).
0x02 Unknown.
0x03 Intro camera (top screen).
0x04 Intro camera (bottom screen).
0x05 Unknown.
0x06 Unknown.
0x07 Battle mode camera.
0x08 Mission finish camera.
0x40 UInt16 Linked route (0xFFFF if none).
0x42 UInt16 Route speed.
0x44 UInt16 Point speed.
0x46 UInt16 Camera duration in 1/60 second units.
0x48 UInt16 Next camera (0xFFFF if this is the last one).
0x4A Byte Intro pan first camera indicator (0x00 = none, 0x01 = top screen, 0x02 = bottom screen).
0x4B Byte Unknown

Special (additional) Sections

Since MKDS Course Modifier 4.0 beta 10, some additional information may be stored in the NKM file.

NKMI

The NKMI section describes some information about the track itself, like the name and the version etc. This section is never present in the header. This is because of compatibility reasons. StringNT means a null-terminated string.

Offset Size Type Description
0x00 0x04 String Section magic. NKMI in ASCII.
0x04 0x04 UInt32 Section length.
0x08 a StringNT Track name.
0x08 + a b StringNT Author.
0x08 + a + b c StringNT Version.
0x08 + a + b + c d StringNT Latest edit date. Format: dd/MM/yyyy HH:mm:ss (15/05/2013 16:18:04).

Links

  1. VecFx32 (Vector)
  2. Object list
  3. GXRgb
  4. 4.0 4.1 4.2 4.3 More CPOI Info

Tools

The following tools can handle NKM files: