public ArchiveRef(int id, string name, int type, Hash128 guid, string fileName) { this.ID = id; this.Name = name; this.Type = type; this.GUID = guid; this.FileName = fileName; }
public PropertiesFingerprint(ObjectInfo info, List <PPtr> pptrs, Hash128 propertyHash) { this.info = info; this.pptrs.AddRange(pptrs); this.PropertyHash = propertyHash; }
protected virtual IList ParseArray(TypeNode typeNode, int size, ArchiveBinaryReader reader) { switch (typeNode.TypeFlag) { case "bool": { bool[] result = new bool[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadBoolean(); if (typeNode.IsAlign) { reader.Align(4); } } return(result); } case "SInt8": { sbyte[] result = new sbyte[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadSByte(); } return(result); } case "char": case "UInt8": { if (size <= 0) { return(new byte[0]); } return(reader.ReadBytes(size)); } case "short": case "SInt16": { short[] result = new short[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadInt16(); } return(result); } case "unsigned short": case "UInt16": { ushort[] result = new ushort[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadUInt16(); } return(result); } case "int": case "SInt32": { int[] result = new int[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadInt32(); } return(result); } case "unsigned int": case "UInt32": case "Type*": { uint[] result = new uint[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadUInt32(); } return(result); } case "long long": case "SInt64": { long[] result = new long[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadInt64(); } return(result); } case "unsigned long long": case "UInt64": { ulong[] result = new ulong[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadUInt64(); } return(result); } case "float": { float[] result = new float[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadSingle(); } return(result); } case "double": { double[] result = new double[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadDouble(); } return(result); } case "Quaternionf": { Quaternion[] result = new Quaternion[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadQuaternion(); } return(result); } case "float4": case "Vector4f": { Vector4[] result = new Vector4[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadVector4(); } return(result); } case "float3": case "Vector3f": { Vector3[] result = new Vector3[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadVector3(); } return(result); } case "float2": case "Vector2f": { Vector2[] result = new Vector2[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadVector2(); } return(result); } case "ColorRGBA": { Color[] result = new Color[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadColor(); } return(result); } case "Matrix4x4f": { Matrix4x4[] result = new Matrix4x4[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadMatrix4x4(); } return(result); } case "Hash128": { Hash128[] result = new Hash128[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadHash128(); } return(result); } case "string": { string[] result = new string[size]; for (int i = 0; i < size; i++) { result[i] = reader.ReadString(); } return(result); } default: { object[] result = new object[size]; for (int i = 0; i < size; i++) { result[i] = this.Parse(typeNode, reader); } return(result); } } }
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); } }