Ejemplo n.º 1
0
            public static ParticipantData Create(byte[] bytes)
            {
                ParticipantData  ReturnInstance = new ParticipantData();
                ByteArrayManager BAM            = new ByteArrayManager(bytes);

                //Get AI controlled
                byte nb = BAM.NextByte();

                if (nb == 0)
                {
                    ReturnInstance.IsAiControlled = false;
                }
                else if (nb == 1)
                {
                    ReturnInstance.IsAiControlled = true;
                }


                //Get piloting driver
                ReturnInstance.PilotingDriver = CodemastersToolkit.GetDriverFromDriverId(BAM.NextByte(), Game.F1_2019);

                //Get Team
                ReturnInstance.ManufacturingTeam = CodemastersToolkit.GetTeamFromTeamId(BAM.NextByte(), Game.F1_2019);

                //Get race number
                ReturnInstance.CarRaceNumber = BAM.NextByte();

                //Get nationallity ID
                ReturnInstance.NationalityId = BAM.NextByte();

                //Get name
                string FullName = "";
                int    t        = 1;

                for (t = 1; t <= 48; t++)
                {
                    char ThisChar = Convert.ToChar(BAM.NextByte());
                    FullName = FullName + ThisChar.ToString();
                }
                ReturnInstance.Name = FullName.Trim();

                //Get telemetry private or not.
                nb = BAM.NextByte();
                if (nb == 0)
                {
                    ReturnInstance.TelemetryPrivate = false;
                }
                else if (nb == 1)
                {
                    ReturnInstance.TelemetryPrivate = true;
                }


                return(ReturnInstance);
            }
Ejemplo n.º 2
0
        public static Packet[] BulkConvertByteArraysToPackets(List <byte[]> all_byte_arrays)
        {
            List <Packet> Packets = new List <Packet>();

            foreach (byte[] b in all_byte_arrays)
            {
                PacketType pt = CodemastersToolkit.GetPacketType(b);
                if (pt == PacketType.Motion)
                {
                    MotionPacket mp = new MotionPacket();
                    mp.LoadBytes(b);
                    Packets.Add(mp);
                }
                else if (pt == PacketType.Session)
                {
                    SessionPacket sp = new SessionPacket();
                    sp.LoadBytes(b);
                    Packets.Add(sp);
                }
                else if (pt == PacketType.Lap)
                {
                    LapPacket sp = new LapPacket();
                    sp.LoadBytes(b);
                    Packets.Add(sp);
                }
                else if (pt == PacketType.Participants)
                {
                    ParticipantPacket sp = new ParticipantPacket();
                    sp.LoadBytes(b);
                    Packets.Add(sp);
                }
                else if (pt == PacketType.CarTelemetry)
                {
                    TelemetryPacket sp = new TelemetryPacket();
                    sp.LoadBytes(b);
                    Packets.Add(sp);
                }
            }

            return(Packets.ToArray());
        }
Ejemplo n.º 3
0
            public static CarTelemetryData Create(byte[] bytes)
            {
                CarTelemetryData ReturnInstance = new CarTelemetryData();

                ByteArrayManager BAM = new ByteArrayManager(bytes);

                //Get speed
                ReturnInstance.SpeedKph = BitConverter.ToUInt16(BAM.NextBytes(2), 0);
                double MPH = ReturnInstance.SpeedKph * 0.621371;

                ReturnInstance.SpeedMph = (ushort)MPH;

                //Get throttle
                ReturnInstance.Throttle = BitConverter.ToSingle(BAM.NextBytes(4), 0);

                //Get steer
                ReturnInstance.Steer = BitConverter.ToSingle(BAM.NextBytes(4), 0);

                //Get brake
                ReturnInstance.Brake = BitConverter.ToSingle(BAM.NextBytes(4), 0);

                //Get clutch
                ReturnInstance.Clutch = BAM.NextByte();

                //Get gear
                ReturnInstance.Gear = (sbyte)BAM.NextByte();

                //Get engine RMP
                ReturnInstance.EngineRpm = BitConverter.ToUInt16(BAM.NextBytes(2), 0);

                //Drs on or not
                byte nb = BAM.NextByte();

                if (nb == 0)
                {
                    ReturnInstance.DrsActive = false;
                }
                else if (nb == 1)
                {
                    ReturnInstance.DrsActive = true;
                }

                //Get engine rev lights percentage
                ReturnInstance.RevLightsPercentage = BAM.NextByte();

                //get brake temperature
                ReturnInstance.BrakeTemperature            = new WheelDataArray();
                ReturnInstance.BrakeTemperature.RearLeft   = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);
                ReturnInstance.BrakeTemperature.RearRight  = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);
                ReturnInstance.BrakeTemperature.FrontLeft  = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);
                ReturnInstance.BrakeTemperature.FrontRight = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);

                //get tyre surface temperature
                ReturnInstance.TyreSurfaceTemperature            = new WheelDataArray();
                ReturnInstance.TyreSurfaceTemperature.RearLeft   = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);
                ReturnInstance.TyreSurfaceTemperature.RearRight  = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);
                ReturnInstance.TyreSurfaceTemperature.FrontLeft  = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);
                ReturnInstance.TyreSurfaceTemperature.FrontRight = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);

                //get tyre Inner Temperature
                ReturnInstance.TyreInnerTemperature            = new WheelDataArray();
                ReturnInstance.TyreInnerTemperature.RearLeft   = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);
                ReturnInstance.TyreInnerTemperature.RearRight  = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);
                ReturnInstance.TyreInnerTemperature.FrontLeft  = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);
                ReturnInstance.TyreInnerTemperature.FrontRight = (float)BitConverter.ToUInt16(BAM.NextBytes(2), 0);

                //Get engine temperature
                ReturnInstance.EngineTemperature = BitConverter.ToUInt16(BAM.NextBytes(2), 0);

                //Get tyre pressure
                ReturnInstance.TyrePressure            = new WheelDataArray();
                ReturnInstance.TyrePressure.RearLeft   = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.TyrePressure.RearRight  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.TyrePressure.FrontLeft  = BitConverter.ToSingle(BAM.NextBytes(4), 0);
                ReturnInstance.TyrePressure.FrontRight = BitConverter.ToSingle(BAM.NextBytes(4), 0);

                //Get surface type
                ReturnInstance.SurfaceType_RearLeft   = CodemastersToolkit.GetSurfaceTypeFromSurfaceTypeId(BAM.NextByte(), Game.F1_2019);
                ReturnInstance.SurfaceType_RearRight  = CodemastersToolkit.GetSurfaceTypeFromSurfaceTypeId(BAM.NextByte(), Game.F1_2019);
                ReturnInstance.SurfaceType_FrontLeft  = CodemastersToolkit.GetSurfaceTypeFromSurfaceTypeId(BAM.NextByte(), Game.F1_2019);
                ReturnInstance.SurfaceType_FrontRight = CodemastersToolkit.GetSurfaceTypeFromSurfaceTypeId(BAM.NextByte(), Game.F1_2019);

                return(ReturnInstance);
            }
Ejemplo n.º 4
0
        public override void LoadBytes(byte[] bytes)
        {
            ByteArrayManager BAM = new ByteArrayManager(bytes);

            //Load header
            base.LoadBytes(BAM.NextBytes(23));

            //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;
            }
        }