public static void injectOneFile(MainWindow.fileReplacement fR, List <byte> newFile, byte[] sourceFile, string mapFilePath, string sourcePath) { if (newFile.Count() > fR.size) { throw new Exception("New file greater than source file, which is " + fR.size + " bytes!"); } else { MemoryStream src = new MemoryStream(sourceFile); BinaryDataReader br = new BinaryDataReader(src); MemoryStream o = new MemoryStream(); BinaryDataWriter bw = new BinaryDataWriter(o); byte[] firstJunk = br.ReadBytes(fR.offset); bw.Write(firstJunk); br.ReadBytes(fR.size); //Make size correct. while (newFile.Count() < fR.size) { newFile.Add(0); } bw.Write(newFile.ToArray()); byte[] lastJunk = br.ReadBytes(sourceFile.Length - (int)br.Position); bw.Write(lastJunk); File.WriteAllBytes(sourcePath, o.ToArray()); } }
//Load. public void load(byte[] b) { //New stream stuff. MemoryStream src = new MemoryStream(b); BinaryDataReader br = new BinaryDataReader(src); //Read stuff. magic = br.ReadChars(4); chunkSize = br.ReadUInt32(); identifier = br.ReadChars(4); //FMT fmt.magic = br.ReadChars(4); fmt.chunkSize = br.ReadUInt32(); fmt.chunkFormat = br.ReadUInt16(); fmt.numChannels = br.ReadUInt16(); fmt.sampleRate = br.ReadUInt32(); fmt.byteRate = br.ReadUInt32(); fmt.blockAlign = br.ReadUInt16(); fmt.bitsPerSample = br.ReadUInt16(); fmt.restOfData = br.ReadBytes((int)fmt.chunkSize - 16); //DATA data.magic = br.ReadChars(4); data.chunkSize = br.ReadUInt32(); data.data = br.ReadBytes((int)data.chunkSize); //SMPL smpl = new smplBlock(); smpl.magic = "NULL".ToCharArray(); loop = false; try { smpl.magic = br.ReadChars(4); } catch { } if (new string(smpl.magic) == "smpl") { loop = true; smpl.chunkSize = br.ReadUInt32(); smpl.uselessData = br.ReadUInt32s(3); smpl.midiNote = br.ReadUInt32(); smpl.moreUselessData = br.ReadUInt32s(3); smpl.numLoops = br.ReadUInt32(); smpl.loopDumb = br.ReadUInt32s(3); smpl.loopStart = br.ReadUInt32(); smpl.loopEnd = br.ReadUInt32(); smpl.moreLoopDumb = br.ReadUInt32s(2); } }
public static Dictionary <int, Attributes> ParseATR1(BinaryDataReader reader) { long size = reader.ReadUInt32(); ATR1size = size; if (reader.ReadBytes(8).IsOnly <byte>(0)) // padding { throw new InvalidDataException("Offset 0x08 of ATR1 section is not empty!"); } long entriesLength = reader.ReadUInt32(); long entryLength = reader.ReadUInt32(); Dictionary <int, Attributes> entries = new Dictionary <int, Attributes>(); for (int i = 0; i < entriesLength; i++) { Attributes set = new Attributes { unk1 = reader.ReadByte(), unk2 = reader.ReadByte(), type = reader.ReadByte(), unk3 = reader.ReadByte(), unk4 = reader.ReadUInt16(), unk5 = reader.ReadByte(), unk6 = reader.ReadByte(), unk7 = reader.ReadBytes((int)(entryLength - 8)) ?? new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 } }; if (set.unk2 > 2) { Console.WriteLine($"Entry {i} in ATR1 is invalid! Skipping..."); //reader.Position = reader.Position - entryLength; //break; continue; } if (set == null) { Console.WriteLine($"Entry {i} has an undefined attr set!"); } entries.Add(i, set); } return(entries); }
public void ProcessLabel(BinaryDataReader br, uint size) { long start = br.Position; int count = br.ReadInt32(); for (int i = 0; i < count; i++) { br.Position = start + 4 + 8 * i; //count + (c + off) * i int c = br.ReadInt32(); int off = br.ReadInt32(); br.Position = start + off; for (int j = 0; j < c; j++) { TextEntries.Add(new TextEntry()); byte len = br.ReadByte(); TextEntries.Last().Label = Encoding.ASCII.GetString(br.ReadBytes(len)); br.ReadInt32();//index } } br.Position = start + size; Align(br, 0x10); }
public void ProcessChunk(BinaryDataReader br) { List <Tuple <Action <BinaryDataReader, uint>, string> > callbacks = new List <Tuple <Action <BinaryDataReader, uint>, string> >() { new Tuple <Action <BinaryDataReader, uint>, string>(ProcessLabel, LABEL_MAGIC), new Tuple <Action <BinaryDataReader, uint>, string>(ProcessAttribut, ATTR_MAGIC), new Tuple <Action <BinaryDataReader, uint>, string>(ProcessText, TEXT_MAGIC), }; string magic = Encoding.ASCII.GetString(br.ReadBytes(4)); uint size = br.ReadUInt32(); br.ReadUInt64();//padding bool found = false; foreach (var callback in callbacks) { if (magic == callback.Item2) { callback.Item1(br, size); found = true; break; } } if (!found) { throw new MsbtParsingException($"Unknow chunk : \"{magic}\""); } }
public BasePane(string _name, BinaryDataReader bin) { name = _name; var length = bin.ReadInt32(); data = bin.ReadBytes(length - 8); }
private static AampLibraryCSharp.StringEntry CreateStringEntry(BinaryDataReader reader, int MaxValue) { long pos = reader.Position; if (MaxValue == -1) { MaxValue = 255; } int length = 0; for (int i = 0; i < MaxValue; i++) { if (reader.ReadByte() != 0) { length++; } else { break; } } reader.Seek(pos, SeekOrigin.Begin); byte[] data = reader.ReadBytes(length); return(new AampLibraryCSharp.StringEntry(data, MaxValue)); }
public void ProcessText(BinaryDataReader br, uint size) { long start = br.Position; int count = br.ReadInt32(); List <int> offs = new List <int>(); for (int i = 0; i < count; i++) { offs.Add(br.ReadInt32()); } offs.Add((int)size); for (int i = 0; i < count; i++) { br.Position = start + offs[i]; int len = offs[i + 1] - offs[i]; Encoding enc = br.ByteOrder == ByteOrder.BigEndian ? Encoding.BigEndianUnicode : Encoding.Unicode; TextEntries[i].Value = enc.GetString(br.ReadBytes(len)).Replace("\0", "\r\n\r\n"); } br.Position = start + size; Align(br, 0x10); }
public static Dictionary <int, MsbtString> ParseTXT2(BinaryDataReader reader) { long size = reader.ReadUInt32(); if (reader.ReadBytes(8).IsOnly <byte>(0)) // padding { throw new InvalidDataException("Offset 0x08 of ATR1 section is not empty!"); } long position = reader.Position; long entriesLength = reader.ReadUInt32(); Dictionary <int, MsbtString> entries = new Dictionary <int, MsbtString>(); long[] textPositions = new long[entriesLength]; for (int i = 0; i < entriesLength; i++) { textPositions[i] = reader.ReadUInt32() + position; } for (int i = 0; i < entriesLength; i++) { long currentOffset = textPositions[i]; reader.Seek(currentOffset, SeekOrigin.Begin); MsbtString str = new MsbtString(reader); entries.Add(i, str); } return(entries); }
/// <summary> /// Load a file. /// </summary> /// <param name="b"></param> public void load(byte[] b) { MemoryStream src = new MemoryStream(b); BinaryDataReader br = new BinaryDataReader(src); magic = br.ReadChars(4); identifier = br.ReadUInt32(); fileSize = br.ReadUInt32(); nSize = br.ReadUInt16(); nBlocks = br.ReadUInt16(); data = new swavData[(int)nBlocks]; for (int i = 0; i < data.Length; i++) { data[i].magic = br.ReadChars(4); data[i].size = br.ReadUInt32(); data[i].info.waveType = br.ReadByte(); data[i].info.loopFlag = br.ReadByte(); data[i].info.nSampleRate = br.ReadUInt16(); data[i].info.nTime = br.ReadUInt16(); data[i].info.loopOffset = br.ReadUInt16(); data[i].info.nonLoopLength = br.ReadUInt32(); data[i].data = br.ReadBytes((int)(data[i].size - (8 + 12))); } }
public PaiEntry(BinaryDataReader bin) { uint SectionStart = (uint)bin.Position; Name = bin.ReadFixedLenString(28); var tagCount = bin.ReadByte(); Target = (AnimationTarget)bin.ReadByte(); if (Target >= AnimationTarget.TargetMax) { throw new Exception("Unsupported PaiEntry target value: " + Target); } bin.ReadUInt16(); //padding List <uint> TagOffsets = new List <uint>(); for (int i = 0; i < tagCount; i++) { TagOffsets.Add(bin.ReadUInt32()); } if (tagCount == 0) { return; } UnkwnownData = bin.ReadBytes((int)(TagOffsets[0] + SectionStart - bin.Position)); for (int i = 0; i < tagCount; i++) { bin.BaseStream.Position = TagOffsets[i] + SectionStart; Tags.Add(new PaiTag(bin, (byte)Target)); } }
public UInt32[] actionNumbers; //Always 64 entries, and are always 0x4C484440. May be some sort of sequence command? /// <summary> /// Load a file from bytes. /// </summary> public void load(byte[] b) { MemoryStream src = new MemoryStream(b); BinaryDataReader br = new BinaryDataReader(src); br.ByteOrder = ByteOrder.LittleEndian; tempo = br.ReadByte(); padding = br.ReadByte(); count = br.ReadByte(); unknown = br.ReadByte(); sampleNumbers = br.ReadUInt32s((int)count).ToList(); br.ReadUInt32s(64 - (int)count); danceMoves = br.ReadBytes((int)count).ToList(); br.ReadBytes(64 - (int)count); actionNumbers = br.ReadUInt32s(64); }
public byte[] data; //Remaining ADPCM data. /// <summary> /// Load a dsp file. /// </summary> /// <param name="b"></param> public void load(byte[] b) { MemoryStream src = new MemoryStream(b); BinaryDataReader br = new BinaryDataReader(src); br.ByteOrder = ByteOrder.BigEndian; numSamples = br.ReadUInt32(); adpcmNibbles = br.ReadUInt32(); sampleRate = br.ReadUInt32(); loopFlag = br.ReadUInt16(); format = br.ReadUInt16(); loopStart = br.ReadUInt32(); loopEnd = br.ReadUInt32(); always2 = br.ReadUInt32(); coefficients = br.ReadInt16s(16); gain = br.ReadUInt16(); predictor = br.ReadUInt16(); yn1 = br.ReadUInt16(); yn2 = br.ReadUInt16(); loopPredictor = br.ReadUInt16(); loopYn1 = br.ReadUInt16(); loopYn2 = br.ReadUInt16(); channelCount = br.ReadUInt16(); blockFrameCount = br.ReadUInt16(); padding = br.ReadUInt16s(9); data = br.ReadBytes((int)adpcmNibbles / 2); }
public static GobDelta.CompositeEqu ReadGobCompositeEqu(this BinaryDataReader reader) { while (true) { int h = reader.ReadByte(); if (h == 255) break; int ef = h & 0x80; int et = h & 0x7f; string at = reader.ReadCString(); int resId = reader.ReadUInt16(); if ((resId & 0x8000) != 0) { resId &= ~0x8000; reader.ReadBytes(reader.ReadByte()); } Point3F off; if ((ef & 128) != 0) { int x = reader.ReadInt16(); int y = reader.ReadInt16(); int z = reader.ReadInt16(); off = new Point3F(x / 1000.0f, y / 1000.0f, z / 1000.0f); } else { off = Point3F.Empty; } } return new GobDelta.CompositeEqu(); }
public static MapUpdateGrid ReadMapUpdateEvent(this BinaryDataReader reader) { var msg = new MapUpdateGrid { Coord = reader.ReadInt32Coord(), MinimapName = reader.ReadCString(), Overlays = new int[100 * 100] }; var pfl = new byte[256]; while (true) { int pidx = reader.ReadByte(); if (pidx == 255) { break; } pfl[pidx] = reader.ReadByte(); } reader = new BinaryDataReader(Unpack(reader.ReadRemaining())); msg.Tiles = reader.ReadBytes(100 * 100); while (true) { int pidx = reader.ReadByte(); if (pidx == 255) { break; } int fl = pfl[pidx]; int type = reader.ReadByte(); var c1 = new Point2D(reader.ReadByte(), reader.ReadByte()); var c2 = new Point2D(reader.ReadByte(), reader.ReadByte()); int ol; if (type == 0) { ol = ((fl & 1) == 1) ? 2 : 1; } else if (type == 1) { ol = ((fl & 1) == 1) ? 8 : 4; } else { continue; } for (int y = c1.Y; y <= c2.Y; y++) { for (int x = c1.X; x <= c2.X; x++) { msg.Overlays[y * 100 + x] |= ol; } } } return(msg); }
public static GobDelta.Overlay ReadGobOverlay(this BinaryDataReader reader) { int overlayId = reader.ReadInt32(); var prs = (overlayId & 1) != 0; overlayId >>= 1; int resId = reader.ReadUInt16(); byte[] data = null; if (resId != 65535) { if ((resId & 0x8000) != 0) { resId &= ~0x8000; var len = reader.ReadByte(); data = reader.ReadBytes(len); } else data = new byte[0]; } else resId = -1; return new GobDelta.Overlay { Id = overlayId, IsPersistent = prs, ResourceId = resId, SpriteData = data }; }
/// <summary> /// Read the data. /// </summary> /// <param name="br">The reader.</param> public override void ReadData(BinaryDataReader br) { //DSP-ADPCM. if (Fmt.WaveFormat == WaveFormatType.DSPADPCM) { //Get number of frames. int numFrames = Size / Fmt.NumChannels / 8; List <byte>[] d = new List <byte> [Fmt.NumChannels]; for (int i = 0; i < d.Length; i++) { d[i] = new List <byte>(); } for (int i = 0; i < numFrames; i++) { for (int j = 0; j < Fmt.NumChannels; j++) { d[j].AddRange(br.ReadBytes(8)); } } //Finish. DspApcm = new byte[d.Length][]; for (int i = 0; i < d.Length; i++) { DspApcm[i] = d[i].ToArray(); } } }
/// <summary> /// Just gloss over the data, it will never be used ever. /// </summary> /// <param name="br">The reader.</param> public void Read(BinaryDataReader br) { //Version stuff. FileReader FileReader = new FileReader(); FileReader.OpenFile(br, out writeMode, out Version); //Close file. FileReader.CloseFile(br); //Get byte order. br.Position = 4; br.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; if (br.ReadUInt16() == ByteOrder.LittleEndian) { //Little endian. br.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian; } br.Position += 6; UInt32 length = br.ReadUInt32(); br.Position -= 0x10; BackupSTP = br.ReadBytes((int)length); }
private IList ReadArray(BinaryDataReader reader, Type type, int length) { // Use a given instance as the root array if available. IList array; if (_instance == null) { array = InstantiateType <IList>(type); } else { array = (IList)_instance; _instance = null; } // Find the generic element type by looking at the indexer (this allows IList-inheriting classes to work). Type elementType = type.GetTypeInfo().GetElementType(); // Read the element types of the array. All elements must be of same type or serialization is impossible. byte[] nodeTypes = reader.ReadBytes(length); // Read the elements, which begin after a padding to the next 4 bytes. reader.Align(4); for (int i = 0; i < length; i++) { array.Add(ReadValue(reader, elementType, (ByamlNodeType)nodeTypes[i])); } return(array); }
private PoseEffect ParseEffect(BinaryDataReader reader) { var count = reader.ReadUInt16(); var events = new PoseEvent[count]; for (int i = 0; i < events.Length; i++) { var ev = new PoseEvent(); ev.Time = reader.ReadFloat40(); ev.Type = reader.ReadByte(); switch (ev.Type) { case 0: var resnm = reader.ReadCString(); var resver = reader.ReadUInt16(); ev.ResRef = new ResourceRef(resnm, resver); ev.Data = reader.ReadBytes(reader.ReadByte()); break; case 1: ev.Id = reader.ReadCString(); break; default: throw new ResourceException("Illegal control event: " + ev.Type); } events[i] = ev; } return(new PoseEffect { Events = events.ToArray() }); }
void ParseData(ByteOrder bo) { BinaryDataReader bin = new BinaryDataReader(new MemoryStream(Data)); bin.ByteOrder = bo; AnimationOrder = bin.ReadUInt16(); var groupCount = bin.ReadUInt16(); if (groupCount != 1) { throw new Exception("File with unexpected group count"); } var animName = bin.ReadUInt32() - 8; //all offsets are shifted by 8 cause this byte block doesn't include the section name and size var groupNames = bin.ReadUInt32() - 8; Unk_StartOfFile = bin.ReadUInt16(); Unk_EndOfFile = bin.ReadUInt16(); ChildBinding = bin.ReadByte(); Unk_EndOfHeader = bin.ReadBytes((int)animName - (int)bin.Position); bin.BaseStream.Position = animName; Name = bin.ReadString(BinaryStringFormat.ZeroTerminated); var groups = new List <string>(); for (int i = 0; i < groupCount; i++) { bin.BaseStream.Position = groupNames + i * groupNameLen; groups.Add(bin.ReadFixedLenString(groupNameLen)); } Groups = groups.ToArray(); if (Unk_StartOfFile != 0 || Unk_EndOfFile != 0) { Console.Write(""); } }
public Dictionary <string, byte[]> unpackRam(Stream src) { Dictionary <string, byte[]> res = new Dictionary <string, byte[]>(); BinaryDataReader br = new BinaryDataReader(src, false); br.ByteOrder = ByteOrder.BigEndian; br.BaseStream.Position = 0; br.ReadUInt32(); // Header br.ReadUInt16(); // Chunk length if (br.ReadUInt16() == 0xFFFE) // BOM { br.ByteOrder = ByteOrder.LittleEndian; } else { br.ByteOrder = ByteOrder.BigEndian; } br.ReadUInt32(); // File size UInt32 startingOff = br.ReadUInt32(); br.ReadUInt32(); // Unknown; SFAT sfat = new SFAT(); sfat.parse(br, (int)br.BaseStream.Position); SFNT sfnt = new SFNT(); sfnt.parse(br, (int)br.BaseStream.Position, sfat, (int)startingOff); for (int m = 0; m < sfat.nodeCount; m++) { br.Seek(sfat.nodes[m].nodeOffset + startingOff, 0); byte[] temp; if (m == 0) { temp = br.ReadBytes((int)sfat.nodes[m].EON); } else { int tempInt = (int)sfat.nodes[m].EON - (int)sfat.nodes[m].nodeOffset; temp = br.ReadBytes(tempInt); } res.Add(sfnt.fileNames[m], temp); } new SARC(); return(res); }
protected override TexLayer Deserialize(BinaryDataReader reader) { var data = new TexLayer(); data.Id = reader.ReadInt16(); data.Offset = new Point2D(reader.ReadUInt16(), reader.ReadUInt16()); data.Size = new Point2D(reader.ReadUInt16(), reader.ReadUInt16()); data.Mipmap = TexMipmap.None; TexMinFilter?minFilter = null; TexMagFilter?magFilter = null; while (reader.HasRemaining) { int part = reader.ReadByte(); switch (part) { case ImagePart: data.ImageData = reader.ReadBytes(reader.ReadInt32()); break; case MipmapPart: data.Mipmap = Mipmaps[reader.ReadByte()]; break; case MagFilterPart: magFilter = MagFilters[reader.ReadByte()]; break; case MinFilterPart: minFilter = MinFilters[reader.ReadByte()]; break; case MaskPart: data.MaskImageData = reader.ReadBytes(reader.ReadInt32()); break; default: throw new ResourceException($"Unknown texture data part: {part}"); } } data.MagFilter = magFilter ?? TexMagFilter.Linear; data.MinFilter = minFilter ?? ( data.Mipmap == TexMipmap.None ? TexMinFilter.Linear : TexMinFilter.LinearMipmapLinear); return(data); }
public static GobDelta ReadResAttr(this BinaryDataReader reader) { reader.ReadUInt16(); // resid int len = reader.ReadByte(); if (len > 0) reader.ReadBytes(len); return null; }
public static int ReadInt24(this BinaryDataReader br) { byte[] b = br.ReadBytes(3); return((br.ByteOrder == ByteOrder.BigEndian || (!BitConverter.IsLittleEndian && br.ByteOrder == ByteOrder.System)) ? (b[0] << 16) | (b[1] << 8) | b[2] : (b[2] << 16) | (b[1] << 8) | b[0]); }
public void Load(BinaryDataReader reader) { reader.Seek(0); string Magic = reader.ReadString(4); Console.WriteLine(Magic); if (Magic != "DDS ") { MessageBox.Show("The file does not appear to be a valid DDS file."); } header = new Header(); header.size = reader.ReadUInt32(); header.flags = reader.ReadUInt32(); header.height = reader.ReadUInt32(); header.width = reader.ReadUInt32(); header.pitchOrLinearSize = reader.ReadUInt32(); header.depth = reader.ReadUInt32(); header.mipmapCount = reader.ReadUInt32(); header.reserved1 = new uint[11]; for (int i = 0; i < 11; ++i) { header.reserved1[i] = reader.ReadUInt32(); } header.ddspf.size = reader.ReadUInt32(); header.ddspf.flags = reader.ReadUInt32(); header.ddspf.fourCC = reader.ReadString(4); header.ddspf.RGBBitCount = reader.ReadUInt32(); header.ddspf.RBitMask = reader.ReadUInt32(); header.ddspf.GBitMask = reader.ReadUInt32(); header.ddspf.BBitMask = reader.ReadUInt32(); header.ddspf.ABitMask = reader.ReadUInt32(); header.caps = reader.ReadUInt32(); header.caps2 = reader.ReadUInt32(); header.caps3 = reader.ReadUInt32(); header.caps4 = reader.ReadUInt32(); header.reserved2 = reader.ReadUInt32(); int DX10HeaderSize = 0; if (header.ddspf.fourCC == "DX10") { DX10HeaderSize = 20; ReadDX10Header(reader); } reader.TemporarySeek((int)(4 + header.size + DX10HeaderSize), SeekOrigin.Begin); bdata = reader.ReadBytes((int)(reader.BaseStream.Length - reader.Position)); reader.Dispose(); reader.Close(); }
public QuickBntx(BinaryDataReader Reader) { if (Reader.ReadString(4) != "BNTX") { throw new Exception("Wrong magic"); } Reader.ReadInt32(); int DataLength = Reader.ReadInt32(); ushort ByteOrderMark = Reader.ReadUInt16(); ushort FormatRevision = Reader.ReadUInt16(); int NameAddress = Reader.ReadInt32(); int StringsAddress = Reader.ReadInt32() >> 16; int RelocAddress = Reader.ReadInt32(); int FileLength = Reader.ReadInt32(); if (Reader.ReadString(4) != "NX ") { throw new Exception("Wrong magic"); } uint TexturesCount = Reader.ReadUInt32(); long InfoPtrsAddress = Reader.ReadInt64(); long DataBlkAddress = Reader.ReadInt64(); long DictAddress = Reader.ReadInt64(); uint StrDictLength = Reader.ReadUInt32(); Reader.BaseStream.Seek(InfoPtrsAddress, SeekOrigin.Begin); var FirstBrti = (int)Reader.ReadInt64(); Reader.BaseStream.Position = 0; Head = Reader.ReadBytes(FirstBrti); for (int Index = 0; Index < TexturesCount; Index++) { Reader.BaseStream.Seek(InfoPtrsAddress + Index * 8, SeekOrigin.Begin); Reader.BaseStream.Seek(Reader.ReadInt64(), SeekOrigin.Begin); Textures.Add(new Texture(Reader)); //File.WriteAllBytes("F:\\test", Textures[0].Write()); } Reader.BaseStream.Position = RelocAddress; Rlt = Reader.ReadBytes((int)Reader.BaseStream.Length - (int)Reader.BaseStream.Position); }
/// <summary> /// Make a new adshr curve. /// </summary> /// <param name="br">The reader.</param> public AdshrCurve(ref BinaryDataReader br) { //Read properties. attack = br.ReadByte(); decay = br.ReadByte(); sustain = br.ReadByte(); hold = br.ReadByte(); release = br.ReadByte(); padding = br.ReadBytes(3); }
/// <summary> /// Read a file. /// </summary> /// <param name="b"></param> public void load(byte[] b) { MemoryStream src = new MemoryStream(b); BinaryDataReader br = new BinaryDataReader(src); br.ByteOrder = ByteOrder.LittleEndian; //Magic. magic = br.ReadChars(4); //Stream. stream.magic = br.ReadChars(4); stream.loop = br.ReadByte(); stream.numberOfChannels = br.ReadByte(); stream.sampleRate = br.ReadUInt32(); stream.loopStart = br.ReadUInt32(); stream.loopEnd = br.ReadUInt32(); stream.numberOfTracks = br.ReadUInt32(); stream.sampleSize = br.ReadUInt32(); //Tracks. tracks = new List <trackInfo>(); for (int i = 0; i < (int)stream.numberOfTracks; i++) { trackInfo t = new trackInfo(); t.magic = br.ReadChars(4); t.volume = br.ReadByte(); t.pan = br.ReadByte(); t.flags = br.ReadUInt16(); t.channelCount = br.ReadUInt32(); t.channels = new List <byte>(); for (int j = 0; j < t.channelCount; j++) { t.channels.Add(br.ReadByte()); } tracks.Add(t); } //Seek. seekSize = br.ReadUInt32(); seekBlock = br.ReadBytes((int)seekSize); //Channels. channelMagic = br.ReadChars(4); channelData = new List <UInt16[]>(); for (int i = 0; i < stream.numberOfChannels; i++) { List <UInt16> channel = new List <UInt16>(); for (int j = 0; j < (int)(stream.sampleSize / 2); j++) { channel.Add(br.ReadUInt16()); } channelData.Add(channel.ToArray()); } }
/// <summary> /// Load the file. /// </summary> /// <param name="b"></param> public void load(byte[] b) { //Stream. MemoryStream src = new MemoryStream(b); BinaryDataReader br = new BinaryDataReader(src); br.ByteOrder = ByteOrder.LittleEndian; //Stuff. magic = br.ReadChars(4); identifier = br.ReadUInt32(); fileSize = br.ReadUInt32(); headerSize = br.ReadUInt16(); nBlocks = br.ReadUInt16(); data = new dataBlock(); data.magic = br.ReadChars(4); data.size = br.ReadUInt32(); data.info = new infoStuff(); data.info.waveType = br.ReadByte(); data.info.loopFlag = br.ReadByte(); data.info.nSampleRate = br.ReadUInt16(); data.info.nTime = br.ReadUInt16(); data.info.nloopOffset = br.ReadUInt16(); data.info.nNonLoopLength = br.ReadUInt32(); switch (data.info.waveType) { case 0: data.pcm8 = br.ReadBytes((int)data.size - 0x14); break; case 1: data.pcm16 = br.ReadInt16s(((int)data.size - 0x14) / 2); break; case 2: data.imaAdpcm = br.ReadBytes((int)data.size - 0x14); break; } }