public static AFS_TOC_Entry FromStream(FileStream stream) { var entry = new AFS_TOC_Entry(); entry.offset = BinaryHelper.ReadUInt32(stream); entry.length = BinaryHelper.ReadUInt32(stream); return(entry); }
public static AFS FromStream(FileStream stream) { var afs = new AFS(); afs.header = BinaryHelper.ReadString(stream, 4); afs.numFiles = BinaryHelper.ReadUInt32(stream); afs.tableOfContents = new AFS_TOC_Entry[afs.numFiles]; for (var i = 0; i < afs.numFiles; ++i) { var toc_entry = AFS_TOC_Entry.FromStream(stream); afs.tableOfContents[i] = toc_entry; } afs.filenameDirectoryOffset = BinaryHelper.ReadUInt32(stream); afs.filenameDirectoryLength = BinaryHelper.ReadUInt32(stream); afs.files = new AFS_File[afs.numFiles]; for (var i = 0; i < afs.numFiles; ++i) { var toc_entry = afs.tableOfContents[i]; var file = AFS_File.FromStream(stream, toc_entry.offset, toc_entry.length); afs.files[i] = file; } afs.directory = new AFS_Directory_Entry[afs.numFiles]; // hmm var dataBlockStart = afs.tableOfContents[0].offset; var directoryOffsetStreamStart = dataBlockStart - 8; stream.Position = directoryOffsetStreamStart; stream.Position = BinaryHelper.ReadUInt32(stream); // HMMM // stream.Position = afs.filenameDirectoryOffset; for (var i = 0; i < afs.numFiles; ++i) { var toc_entry = afs.tableOfContents[i]; var directory_entry = AFS_Directory_Entry.FromStream(stream); afs.directory[i] = directory_entry; } return(afs); }