ObjectData GetObjectDataFromPtr(object ptr) { PPtrObject pobj = new PPtrObject(); pobj.m_FileID = -1; pobj.m_PathID = -1; if (ptr.GetType() == typeof(PPtrObject)) { pobj = (PPtrObject)ptr; } else if (ptr.GetType() == typeof(AssetInfo)) { AssetInfo ai = (AssetInfo)ptr; pobj = ai.asset; } if (pobj.m_FileID >= 0 && pobj.m_FileID < afnames.Length) { string assetfilename = afnames[pobj.m_FileID]; AssetFileEx af = afs[assetfilename]; Dictionary <long, ObjectData> ods = af.objects; if (ods.ContainsKey(pobj.m_PathID)) { ObjectData od = ods[pobj.m_PathID]; return(od); } } return(null); }
public void ReadFolder(string folder, string[] filter) { extractFiles(folder + "\\Resources", "*.", filter); extractFiles(folder, "resources.assets", filter); extractFiles(folder, "maindata.", filter); extractFiles(folder, "*.assets", filter); extractFiles(folder, "*.", filter); if (afs.Count > 0) { foreach (KeyValuePair <string, AssetFileEx> pair in afs) { AssetFileEx af = pair.Value; if (af != null) { ObjectData abod = null; if (af.extractlist.ContainsKey("ResourceManager")) { abod = af.extractlist["ResourceManager"][0]; if (abod.instance != null) { m_Container = (Dictionary <object, object>)abod.instance.getObject("m_Container"); m_DependentAssets = GenerateDependentMap((List <object>)abod.instance.getObject("m_DependentAssets")); } break; } } } } AttachContainData(); }
//throws IOException public void loadExternals(Dictionary <string, AssetFileEx> loadedAssets) { foreach (FileIdentifier external in externalsStruct.fileIDs) { String filePath = external.filePath; if (filePath == null || filePath.Length <= 0) { continue; } filePath = filePath.Replace("library/", "resources/"); string folder = Path.GetDirectoryName(sourceFile); string refFile = Path.Combine(folder, filePath);// sourceFile.resolveSibling(filePath); string refName = Path.GetFileNameWithoutExtension(refFile); if (File.Exists(refFile) && loadedAssets.ContainsKey(refName) == false) { Logger.Log("Loading dependency {0} for {1}" + new object[] { refFile, sourceFile }); AssetFileEx childAsset = new AssetFileEx(); bool ret = childAsset.load(refFile); if (ret) { loadedAssets[refName] = childAsset; childAsset.loadExternals(loadedAssets); external.assetFile = childAsset; } } } }
//private void TravellObjectData(ObjectData srcod) //{ // if (srcod.instance != null) // { // TravellObjectDataNode(srcod, srcod.instance); // } //} //private void TravellObjectDataValue(ObjectData srcod, object val) //{ // if (val != null) // { // if (val is PPtrObject || val is AssetInfo) // { // ObjectData od = GetObjectDataFromPtr(val); // if (od != null) // { // if (od.path == null || od.path.Length <= 0) // { // od.path = srcod.path; // } // } // } // } //} //private void TravellObjectDataNode(ObjectData srcod, FieldNode node) //{ // object val = node.value; // TravellObjectDataValue(srcod, val); // Dictionary<String, FieldNode> childnodes = node.getChilds(); // if (childnodes == null) return; // foreach (KeyValuePair<string, FieldNode> keypair in childnodes) // { // FieldNode childnode = keypair.Value; // TravellObjectDataNode(srcod, childnode); // } //} private void extractFile(Stream news, string path, string[] filter) { DataReader inr = new DataReader(news); AssetFileEx af = new AssetFileEx(); af.sourceFile = path; if (filter != null) { foreach (string type in filter) { af.extractTypes[type] = false; } } bool ret = af.load(inr); if (ret) { afs[af.sourceFile] = af; af.loadExternals(afs); } }
public static void embedTypes(AssetFileEx asset) { UnityVersion unityRevision = asset.versionInfo.unityRevision; if (unityRevision == null) { Logger.Log("unityRevision = null"); return; } Dictionary <long, ObjectData> objects = asset.objects; Dictionary <int, EmbeddedTypeInfo> typemap = asset.embeddedTypeMap; foreach (KeyValuePair <long, ObjectData> pair in objects) { ObjectData obj = pair.Value; int typeID = obj.typeID; // skip types that already exist if (typemap.ContainsKey(typeID)) { continue; } TypeNode typeNode = getTypeNode(obj, false); // remove objects with no type tree, which would crash the editor // when loading the file otherwise if (typeNode == null) { Logger.Log("Removing object {0} with unresolvable type {1}" + new Object[] { obj, typeID }); //objectIter.remove(); continue; } typemap[typeID].typeTree = typeNode; } }
public void ReadPackage(Stream inputs, string[] filter) { //DataReaders.forFile(file, READ inr = new DataReader(inputs, Encoding.ASCII); readheader(inr); // check signature if (!hasValidSignature()) { throw new Exception("Invalid signature"); } if (dataHeaderSize == 0) { // old stream versions don't store the data header size, so use a large // fixed number instead dataHeaderSize = 4096; } MemoryStream unzips = getDataInputStream(0, dataHeaderSize); //DataReader inData = DataReaders.forInputStream(is); //int files = inData.readInt(); DataReader inData = new DataReader(unzips, Encoding.ASCII); int files = inData.readInt(); for (int i = 0; i < files; i++) { AssetBundleEntryInfo info = new AssetBundleEntryInfo(); info.read(inData); entryInfos.Add(info); } //// sort entries by offset so that they're in the order in which they //// appear in the file, which is convenient for compressed bundles //Collections.sort(entryInfos, new EntryComparator()); //for (AssetBundleEntryInfo entryInfo : entryInfos) { // entries.add(new AssetBundleInternalEntry(this, entryInfo)); //} foreach (AssetBundleEntryInfo info in entryInfos) { MemoryStream newms = new MemoryStream(unzips.GetBuffer(), (int)info.offset, (int)info.size); extractFile(newms, info.name, filter); if (!AssetFileEx.maintainstream) { newms.Close(); newms.Dispose(); newms = null; } } if (unzips != null) { unzips.Close(); unzips.Dispose(); unzips = null; } if (afs.Count > 0) { foreach (KeyValuePair <string, AssetFileEx> pair in afs) { AssetFileEx af = pair.Value; if (af != null) { ObjectData abod = null; if (af.extractlist.ContainsKey("AssetBundle")) { abod = af.extractlist["AssetBundle"][0]; if (abod.instance != null) { m_MainAsset = (AssetInfo)abod.instance.getObject("m_MainAsset"); m_PreloadTable = (List <object>)abod.instance.getObject("m_PreloadTable"); m_Container = (Dictionary <object, object>)abod.instance.getObject("m_Container"); } break; } } } } AttachContainData(); Close(); }
public static int learnTypes(AssetFileEx asset) { if (asset.isStandalone()) { Logger.Log("File doesn't contain type information"); return(0); } Dictionary <int, EmbeddedTypeInfo> typemap = asset.embeddedTypeMap; UnityVersion unityRevision = asset.versionInfo.unityRevision; if (unityRevision == null) { Logger.Log("unityRevision = null"); return(0); } int learned = 0; // merge the TypeTree map with the database field map foreach (KeyValuePair <int, EmbeddedTypeInfo> typeTreeEntry in typemap) { int typeID = typeTreeEntry.Key; TypeNode typeNode = typeTreeEntry.Value.typeTree; // skip MonoBehaviour types if (typeID < 1) { continue; } UnityClass unityClass = new UnityClass(typeID); TypeNode typeNodeDB = TypeTreeUtils.getTypeNode(unityClass, unityRevision, true); if (typeNodeDB == null) { Logger.Log("New: {0}" + unityClass); TypeTreeDatabase.Instance.addEntry(unityClass, unityRevision, typeNode); typeNodeDB = typeNode; learned++; } // check the hashes, they must be identical at this point //int hash1 = typeNode.hashCode(); //int hash2 = typeNodeDB.hashCode(); //if (hash1 != hash2) //{ // Logger.Log("Database hash mismatch for {0}: {1} != {2}"+ // new Object[] {typeNodeDB.type.typeName(), hash1, hash2}); //} // check if the class name is known and suggest the type base name if not if (unityClass.name() == null) { Logger.Log("Unknown ClassID {0}, suggested name: {1}" + new Object[] { unityClass.ID(), typeNode.type }); } } return(learned); }