Difference between revisions of "Network Protocol/RACEHEADER 2"

From Custom Mario Kart
Jump to navigation Jump to search
(Add coin battle packet structure and mark things as unused/padding)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{DISPLAYTITLE:{{BASEPAGENAME}}/RACEHEADER_2}}
 
{{DISPLAYTITLE:{{BASEPAGENAME}}/RACEHEADER_2}}
This pages is related to [[MKWii Network Protocol]] and describes the record type '''RACEHEADER_2'''.
+
This article describes the record type '''RACEHEADER_2''' of the [[Network Protocol]]. This record is not sent during live view, and its contents depend on the game mode.
  
'''RACEHEADRER_2''' is not present during being in a live view (but '''RACEHEADER_1''' is).
+
{{Network Protocol RACE}}
  
Here is the record read function in GNU C notation. The function notation is used, because some values are bit packed. This code was created by a code generator.
+
== VS Race Structure ==
 +
{| class="wikitable"
 +
! Offset
 +
! Size
 +
! Description
 +
|-
 +
| 0x00 || 13 bits || Players who have finished the race (1 bit per player + 1).
 +
|-
 +
| 0x01.5 || 13 bits || Players who are participating in the race (1 bit per player + 1).
 +
|-
 +
| 0x03.2 || 13 bits || Players who have disconnected (1 bit per player + 1).
 +
|-
 +
| 0x04.7 || 2 bits || Local player count.
 +
|-
 +
| 0x05.1 || 4 bits || Client slot for Player 1.
 +
|-
 +
| 0x05.5 || 22 bits || Finishing time for Player 1 (6 bits for minutes, 6 for seconds and 10 for milliseconds).
 +
|-
 +
| 0x08.3 || 13 bits || Players who are ahead of Player 1 (1 bit per player + 1).
 +
|-
 +
| 0x0A || 4 bits || Client slot for Player 2.
 +
|-
 +
| 0x0A.4 || 22 bits || Finishing time for Player 2 (6 bits for minutes, 6 for seconds and 10 for milliseconds).
 +
|-
 +
| 0x0D.2 || 13 bits || Players who are ahead of Player 2 (1 bit per player + 1).
 +
|-
 +
| 0x0F || 1 byte || {{Unknown-left|'''Padding'''.}}
 +
|-
 +
| 0x10 || 2 bytes || {{Unknown-left|'''Unused'''. Local client slots.}}
 +
|-
 +
| 0x12 || 1 byte || {{Unknown-left|'''Unused'''. Incomplete client slots bitfield.}}
 +
|-
 +
| 0x13 || 1 byte || {{Unknown-left|'''Unused'''. Local player count.}}
 +
|-
 +
| 0x14 || 4 bytes || Time since the race leader finished (in frames).
 +
|-
 +
| 0x18 || 4 bytes || Minimum time before the race can time out (in frames). The value for each Nintendo track can be found at 0x808903A4 PAL.
 +
|-
 +
| 0x1C || 1 byte || Marks the player as disconnected if set to 1.
 +
|-
 +
| 0x1D || 1 byte || {{Unknown-left|'''Padding'''.}}
 +
|-
 +
| 0x1E || 4 bytes || Time (in frames) since each local player last moved faster than 30km/h. Caps at 300 (5 seconds).
 +
|-
 +
| 0x22 || 4 bytes || Time (in frames) since each countdown value maxed out. Caps at 3600 (1 minute), after which the player is disconnected if in a public room.
 +
|-
 +
| 0x26 || 2 bytes || {{Unknown-left|'''Padding'''.}}
 +
|}
  
<pre>
+
== Balloon Battle Structure ==
    d->end_time[0] = be32(src+ 0x005 )  >> 5 & 0x003FFFFFu;
