IBinaryStream migration.

This commit is contained in:
morkt
2016-10-16 09:22:53 +04:00
parent d0c1d5da01
commit bb18303eb4
251 changed files with 3277 additions and 3630 deletions

View File

@@ -37,19 +37,18 @@ namespace GameRes.Formats.WildBug
public override string Description { get { return "Wild Bug's audio format"; } }
public override uint Signature { get { return 0x1A444257; } } // 'WBD'
public override SoundInput TryOpen (Stream file)
public override SoundInput TryOpen (IBinaryStream file)
{
var header = new byte[0x24];
if (header.Length != file.Read (header, 0, header.Length))
var header = file.ReadHeader (0x24);
if (!header.AsciiEqual (4, "WAV"))
return null;
if (!Binary.AsciiEqual (header, 4, "WAV"))
if (header.ToInt32 (8) < 2)
return null;
if (LittleEndian.ToInt32 (header, 8) < 2)
return null;
int fmt_offset = LittleEndian.ToInt32 (header, 0x10);
int fmt_size = LittleEndian.ToInt32 (header, 0x14);
int data_offset = LittleEndian.ToInt32 (header, 0x1C);
int data_size = LittleEndian.ToInt32 (header, 0x20);
int fmt_offset = header.ToInt32 (0x10);
int fmt_size = header.ToInt32 (0x14);
int data_offset = header.ToInt32 (0x1C);
int data_size = header.ToInt32 (0x20);
var wav_header = new byte[8+12+fmt_size+8];
Buffer.BlockCopy (WavHeader, 0, wav_header, 0, WavHeader.Length);
LittleEndian.Pack (wav_header.Length-8+data_size, wav_header, 4);
@@ -62,7 +61,7 @@ namespace GameRes.Formats.WildBug
wav_header[d++]= (byte)'t';
wav_header[d++]= (byte)'a';
LittleEndian.Pack (data_size, wav_header, d);
var wav_data = new StreamRegion (file, data_offset, data_size);
var wav_data = new StreamRegion (file.AsStream, data_offset, data_size);
return new WaveInput (new PrefixStream (wav_header, wav_data));
}

View File

@@ -37,12 +37,10 @@ namespace GameRes.Formats.WildBug
public override string Description { get { return "Wild Bug's compressed audio format"; } }
public override uint Signature { get { return 0x1A585057; } } // 'WPX'
public override SoundInput TryOpen (Stream file)
public override SoundInput TryOpen (IBinaryStream file)
{
var header = new byte[0x10];
if (header.Length != file.Read (header, 0, header.Length))
return null;
if (!Binary.AsciiEqual (header, 4, "WAV"))
var header = file.ReadHeader (0x10);
if (!header.AsciiEqual (4, "WAV"))
return null;
int count = header[0xE];
int dir_size = header[0xF];
@@ -50,22 +48,19 @@ namespace GameRes.Formats.WildBug
return null;
file.Position = 0x10;
header = new byte[count * dir_size];
if (header.Length != file.Read (header, 0, header.Length))
throw new InvalidFormatException();
var index = file.ReadBytes (count * dir_size);
var section = WpxSection.Find (header, 0x20, count, dir_size);
var section = WpxSection.Find (index, 0x20, count, dir_size);
if (null == section || section.UnpackedSize < 0x10 || section.DataFormat != 0x80)
throw new InvalidFormatException();
var fmt = new byte[section.UnpackedSize];
file.Position = section.Offset;
file.Read (fmt, 0, section.UnpackedSize);
var fmt = file.ReadBytes (section.UnpackedSize);
section = WpxSection.Find (header, 0x21, count, dir_size);
section = WpxSection.Find (index, 0x21, count, dir_size);
if (null == section)
throw new InvalidFormatException();
var reader = new WwaReader (file, section);
var reader = new WwaReader (file.AsStream, section);
var data = reader.Unpack (section.DataFormat);
if (null == data)
throw new InvalidFormatException();

View File

@@ -74,29 +74,25 @@ namespace GameRes.Formats.WildBug
public override string Description { get { return "Wild Bug's image format"; } }
public override uint Signature { get { return 0x1A585057; } } // 'WPX'
public override ImageMetaData ReadMetaData (Stream stream)
public override ImageMetaData ReadMetaData (IBinaryStream stream)
{
byte[] header = new byte[0x10];
if (header.Length != stream.Read (header, 0, header.Length))
return null;
if (!Binary.AsciiEqual (header, 4, "BMP"))
var header = stream.ReadHeader (0x10);
if (!header.AsciiEqual (4, "BMP"))
return null;
int count = header[0xE];
int dir_size = header[0xF];
if (1 != header[0xC] || 0 == count || 0 == dir_size)
return null;
header = new byte[count * dir_size];
if (header.Length != stream.Read (header, 0, header.Length))
return null;
var section = WpxSection.Find (header, 0x10, count, dir_size);
var dir = stream.ReadBytes (count * dir_size);
var section = WpxSection.Find (dir, 0x10, count, dir_size);
if (null == section)
return null;
if (section.UnpackedSize < 0x10)
return null;
stream.Seek (section.Offset, SeekOrigin.Begin);
byte[] data = new byte[section.UnpackedSize];
if (data.Length != stream.Read (data, 0, data.Length))
stream.Position = section.Offset;
var data = stream.ReadBytes (section.UnpackedSize);
if (data.Length != section.UnpackedSize)
return null;
return new WbmMetaData
@@ -106,15 +102,13 @@ namespace GameRes.Formats.WildBug
BPP = data[0xC],
EntryCount = count,
EntrySize = dir_size,
Header = header,
Header = header.ToArray(),
};
}
public override ImageData Read (Stream stream, ImageMetaData info)
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
{
var meta = info as WbmMetaData;
if (null == meta)
throw new ArgumentException ("WbmFormat.Read should be supplied with WbmMetaData", "info");
var meta = (WbmMetaData)info;
var section = WpxSection.Find (meta.Header, 0x11, meta.EntryCount, meta.EntrySize);
if (null == section)
@@ -215,7 +209,7 @@ namespace GameRes.Formats.WildBug
internal class WbmReader : WpxDecoder
{
public WbmReader (Stream input, WpxSection section) : base (input, section)
public WbmReader (IBinaryStream input, WpxSection section) : base (input.AsStream, section)
{
}