Exemplo n.º 1
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            uint signature = ~FormatCatalog.ReadSignature(stream);
            int  bpp;

            switch (signature)
            {
            case 0x4c4c5546: /* fall through */
            case 0x45555254: bpp = 24; break;

            case 0x48474948: bpp = 16; break;

            default: return(null);
            }
            using (var input = new BinaryReader(stream, Encoding.ASCII, true))
            {
                uint width  = input.ReadUInt16();
                uint height = input.ReadUInt16();
                return(new ImageMetaData {
                    Width = width,
                    Height = height,
                    BPP = bpp,
                });
            }
        }
Exemplo n.º 2
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (!file.Name.HasExtension(".ads"))
            {
                return(null);
            }
            var arc_name = Path.GetFileNameWithoutExtension(file.Name);

            foreach (var key in KnownKeys.Values)
            {
                using (var arc = new EncryptedViewStream(file, key))
                {
                    uint signature = FormatCatalog.ReadSignature(arc);
                    if (2 == signature || 4 == signature || 5 == signature)
                    {
                        var dir = ReadIndex(arc, key, arc_name);
                        if (dir != null)
                        {
                            return(new AdsArchive(file, this, dir, key));
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        public override SoundInput TryOpen(Stream file)
        {
            uint signature = FormatCatalog.ReadSignature(file);

            if (0x80 != (signature & 0xFFFF))
            {
                return(null);
            }
            uint header_size = Binary.BigEndian(signature & 0xFFFF0000);

            if (header_size < 0x10 || header_size >= file.Length)
            {
                return(null);
            }
            var header = new byte[header_size];

            if (header.Length != file.Read(header, 0, header.Length))
            {
                return(null);
            }
            if (!Binary.AsciiEqual(header, header.Length - 6, "(c)CRI"))
            {
                return(null);
            }

            return(new AdxInput(file, header));
        }
Exemplo n.º 4
0
        uint WriteImageEntry(PackedEntry entry, Stream input, Stream output)
        {
            var grp = s_grp_format.Value;

            if (null == grp) // probably never happens
            {
                throw new FileFormatException("GRP image encoder not available");
            }
            bool is_grp = grp.Signature == FormatCatalog.ReadSignature(input);

            input.Position = 0;
            var start = output.Position;

            using (var zstream = new ZLibStream(output, CompressionMode.Compress, CompressionLevel.Level9, true))
            {
                if (is_grp)
                {
                    input.CopyTo(zstream);
                }
                else
                {
                    var image = ImageFormat.Read(input);
                    if (null == image)
                    {
                        throw new InvalidFormatException(string.Format(arcStrings.MsgInvalidImageFormat, entry.Name));
                    }
                    grp.Write(zstream, image);
                    entry.UnpackedSize = (uint)zstream.TotalIn;
                }
            }
            return((uint)(output.Position - start));
        }
Exemplo n.º 5
0
        public override SoundInput TryOpen(Stream file)
        {
            uint signature = FormatCatalog.ReadSignature(file) & 0xF0FFFFFF;

            if (0x564157 != signature) // 'WAV'
            {
                return(null);
            }
            return(new PcmInput(file));
        }
Exemplo n.º 6
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            uint unpacked_size = FormatCatalog.ReadSignature(stream);

            if (unpacked_size <= 0x20 || unpacked_size > 0x5000000) // ~83MB
            {
                return(null);
            }
            using (var lzss = new LzssStream(stream, LzssMode.Decompress, true))
                using (var input = new SeekableStream(lzss))
                    return(base.ReadMetaData(input));
        }
Exemplo n.º 7
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            var header = new byte[0x10];

            if (0x10 != stream.Read(header, 0, 0x10))
            {
                return(null);
            }
            int unpacked_size = LittleEndian.ToInt32(header, 8);

            using (var alb = new AlbStream(stream, unpacked_size))
                using (var file = new SeekableStream(alb))
                {
                    uint signature = FormatCatalog.ReadSignature(file);
                    file.Position = 0;
                    ImageFormat format;
                    if (ImageFormat.Png.Signature == signature)
                    {
                        format = ImageFormat.Png;
                    }
                    else if (Dds.Value.Signature == signature)
                    {
                        format = Dds.Value;
                    }
                    else
                    {
                        format = ImageFormat.Jpeg;
                    }
                    var info = format.ReadMetaData(file);
                    if (null == info)
                    {
                        return(null);
                    }
                    return(new AlbMetaData
                    {
                        Width = info.Width,
                        Height = info.Height,
                        OffsetX = info.OffsetX,
                        OffsetY = info.OffsetY,
                        BPP = info.BPP,
                        Format = format,
                        Info = info,
                        UnpackedSize = unpacked_size,
                    });
                }
        }
Exemplo n.º 8
0
        public override ScriptData Read(string name, Stream stream)
        {
            if (Signature != FormatCatalog.ReadSignature(stream))
            {
                return(null);
            }
            uint script_id  = Convert.ToUInt32(name, 16);
            uint max_offset = (uint)Math.Min(stream.Length, 0xffffffff);

            using (var file = new BinaryReader(stream, Encodings.cp932, true))
            {
                uint script_type = file.ReadUInt32();
                var  script      = new AmiScriptData {
                    Id   = script_id,
                    Type = script_type
                };
                uint count = file.ReadUInt32();
                for (uint i = 0; i < count; ++i)
                {
                    uint offset = file.ReadUInt32();
                    if (offset >= max_offset)
                    {
                        throw new InvalidFormatException("Invalid offset in script data file");
                    }
                    int  size       = file.ReadInt32();
                    uint id         = file.ReadUInt32();
                    var  header_pos = file.BaseStream.Position;
                    file.BaseStream.Position = offset;
                    byte[] line = file.ReadBytes(size);
                    if (line.Length != size)
                    {
                        throw new InvalidFormatException("Premature end of file");
                    }
                    string text = Encodings.cp932.GetString(line);

                    script.TextLines.Add(new ScriptLine {
                        Id = id, Text = text
                    });
                    file.BaseStream.Position = header_pos;
                }
                return(script);
            }
        }
Exemplo n.º 9
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var input = arc.File.CreateStream(entry.Offset, entry.Size);

            if (entry.Size <= 8)
            {
                return(input);
            }
            var sign = FormatCatalog.ReadSignature(input);

            if (0x32434c5a != sign) // 'ZLC2'
            {
                input.Position = 0;
                return(input);
            }
            using (input)
                using (var reader = new Zlc2Reader(input, (int)entry.Size))
                {
                    reader.Unpack();
                    return(new MemoryStream(reader.Data));
                }
        }
Exemplo n.º 10
0
        }                                                        // 'RIFF'

        public override ImageMetaData ReadMetaData(Stream stream)
        {
            // 'RIFF' isn't included into signature to avoid auto-detection of the WAV files as IPH images.
            if (0x46464952 != FormatCatalog.ReadSignature(stream))  // 'RIFF'
            {
                return(null);
            }
            using (var reader = new ArcView.Reader(stream))
            {
                if (0x38 != reader.ReadInt32())
                {
                    return(null);
                }
                var signature = reader.ReadInt32();
                if (signature != 0x20485049 && signature != 0x00485049) // 'IPH'
                {
                    return(null);
                }
                if (0x20746D66 != reader.ReadInt32()) // 'fmt '
                {
                    return(null);
                }
                reader.BaseStream.Position = 0x38;
                if (0x20706D62 != reader.ReadInt32()) // 'bmp '
                {
                    return(null);
                }
                var info = new IphMetaData();
                info.PackedSize            = reader.ReadInt32();
                info.Width                 = reader.ReadUInt16();
                info.Height                = reader.ReadUInt16();
                reader.BaseStream.Position = 0x50;
                info.BPP          = reader.ReadUInt16();
                info.IsCompressed = 0 != reader.ReadInt16();
                // XXX int16@[0x54] is a transparency color or 0xFFFF if image is not transparent
                return(info);
            }
        }
Exemplo n.º 11
0
 public override ArcFile TryOpen(ArcView file)
 {
     if (!file.Name.EndsWith(".ads", StringComparison.InvariantCultureIgnoreCase))
     {
         return(null);
     }
     foreach (var key in KnownKeys.Values)
     {
         using (var arc = new EncryptedViewStream(file, key))
         {
             uint signature = FormatCatalog.ReadSignature(arc);
             if (2 == signature || 4 == signature || 5 == signature)
             {
                 var dir = ReadIndex(arc, key);
                 if (dir != null)
                 {
                     return(new AdsArchive(file, this, dir, key));
                 }
             }
         }
     }
     return(null);
 }
Exemplo n.º 12
0
        public override SoundInput TryOpen(Stream file)
        {
            uint offset = 4 + Binary.BigEndian(FormatCatalog.ReadSignature(file));

            return(base.TryOpen(new StreamRegion(file, offset)));
        }