Exemplo n.º 1
0
 public ObjectItem(long id, int offset, int size, TypeTree typeTree)
 {
     this.ID       = id;
     this.Offset   = offset;
     this.Size     = size;
     this.TypeTree = typeTree;
 }
Exemplo n.º 2
0
        public ObjectInfo(ObjectArchive archive, long id, TypeTree tree, long offset, int size, bool isPublic) : base(archive)
        {
            this.ID       = id;
            this.IsPublic = isPublic;
            this.TypeTree = tree;

            this.dataSize   = size;
            this.dataOffset = offset;

            this.TypeID = this.TypeTree.TypeID;
            this.IsPotentialRedundancy = PotentialRedundancy();
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
 public TypeNode(TypeTree root)
 {
     this.Root = root;
 }