Example #1
0
        public override IImageDecoder OpenImage(ArcFile arc, Entry entry)
        {
            var aent = entry as AssetEntry;

            if (null == aent || aent.AssetObject.TypeId != 28)
            {
                return(base.OpenImage(arc, entry));
            }

            var obj = aent.AssetObject;

            using (var stream = arc.File.CreateStream(obj.Offset, obj.Size))
                using (var reader = new AssetReader(stream))
                {
                    reader.SetupReaders(obj.Asset);
                    var tex = new Texture2D();
                    tex.Load(reader);

                    var input = OpenEntry(arc, entry);
                    try
                    {
                        tex.m_Data = new byte[entry.Size];
                        input.Read(tex.m_Data, 0, tex.m_Data.Length);
                        var tex_reader = new AssetReader(input, entry.Name);
                        tex_reader.SetupReaders(obj.Asset);
                        return(new Texture2DDecoder(tex, tex_reader));
                    }
                    catch
                    {
                        input.Dispose();
                        throw;
                    }
                }
        }
Example #2
0
        public void Load(AssetReader input)
        {
            input.ReadInt32();  // header_size
            input.ReadUInt32(); // file_size
            m_format      = input.ReadInt32();
            m_data_offset = input.ReadUInt32();
            if (m_format >= 9)
            {
                m_is_little_endian = 0 == input.ReadInt32();
            }
            if (m_format >= 22)
            {
                input.ReadInt32();  // header_size
                input.ReadInt64();  // file_size
                m_data_offset = input.ReadInt64();
                input.ReadInt64();
            }
            input.SetupReaders(this);
            m_tree.Load(input);

            bool long_ids = Format >= 14;

            if (Format >= 7 && Format < 14)
            {
                long_ids = 0 != input.ReadInt32();
            }
            input.SetupReadId(long_ids);

            int obj_count = input.ReadInt32();

            for (int i = 0; i < obj_count; ++i)
            {
                input.Align();
                var obj = new UnityObject(this);
                obj.Load(input);
                RegisterObject(obj);
            }
            if (Format >= 11)
            {
                int count = input.ReadInt32();
                m_adds = new Dictionary <long, int> (count);
                for (int i = 0; i < count; ++i)
                {
                    input.Align();
                    var id = input.ReadId();
                    m_adds[id] = input.ReadInt32();
                }
            }
            if (Format >= 6)
            {
                int count = input.ReadInt32();
                m_refs = new List <AssetRef> (count);
                for (int i = 0; i < count; ++i)
                {
                    var asset_ref = AssetRef.Load(input);
                    m_refs.Add(asset_ref);
                }
            }
            input.ReadCString();
        }
Example #3
0
        public AssetReader Open(Stream input)
        {
            var stream = new StreamRegion(input, Offset, Size, true);
            var reader = new AssetReader(stream, "");

            reader.SetupReaders(Asset);
            return(reader);
        }
Example #4
0
        public override IImageDecoder OpenImage(ArcFile arc, Entry entry)
        {
            var aent = entry as AssetEntry;

            if (null == aent || aent.AssetObject.Type != "Texture2D")
            {
                return(base.OpenImage(arc, entry));
            }
            var    uarc  = (UnityBundle)arc;
            var    obj   = aent.AssetObject;
            Stream input = new BundleStream(uarc.File, uarc.Segments);

            input = new StreamRegion(input, obj.Offset, obj.Size);
            var reader = new AssetReader(input, entry.Name);

            reader.SetupReaders(obj.Asset);
            return(new Texture2DDecoder(reader));
        }
Example #5
0
        public override IImageDecoder OpenImage(ArcFile arc, Entry entry)
        {
            var aent = entry as AssetEntry;

            if (null == aent || aent.AssetObject.TypeName != "Texture2D")
            {
                return(base.OpenImage(arc, entry));
            }
            var uarc    = (UnityBundle)arc;
            var obj     = aent.AssetObject;
            var bundles = new BundleStream(uarc.File, uarc.Segments);
            var input   = new StreamRegion(bundles, obj.Offset, obj.Size);
            var reader  = new AssetReader(input, entry.Name);

            reader.SetupReaders(obj.Asset);
            Texture2D tex  = null;
            var       type = obj.Type;

            if (type != null && type.Children.Any(t => t.Type == "StreamingInfo"))
            {
                var fields = obj.Deserialize(reader);
                tex = new Texture2D();
                tex.Import(fields);
                var info = fields["m_StreamData"] as StreamingInfo;
                if (info != null)
                {
                    var bundle = uarc.Bundles.FirstOrDefault(b => VFS.IsPathEqualsToFileName(info.Path, b.Name));
                    if (bundle != null)
                    {
                        tex.m_DataLength = (int)info.Size;
                        input            = new StreamRegion(bundles, bundle.Offset + info.Offset, info.Size);
                        reader           = new AssetReader(input, entry.Name);
                    }
                }
            }
            if (null == tex)
            {
                tex = new Texture2D();
                tex.Load(reader);
            }
            return(new Texture2DDecoder(tex, reader));
        }
Example #6
0
        public override IImageDecoder OpenImage(ArcFile arc, Entry entry)
        {
            var aent = entry as AssetEntry;

            if (null == aent || aent.AssetObject.TypeId != 28)
            {
                return(base.OpenImage(arc, entry));
            }

            var obj    = aent.AssetObject;
            var stream = arc.File.CreateStream(obj.Offset, obj.Size);
            var reader = new AssetReader(stream);

            try
            {
                reader.SetupReaders(obj.Asset);
                var tex = new Texture2D();
                tex.Load(reader);
                if (0 == tex.m_DataLength)
                {
                    reader.Dispose();
                    var input = OpenEntry(arc, entry);
                    reader = new AssetReader(input, entry.Name);
                    reader.SetupReaders(obj.Asset);
                    tex.m_DataLength = (int)entry.Size;
                }
                var decoder = new Texture2DDecoder(tex, reader);
                reader = null;
                return(decoder);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
            }
        }