Network Protocol/RACEDATA

From Custom Mario Kart
Jump to navigation Jump to search

Overview

This article describes the record type RACEDATA of the Network Protocol. It contains the player-specific race data of a client. Depending on the number of players using the console, one or two records are sent.

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.


    d->position[0]	= be32(src+ 0x000 )   >> 4 & 0x0FFFFFFFu;
    d->position[1]	= be32(src+ 0x003 )        & 0x0FFFFFFFu;
    d->position[2]	= be32(src+ 0x007 )   >> 4 & 0x0FFFFFFFu;
    d->direction[0]	= be32(src+ 0x00a -1) >> 3 & 0x0001FFFFu;
    d->direction[1]	= be32(src+ 0x00c -1) >> 2 & 0x0001FFFFu;
    d->direction[2]	= be32(src+ 0x00e -1) >> 1 & 0x0001FFFFu;
    d->speed            = be16(src+ 0x011 ); 
    d->tilt_angle       = be32(src+ 0x018 ); 
    d->nunchuk_X_axis   =      src[ 0x025 ]   >> 4 &       0x0Fu;   
    d->nunchuk_Y_axis   =      src[ 0x026 ]   >> 4 &       0x0Fu;   
    d->thundercloud     =      src[ 0x026 ]        &       0x01u; 
    d->lakitu		=      src[ 0x027 ]   >> 6 &       0x03u;
    d->falldown         =      src[ 0x027 ]        &       0x01u;
    d->buttons		=      src[ 0x028 ]   >> 4 &       0x0Fu;
    d->mt_start         =      src[ 0x028 ]   >> 3 &       0x01u;
    d->goldenshroom     =      src[ 0x029 ]   >> 6 &       0x01u;
    d->blooper_ink      =      src[ 0x029 ]   >> 1 &       0x01u; 
    d->megamushroom     =      src[ 0x029 ]        &       0x01u;
    d->star             =      src[ 0x02a ]   >> 7 &       0x01u; 
    d->twanwan          =      src[ 0x02a ]   >> 2 &       0x01u; 
    d->thwomp_hit       =      src[ 0x02a ]        &       0x01u;
    d->fire             =      src[ 0x02b ]   >> 5 &       0x01u;
    d->cataquack        =      src[ 0x02b ]   >> 4 &       0x01u;
    d->star_hit         =      src[ 0x02c ]   >> 7 &       0x01u; 
    d->fakebox_hit      =      src[ 0x02c ]   >> 6 &       0x01u; 
    d->bomb_blue_hit    =      src[ 0x02c ]   >> 5 &       0x01u; 
    d->bomb_blue_half   =      src[ 0x02c ]   >> 4 &       0x01u; 
    d->goomba_hit       =      src[ 0x02c ]   >> 1 &       0x01u; 
    d->collision        =      src[ 0x02e ]        &       0x01u;
    d->wheelie_start    =      src[ 0x02f ]   >> 7 &       0x01u; 
    d->stunt            =      src[ 0x02f ]   >> 5 &       0x01u;
    d->hop              =      src[ 0x02f ]   >> 3 &       0x01u;
    d->cannon		= be16(src+ 0x02f )   >> 6 &     0x0007u;
    d->drift		=      src[ 0x032 ]   >> 6 &       0x03u;
    d->already_drifted	=      src[ 0x032 ]   >> 4 &       0x01u;
    d->rank		= be16(src+ 0x032 )   >> 7 &     0x000Fu;

    return 0x40; // record size

