Example #1
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var    uarc  = (UnityBundle)arc;
            Stream input = new BundleStream(uarc.File, uarc.Segments);

            input = new StreamRegion(input, entry.Offset, entry.Size);
            var aent = entry as AssetEntry;

            if (null == aent || !aent.IsEncrypted)
            {
                return(input);
            }
            using (input)
            {
                var data = new byte[entry.Size];
                input.Read(data, 0, data.Length);
                DecryptAsset(data);
                return(new BinMemoryStream(data));
            }
        }
Example #2
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            var header = new byte[0x40];

            if (header.Length != stream.Read(header, 0, header.Length))
            {
                return(null);
            }
            if (!Binary.AsciiEqual(header, 4, "00\0\0"))
            {
                return(null);
            }
            var ykg = new YkgMetaData {
                DataOffset = LittleEndian.ToUInt32(header, 0x28),
                DataSize   = LittleEndian.ToUInt32(header, 0x2C)
            };

            if (0 == ykg.DataOffset)
            {
                ykg.DataOffset = LittleEndian.ToUInt32(header, 8);
            }
            if (ykg.DataOffset < 0x30)
            {
                return(null);
            }
            if (0 == ykg.DataSize)
            {
                ykg.DataSize = (uint)(stream.Length - ykg.DataOffset);
            }
            ImageMetaData info = null;

            using (var img = new StreamRegion(stream, ykg.DataOffset, ykg.DataSize, true))
            {
                if (4 != img.Read(header, 0, 4))
                {
                    return(null);
                }
                if (Binary.AsciiEqual(header, "BM"))
                {
                    img.Position = 0;
                    info         = ImageFormat.Bmp.ReadMetaData(img);
                    ykg.Format   = YkgImage.Bmp;
                }
                else if (Binary.AsciiEqual(header, "\x89PNG"))
                {
                    img.Position = 0;
                    info         = Png.ReadMetaData(img);
                    ykg.Format   = YkgImage.Png;
                }
                else if (Binary.AsciiEqual(header, "\x89GNP"))
                {
                    using (var body = new StreamRegion(stream, ykg.DataOffset + 4, ykg.DataSize - 4, true))
                        using (var png = new PrefixStream(PngPrefix, body))
                            info = Png.ReadMetaData(png);
                    ykg.Format = YkgImage.Gnp;
                }
            }
            if (null == info)
            {
                return(null);
            }
            ykg.Width   = info.Width;
            ykg.Height  = info.Height;
            ykg.BPP     = info.BPP;
            ykg.OffsetX = info.OffsetX;
            ykg.OffsetY = info.OffsetY;
            return(ykg);
        }
Example #3
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     var header = new byte[0x40];
     if (header.Length != stream.Read (header, 0, header.Length))
         return null;
     if (!Binary.AsciiEqual (header, 4, "00\0\0"))
         return null;
     var ykg = new YkgMetaData {
         DataOffset = LittleEndian.ToUInt32 (header, 0x28),
         DataSize   = LittleEndian.ToUInt32 (header, 0x2C)
     };
     if (0 == ykg.DataOffset)
         ykg.DataOffset = LittleEndian.ToUInt32 (header, 8);
     if (ykg.DataOffset < 0x30)
         return null;
     if (0 == ykg.DataSize)
         ykg.DataSize = (uint)(stream.Length - ykg.DataOffset);
     ImageMetaData info = null;
     using (var img = new StreamRegion (stream, ykg.DataOffset, ykg.DataSize, true))
     {
         if (4 != img.Read (header, 0, 4))
             return null;
         if (Binary.AsciiEqual (header, "BM"))
         {
             img.Position = 0;
             info = ImageFormat.Bmp.ReadMetaData (img);
             ykg.Format = YkgImage.Bmp;
         }
         else if (Binary.AsciiEqual (header, "\x89PNG"))
         {
             img.Position = 0;
             info = Png.ReadMetaData (img);
             ykg.Format = YkgImage.Png;
         }
         else if (Binary.AsciiEqual (header, "\x89GNP"))
         {
             using (var body = new StreamRegion (stream, ykg.DataOffset+4, ykg.DataSize-4, true))
             using (var png = new PrefixStream (PngPrefix, body))
                 info = Png.ReadMetaData (png);
             ykg.Format = YkgImage.Gnp;
         }
     }
     if (null == info)
         return null;
     ykg.Width = info.Width;
     ykg.Height = info.Height;
     ykg.BPP = info.BPP;
     ykg.OffsetX = info.OffsetX;
     ykg.OffsetY = info.OffsetY;
     return ykg;
 }