Beispiel #1
0
        private void Button_SelectCustomTrack_Clicked(object sender, RoutedEventArgs e)
        {
            var open = new OpenFileDialog();

            open.ShowDialog();

            if (!string.IsNullOrEmpty(open.FileName))
            {
                var ext = Path.GetExtension(open.FileName);

                CustomCourse customCourse;
                if (ext.Equals(".b64"))
                {
                    customCourse = CustomCourse.FromBase64File(open.FileName);
                }
                else if (ext.Equals(".ted"))
                {
                    customCourse = CustomCourse.FromTED(open.FileName);
                }
                else
                {
                    return;
                }


                CurrentEvent.Course.CustomCourse = customCourse;
                PrePopulateCourses();
            }
        }
Beispiel #2
0
        private static CustomCourse Read(byte[] bytes)
        {
            var course = new CustomCourse();

            if (BinaryPrimitives.ReadUInt32LittleEndian(bytes) == 0xFFF7EEC5)
            {
                bytes = MiscUtils.Deflate(bytes);
            }

            course.Data = bytes;
            using (var bs = new BinaryStream(new MemoryStream(bytes), ByteConverter.Big))
            {
                var magic = bs.ReadString(6);
                if (magic != "GT6TED")
                {
                    throw new FileFormatException($"Not a valid Custom Track File. (Magic needed is GT6TED, got {magic})");
                }
                bs.Position += 2;

                bs.Position += 4;

                course.Scenery    = (SceneryType)bs.ReadInt32();
                course.RoadWidth  = bs.ReadSingle();
                bs.Position      += 8;
                course.StartPoint = bs.ReadSingle();

                var time = new PDIDATETIME32();
                time.SetRawData(bs.ReadUInt32());
                course.Time      = time.GetDateTime();
                course.IsCircuit = bs.ReadBoolean(BooleanCoding.Dword);
                bs.Position     += 8;

                course.HomeStraightLength  = bs.ReadSingle();
                course.ElevationDifference = bs.ReadSingle();
                course.CornerCount         = bs.ReadInt32();
                course.FinishLine          = bs.ReadSingle();
                course.StartLine           = bs.ReadSingle();

                return(course);
            }
        }