I am currently stuck with my project. I currently recieve UDP packets from a game. These packets contain byte arrays. These byte arrays need to be converted to a struct.
I've tackled a previous problem in this question: F1 2019 UDP decoding
I have got some part of this to work. I use this code to convert the byte array in to a struct:
PacketHeader ByteArrayToPacketHeader(byte[] bytes)
{
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
PacketHeader stuff;
try
{
stuff = (PacketHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PacketHeader));
}
finally
{
handle.Free();
}
return stuff;
}
My Packet Header (Struct) Looks like this:
public struct PacketHeader
{
public ushort m_packetFormat; // 2019
public byte m_gameMajorVersion; // Game major version - "X.00"
public byte m_gameMinorVersion; // Game minor version - "1.XX"
public byte m_packetVersion; // Version of this packet type, all start from 1
public byte m_packetId; // Identifier for the packet type, see below
public ulong m_sessionUID; // Unique identifier for the session
public float m_sessionTime; // Session timestamp
public uint m_frameIdentifier; // Identifier for the frame the data was retrieved on
public byte m_playerCarIndex; // Index of player's car in the array
};
Through this code I get the correct information. So this works!
The game sends multiple "Packets" (Structs) through the same byte array.
But when I use the same code to convert the byte array to the new structlayout I don't get the right information out of the array. Example:
PacketCarTelemetryData ByteArrayToPacketCarTelemetryData(byte[] bytes)
{
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
PacketCarTelemetryData stuff;
try
{
stuff = (PacketCarTelemetryData)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(PacketCarTelemetryData));
}
finally
{
handle.Free();
}
return stuff;
This code uses this structlayout:
public struct PacketCarTelemetryData
{
public PacketHeader m_header; // Header
public CarTelemetryData m_carTelemetryData;
public uint m_buttonStatus; // Bit flags specifying which buttons are being pressed
// currently - see appendices
};
In the struct above there are other structs stored:
public struct CarTelemetryData
{
public ushort m_speed; // Speed of car in kilometres per hour
public float m_throttle; // Amount of throttle applied (0.0 to 1.0)
public float m_steer; // Steering (-1.0 (full lock left) to 1.0 (full lock right))
public float m_brake; // Amount of brake applied (0.0 to 1.0)
public byte m_clutch; // Amount of clutch applied (0 to 100)
public sbyte m_gear; // Gear selected (1-8, N=0, R=-1)
public ushort m_engineRPM; // Engine RPM
public byte m_drs; // 0 = off, 1 = on
public byte m_revLightsPercent; // Rev lights indicator (percentage)
public ushort m_brakesTemperature; // Brakes temperature (celsius)
public ushort m_tyresSurfaceTemperature; // Tyres surface temperature (celsius)
public ushort m_tyresInnerTemperature; // Tyres inner temperature (celsius)
public ushort m_engineTemperature; // Engine temperature (celsius)
public float tyresPressure; // Tyres pressure (PSI)
public byte m_surfaceType; // Driving surface, see appendice
};
So my problem now is that when I use this code to convert the byte array to this specific struct I don't get the information I want.
P.s. There are no 36 gears in the car and my brakes are not 21760 degree celcius...
Does anyone have a suggestion?
With kind regards,
Edit:
For more information, this is the hex code I get when I want to read the packet CarTelemetryData:
E3-07-01-15-01-06-F8-CE-BE-09-64-7F-EA-D1-DC-A1-16-41-91-01-00-00-13-7B-00-00-00-80-3F-36-53-7E-3C-00-00-00-00-00-02-F3-2F-00-64-1D-00-1D-00-1D-00-1D-00-74-00-74-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-74-00-00-00-80-3F-1B-F2-3A-3C-00-00-00-00-00-02-35-2D-00-22-1D-00-1D-00-1D-00-1D-00-69-00-69-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7B-00-00-00-80-3F-F3-59-A1-BA-00-00-00-00-00-02-59-2F-00-64-1D-00-1D-00-1D-00-1D-00-72-00-72-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-77-00-00-00-80-3F-FE-5F-3F-3C-00-00-00-00-00-02-3D-2E-00-3E-1D-00-1D-00-1D-00-1D-00-71-00-71-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-81-00-00-00-80-3F-89-78-23-3C-00-00-00-00-00-03-E0-28-00-00-1D-00-1D-00-1D-00-1D-00-77-00-78-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-77-00-00-00-80-3F-C3-73-98-3C-00-00-00-00-00-02-2F-2E-00-54-1D-00-1D-00-1D-00-1D-00-75-00-75-00-50-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-76-00-00-00-80-3F-F3-F4-BA-BA-00-00-00-00-00-02-21-2E-00-59-1D-00-1D-00-1D-00-1D-00-75-00-75-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7C-00-00-00-80-3F-4D-7D-04-3B-00-00-00-00-00-02-FB-2F-00-64-1D-00-1D-00-1D-00-1D-00-70-00-70-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-75-00-00-00-80-3F-84-45-AB-3C-00-00-00-00-00-02-BF-2D-00-31-1D-00-1D-00-1D-00-1D-00-77-00-77-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-80-00-00-00-80-3F-B5-8C-BD-3B-00-00-00-00-00-03-1B-28-00-00-1D-00-1D-00-1D-00-1D-00-71-00-71-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-72-00-00-00-80-3F-F8-D0-87-3A-00-00-00-00-00-02-63-2C-00-37-1D-00-1D-00-1D-00-1D-00-79-00-79-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7B-00-00-00-80-3F-FF-A7-60-3A-00-00-00-00-00-02-DE-2F-00-64-1D-00-1D-00-1D-00-1D-00-6E-00-6E-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7A-00-00-00-80-3F-B9-2E-2F-3C-00-00-00-00-00-02-D1-2F-00-64-1D-00-1D-00-1D-00-1D-00-75-00-75-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-74-00-00-00-80-3F-CD-1E-18-3A-00-00-00-00-00-02-3F-2D-00-23-1D-00-1D-00-1D-00-1D-00-6F-00-6F-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-73-00-00-00-80-3F-15-0F-AF-3B-00-00-00-00-00-02-A5-2B-00-0C-1D-00-1D-00-1D-00-1D-00-70-00-70-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7A-00-00-00-80-3F-2B-C0-14-3C-00-00-00-00-00-02-49-2F-00-64-1D-00-1D-00-1D-00-1D-00-6F-00-6F-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-7F-00-00-00-80-3F-41-CA-C0-3C-00-00-00-00-00-03-85-2B-00-64-1D-00-1D-00-1D-00-1D-00-79-00-79-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-72-00-00-00-80-3F-07-1F-D5-3C-00-00-00-00-00-02-DE-2A-00-00-1D-00-1D-00-1D-00-1D-00-78-00-78-00-4F-00-4F-00-5B-00-5B-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-71-00-00-00-80-3F-DD-C0-1C-3C-00-00-00-00-00-02-DD-2A-00-00-1D-00-1D-00-1D-00-1D-00-6F-00-6F-00-4F-00-4F-00-5A-00-5A-00-58-00-58-00-5A-00-00-00-AC-41-00-00-AC-41-00-00-B8-41-00-00-B8-41-00-00-00-00-31-00-97-96-96-3E-00-00-00-00-00-00-00-00-00-01-9B-17-00-00-1D-00-1D-00-1D-00-1D-00-62-00-62-00-4F-00-4F-00-59-00-59-00-58-00-58-00-5A-00-CD-CC-A8-41-CD-CC-A8-41-33-33-BB-41-33-33-BB-41-00-00-00-00-00-00-00-00
I know that with this information the following numbers don't match with what is happening in the game:
The current gear should be: 1. That is one fact I know.
The reflight percentage should be under 100%
The temps should be a lot lower,
The RPM is way to high (Probbably around 10000 is normal).
I hope this is information will suffice.