public AssetsType CloneWithoutTypeTree() { var clone = new AssetsType() { ClassID = this.ClassID, TypeHash = this.TypeHash, Unknown1 = this.Unknown1, Unknown2 = this.Unknown2 }; if (IsScriptType) { clone.ScriptHash = this.ScriptHash; } return(clone); }
public int GetOrCreateMatchingTypeIndex(AssetsType type) { var toFileType = Metadata.Types.Where(x => x.ClassID == type.ClassID //only require hashes to match if it's a monobehaviour && (x.ClassID != AssetsConstants.ClassID.MonoBehaviourScriptType || (x.TypeHash == type.TypeHash && x.ScriptHash == type.ScriptHash))) //order by class ID and typehash matching first (prefer type hash) .OrderBy(x => ((x.ScriptHash == type.ScriptHash) ? 0 : 1) + ((x.TypeHash == type.TypeHash) ? 0 : 2)) .FirstOrDefault(); if (toFileType == null) { //attempt to add a type reference. Not sure the implications of this, e.g. circular references or something Log.LogMsg($"Attempting to add type to file {AssetsFilename} likely as part of a clone..."); toFileType = type.CloneWithoutTypeTree(); Metadata.Types.Add(toFileType); } return(Metadata.Types.IndexOf(toFileType)); }