예제 #1
0
 /// <summary>
 // Try to parse file containing game meta-information.
 /// </summary>
 internal string TryParseMeta(string meta_arc_name)
 {
     if (!VFS.FileExists(meta_arc_name))
     {
         return(null);
     }
     using (var unpacker = new TocUnpacker(meta_arc_name))
     {
         if (unpacker.Length > 0x1000)
         {
             return(null);
         }
         var data = unpacker.Unpack(8);
         if (null == data)
         {
             return(null);
         }
         using (var content = new BinMemoryStream(data))
         {
             int title_length = content.ReadInt32();
             if (title_length <= 0 || title_length > content.Length)
             {
                 return(null);
             }
             var title = content.ReadBytes(title_length);
             if (title.Length != title_length)
             {
                 return(null);
             }
             return(Encodings.cp932.GetString(title));
         }
     }
 }
예제 #2
0
파일: AudioFSB5.cs 프로젝트: zxc120/GARbro
        SoundInput RebuildVorbis(Sample sample)
        {
            if (!sample.MetaData.ContainsKey(ChunkType.VorbisData))
            {
                throw new InvalidFormatException("No VORBISDATA chunk in FSB5 Vorbis stream.");
            }
            var vorbis_data = sample.MetaData[ChunkType.VorbisData] as VorbisData;
            var setup_data  = GetVorbisHeader(vorbis_data.Crc32);
            var state       = new OggStreamState(1);

            var id_packet      = RebuildIdPacket(sample, 0x100, 0x800);
            var comment_packet = RebuildCommentPacket();
            var setup_packet   = RebuildSetupPacket(setup_data);
            var info           = CreateVorbisInfo(sample, setup_packet);

            var output = new MemoryStream();

            state.PacketIn(id_packet);
            state.Write(output);
            state.PacketIn(comment_packet);
            state.Write(output);
            state.PacketIn(setup_packet);
            state.Write(output);
            state.Flush(output);

            long packet_no       = setup_packet.PacketNo + 1;
            long granule_pos     = 0;
            int  prev_block_size = 0;

            using (var input = new BinMemoryStream(sample.Data))
            {
                var packet      = new OggPacket();
                int packet_size = ReadPacketSize(input);
                while (packet_size > 0)
                {
                    packet.SetPacket(packet_no++, input.ReadBytes(packet_size));
                    packet_size = ReadPacketSize(input);
                    packet.EoS  = 0 == packet_size;

                    int block_size = info.PacketBlockSize(packet);
                    if (prev_block_size != 0)
                    {
                        granule_pos += (block_size + prev_block_size) / 4;
                    }
                    else
                    {
                        granule_pos = 0;
                    }
                    packet.GranulePos = granule_pos;
                    prev_block_size   = block_size;

                    state.PacketIn(packet);
                    state.Write(output);
                }
            }
            output.Position = 0;
            return(new OggInput(output));
        }
예제 #3
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (!file.View.AsciiEqual(4, "ARC\0"))
            {
                return(null);
            }
            uint data_offset   = file.View.ReadUInt32(8);
            uint unpacked_size = file.View.ReadUInt32(0xC);
            uint packed_size   = file.View.ReadUInt32(0x10);

            byte[] unpacked = new byte[unpacked_size];
            using (var packed = file.CreateStream(0x14, packed_size))
                using (var input = new XoredStream(packed, 0xFF))
                {
                    LzssUnpack(input, unpacked);
                }
            using (var index = new BinMemoryStream(unpacked))
            {
                var key   = index.ReadBytes(256);
                int count = index.ReadInt32();
                if (!IsSaneCount(count))
                {
                    return(null);
                }
                var dir = new List <Entry> (count);
                for (int i = 0; i < count; ++i)
                {
                    int name_length = index.ReadInt32();
                    var name        = index.ReadCString(name_length);
                    var entry       = FormatCatalog.Instance.Create <GmlEntry> (name);
                    entry.Offset = index.ReadUInt32() + data_offset;
                    entry.Size   = index.ReadUInt32();
                    if (!entry.CheckPlacement(file.MaxOffset))
                    {
                        return(null);
                    }
                    dir.Add(entry);
                    entry.Header = index.ReadBytes(4);
                }
                return(new GmlArchive(file, this, dir, key));
            }
        }