Guest User

SMS_UDP_Definitions.hpp from SMS_UDP_Definitions_v2_Patch5

a guest
Apr 29th, 2024
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.28 KB | Gaming | 0 0
  1. /*************************************************************************************************
  2.  
  3.   Description:
  4.     Base definitions of udp packet structure
  5.     The data definition mostly follows the data set for the Shared memory, so it is strongly suggested to have a look to the
  6.     latest shared memory header if you have problem decoding any data.
  7.  
  8. *************************************************************************************************/
  9. #ifndef _SMS_UDP_DEFINITIONS_HPP_
  10. #define _SMS_UDP_DEFINITIONS_HPP_
  11.  
  12. #define SMS_UDP_PORT 5606
  13. #define SMS_UDP_MAX_PACKETSIZE 1500
  14.  
  15. enum EUDPStreamerPacketHandlerType
  16. {
  17.     eCarPhysics = 0,
  18.     eRaceDefinition = 1,
  19.     eParticipants = 2,
  20.     eTimings = 3,
  21.     eGameState = 4,
  22.     eWeatherState = 5, // not sent at the moment, information can be found in the game state packet
  23.     eVehicleNames = 6, //not sent at the moment
  24.     eTimeStats = 7,
  25.     eParticipantVehicleNames = 8
  26. };
  27.  
  28. /*
  29. Each packet holds a base header with identification info to help with UDP unreliability.
  30. */
  31.  
  32. struct PacketBase
  33. {
  34.     unsigned int    mPacketNumber;                      //0 counter reflecting all the packets that have been sent during the game run
  35.     unsigned int    mCategoryPacketNumber;      //4 counter of the packet groups belonging to the given category
  36.     unsigned char   mPartialPacketIndex;            //8 If the data from this class had to be sent in several packets, the index number
  37.     unsigned char   mPartialPacketNumber;           //9 If the data from this class had to be sent in several packets, the total number
  38.     unsigned char   mPacketType;                            //10 what is the type of this packet (see EUDPStreamerPacketHanlderType for details)
  39.     unsigned char   mPacketVersion;                     //11 what is the version of protocol for this handler, to be bumped with data structure change
  40. };                                                                              //12 total size
  41.  
  42. /*******************************************************************************************************************
  43. //
  44. //  Telemetry data for the viewed participant.
  45. //
  46. //  Frequency: Each tick of the UDP streamer how it is set in the options
  47. //  When it is sent: in race
  48. //
  49. *******************************************************************************************************************/
  50. #define UDP_STREAMER_CAR_PHYSICS_HANDLER_VERSION                        2
  51. #define TYRE_NAME_LENGTH_MAX                                            40
  52.  
  53. #pragma pack(push)
  54. #pragma pack(1)
  55.         struct sTelemetryData
  56.         {
  57.             static const    unsigned int    sPacketSize = 559;
  58.             PacketBase          sBase;                                                      // 0 12
  59.                                                                                                                 // Participant info
  60.             signed char                         sViewedParticipantIndex;                    // 12 1
  61.                                                                                                                 // Unfiltered input
  62.             unsigned char                           sUnfilteredThrottle;                            // 13 1
  63.             unsigned char                           sUnfilteredBrake;                                   // 14 1
  64.             signed char                         sUnfilteredSteering;                            // 15 1
  65.             unsigned char                           sUnfilteredClutch;                              // 16 1
  66.                                                                                                                 // Car state
  67.             unsigned char                           sCarFlags;                                              // 17 1
  68.             signed short                            sOilTempCelsius;                                    // 18 2
  69.             unsigned short                          sOilPressureKPa;                                    // 20 2
  70.             signed short                            sWaterTempCelsius;                              // 22 2
  71.             unsigned short                          sWaterPressureKpa;                              // 24 2
  72.             unsigned short                          sFuelPressureKpa;                                   // 26 2
  73.             unsigned char                           sFuelCapacity;                                      // 28 1
  74.             unsigned char                           sBrake;                                                     // 29 1
  75.             unsigned char                           sThrottle;                                              // 30 1
  76.             unsigned char                           sClutch;                                                    // 31 1
  77.             float                           sFuelLevel;                                             // 32 4
  78.             float                           sSpeed;                                                     // 36 4
  79.             unsigned short                          sRpm;                                                           // 40 2
  80.             unsigned short                          sMaxRpm;                                                    // 42 2
  81.             signed char                         sSteering;                                              // 44 1
  82.             unsigned char                           sGearNumGears;                                      // 45 1
  83.             unsigned char                           sBoostAmount;                                           // 46 1
  84.             unsigned char                           sCrashState;                                            // 47 1
  85.             float                           sOdometerKM;                                            // 48 4
  86.             float                           sOrientation[3];                                    // 52 12
  87.             float                           sLocalVelocity[3];                              // 64 12
  88.             float                           sWorldVelocity[3];                              // 76 12
  89.             float                           sAngularVelocity[3];                            // 88 12
  90.             float                           sLocalAcceleration[3];                      // 100 12
  91.             float                           sWorldAcceleration[3];                      // 112 12
  92.             float                           sExtentsCentre[3];                              // 124 12
  93.             unsigned char                           sTyreFlags[4];                                      // 136 4
  94.             unsigned char                           sTerrain[4];                                            // 140 4
  95.             float                           sTyreY[4];                                              // 144 16
  96.             float                           sTyreRPS[4];                                            // 160 16
  97.             unsigned char                           sTyreTemp[4];                                           // 176 4
  98.             float                           sTyreHeightAboveGround[4];              // 180 16
  99.             unsigned char                           sTyreWear[4];                                           // 196 4
  100.             unsigned char                           sBrakeDamage[4];                                    // 200 4
  101.             unsigned char                           sSuspensionDamage[4];                           // 204 4
  102.             signed short                            sBrakeTempCelsius[4];                           // 208 8
  103.             unsigned short                          sTyreTreadTemp[4];                              // 216 8
  104.             unsigned short                          sTyreLayerTemp[4];                              // 224 8
  105.             unsigned short                          sTyreCarcassTemp[4];                            // 232 8
  106.             unsigned short                          sTyreRimTemp[4];                                    // 240 8
  107.             unsigned short                          sTyreInternalAirTemp[4];                    // 248 8
  108.             unsigned short                          sTyreTempLeft[4];                                   // 256 8
  109.             unsigned short                          sTyreTempCenter[4];                             // 264 8
  110.             unsigned short                          sTyreTempRight[4];                              // 272 8
  111.             float                           sWheelLocalPositionY[4];                    // 280 16
  112.             float                           sRideHeight[4];                                     // 296 16
  113.             float                           sSuspensionTravel[4];                           // 312 16
  114.             float                           sSuspensionVelocity[4];                     // 328 16
  115.             unsigned short                          sSuspensionRideHeight[4];                   // 344 8
  116.             unsigned short                          sAirPressure[4];                                    // 352 8
  117.             float                           sEngineSpeed;                                           // 360 4
  118.             float                           sEngineTorque;                                      // 364 4
  119.             unsigned char                           sWings[2];                                              // 368 2
  120.             unsigned char                           sHandBrake;                                             // 370 1
  121.                                                                                                                 // Car damage
  122.             unsigned char                           sAeroDamage;                                            // 371 1
  123.             unsigned char                           sEngineDamage;                                      // 372 1
  124.                                                                                                                 //  HW state
  125.             unsigned int                            sJoyPad0;                                                   // 376 4
  126.             unsigned char                           sDPad;                                                      // 377 1
  127.             char                        sTyreCompound[4][TYRE_NAME_LENGTH_MAX]; // 378 160
  128.             float                           sTurboBoostPressure;                            // 538 4
  129.             float                           sFullPosition[3];                                   // 542 12
  130.             unsigned char                           sBrakeBias;                                             // 554 1 -- quantized brake bias
  131.             unsigned int                            sTickCount;                                             // 555
  132.         };                                                                                                  // 559
  133. #pragma pack(pop)
  134.  
  135. #define PARTICIPANT_NAME_LENGTH_MAX                                     64
  136. #define PARTICIPANTS_PER_PACKET                                         16
  137. #define UDP_STREAMER_PARTICIPANTS_SUPPORTED 32
  138.  
  139. /*******************************************************************************************************************
  140. //
  141. //  Race stats data.  
  142. //
  143. //  Frequency: Logaritmic decrease
  144. //  When it is sent: Counter resets on entering InRace state and again each time any of the values changes
  145. //
  146. *******************************************************************************************************************/
  147. #define UDP_STREAMER_RACE_STATE_HANDLER_VERSION 1
  148. #define TRACKNAME_LENGTH_MAX                                            64
  149. struct sRaceData
  150. {
  151.     static const    unsigned int    sPacketSize = 308;
  152.     PacketBase                      sBase;                                              // 0 12
  153.     float                           sWorldFastestLapTime;                               // 12
  154.     float                           sPersonalFastestLapTime;                            // 16
  155.     float                           sPersonalFastestSector1Time;                        // 20
  156.     float                           sPersonalFastestSector2Time;                        // 24
  157.     float                           sPersonalFastestSector3Time;                        // 28
  158.     float                           sWorldFastestSector1Time;                           // 32
  159.     float                           sWorldFastestSector2Time;                           // 36
  160.     float                           sWorldFastestSector3Time;                           // 40
  161.     float                           sTrackLength;                                       // 44
  162.     char                            sTrackLocation[TRACKNAME_LENGTH_MAX];               // 48
  163.     char                            sTrackVariation[TRACKNAME_LENGTH_MAX];              // 112
  164.     char                            sTranslatedTrackLocation[TRACKNAME_LENGTH_MAX];     // 176
  165.     char                            sTranslatedTrackVariation[TRACKNAME_LENGTH_MAX];    // 240
  166.     unsigned short      sLapsTimeInEvent;                                               // 304 contains lap number for lap based session or quantized session duration (number of 5mins) for timed sessions, the top bit is 1 for timed sessions
  167.     signed char             sEnforcedPitStopLap;                                        // 306
  168. };                                                                                      // 308
  169.  
  170. /*******************************************************************************************************************
  171. //
  172. //  Participant names data.  
  173. //
  174. //  Frequency: Logarithmic decrease
  175. //  When it is sent: Counter resets on entering InRace state and again each  the participants change.
  176. //  The sParticipantsChangedTimestamp represent last time the participants has changed and is to be used to sync
  177. //  this information with the rest of the participant related packets
  178. //
  179. *******************************************************************************************************************/
  180. #define UDP_STREAMER_PARTICIPANTS_HANDLER_VERSION       2
  181. struct sParticipantsData
  182. {
  183.     static const unsigned int   sPacketSize = 1136;
  184.     PacketBase                  sBase;                                                      //  0   12
  185.     unsigned int                sParticipantsChangedTimestamp;                              //  12  4
  186.     char                        sName[PARTICIPANTS_PER_PACKET][PARTICIPANT_NAME_LENGTH_MAX];//  16  1024
  187.     unsigned int                sNationality[PARTICIPANTS_PER_PACKET];                      //  1040 64
  188.     unsigned short              sIndex[PARTICIPANTS_PER_PACKET];                            //  1104 32 -- session unique index for MP races
  189. };                                                                                          //  1136
  190.  
  191. /*******************************************************************************************************************
  192. //
  193. //  Participant timings data.  
  194. //
  195. //  Frequency: Each tick of the UDP streamer how it is set in the options.
  196. //  When it is sent: in race
  197. //
  198. *******************************************************************************************************************/
  199. #define UDP_STREAMER_TIMINGS_HANDLER_VERSION                        3
  200. #pragma pack(push)
  201. #pragma pack(1)
  202. struct sParticipantInfo
  203. {
  204.     signed short                            sWorldPosition[3];                              // 0 --
  205.     signed short                            sOrientation[3];                                // 6 -- Quantized heading (-PI .. +PI) , Quantized pitch (-PI / 2 .. +PI / 2),  Quantized bank (-PI .. +PI).
  206.     unsigned short                          sCurrentLapDistance;                            // 12 --
  207.     unsigned char                           sRacePosition;                                  // 14 -- holds the race position, + top bit shows if the participant is active or not
  208.     unsigned char                           sSector;                                        // 15 -- sector + extra precision bits for x/z position
  209.     unsigned char                           sHighestFlag;                                   // 16 -- (enum 3 bits/enum 2 bits) Flag colour and reason
  210.     unsigned char                           sPitModeSchedule;                               // 17 -- (enum 3 bits/enum 2 bits) Pit mode and Pit schedule
  211.     unsigned short                          sCarIndex;                                      // 18 -- top bit shows if participant is (local or remote) human player or not
  212.     unsigned char                           sRaceState;                                     // 20 -- race state flags + invalidated lap indication --
  213.     unsigned char                           sCurrentLap;                                    // 21 --
  214.     float                                   sCurrentTime;                                   // 22 --
  215.     float                                   sCurrentSectorTime;                             // 26 --
  216.     unsigned short                          sMPParticipantIndex;                            // 30 --  matching sIndex from sParticipantsData
  217.    
  218. };                                                                                          // 32
  219.  
  220. struct sTimingsData
  221. {
  222.     static const unsigned int                       sPacketSize = 1063;
  223.     PacketBase                      sBase;                                                  // 0 12
  224.     signed char                     sNumParticipants;                                       // 12 --
  225.     unsigned int                    sParticipantsChangedTimestamp;                          // 13 --
  226.     float                           sEventTimeRemaining;                                    // 17  // time remaining, -1 for invalid time,  -1 - laps remaining in lap based races  --
  227.     float                           sSplitTimeAhead;                                        // 21 --
  228.     float                           sSplitTimeBehind;                                       // 25 --
  229.     float                           sSplitTime;                                             // 29 --
  230.     sParticipantInfo                sPartcipants[UDP_STREAMER_PARTICIPANTS_SUPPORTED];      // 33 1024
  231.     unsigned short                  sLocalParticipantIndex;                                 // 1057 -- identifies which of the MP participants is the local player
  232.     unsigned int                    sTickCount;                                             // 1059
  233.     };                                                                                      // 1063
  234. #pragma pack(pop)  
  235.  
  236. /*******************************************************************************************************************
  237. //
  238. //  Game State.
  239. //
  240. //  Frequency: Each 5s while being in Main Menu, Each 10s while being in race + on each change Main Menu<->Race several times.
  241. //  the frequency in Race is increased in case of weather timer being faster  up to each 5s for 30x time progression
  242. //  When it is sent: Always
  243. //
  244. *******************************************************************************************************************/
  245. #define UDP_STREAMER_GAME_STATE_HANDLER_VERSION 2
  246. struct sGameStateData
  247. {
  248.     static const unsigned int                               sPacketSize = 24;
  249.     PacketBase                                              sBase;                      //10
  250.     unsigned short                                          mBuildVersionNumber;        //12
  251.     char                                                    mGameState;                 //15 -- first 3 bits are used for game state enum, second 3 bits for session state enum See shared memory example file for the enums
  252.     signed char                                             sAmbientTemperature;        //16
  253.     signed char                                             sTrackTemperature;          //17
  254.     unsigned char                                           sRainDensity;               //18
  255.     unsigned char                                           sSnowDensity;               //19 --  this will be non zero only in Snow season, in other seasons whatever is falling from the sky is reported as rain
  256.     signed char                                             sWindSpeed;                 //20
  257.     signed char                                             sWindDirectionX;            //21
  258.     signed char                                             sWindDirectionY;            //22 padded to 24
  259. }; 
  260.  
  261.  
  262. /*******************************************************************************************************************
  263. //
  264. //  Participant Stats and records
  265. //
  266. //  Frequency: When entering the race and each time any of the values change, so basically each time any of the participants
  267. //                      crosses a sector boundary.
  268. //  When it is sent: In Race
  269. //
  270. *******************************************************************************************************************/
  271. #define UDP_STREAMER_TIME_STATS_HANDLER_VERSION                     2
  272. struct sParticipantStatsInfo
  273. {
  274.     float                           sFastestLapTime;                                // 0
  275.     float                           sLastLapTime;                                   // 4
  276.     float                           sLastSectorTime;                                // 8
  277.     float                           sFastestSector1Time;                            // 11
  278.     float                           sFastestSector2Time;                            // 16
  279.     float                           sFastestSector3Time;                            // 20
  280.     unsigned int                    sParticipantOnlineRep;                          // 24 (unsigned short rank type + unsigned short strength, 0 in SP races)
  281.     unsigned short                  sMPParticipantIndex;                            // 28 -- matching sIndex from sParticipantsData
  282. };                                                                                  // 32 -- padded to  32
  283.  
  284.  
  285. struct sParticipantsStats
  286. {
  287.     sParticipantStatsInfo   sParticipants[UDP_STREAMER_PARTICIPANTS_SUPPORTED]; //1024
  288. };
  289.  
  290. struct sTimeStatsData
  291. {
  292.     static const unsigned int       sPacketSize = 1024;
  293.     PacketBase                      sBase;                                          // 0 12
  294.     unsigned int                    sParticipantsChangedTimestamp;                  // 12
  295.     sParticipantsStats              sStats;                                         // 16 + 1024
  296. };                                                                                  // 1040
  297.  
  298. /*******************************************************************************************************************
  299. //
  300. //  Participant Vehicle names
  301. //
  302. //  Frequency: Logarithmic decrease
  303. //  When it is sent: Counter resets on entering InRace state and again each  the participants change.
  304. //  The sParticipantsChangedTimestamp represent last time the participants has changed and is  to be used to sync
  305. //  this information with the rest of the participant related packets
  306. //
  307. //  Note: This data is always sent with at least 2 packets. The 1-(n-1) holds the vehicle name for each participant
  308. //  The last one holding the class names.
  309. //
  310. *******************************************************************************************************************/
  311. #define UDP_STREAMER_PARTICIPANT_VEHICLE_NAMES_HANDLER_VERSION  2
  312. #define VEHICLE_NAME_LENGTH_MAX                                         64
  313. #define CLASS_NAME_LENGTH_MAX                                           20
  314. #define VEHICLES_PER_PACKET                                             16
  315. #define CLASSES_SUPPORTED_PER_PACKET                                    60
  316.  
  317. struct sVehicleInfo
  318. {
  319.     unsigned short              sIndex; // 0 2
  320.     unsigned int                sClass; // 2 6
  321.     char                        sName[VEHICLE_NAME_LENGTH_MAX]; // 6 70
  322. }; // padded to 72
  323.  
  324.        
  325. struct sParticipantVehicleNamesData
  326. {
  327.     static const unsigned int   sPacketSize = 1164;
  328.     PacketBase                  sBase; // 0 12
  329.     sVehicleInfo                sVehicles[VEHICLES_PER_PACKET]; //12 16*72
  330. };  // 1164
  331.  
  332. struct sClassInfo
  333. {
  334.     unsigned int                sClassIndex; // 0 4
  335.     char                        sName[CLASS_NAME_LENGTH_MAX]; // 4 24
  336. };
  337.  
  338. struct sVehicleClassNamesData
  339. {
  340.     static const unsigned int   sPacketSize = 1452;
  341.     PacketBase                  sBase; // 0 12
  342.     sClassInfo                  sClasses[CLASSES_SUPPORTED_PER_PACKET]; //12 24*60
  343. };                          // 1452
  344.                                        
  345. #endif //_SMS_UDP_DEFINITIONS_HPP_
  346.  
Advertisement
Add Comment
Please, Sign In to add comment