Exemplo n.º 1
0
        public void Load()
        {
            if (Configuration.Verbose)
            {
                Console.WriteLine($"Extracting TOC.");
            }

            rootDirectory = new FSTDirectory(0, 0, 0);
            var numberOfEntries = ExtractedFile.GetIntAtOffset(TOCNumberEntriesOffset);

            LoadFST(rootDirectory, numberOfEntries);

            if (Configuration.Verbose)
            {
                Console.WriteLine($"Finished reading FST.");
            }
        }
Exemplo n.º 2
0
        void LoadFST(FSTDirectory root, int endEntryIndex, int firstEntryIndex = 1)
        {
            int index = firstEntryIndex;

            while (index < endEntryIndex)
            {
                var entryOffset = index * 12;
                var folder      = ExtractedFile.GetByteAtOffset(entryOffset) == 1;

                FSTEntry fileEntry;
                uint     nameOffset;
                if (folder)
                {
                    nameOffset = (ExtractedFile.GetUIntAtOffset(entryOffset) & 0x00FFFFFF);
                    var parentEntry = ExtractedFile.GetIntAtOffset(entryOffset + 4);
                    var endDirEntry = ExtractedFile.GetIntAtOffset(entryOffset + 8);
                    var directory   = new FSTDirectory(index, nameOffset, parentEntry);

                    LoadFST(directory, endDirEntry, index + 1);
                    fileEntry = directory;
                    index    += endDirEntry - index;
                }
                else
                {
                    nameOffset = ExtractedFile.GetUIntAtOffset(entryOffset);
                    var fileOffset = ExtractedFile.GetUIntAtOffset(entryOffset + 4);
                    var fileSize   = ExtractedFile.GetUIntAtOffset(entryOffset + 8);
                    fileEntry = new FSTFileEntry(index, nameOffset, fileOffset, fileSize);
                    index++;
                    if (fileOffset < StartDataOffset)
                    {
                        StartDataOffset = fileOffset;
                    }
                }

                if (nameOffset > LastNameOffset)
                {
                    LastNameOffset = nameOffset;
                }

                var fileName = ExtractedFile.GetStringAtOffset(nameOffset + TOCFirstStringOffset);
                fileEntry.Name = fileName;
                root.Children.Add(fileEntry);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get an in order list of FST entries (directories and files) as they would appear in fst.bin. Excludes the root directory.
        /// </summary>
        /// <param name="root"></param>
        /// <returns></returns>
        public List <FSTEntry> GetFlattenedFST(FSTDirectory root = null)
        {
            if (root == null)
            {
                root = rootDirectory;
            }

            var fileEntries = new List <FSTEntry>();

            foreach (var fe in root.Children)
            {
                if (fe is FSTFileEntry file)
                {
                    fileEntries.Add(file);
                }
                else if (fe is FSTDirectory dir)
                {
                    fileEntries.Add(dir);
                    fileEntries.AddRange(GetFlattenedFST(dir));
                }
            }
            return(fileEntries.OrderBy(f => f.FileEntry).ToList());
        }