示例#1
0
        public override ArcFile TryOpen(ArcView file)
        {
            int format_count = file.View.ReadUInt16(4);
            int count        = file.View.ReadUInt16(6);

            if (0 == format_count || 0 == count)
            {
                return(null);
            }
            uint index_offset = 8;
            long base_offset  = index_offset + format_count * 0x14 + count * 0x18;

            if (base_offset >= file.MaxOffset)
            {
                return(null);
            }
            var formats = new List <WaveFormat> (format_count);

            for (int i = 0; i < format_count; ++i)
            {
                var format = new WaveFormat
                {
                    FormatTag             = file.View.ReadUInt16(index_offset),
                    Channels              = file.View.ReadUInt16(index_offset + 2),
                    SamplesPerSecond      = file.View.ReadUInt32(index_offset + 4),
                    AverageBytesPerSecond = file.View.ReadUInt32(index_offset + 8),
                    BitsPerSample         = file.View.ReadUInt16(index_offset + 12),
                    BlockAlign            = file.View.ReadUInt16(index_offset + 14),
                };
                index_offset += 0x14;
                formats.Add(format);
            }
            var dir = new List <Entry> (count);

            for (int i = 0; i < count; ++i)
            {
                int fmt_index = file.View.ReadUInt16(index_offset);
                if (fmt_index > formats.Count)
                {
                    return(null);
                }
                string name  = file.View.ReadString(index_offset + 2, 0x0A);
                var    entry = new PkwEntry
                {
                    Name     = name + ".wav",
                    Type     = "audio",
                    Offset   = base_offset + file.View.ReadInt64(index_offset + 0x10),
                    Size     = file.View.ReadUInt32(index_offset + 0x0C),
                    IsPacked = true,
                    Format   = formats[fmt_index],
                };
                if (!entry.CheckPlacement(file.MaxOffset))
                {
                    return(null);
                }
                entry.UnpackedSize = entry.Size + WaveHeaderSize;
                dir.Add(entry);
                index_offset += 0x18;
            }
            return(new ArcFile(file, this, dir));
        }
示例#2
0
文件: ArcPCK.cs 项目: Casidi/GARbro
 public override ArcFile TryOpen(ArcView file)
 {
     int format_count = file.View.ReadUInt16 (4);
     int count = file.View.ReadUInt16 (6);
     if (0 == format_count || 0 == count)
         return null;
     uint index_offset = 8;
     long base_offset = index_offset + format_count*0x14 + count*0x18;
     if (base_offset >= file.MaxOffset)
         return null;
     var formats = new List<WaveFormat> (format_count);
     for (int i = 0; i < format_count; ++i)
     {
         var format = new WaveFormat
         {
             FormatTag               = file.View.ReadUInt16 (index_offset),
             Channels                = file.View.ReadUInt16 (index_offset+2),
             SamplesPerSecond        = file.View.ReadUInt32 (index_offset+4),
             AverageBytesPerSecond   = file.View.ReadUInt32 (index_offset+8),
             BitsPerSample           = file.View.ReadUInt16 (index_offset+12),
             BlockAlign              = file.View.ReadUInt16 (index_offset+14),
         };
         index_offset += 0x14;
         formats.Add (format);
     }
     var dir = new List<Entry> (count);
     for (int i = 0; i < count; ++i)
     {
         int fmt_index = file.View.ReadUInt16 (index_offset);
         if (fmt_index > formats.Count)
             return null;
         string name = file.View.ReadString (index_offset+2, 0x0A);
         var entry = new PkwEntry
         {
             Name = name + ".wav",
             Type = "audio",
             Offset = base_offset + file.View.ReadInt64 (index_offset+0x10),
             Size = file.View.ReadUInt32 (index_offset+0x0C),
             IsPacked = true,
             Format = formats[fmt_index],
         };
         if (!entry.CheckPlacement (file.MaxOffset))
             return null;
         entry.UnpackedSize = entry.Size + WaveHeaderSize;
         dir.Add (entry);
         index_offset += 0x18;
     }
     return new ArcFile (file, this, dir);
 }