Exemplo n.º 1
0
        public override ArcFile TryOpen(ArcView file)
        {
            uint signature = file.View.ReadUInt32(0);

            if (0x53474d != (signature & 0xffffff)) // 'MGS'
            {
                return(null);
            }
            int count = file.View.ReadInt16(0x20);

            if (count <= 0)
            {
                return(null);
            }
            int flag         = file.View.ReadUInt16(3);
            var dir          = new List <Entry> (count);
            int index_offset = 0x22;

            byte[] name_buf = new byte[16];
            for (uint i = 0; i < count; ++i)
            {
                ushort channels  = file.View.ReadUInt16(index_offset + 1);
                uint   rate      = file.View.ReadUInt32(index_offset + 3);
                ushort bits      = file.View.ReadUInt16(index_offset + 7);
                int    name_size = file.View.ReadByte(index_offset + 9);
                if (0 == name_size)
                {
                    return(null);
                }
                if (name_size > name_buf.Length)
                {
                    Array.Resize(ref name_buf, name_size);
                }
                file.View.Read(index_offset + 10, name_buf, 0, (uint)name_size);
                if (100 == flag)
                {
                    MgdOpener.Decrypt(name_buf, 0, name_size);
                }
                index_offset += 10 + name_size;

                var entry = new MgsEntry
                {
                    Name             = Encodings.cp932.GetString(name_buf, 0, name_size) + ".wav",
                    Type             = "audio",
                    Size             = file.View.ReadUInt32(index_offset),
                    Offset           = file.View.ReadUInt32(index_offset + 4),
                    Channels         = channels,
                    SamplesPerSecond = rate,
                    BitsPerSample    = bits,
                };
                if (!entry.CheckPlacement(file.MaxOffset))
                {
                    return(null);
                }
                dir.Add(entry);
                index_offset += 8;
            }
            return(new ArcFile(file, this, dir));
        }
Exemplo n.º 2
0
        public PcmDecoder(MgsEntry went)
        {
            Channels      = went.Channels & 0x7FFF;
            BytesPerChunk = went.BitsPerSample;
            int output_size;

            if (1 == Channels)
            {
                output_size = (int)went.Size / BytesPerChunk * ((BytesPerChunk - 4) * 4 + 2);
            }
            else
            {
                output_size = (int)went.Size / BytesPerChunk * ((BytesPerChunk - 8) * 4 + 4);
            }
            m_output = new byte[output_size];
        }
Exemplo n.º 3
0
        public override ArcFile TryOpen(ArcView file)
        {
            uint signature = file.View.ReadUInt32 (0);
            if (0x53474d != (signature & 0xffffff)) // 'MGS'
                return null;
            int count = file.View.ReadInt16 (0x20);
            if (count <= 0)
                return null;
            int flag = file.View.ReadUInt16 (3);
            var dir = new List<Entry> (count);
            int index_offset = 0x22;
            byte[] name_buf = new byte[16];
            for (uint i = 0; i < count; ++i)
            {
                ushort channels = file.View.ReadUInt16 (index_offset+1);
                uint rate = file.View.ReadUInt32 (index_offset+3);
                ushort bits = file.View.ReadUInt16 (index_offset+7);
                int name_size = file.View.ReadByte (index_offset+9);
                if (0 == name_size)
                    return null;
                if (name_size > name_buf.Length)
                    Array.Resize (ref name_buf, name_size);
                file.View.Read (index_offset+10, name_buf, 0, (uint)name_size);
                if (100 == flag)
                    MgdOpener.Decrypt (name_buf, 0, name_size);
                index_offset += 10 + name_size;

                var entry = new MgsEntry
                {
                    Name = Encodings.cp932.GetString (name_buf, 0, name_size) + ".wav",
                    Type = "audio",
                    Size = file.View.ReadUInt32 (index_offset),
                    Offset = file.View.ReadUInt32 (index_offset + 4),
                    Channels = channels,
                    SamplesPerSecond = rate,
                    BitsPerSample = bits,
                };
                if (!entry.CheckPlacement (file.MaxOffset))
                    return null;
                dir.Add (entry);
                index_offset += 8;
            }
            return new ArcFile (file, this, dir);
        }