public RealTimeUpdateResponse(BinaryReader reader) { EventIndex = reader.ReadUInt16(); SessionIndex = reader.ReadUInt16(); SessionType = (SessionType)reader.ReadByte(); Phase = (SessionPhase)reader.ReadByte(); var sessionTime = reader.ReadSingle(); SessionTime = TimeSpan.FromMilliseconds(sessionTime); var sessionEndTime = reader.ReadSingle(); SessionEndTime = TimeSpan.FromMilliseconds(sessionEndTime); FocusedCarIndex = reader.ReadInt32(); ActiveCameraSet = ReadString(reader); ActiveCamera = ReadString(reader); CurrentHudPage = ReadString(reader); IsReplayPlaying = reader.ReadByte() > 0; if (IsReplayPlaying) { ReplaySessionTime = reader.ReadSingle(); ReplayRemainingTime = reader.ReadSingle(); } TimeOfDay = TimeSpan.FromMilliseconds(reader.ReadSingle()); AmbientTemp = reader.ReadByte(); TrackTemp = reader.ReadByte(); Clouds = reader.ReadByte() / 10.0f; RainLevel = reader.ReadByte() / 10.0f; Wetness = reader.ReadByte() / 10.0f; BestSessionLap = LapInfo.FromReader(reader); }
public static LapInfo FromReader(BinaryReader reader) { var lap = new LapInfo(); lap.LapTimeMilliseconds = reader.ReadInt32(); lap.CarIndex = reader.ReadUInt16(); lap.DriverIndex = reader.ReadUInt16(); var splitCount = reader.ReadByte(); for (var i = 0; i < splitCount; i++) { lap.Splits.Add(reader.ReadInt32()); } lap.IsInvalid = reader.ReadByte() > 0; lap.IsValidForBest = reader.ReadByte() > 0; var isOutlap = reader.ReadByte() > 0; var isInlap = reader.ReadByte() > 0; if (isOutlap) { lap.Type = LapType.Outlap; } else if (isInlap) { lap.Type = LapType.Inlap; } else { lap.Type = LapType.Regular; } // Now it's possible that this is "no" lap that doesn't even include a // first split, we can detect this by comparing with int32.Max while (lap.Splits.Count < 3) { lap.Splits.Add(null); } // "null" entries are Int32.Max, in the C# world we can replace this to null for (var i = 0; i < lap.Splits.Count; i++) { if (lap.Splits[i] == int.MaxValue) { lap.Splits[i] = null; } } if (lap.LapTimeMilliseconds == int.MaxValue) { lap.LapTimeMilliseconds = null; } return(lap); }
public RealTimeCarUpdateResponse(BinaryReader reader) { CarIndex = reader.ReadUInt16(); DriverIndex = reader.ReadUInt16(); // Driver swap will make this change DriverCount = reader.ReadByte(); Gear = reader.ReadByte() - 2; // -2 makes the R -1, N 0 and the rest as-is WorldPosX = reader.ReadSingle(); WorldPosY = reader.ReadSingle(); Yaw = reader.ReadSingle(); CarLocation = (CarLocation)reader.ReadByte(); // - , Track, Pitlane, PitEntry, PitExit = 4 Kmh = reader.ReadUInt16(); Position = reader.ReadUInt16(); // official P/Q/R position (1 based) CupPosition = reader.ReadUInt16(); // official P/Q/R position (1 based) TrackPosition = reader.ReadUInt16(); // position on track (1 based) SplinePosition = reader.ReadSingle(); // track position between 0.0 and 1.0 Laps = reader.ReadUInt16(); Delta = reader.ReadInt32(); // Realtime delta to best session lap BestSessionLap = LapInfo.FromReader(reader); LastLap = LapInfo.FromReader(reader); CurrentLap = LapInfo.FromReader(reader); }