+
Unlike the VS race structure, this packet has variable content that depends on the local ('''L''') and total ('''N''') player count.
    d->end_time[1] = be32(src+ 0x00a )  >> 6 & 0x003FFFFFu;
 
    d->player_idx[0] =     src[ 0x010 ];
 
    d->player_idx[1] =     src[ 0x011 ];
 
    d->finish_timer = be16(src+ 0x016 );
 
    return 0x30; // last analyzed offset + 1
 
</pre>
 
  
And here the code of a self written code generator script. The script creates data structures and the read function above. The byte offset is hex, all others are decimal numbers.
+
{| class="wikitable"
<pre>
+
! Size
!------------------------------------------------------------------------------------------
+
! Description
!                        byte+bit
+
|-
! type name N offset bits comment
+
| 1 byte || Player slot for each local player (4 bits each). Value is 0xC if a guest is not present.
!------------------------------------------------------------------------------------------
+
|-
  u32  *end_time 2   -  -  - the end time of each user, max is 63:59.999
+
| 14 bits || Battle score for each local player (7 bits each) Value is 0 if a guest is not present.
  > *end_time[0] -  05  5 22
+
|-
  > *end_time[1] -  0a  4 22
+
| '''N''' * 5 bits || {{Unknown-left|'''Unknown'''. A 2-bit value followed by a 3-bit value for each player.}}
  u8    player_idx 2 10  0  8 race slot of both players
+
|-
  u16  finish_timer - 16  0 16 time since leader finish, 59.94 Hz
+
| 4 bits || Players who have disconnected (1 bit per player). The game keeps track of all players but cuts the bitfield off when sending it.
!------------------------------------------------------------------------------------------
+
|-
</pre>
+
| '''L''' * 10 bits || Balloon colors for each local player (2 bits each):
 +
* 0: No balloon
 +
* 1: Red balloon
 +
* 2: Blue balloon
 +
|-
 +
| 7 bits || Battle event count (1 bit per event).
 +
|-
 +
| '''C''' * 27 bits || '''C''' battle events. See below for the event structure.
 +
|}
  
<br/>
+
=== Battle Event Structure ===
{{MKWii Network Protocol}}
+
{| class="wikitable"
[[category: Network Protocol|R]]
+
! Offset
 +
! Size
 +
! Description
 +
|-
 +
| 0x00 || 4 bits || Event type:
 +
* 0: None (no event)
 +
* 1: Player stole a balloon from another
 +
* 2: Player fell off the course
 +
* 3: Player hit another with an item
 +
* 4: Player lost all their balloons
 +
* 5: Player hit an obstacle
 +
* 6: Unknown, but not unused
 +
* 7: Player disconnected
 +
* 8: Player's battle timer ran out
 +
|-
 +
| 0x00.4 || 15 bits || {{Unknown-left|'''Unknown'''. Seems to be some sort of time value.}}
 +
|-
 +
| 0x02.3 || 4 bits || First player value, with different usage based on event type:
 +
* Events 1-7: Player who performed the action
 +
* Event 8: Value set to 0xC and ignored by the parsing code
 +
|-
 +
| 0x02.7 || 4 bits || Second player value, with different usage based on event type:
 +
* Events 1 and 3: Player that was hit/stolen from
 +
* Event 7: Guest of the player who disconnected (or 0xC)
 +
* Other event types: Value set to 0xC and ignored by the parsing code
 +
|}
 +
 
 +
== Coin Runners Structure ==
 +
The packet structure for this game mode is unknown.
 +
 
 +
{{Network Protocol}}
 +
[[Category:Network Protocol|R]]

Latest revision as of 15:55, 29 January 2024

This article describes the record type RACEHEADER_2 of the Network Protocol. This record is not sent during live view, and its contents depend on the game mode.