Using the vector (0A, 4, 6) as an example, we would have a 6 bit number beginning at offset 0x0A bit 4 (MSB, mask 0x0f) and ending at offset 0x0B bit 1 (LSB, mask 0xc0).

 !---------------------------------------------------------------------------------------
 !                        byte+bit
 ! type	name		 N offset bits	comment
 !---------------------------------------------------------------------------------------
   s32	position	 3   0  0 28	x+y+z positions in 1/16 units, 0x9f42410 is 0.0.
   u32	direction	 3  0a  4 17	Curious direction vector, see comment.
   s16  speed            -  11  0 16    Speed value (0x3e90 = 0, > 0x3e90 for forward, < 0x3e90 for backward).
   s32  tilt_angle       -  18  0 32    Float value for tilting angle - 1=center, <1=left, >1=right.
  ---------------------------------------------------------------------------------------
   u8   nunchuk_X_axis   -  25  0  4    Nunchuk X-axis - from 0 (left) to e (right). center = 7. 
   u8   nunchuk_Y_axis   -  26  0  4    Nunchuk Y-axis - from 0 (down) to e (up). center = 7. 
   u8   thundercloud     -  26  7  1    0: lost Thunder Cloud (by Thunder Cloud hit?), 1: got Thunder Cloud.
   u8	lakitu		 -  27  0  2	0: no Lakitu, 1: phase 1, 2: phase 2, 3: ?
   u8   falldown         -  27  7  1    Falldown, 1 during falldown animation, 0 at Lakitu/race.
   u8   buttons		 -  28  0  4	1: drive (A or Mushroom), 2: break/backwards(B), 3: A and B, 7: Hop or drift phase 1, 15: drift phase 2.
   u8   mt_start         -  28  4  1    This bit flips every time you release a Mini-Turbo (turbo start).
   u8   shroom           -  29  1  1    1 when you hit the item button, 0 when the single boost is finished.
   u8   blooper_ink      -  29  6  1    This bit flips every time you get hit by Blooper ink. 
   u8   megamushroom     -  29  7  1    This bit flips every time you use a Mega Mushroom.
   u8   star             -  2a  0  1    This bit flips every time you use a Star.
   u8   twanwan          -  2a  5  1    This bit flips every time the Chain Chomp in Battle Mode hits you.
   u8   thwomp_hit       -  2a  7  1    This bit flips every time you got hit by a Thwomp or a press in Toad's Factory.
   u8   fire             -  2b  2  1    This bit flips every time you got hit by a lava bubble on DS Desert Hills (or by fire in general?).
   u8   cataquack        -  2b  3  1    This bit flips every time the Cataquack at GCN Peach Beach throws you in the air.
   u8   star_hit         -  2c  0  1    This bit flips every time you got hit by someone with a Star or drive into a cow (Moo Moo Meadows).
   u8   fakebox_hit      -  2c  1  1    This bit flips every time you collide with a Fake Item Box or Monty Mole.
   u8   bomb_blue_hit    -  2c  2  1    This bit flips every time you got completely hit with a Blue Shell or a Bob-omb. Also flips unknown highest bit at 0x38.
   u8   bomb_blue_half   -  2c  3  1    This bit flips every time you drive into an exploding Blue Shell, exploding Bob-omb, cactus, Pokey (Dry Dry Ruins), Shy Guy snowboarder (DK Summit), or penguin (N64 Sherbet Land). Also flips unknown highest bit at 0x38.
   u8   goomba_hit       -  2c  6  1    This bit flips every time you drive into a Goomba. 
   u8   collision        -  2e  7  1    Flips with every collision (flips every packet when driving while touching an object) and flips when you end a wheelie.
   u8   wheelie_start    -  2f  0  1    Flips every time you start a wheelie (wheelie ends with "collision").
   u8   stunt            -  2f  2  1    Flips every time you do a stunt.
   u8   hop              -  2f  4  1    Flips with every hop/drift begun during driving.
   u8	cannon		 -  2f  7  3	Flips with cannon #0..2 activation.
   u8	drift		 -  32  0  2	0: no drift, 1: drift, 2: blue spark, 3: orange spark.
   u8  	already_drifted	 -  32  3  1	1: driver has drifted at least once.
   u8	rank		 -  32  5  4	Rank in-race.
 !---------------------------------------------------------------------------------------

The values described with "This bit flips ..." do not indicate when the action ends. When a certain action happens, its according bit would flip when it begins. The duration and end of the actual event are calculated by each console on their own.

Vectors

Position Vectors

The three coordinates of the position vector are sent as three 28 bit unsigned integers packed without padding. Getting the coordinate is done by adding 0x3f800000 as an unsigned integer to the raw value. Interpreting this 32 bit value as a single precision float and subtracting 1e6 would give the result.

Direction Vectors

It seems that 17 bits are also a minimized float, namely 1 bit sign, 2 bits exponent and 14 bits mantissa. After the sign bit is set, assume the value is 0. Shift it 9 bits to the left and add 0x3e800000. Interpreting this 32 bit value as a float and subtracting 1.0 would give a unit vector.

------------------------------------------
  3D vector in hex   horizontal
    x     y     z     direction  comment
------------------------------------------
[ 8000, 8000, c000]    0    S
[ ad41, 8000, ad41]   45    SO
[ b76b, 8000, a001]   60
[ bb20, 8000, 987d]   67.5 
[ c000, 8000, 7fff]   90    O
[ bb20, 8000, 4f04]  112.5 
[ b76b, 8000, 4006]  120
[ ad41, 8000, 257d]  135    NO
[ 9ffe, 8000, 112e]  150
[ 987d, 8000,  9be]  157.5 
[ 8000, 8000,    0]  180    N
[ 4f04, 8000,  9be]  202.5 
[ 4002, 8000, 112e]  210
[ 257d, 8000, 257d]  225    NW
[1ffff, 8000, 7fff]  270    W    1ffff=-1
[    0, 8000, 8000] ~270   ~W    a guess
[ 257d, 8000, ad41]  315    SW
------------------------------------------
[ 8000, 8000, c000]    0    S
[ c000, 8000, 7fff]   90    O
[1ffff, 8000, 7fff]  270    W    1ffff=-1
[ 8000, 8000,    0]  180    N
------------------------------------------