public TypeTreeDatabaseEntry getEntry(UnityClass unityClass, UnityVersion unityVersion, bool exact) { // search for exact matches string pair = unityClass.name() + "_" + unityVersion.build; TypeTreeDatabaseEntry entryA = null; if (entryMap.ContainsKey(pair)) { entryA = entryMap[pair]; } if (entryA != null) { return(entryA); } // cancel if exact matches are required if (exact) { return(null); } TypeTreeDatabaseEntry entryB = null; UnityVersion versionB = null; TypeTreeDatabaseEntry entryC = null; UnityVersion versionC = null; foreach (TypeTreeDatabaseEntry entry in entries) { UnityClass uclass = entry.unityClass; UnityVersion version = entry.unityVersion; if (uclass.equals(unityClass)) { if (version.major == unityVersion.major) { if (version.minor == unityVersion.minor) { // if major and minor versions match, it will probably work return(entry); } else { // suboptimal choice entryB = entry; versionB = version; } } // worst choice entryC = entry; versionC = version; } } // return less perfect match if (entryB != null) { //Logger.Log( "Unprecise match for class {0} (required: {1}, available: {2})"+ new Object[]{unityClass, unityVersion, versionB}); return(entryB); } // return field node from any revision as the very last resort if (entryC != null) { //Logger.Log("Bad match for class {0} (required: {1}, available: {2})"+ new Object[]{unityClass, unityVersion, versionC}); return(entryC); } // no matches at all return(null); }
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); }