Race Packet Sections
Name Amount Size Description
SLOT 0-1 0x08 Only used for redirected data via a proxy. The record identifies the original client by its slot number.
HEADER 1 0x10 A header for a race packet.
RACEHEADER_1 1 0x28 A record with basic race data.
RACEHEADER_2 0-1 0x28 A record with game-mode specific race data (not present in live view).
ROOM 0-1 0x04 A record containing a friend room message (not present outside friend room lobbies).
SELECT 0-1 0x38 A record containing data to set up a match (not present during races).
RACEDATA 1-2 0x40 A record containing race data for each player, such as positions or inputs.
USER 0-1 0xC0 A record containing user data such as Miis and friend codes.
ITEM 1-2 0x08 A record containing information about players' items.
EVENT 1 ≥ 0x18 A record transmitting item events.


VS Race Structure

Offset Size Description
0x00 13 bits Players who have finished the race (1 bit per player + 1).
0x01.5 13 bits Players who are participating in the race (1 bit per player + 1).
0x03.2 13 bits Players who have disconnected (1 bit per player + 1).
0x04.7 2 bits Local player count.
0x05.1 4 bits Client slot for Player 1.
0x05.5 22 bits Finishing time for Player 1 (6 bits for minutes, 6 for seconds and 10 for milliseconds).
0x08.3 13 bits Players who are ahead of Player 1 (1 bit per player + 1).
0x0A 4 bits Client slot for Player 2.
0x0A.4 22 bits Finishing time for Player 2 (6 bits for minutes, 6 for seconds and 10 for milliseconds).
0x0D.2 13 bits Players who are ahead of Player 2 (1 bit per player + 1).
0x0F 1 byte Padding.
0x10 2 bytes Unused. Local client slots.
0x12 1 byte Unused. Incomplete client slots bitfield.
0x13 1 byte Unused. Local player count.
0x14 4 bytes Time since the race leader finished (in frames).
0x18 4 bytes Minimum time before the race can time out (in frames). The value for each Nintendo track can be found at 0x808903A4 PAL.
0x1C 1 byte Marks the player as disconnected if set to 1.
0x1D 1 byte Padding.
0x1E 4 bytes Time (in frames) since each local player last moved faster than 30km/h. Caps at 300 (5 seconds).
0x22 4 bytes Time (in frames) since each countdown value maxed out. Caps at 3600 (1 minute), after which the player is disconnected if in a public room.
0x26 2 bytes Padding.

Balloon Battle Structure

Unlike the VS race structure, this packet has variable content that depends on the local (L) and total (N) player count.

Size Description
1 byte Player slot for each local player (4 bits each). Value is 0xC if a guest is not present.
14 bits Battle score for each local player (7 bits each) Value is 0 if a guest is not present.
N * 5 bits Unknown. A 2-bit value followed by a 3-bit value for each player.
4 bits Players who have disconnected (1 bit per player). The game keeps track of all players but cuts the bitfield off when sending it.
L * 10 bits Balloon colors for each local player (2 bits each):
  • 0: No balloon
  • 1: Red balloon
  • 2: Blue balloon
7 bits Battle event count (1 bit per event).
C * 27 bits C battle events. See below for the event structure.

Battle Event Structure

Offset Size Description
0x00 4 bits Event type:
  • 0: None (no event)
  • 1: Player stole a balloon from another
  • 2: Player fell off the course
  • 3: Player hit another with an item
  • 4: Player lost all their balloons
  • 5: Player hit an obstacle
  • 6: Unknown, but not unused
  • 7: Player disconnected
  • 8: Player's battle timer ran out
0x00.4 15 bits Unknown. Seems to be some sort of time value.
0x02.3 4 bits First player value, with different usage based on event type:
  • Events 1-7: Player who performed the action
  • Event 8: Value set to 0xC and ignored by the parsing code
0x02.7 4 bits Second player value, with different usage based on event type:
  • Events 1 and 3: Player that was hit/stolen from
  • Event 7: Guest of the player who disconnected (or 0xC)
  • Other event types: Value set to 0xC and ignored by the parsing code

Coin Runners Structure

The packet structure for this game mode is unknown.