public static AFS_File FromStream(FileStream stream, uint offset, uint length) { var file = new AFS_File(); file.data = new byte[length]; stream.Position = offset; stream.Read(file.data, 0, (int)length); return(file); }
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); }