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(); }
/// <summary> /// Read the chunk. /// </summary> /// <param name="br">The reader.</param> public void Read(BinaryDataReader br) { //Read chunk. Magic = new string(br.ReadChars(4)); int size = br.ReadInt32(); Data = br.ReadBytes(size); //Read data. MemoryStream src = new MemoryStream(Data); BinaryDataReader r = new BinaryDataReader(src); ReadData(r); try { r.Dispose(); } catch { } try { src.Dispose(); } catch { } }
/// <summary> /// Read a RIFF from a file. /// </summary> /// <param name="file">File to read the RIFF from.</param> public Riff(byte[] file) { //Set up stream. MemoryStream src = new MemoryStream(file); BinaryDataReader br = new BinaryDataReader(src); //Read file. Magic = new string(br.ReadChars(4)); int size = br.ReadInt32() - 4; Type = new string(br.ReadChars(4)); Chunks = new List <RiffChunk>(); while (br.Position < file.Length) { string magic = new string(br.ReadChars(4)); br.Position -= 4; ReadChunk(magic, br); } //Dispose stream. try { br.Dispose(); } catch { } try { src.Dispose(); } catch { } }
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.ReadUInt32(); 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 == FOURCC_DX10) { IsDX10 = true; DX10HeaderSize = 20; ReadDX10Header(reader); } if (IsCompressed()) { imageSize = ((header.width + 3) >> 2) * ((header.height + 3) >> 2) * getFormatSize(header.ddspf.fourCC); } else { imageSize = header.width * header.height * getFormatSize(header.ddspf.fourCC); } reader.TemporarySeek((int)(4 + header.size + DX10HeaderSize), SeekOrigin.Begin); bdata = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); reader.Dispose(); reader.Close(); ArrayCount = 1; MipCount = header.mipmapCount; Width = header.width; Height = header.height; Format = GetFormat(); }
static void Main(string[] args) { Console.WriteLine("Dank Moon Sound Extractor - c2019 Gota7"); if (!Directory.Exists("wwiseaudio")) { Console.WriteLine("wwiseaudio folder not found!"); Console.WriteLine(" Press any key to continue . . ."); Console.ReadKey(); Environment.Exit(0); } foreach (string s in Directory.EnumerateFiles("wwiseaudio")) { //Create folders. Directory.CreateDirectory("Extracted/" + Path.GetFileNameWithoutExtension(s)); //New writer. BinaryDataReader br = new BinaryDataReader(new FileStream(s, FileMode.Open)); //File count. int fileCount = 0; //READ. while (br.Position <= br.BaseStream.Length - 4) { //RIFF. try { if (br.ReadUInt32() == 0x46464952) { //Read RIFF. br.Position -= 4; Wave w = new Wave(br); FormatChunk f = w.Chunks.Where(x => x.Magic.Equals("fmt ")).ElementAt(0) as FormatChunk; f.WaveFormat = WaveFormatType.PCM; f.BitsPerSample = 16; //Convert data. try { DataChunk d = w.Chunks.Where(x => x.Magic.Equals("data")).ElementAt(0) as DataChunk; d.Pcm16 = EncoderFactory.DspApcmToPcm16(d.DspApcm, f.DspAdpcmNumSamples, f.ChannelInfo.ToArray()); File.WriteAllBytes("Extracted/" + Path.GetFileNameWithoutExtension(s) + "/" + fileCount.ToString("D4") + ".wav", w.ToFile()); } catch { Console.WriteLine("Failed for " + s + " (Sound " + fileCount.ToString("D4") + ")"); } fileCount++; } //Nothing. else { br.Position -= 3; } } catch { break; } } //Close. br.Dispose(); } //Exit. Console.WriteLine(" Press any key to continue . . ."); Console.ReadKey(); }
/// <summary> /// Read the sequence data. /// </summary> /// <param name="data">Sequence data.</param> /// <param name="byteOrder">Byte order.</param> public void Read(byte[] data, ByteOrder byteOrder) { //New reader. MemoryStream src = new MemoryStream(data); BinaryDataReader br = new BinaryDataReader(src) { ByteOrder = byteOrder }; //Read the data. Commands = new List <SequenceCommand>(); bool ended = false; while (br.Position < data.Length && !ended) { //Add command. var s = SequenceCommand.Read(br); Commands.Add(s); //If the command is end, and the rest is just padding. if (s as FinCommand != null) { long currPos = br.Position; byte[] raw = br.ReadBytes((int)(data.Length - currPos)); if (raw.Length > 0) { if (raw.Max() == 0) { ended = true; } } else { ended = true; } br.Position = currPos; } } //Go ahead and convert the public offsets to command indices. for (int i = 0; i < PublicLabelOffsets.Count; i++) { //Convert the offset to an index. PublicLabelOffsets[PublicLabelOffsets.ElementAt(i).Key] = OffsetToCommandIndex(Commands, PublicLabelOffsets.ElementAt(i).Value); } //Fix control commands. for (int i = 0; i < Commands.Count; i++) { //Make sure the command is a control command. if ((CommandType)Commands[i].Identifier == CommandType.Call || (CommandType)Commands[i].Identifier == CommandType.Jump || (CommandType)Commands[i].Identifier == CommandType.OpenTrack || (CommandType)Commands[i].Identifier == CommandType.If) { if ((CommandType)Commands[i].Identifier == CommandType.If) { //The first parameter is going to be the offset. int offset = 0; if ((CommandType)((IfCommand)Commands[i]).SequenceCommand.Identifier == CommandType.Call || (CommandType)((IfCommand)Commands[i]).SequenceCommand.Identifier == CommandType.Jump) { offset = (int)((UInt24)((IfCommand)Commands[i]).SequenceCommand.Parameters[0]).Value; } else if ((CommandType)((IfCommand)Commands[i]).SequenceCommand.Identifier == CommandType.OpenTrack) { offset = (int)((UInt24)((IfCommand)Commands[i]).SequenceCommand.Parameters[1]).Value; } //Get the index. int index = OffsetToCommandIndex(Commands, offset); //Set the property to this. if ((CommandType)((IfCommand)Commands[i]).SequenceCommand.Identifier == CommandType.Call || (CommandType)((IfCommand)Commands[i]).SequenceCommand.Identifier == CommandType.Jump) { ((UInt24)((IfCommand)Commands[i]).SequenceCommand.Parameters[0]).Value = (uint)index; } else if ((CommandType)((IfCommand)Commands[i]).SequenceCommand.Identifier == CommandType.OpenTrack) { ((UInt24)((IfCommand)Commands[i]).SequenceCommand.Parameters[1]).Value = (uint)index; } } else { //The first parameter is going to be the offset. int offset = 0; if ((CommandType)Commands[i].Identifier == CommandType.Call || (CommandType)Commands[i].Identifier == CommandType.Jump) { offset = (int)((UInt24)Commands[i].Parameters[0]).Value; } else { offset = (int)((UInt24)Commands[i].Parameters[1]).Value; } //Get the index. int index = OffsetToCommandIndex(Commands, offset); //Set the property to this. if ((CommandType)Commands[i].Identifier == CommandType.Call || (CommandType)Commands[i].Identifier == CommandType.Jump) { ((UInt24)Commands[i].Parameters[0]).Value = (uint)index; } else { ((UInt24)Commands[i].Parameters[1]).Value = (uint)index; } } } } //Update private offsets. RefreshPrivateOffsets(); //Free. br.Dispose(); }
/// <summary> /// Load a wave file. /// </summary> /// <param name="b">The byte array.</param> public void Load(byte[] b) { //Read file. MemoryStream src = new MemoryStream(b); BinaryDataReader br = new BinaryDataReader(src); //Get byte order. br.ByteOrder = ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; br.Position = 4; if (br.ReadUInt16() == CitraFileLoader.ByteOrder.LittleEndian) { br.ByteOrder = ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian; } //Get version. ushort version = br.ReadUInt16(); Major = (byte)((version & 0xFF00) >> 8); Minor = (byte)(version & 0xFF); //Get num channels. br.Position = 0x0E; ushort numChannels = br.ReadUInt16(); ChannelPans = new ChannelPan[numChannels]; //Get codic. Reference:vgmstream/src/meta/bwav.c . br.Position = 0x10; Codic = br.ReadUInt16(); //Get info from first channel. br.Position = 0x12; ChannelPans[0] = (ChannelPan)br.ReadUInt16(); SampleRate = br.ReadUInt32(); NumSamples = br.ReadUInt32(); br.ReadUInt32(); DspAdpcmInfo = new DspAdpcmInfo[numChannels]; DspAdpcmInfo[0] = new DspAdpcmInfo(); DspAdpcmInfo[0].coefs = new short[8][]; DspAdpcmInfo[0].coefs[0] = br.ReadInt16s(2); DspAdpcmInfo[0].coefs[1] = br.ReadInt16s(2); DspAdpcmInfo[0].coefs[2] = br.ReadInt16s(2); DspAdpcmInfo[0].coefs[3] = br.ReadInt16s(2); DspAdpcmInfo[0].coefs[4] = br.ReadInt16s(2); DspAdpcmInfo[0].coefs[5] = br.ReadInt16s(2); DspAdpcmInfo[0].coefs[6] = br.ReadInt16s(2); DspAdpcmInfo[0].coefs[7] = br.ReadInt16s(2); //Start offsets. uint[] startOffsets = new uint[numChannels]; startOffsets[0] = br.ReadUInt32(); br.Position += 4; //Loop info. Loops = br.ReadUInt32() > 0; LoopEndSample = br.ReadUInt32(); LoopStartSample = br.ReadUInt32(); //More DSP info. DspAdpcmInfo[0].pred_scale = DspAdpcmInfo[0].loop_pred_scale = br.ReadUInt16(); DspAdpcmInfo[0].yn1 = DspAdpcmInfo[0].loop_yn1 = br.ReadInt16(); DspAdpcmInfo[0].yn2 = DspAdpcmInfo[0].loop_yn2 = br.ReadInt16(); //Read each channel start offset. for (int i = 1; i < numChannels; i++) { //Get channel pan. br.Position = i * 0x4C + 0x10 + 0x2; ChannelPans[i] = (ChannelPan)br.ReadUInt16(); //Start offset. br.Position = i * 0x4C + 0x10 + 0x30; startOffsets[i] = br.ReadUInt32(); //Get DSP info. br.Position = i * 0x4C + 0x10 + 0x10; DspAdpcmInfo[i] = new DspAdpcmInfo(); DspAdpcmInfo[i].coefs = new short[8][]; DspAdpcmInfo[i].coefs[0] = br.ReadInt16s(2); DspAdpcmInfo[i].coefs[1] = br.ReadInt16s(2); DspAdpcmInfo[i].coefs[2] = br.ReadInt16s(2); DspAdpcmInfo[i].coefs[3] = br.ReadInt16s(2); DspAdpcmInfo[i].coefs[4] = br.ReadInt16s(2); DspAdpcmInfo[i].coefs[5] = br.ReadInt16s(2); DspAdpcmInfo[i].coefs[6] = br.ReadInt16s(2); DspAdpcmInfo[i].coefs[7] = br.ReadInt16s(2); br.Position += 20; DspAdpcmInfo[i].pred_scale = DspAdpcmInfo[i].loop_pred_scale = br.ReadUInt16(); DspAdpcmInfo[i].yn1 = DspAdpcmInfo[i].loop_yn1 = br.ReadInt16(); DspAdpcmInfo[i].yn2 = DspAdpcmInfo[i].loop_yn2 = br.ReadInt16(); } //Read the wave data. Data = new SoundNStreamDataBlock(br, startOffsets); try { br.Dispose(); } catch { } try { src.Dispose(); } catch { } }