Esempio n. 1
0
        public virtual IObjectInfo GetObjectInfo(PPtr pptr)
        {
            if (pptr.FileID == 0 && pptr.PathID == 0)
            {
                return(new NullObjectInfo(pptr.TypeID));
            }

            if (pptr.FileID == 0)
            {
                ObjectInfo info = null;
                if (objects.TryGetValue(pptr.PathID, out info))
                {
                    return(info);
                }

                return(new MissingObjectInfo(this, pptr.PathID, pptr.TypeID));
            }

            ArchiveRef    assetRef = this.archiveRefs[pptr.FileID];
            ObjectArchive asset    = this.Bundle.GetAssetArchive(assetRef.FileName) as ObjectArchive;

            if (asset != null)
            {
                return(asset.GetObjectInfo(pptr.PathID));
            }

            var container = this.Bundle.ArchiveContainer;

            if (container == null)
            {
                return(new MissingObjectInfo(null, pptr.PathID, pptr.TypeID));
            }

            return(container.GetObjectInfo(assetRef.FileName, pptr.PathID));
        }
Esempio n. 2
0
        protected virtual void Load(ArchiveBinaryReader reader)
        {
            try
            {
                long startPos   = reader.BaseStream.Position;
                int  headerSize = reader.ReadInt32(true);
                var  fileSize   = reader.ReadInt32(true);
                this.Format          = reader.ReadInt32(true);
                this.assetDataOffset = reader.ReadUInt32(true);

                if (this.Format < 17)
                {
                    throw new NotSupportedException(string.Format("The AssetBundle's format not supported,format:{0}", this.Format));
                }

                bool bigEndian = reader.ReadBoolean();
                reader.IsBigEndian = bigEndian;
                reader.ReadBytes(3);
                this.Version        = reader.ReadCString();
                this.TargetPlatform = reader.ReadUInt32();

                //读取类型树
                var hasTypeTree = reader.ReadBoolean();
                if (!hasTypeTree)
                {
                    throw new NotSupportedException("Missing type tree, not supported");
                }

                Hash128 zero          = new Hash128(new byte[16]);
                var     typeTreeCount = reader.ReadInt32();
                for (var i = 0; i < typeTreeCount; i++)
                {
                    var typeId = reader.ReadInt32();
                    reader.ReadByte();
                    var scriptIndex    = reader.ReadInt16();
                    var hash           = reader.ReadHash128();
                    var propertiesHash = typeId == 114 ? reader.ReadHash128() : zero;
                    var tree           = new TypeTree(this, i, Enum.IsDefined(typeof(TypeID), typeId) ? (TypeID)typeId : TypeID.UnknownType, scriptIndex, hash, propertiesHash);
                    tree.Load(reader);
                    this.trees.Add(tree);
                }

                //读取对象信息
                var objectCount = reader.ReadInt32();
                List <ObjectItem> objectItems = new List <ObjectItem>();
                for (var i = 0; i < objectCount; i++)
                {
                    reader.Align(4);
                    var id       = reader.ReadInt64();
                    var offset   = reader.ReadInt32();
                    var size     = reader.ReadInt32();
                    var index    = reader.ReadInt32();
                    var typeTree = trees[index];
                    var item     = new ObjectItem(id, offset, size, typeTree);
                    objectItems.Add(item);
                }

                //自定义脚本预载表
                var scriptCount = reader.ReadInt32();
                for (int i = 0; i < scriptCount; i++)
                {
                    var fileID = reader.ReadInt32();
                    var pathID = reader.ReadInt64();
                    var pptr   = new PPtr(fileID, pathID, "PPtr<MonoScript>");
                    this.preloadScripts.Add(pptr);
                }

                //读取共享对象
                int refCount = reader.ReadInt32();
                for (int i = 1; i <= refCount; i++)
                {
                    var name     = reader.ReadCString();
                    var guid     = reader.ReadHash128();
                    var type     = reader.ReadInt32();
                    var fileName = reader.ReadCString();
                    fileName = string.IsNullOrEmpty(fileName) ? "" : fileName.ToLower();
                    var assetRef = new ArchiveRef(i, name, type, guid, fileName);
                    this.archiveRefs.Add(assetRef);
                }

                foreach (var item in objectItems)
                {
                    TypeID typeId = item.TypeTree.TypeID;
                    if (typeId != TypeID.AssetBundle && typeId != TypeID.PreloadData)
                    {
                        continue;
                    }

                    ObjectInfo info = new ObjectInfo(this, item.ID, item.TypeTree, item.Offset, item.Size, false);
                    if (info.TypeID == TypeID.AssetBundle)
                    {
                        AssetBundle assetBundle = info.GetObject <AssetBundle>();
                        this.AssetBundle   = assetBundle;
                        Bundle.AssetBundle = assetBundle;
                    }
                    else if (info.TypeID == TypeID.PreloadData)
                    {
                        PreloadData preloadData = info.GetObject <PreloadData>();
                        this.PreloadData = preloadData;
                    }
                }

                foreach (var item in objectItems)
                {
                    TypeID typeId = item.TypeTree.TypeID;
                    if (typeId == TypeID.AssetBundle || typeId == TypeID.PreloadData)
                    {
                        continue;
                    }

                    bool       isPublic = !this.Bundle.IsStreamed && this.AssetBundle != null && this.AssetBundle.IsPublic(item.ID);
                    ObjectInfo info     = new ObjectInfo(this, item.ID, item.TypeTree, item.Offset, item.Size, isPublic);
                    this.objects.Add(info.ID, info);

                    if (info.IsPotentialRedundancy)
                    {
                        reader.BaseStream.Seek(this.assetDataOffset + item.Offset, SeekOrigin.Begin);
                        FeatureInfo featureInfo = this.extractor.Extract(info, reader);
                        info.Fingerprint = new PropertiesFingerprint(info, featureInfo.References, featureInfo.PropertyHash);
                        info.Name        = featureInfo.Name;
                        info.Resources   = featureInfo.Resources;
                    }
                    else
                    {
                        info.Fingerprint = new IdentifierFingerprint(info.ID, this.Name);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat("{0}", e);
            }
        }