示例#1
0
        /// <summary>
        /// Reads the STF file.
        /// </summary>
        /// <returns>The statistics.</returns>
        /// <param name="path">Path.</param>
        public TrackRecordsEntity Read(string path)
        {
            TrackRecordsEntity trackRecordEntity = new TrackRecordsEntity();

            using (NfsFileReader reader = new NfsFileReader(path, FileMode.Open))
            {
                reader.ReaderEndianness = Endianness.BigEndian;

                trackRecordEntity.LapRecords = new LapRecordEntity[31];

                for (int i = 0; i < 31; i++)
                {
                    LapRecordEntity record = new LapRecordEntity();

                    record.PlayerName = reader.ReadString(9);
                    record.CarId      = (short)(reader.ReadInt16() & 0x00FF);
                    record.Time       = reader.ReadInt32(Endianness.LittleEndian);
                    record.RaceType   = reader.ReadInt16();
                    reader.ReadBytes(3);

                    // Clean the name
                    int endIndex = record.PlayerName.IndexOf('\0');
                    if (endIndex > 0)
                    {
                        record.PlayerName = record.PlayerName.Substring(0, endIndex);
                    }
                    record.PlayerName = record.PlayerName.Replace("\t", "");

                    trackRecordEntity.LapRecords[i] = record;
                }
            }

            return(trackRecordEntity);
        }
示例#2
0
        /// <summary>
        /// Reads the localisation file.
        /// </summary>
        /// <returns>The localisation data.</returns>
        /// <param name="path">Path.</param>
        public LocalisationEntity Read(string path)
        {
            LocalisationEntity locale = new LocalisationEntity();

            using (NfsFileReader reader = new NfsFileReader(path, FileMode.Open))
            {
                locale.Entries  = new List <LocalisationEntryEntity>();
                locale.Unknown1 = reader.ReadBytes(8);

                firstValueOffset = int.MaxValue;

                while (reader.BaseStream.Position < firstValueOffset - 12)
                {
                    LocalisationEntryEntity entry = new LocalisationEntryEntity();
                    entry.Offset       = reader.ReadInt32();
                    entry.UnknownBytes = reader.ReadBytes(8);

                    locale.Entries.Add(entry);

                    if (entry.Offset < firstValueOffset)
                    {
                        firstValueOffset = entry.Offset;
                    }
                }

                locale.Unknown2 = reader.ReadBytes((int)(firstValueOffset - reader.BaseStream.Position));

                for (int i = 0; i < locale.Entries.Count; i++)
                {
                    if (i < locale.Entries.Count - 1)
                    {
                        int length = locale.Entries[i + 1].Offset - locale.Entries[i].Offset - 1;
                        locale.Entries[i].Value = reader.ReadString(length + 1);
                    }
                    else
                    {
                        locale.Entries[i].Value = reader.ReadString();
                    }
                }

                locale.Unknown3 = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position));
            }

            return(locale);
        }