Esempio n. 1
0
        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)
            {
                throw new NotSupportedException($"Target file does not seem to have a type that matches the source file's type.  Adding in other type references isn't supported yet.");
            }
            return(Metadata.Types.IndexOf(toFileType));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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();
                this.Metadata.Types.Add(toFileType);
            }
            return(Metadata.Types.IndexOf(toFileType));
        }