public void MontrealBestLine() { var trackData = TrackFactsHelper.GetTrackMontreal(); using (var reader = new BinaryReader(MemoryStreamProvider.Open(trackData.Path))) { var bestLines = ComputerCarLineReader.Read(reader, trackData.KnownBestLineSectionDataStart); bestLines.Header.LineStartX.Should().Be(4); bestLines.Header.LineStartXHigh.Should().Be(208); bestLines.Header.LineStartY.Should().Be(0); //bestLines.Header.LineStartYHigh.Should().Be(0); bestLines.Header.Unknown1.Should().Be(65354); bestLines.Header.Unknown2.Should().Be(0); bestLines.Header.Unknown3.Should().Be(0); bestLines.Header.Unknown4.Should().Be(0); var firstSegment = bestLines.Segments[0]; firstSegment.Length.Should().Be(26); firstSegment.Command.Should().Be(0x50); firstSegment.SignScale.Should().Be(1); firstSegment.Radius.Should().Be(65092); var segment2 = bestLines.Segments[1]; segment2.Length.Should().Be(37); segment2.Radius.Should().Be(0); var segment3 = bestLines.Segments[2]; segment3.Correction.Should().Be(185); var segment6 = bestLines.Segments[5]; segment6.Length.Should().Be(17); segment6.Command.Should().Be(0x70); segment6.Radius.Should().Be(8280); segment6.Sign0x70.Should().Be(0); segment6.Radius0x70.Should().Be(9650); var lastSegment = bestLines.Segments.Last(); lastSegment.Length.Should().Be(48); lastSegment.Command.Should().Be(0x50); lastSegment.Radius.Should().Be(48032); } }
/// <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); } }