/// <summary> /// Returns a stream of bytes of the specified entry in the archive. /// </summary> /// <param name="fileEntry">The file entry to read.</param> /// <returns> /// A <see cref="MemoryStream"/> containing the data of a file selected by <paramref name="fileEntry"/>. /// </returns> public Stream GetFile(RaidyFileEntry fileEntry) { MemoryStream stream = new MemoryStream(); reader.BaseStream.Position = fileEntry.offset; byte[] buffer = new byte[81920]; for (int remaining = (int)fileEntry.length; remaining > 0;) { int read = reader.Read(buffer, 0, Math.Min(buffer.Length, remaining)); stream.Write(buffer, 0, read); remaining -= read; } stream.Position = 0; // Reset the stream before returning it. return(stream); }
/// <summary> /// Initializes a new instance of the <see cref="RaidyReader"/> class with the specified stream. /// </summary> /// <param name="source">The stream to read from.</param> public RaidyReader(Stream source) { reader = new BinaryReader(source); // Read the header. header.magic = reader.ReadChars(8); // Should be SM2MPX10. // TODO: Handle invalid files. header.fileCount = reader.ReadUInt32(); header.dataOffset = reader.ReadUInt32(); header.fileName = reader.ReadChars(12); // Always 12 chars. header.tocOffset = reader.ReadUInt32(); // Populate the FileEntries array. FileEntries = new RaidyFileEntry[header.fileCount]; for (int i = 0; i < header.fileCount; i++) { FileEntries[i].fileName = reader.ReadChars(12); // Always 12 chars. FileEntries[i].offset = reader.ReadUInt32(); FileEntries[i].length = reader.ReadUInt32(); } }