private static IPacket Session(PacketHeader packetHeader, BinaryReader reader) { var packetSessionData = new PacketSessionData(packetHeader); packetSessionData.Weather = (WeatherType)reader.ReadByte(); packetSessionData.TrackTemperature = reader.ReadSByte(); packetSessionData.AirTemperature = reader.ReadSByte(); packetSessionData.TotalLaps = reader.ReadByte(); packetSessionData.TrackLength = reader.ReadUInt16(); packetSessionData.SessionType = (SessionType)reader.ReadByte(); packetSessionData.TrackId = reader.ReadSByte(); packetSessionData.Formula = reader.ReadByte(); packetSessionData.SessionTimeLeft = reader.ReadUInt16(); packetSessionData.SessionDuration = reader.ReadUInt16(); packetSessionData.PitSpeedLimit = reader.ReadByte(); packetSessionData.GamePaused = reader.ReadByte(); packetSessionData.IsSpectating = reader.ReadByte(); packetSessionData.SpectatorCarIndex = reader.ReadByte(); packetSessionData.SliProNativeSupport = reader.ReadByte(); packetSessionData.NumMarshalZones = reader.ReadByte(); for (int j = 0; j < MaxNumberOfMarshalZones; j++) { var marshalZone = new MarshalZone(); marshalZone.ZoneStart = reader.ReadSingle(); marshalZone.ZoneFlag = (ZoneFlag)reader.ReadSByte(); packetSessionData.MarshalZones[j] = marshalZone; } packetSessionData.SafetyCarStatus = reader.ReadByte(); packetSessionData.NetworkGame = reader.ReadByte(); packetSessionData.NumWeatherForecastSamples = reader.ReadByte(); for (int j = 0; j < MaxNumberOfWeatherSamples; j++) { var newWeatherForecastSample = new WeatherForecastSample(); newWeatherForecastSample.SessionType = (SessionType)reader.ReadByte(); newWeatherForecastSample.TimeOffset = reader.ReadByte(); newWeatherForecastSample.Weather = (WeatherType)reader.ReadByte(); newWeatherForecastSample.TrackTemperature = reader.ReadSByte(); newWeatherForecastSample.AirTemperature = reader.ReadSByte(); packetSessionData.WeatherForecastSamples[j] = newWeatherForecastSample; } return(packetSessionData); }
public override void LoadBytes(byte[] bytes) { ByteArrayManager BAM = new ByteArrayManager(bytes); //Load header base.LoadBytes(BAM.NextBytes(24)); //Get weather byte nb = BAM.NextByte(); if (nb == 0) { CurrentWeatherCondition = WeatherCondition.Clear; } else if (nb == 1) { CurrentWeatherCondition = WeatherCondition.LightClouds; } else if (nb == 2) { CurrentWeatherCondition = WeatherCondition.Overcast; } else if (nb == 3) { CurrentWeatherCondition = WeatherCondition.LightRain; } else if (nb == 4) { CurrentWeatherCondition = WeatherCondition.HeavyRain; } else if (nb == 5) { CurrentWeatherCondition = WeatherCondition.Storm; } //Get track temperature TrackTemperatureCelsius = BAM.NextByte(); //Get air temperature AirTemperatureCelsius = BAM.NextByte(); //Get total laps TotalLapsInRace = BAM.NextByte(); //get track length TrackLengthMeters = BitConverter.ToUInt16(BAM.NextBytes(2), 0); //Get session type nb = BAM.NextByte(); if (nb == 0) { SessionTypeMode = SessionType.Unknown; } else if (nb == 1) { SessionTypeMode = SessionType.Practice1; } else if (nb == 2) { SessionTypeMode = SessionType.Practice2; } else if (nb == 3) { SessionTypeMode = SessionType.Practice3; } else if (nb == 4) { SessionTypeMode = SessionType.ShortPractice; } else if (nb == 5) { SessionTypeMode = SessionType.Qualifying1; } else if (nb == 6) { SessionTypeMode = SessionType.Qualifying2; } else if (nb == 7) { SessionTypeMode = SessionType.Qualifying3; } else if (nb == 8) { SessionTypeMode = SessionType.ShortPractice; } else if (nb == 9) { SessionTypeMode = SessionType.OneShotQualifying; } else if (nb == 10) { SessionTypeMode = SessionType.Race; } else if (nb == 11) { SessionTypeMode = SessionType.Race2; } else if (nb == 12) { SessionTypeMode = SessionType.TimeTrial; } //Get track SessionTrack = CodemastersToolkit.GetTrackFromTrackId(BAM.NextByte()); //Get formula nb = BAM.NextByte(); if (nb == 0) { Formula = FormulaType.Formula1Modern; } else if (nb == 1) { Formula = FormulaType.Formula1Classic; } else if (nb == 2) { Formula = FormulaType.Formula2; } else if (nb == 3) { Formula = FormulaType.Formula1Generic; } //Get session time left SessionTimeLeft = BitConverter.ToUInt16(BAM.NextBytes(2), 0); //Get session duration SessionDuration = BitConverter.ToUInt16(BAM.NextBytes(2), 0); //Get pit speed limit PitSpeedLimitKph = BAM.NextByte(); //get game paused nb = BAM.NextByte(); if (nb == 0) { GamePaused = false; } else if (nb == 1) { GamePaused = true; } //Get is spectating nb = BAM.NextByte(); if (nb == 0) { IsSpectating = false; } else if (nb == 1) { IsSpectating = true; } //Get spectating car index CarIndexBeingSpectated = BAM.NextByte(); //Get sli pro native support nb = BAM.NextByte(); if (nb == 0) { SliProNativeSupport = false; } else if (nb == 1) { SliProNativeSupport = true; } //Get number of marshall zones NumberOfMarshallZones = BAM.NextByte(); //Get marshall zones List <MarshallZone> MZs = new List <MarshallZone>(); int t = 1; for (t = 1; t <= 21; t++) { MZs.Add(MarshallZone.Create(BAM.NextBytes(5))); } //Get safety car status nb = BAM.NextByte(); if (nb == 0) { CurrentSafetyCarStatus = SafetyCarStatus.None; } else if (nb == 1) { CurrentSafetyCarStatus = SafetyCarStatus.Full; } else if (nb == 2) { CurrentSafetyCarStatus = SafetyCarStatus.Virtual; } //Get network game boolean nb = BAM.NextByte(); if (nb == 0) { IsNetworkGame = false; } else if (nb == 1) { IsNetworkGame = true; } //Get number of weather forecast samples NumberOfWeatherForecastSamples = BAM.NextByte(); //Get the next 20 weather forecast samples List <WeatherForecastSample> wfss = new List <WeatherForecastSample>(); t = 0; for (t = 0; t < 20; t++) { wfss.Add(WeatherForecastSample.Create(BAM.NextBytes(5))); } WeatherForecastSamples = wfss.ToArray(); }
public static WeatherForecastSample Create(byte[] bytes) { WeatherForecastSample ToReturn = new WeatherForecastSample(); ByteArrayManager BAM = new ByteArrayManager(bytes); //Get session type byte nb = BAM.NextByte(); if (nb == 0) { ToReturn.SessionTypeMode = SessionType.Unknown; } else if (nb == 1) { ToReturn.SessionTypeMode = SessionType.Practice1; } else if (nb == 2) { ToReturn.SessionTypeMode = SessionType.Practice2; } else if (nb == 3) { ToReturn.SessionTypeMode = SessionType.Practice3; } else if (nb == 4) { ToReturn.SessionTypeMode = SessionType.ShortPractice; } else if (nb == 5) { ToReturn.SessionTypeMode = SessionType.Qualifying1; } else if (nb == 6) { ToReturn.SessionTypeMode = SessionType.Qualifying2; } else if (nb == 7) { ToReturn.SessionTypeMode = SessionType.Qualifying3; } else if (nb == 8) { ToReturn.SessionTypeMode = SessionType.ShortPractice; } else if (nb == 9) { ToReturn.SessionTypeMode = SessionType.OneShotQualifying; } else if (nb == 10) { ToReturn.SessionTypeMode = SessionType.Race; } else if (nb == 11) { ToReturn.SessionTypeMode = SessionType.Race2; } else if (nb == 12) { ToReturn.SessionTypeMode = SessionType.TimeTrial; } //Get time offset ToReturn.TimeOffSet = BAM.NextByte(); //Get weather nb = BAM.NextByte(); if (nb == 0) { ToReturn.ForecastedWeatherCondition = WeatherCondition.Clear; } else if (nb == 1) { ToReturn.ForecastedWeatherCondition = WeatherCondition.LightClouds; } else if (nb == 2) { ToReturn.ForecastedWeatherCondition = WeatherCondition.Overcast; } else if (nb == 3) { ToReturn.ForecastedWeatherCondition = WeatherCondition.LightRain; } else if (nb == 4) { ToReturn.ForecastedWeatherCondition = WeatherCondition.HeavyRain; } else if (nb == 5) { ToReturn.ForecastedWeatherCondition = WeatherCondition.Storm; } //Get track temperature ToReturn.TrackTemperatureCelsius = BAM.NextByte(); //Get air temperature ToReturn.AirTemperatureCelsius = BAM.NextByte(); return(ToReturn); }