public static bool Decrypt(string path) { byte[] src = File.ReadAllBytes(path); if (Encoding.ASCII.GetString(src, 0, 6) == "GT6TED") { return(false); } else if (src.AsSpan(0, 4).SequenceEqual(new byte[] { 0xC5, 0xEE, 0xF7, 0xFF })) { src = MiscUtils.Deflate(src); File.WriteAllBytes(path, MiscUtils.Deflate(src)); return(true); } else { int j = 1; for (int i = 0; i < src.Length; i++) { src[i] ^= k[j++ - 1]; if (j > k.Length) { j = 1; } } if (src.AsSpan(0, 4).SequenceEqual(new byte[] { 0xC5, 0xEE, 0xF7, 0xFF })) { src = MiscUtils.Deflate(src); } File.WriteAllBytes(path, src); return(true); } }
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); } }