Beispiel #1
0
        public void Read_MontrealTrack_HasExpectedData()
        {
            var trackData = TrackFactsHelper.GetTrackMontreal();

            using (var reader = new BinaryReader(MemoryStreamProvider.Open(trackData.Path)))
            {
                var result = ComputerCarDataReader.Read(reader, trackData.KnownOffsets.ComputerCarSetup);
                var data   = result.ComputerCarData;

                data.GripFactor.Should().Be(16384);
                data.Acceleration.Should().Be(16384);
                data.AirResistance.Should().Be(16384);
                data.FuelLoad.Should().Be(5203);
            }
        }
Beispiel #2
0
        public void Read_MontrealTrack_HasExpectedSetup()
        {
            var trackData = TrackFactsHelper.GetTrackMontreal();

            using (var reader = new BinaryReader(MemoryStreamProvider.Open(trackData.Path)))
            {
                var result = ComputerCarDataReader.Read(reader, trackData.KnownOffsets.ComputerCarSetup);
                var setup  = result.Setup;

                setup.FrontWing.Should().Be(11);
                setup.RearWing.Should().Be(10);
                setup.GearRatio1.Should().Be(28);
                setup.GearRatio2.Should().Be(35);
                setup.GearRatio3.Should().Be(42);
                setup.GearRatio4.Should().Be(49);
                setup.GearRatio5.Should().Be(55);
                setup.GearRatio6.Should().Be(61);
                setup.TyreCompound.Should().Be(SetupTyreCompound.C);
                setup.BrakeBalance.Should().Be(0);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Reads the track file at the specified path and returns a Track object.
        /// </summary>
        /// <param name="path">Path to GP2 track file.</param>
        /// <returns>Track object.</returns>
        public Track Read(string path)
        {
            var track = new Track();

            using (var reader = new BinaryReader(StreamProvider(path)))
            {
                track.Offsets = OffsetReader.Read(reader);

                track.ObjectShapes    = ObjectShapesReader.Read(reader, track.Offsets.ObjectData);
                track.ObjectSettings  = TrackObjectSettingsReader.Read(reader, track.Offsets.ObjectData, track.Offsets.TrackData);
                track.TrackDataHeader = TrackSectionHeaderReader.Read(reader, track.Offsets.TrackData);

                var options = new TrackSectionCommandOptions();
                options.Command0xC5Length = track.TrackDataHeader.CommandLength0xC5;

                var sectionReading = TrackSectionReader.Read(reader, track.Offsets.TrackData + track.TrackDataHeader.GetHeaderLength(), options);
                track.TrackSections = sectionReading.TrackSections;

                var lines = ComputerCarLineReader.Read(reader, sectionReading.Position);
                track.ComputerCarLineHeader   = lines.Header;
                track.ComputerCarLineSegments = lines.Segments;

                var setup = ComputerCarDataReader.Read(reader, track.Offsets.ComputerCarSetup);
                track.ComputerCarSetup = setup.Setup;

                var pitlaneResult = TrackSectionReader.Read(reader, track.Offsets.PitLaneData, options);
                track.PitLaneSections = pitlaneResult.TrackSections;

                reader.BaseStream.Position = pitlaneResult.Position;

                // read until 0xFF 0xFF, i.e. skip camera definitions
                bool previousWas255 = false;

                while (true)
                {
                    byte byte1 = reader.ReadByte();

                    if (byte1 == 0xFF)
                    {
                        if (previousWas255)
                        {
                            break;
                        }

                        previousWas255 = true;
                    }
                    else
                    {
                        previousWas255 = false;
                    }
                }

                var posBefore = reader.BaseStream.Position;

                var behavior = ComputerCarBehaviorReader.Read(reader, (int)reader.BaseStream.Position);
                track.ComputerCarBehavior = behavior;

                reader.BaseStream.Position = posBefore;

                var settings = TrackSettingsReader.Read(reader, (int)reader.BaseStream.Position);
                track.TrackSettings = settings;

                return(track);
            }
        }