Example #1
0
        public PC2BasePacket CreateVersion8(PC2RawPacket rawPacket)
        {
            var meta = PC2PacketMeta.Create(rawPacket);

            switch (meta.packetType)
            {
            case PC2PacketType.Telemetry:
                return(PCars2TelemetryData.Create(rawPacket, meta));

            case PC2PacketType.Timings:
                return(PCars2Timings.Create(rawPacket, meta));

            case PC2PacketType.TimeStats:
                return(PCars2TimeStatsData.Create(rawPacket, meta));

            case PC2PacketType.GameState:
                return(PC2GameStatePacket.Create(rawPacket, meta));

            case PC2PacketType.RaceDefinition:
                return(PC2RaceDefinition.Create(rawPacket, meta));

            case PC2PacketType.Participants:
            case PC2PacketType.WeatherState:
            case PC2PacketType.VehicleNames:
            case PC2PacketType.ParticipantVehicleNames:
            default:
                throw new NotImplementedException("Project Cars 2 packet type not handled: " + meta.packetType);
            }
        }
Example #2
0
        public static PCars2Timings Create(PC2RawPacket rawPacket, PC2PacketMeta meta)
        {
            var timings = new PCars2Timings(meta);

            timings.numberParticipants           = rawPacket.Data.ReadSByte();
            timings.participantsChangedTimestamp = rawPacket.Data.ReadUInt32();
            timings.eventTimeRemaining           = rawPacket.Data.ReadSingle();
            timings.splitTimeAhead  = rawPacket.Data.ReadSingle();
            timings.splitTimeBehind = rawPacket.Data.ReadSingle();
            timings.splitTime       = rawPacket.Data.ReadSingle();
            timings.participants    = Enumerable.Range(0, PCars2Timings.MAX_PARTICIPANTS).Select(i => {
                var participant = new PCars2ParticipantTiming();
                participant.participantIndex   = i;
                participant.worldPositionX     = rawPacket.Data.ReadInt16();
                participant.worldPositionY     = rawPacket.Data.ReadInt16();
                participant.worldPositionZ     = rawPacket.Data.ReadInt16();
                participant.orientationX       = rawPacket.Data.ReadInt16();
                participant.orientationY       = rawPacket.Data.ReadInt16();
                participant.orientationZ       = rawPacket.Data.ReadInt16();
                participant.currentLapDistance = rawPacket.Data.ReadUInt16();
                var fullRacePosition           = rawPacket.Data.ReadByte();
                participant.active             = fullRacePosition >= 128;
                participant.racePosition       = fullRacePosition >= 128 ? (byte)(fullRacePosition - 128) : fullRacePosition;
                byte Sector_ALL               = rawPacket.Data.ReadByte();
                var Sector_Extracted          = Sector_ALL & 0x0F;
                participant.sector            = Sector_Extracted + 1;
                participant.highestFlag       = rawPacket.Data.ReadByte();
                participant.pitModeSchedule   = rawPacket.Data.ReadByte();
                participant.carIndex          = rawPacket.Data.ReadUInt16();
                participant.raceState         = (PC2RaceState)rawPacket.Data.ReadByte();
                participant.currentLap        = rawPacket.Data.ReadByte();
                participant.currentTime       = rawPacket.Data.ReadSingle();
                participant.currentSectorTime = rawPacket.Data.ReadSingle();
                return(participant);
            });
            return(timings);
        }