Esempio n. 1
0
        public static AssetTypeValueField GetMonoBaseField(AssetsManager am, AssetsFileInstance inst, AssetFileInfoEx info, string managedPath, bool cached = true)
        {
            AssetsFile             file      = inst.file;
            AssetTypeTemplateField baseField = new AssetTypeTemplateField();

            baseField.FromClassDatabase(am.classFile, AssetHelper.FindAssetClassByID(am.classFile, info.curFileType), 0);
            AssetTypeInstance mainAti     = new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos);
            ushort            scriptIndex = AssetHelper.GetScriptIndex(file, info);

            if (scriptIndex != 0xFFFF)
            {
                AssetTypeInstance scriptAti       = am.GetExtAsset(inst, mainAti.GetBaseField().Get("m_Script")).instance;
                string            scriptName      = scriptAti.GetBaseField().Get("m_Name").GetValue().AsString();
                string            scriptNamespace = scriptAti.GetBaseField().Get("m_Namespace").GetValue().AsString();
                string            assemblyName    = scriptAti.GetBaseField().Get("m_AssemblyName").GetValue().AsString();
                string            assemblyPath    = Path.Combine(managedPath, assemblyName);

                if (scriptNamespace != string.Empty)
                {
                    scriptName = scriptNamespace + "." + scriptName;
                }

                if (File.Exists(assemblyPath))
                {
                    AssemblyDefinition asmDef;
                    if (cached)
                    {
                        if (!loadedAssemblies.ContainsKey(assemblyName))
                        {
                            loadedAssemblies.Add(assemblyName, GetAssemblyWithDependencies(assemblyPath));
                        }
                        asmDef = loadedAssemblies[assemblyName];
                    }
                    else
                    {
                        asmDef = GetAssemblyWithDependencies(assemblyPath);
                    }

                    MonoDeserializer mc = new MonoDeserializer();
                    mc.Read(scriptName, asmDef, inst.file.header.format);
                    List <AssetTypeTemplateField> monoTemplateFields = mc.children;

                    AssetTypeTemplateField[] templateField = baseField.children.Concat(monoTemplateFields).ToArray();
                    baseField.children      = templateField;
                    baseField.childrenCount = baseField.children.Length;

                    mainAti = new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos);
                }
            }
            return(mainAti.GetBaseField());
        }
        public AssetTypeInstance GetATI(AssetsFile file, AssetFileInfoEx info, bool forceFromCldb = false)
        {
            ushort scriptIndex = AssetHelper.GetScriptIndex(file, info);
            uint   fixedId     = AssetHelper.FixAudioID(info.curFileType);

            bool hasTypeTree = file.typeTree.hasTypeTree;
            AssetTypeTemplateField baseField;

            if (useTemplateFieldCache && templateFieldCache.ContainsKey(fixedId))
            {
                baseField = templateFieldCache[fixedId];
            }
            else
            {
                baseField = new AssetTypeTemplateField();
                if (hasTypeTree && !forceFromCldb)
                {
                    if (file.header.format < 0x10)
                    {
                        if (scriptIndex == 0xFFFF)
                        {
                            baseField.From0D(AssetHelper.FindTypeTreeTypeByID(file.typeTree, fixedId), 0);
                        }
                        else
                        {
                            baseField.From0D(AssetHelper.FindTypeTreeTypeByScriptIndex(file.typeTree, scriptIndex), 0);
                        }
                    }
                    else
                    {
                        baseField.From0D(AssetHelper.FindTypeTreeTypeByID(file.typeTree, fixedId), 0);
                    }
                }
                else
                {
                    baseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0);
                }

                if (useTemplateFieldCache)
                {
                    templateFieldCache[fixedId] = baseField;
                }
            }

            return(new AssetTypeInstance(baseField, file.reader, info.absoluteFilePos));
        }
Esempio n. 3
0
        public AssetTypeValueField GetMonoBaseFieldCached(AssetsFileInstance inst, AssetFileInfoEx info, string managedPath)
        {
            AssetsFile file        = inst.file;
            ushort     scriptIndex = AssetHelper.GetScriptIndex(file, info);

            if (scriptIndex == 0xFFFF)
            {
                return(null);
            }

            string scriptName;

            if (!inst.monoIdToName.ContainsKey(scriptIndex))
            {
                AssetTypeInstance scriptAti = GetExtAsset(inst, GetTypeInstance(inst.file, info).GetBaseField().Get("m_Script")).instance;
                scriptName = scriptAti.GetBaseField().Get("m_Name").GetValue().AsString();
                string scriptNamespace = scriptAti.GetBaseField().Get("m_Namespace").GetValue().AsString();
                string assemblyName    = scriptAti.GetBaseField().Get("m_AssemblyName").GetValue().AsString();

                if (scriptNamespace != string.Empty)
                {
                    scriptNamespace = "-";
                }

                scriptName = $"{assemblyName}.{scriptNamespace}.{scriptName}";
                inst.monoIdToName[scriptIndex] = scriptName;
            }
            else
            {
                scriptName = inst.monoIdToName[scriptIndex];
            }

            if (monoTemplateFieldCache.ContainsKey(scriptName))
            {
                AssetTypeTemplateField baseTemplateField = monoTemplateFieldCache[scriptName];
                AssetTypeInstance      baseAti           = new AssetTypeInstance(baseTemplateField, file.reader, info.absoluteFilePos);
                return(baseAti.GetBaseField());
            }
            else
            {
                AssetTypeValueField baseValueField = MonoDeserializer.GetMonoBaseField(this, inst, info, managedPath);
                monoTemplateFieldCache[scriptName] = baseValueField.templateField;
                return(baseValueField);
            }
        }
        public AssetTypeValueField GetMonoBaseFieldCached(AssetsFileInstance inst, AssetFileInfoEx info, string managedPath)
        {
            AssetsFile file        = inst.file;
            ushort     scriptIndex = AssetHelper.GetScriptIndex(file, info);

            if (scriptIndex != 0xFFFF && inst.templateFieldCache.ContainsKey(scriptIndex))
            {
                AssetTypeTemplateField baseTemplateField = inst.templateFieldCache[scriptIndex];
                AssetTypeInstance      baseAti           = new AssetTypeInstance(baseTemplateField, file.reader, info.absoluteFilePos);
                return(baseAti.GetBaseField());
            }
            else
            {
                AssetTypeValueField baseValueField = MonoDeserializer.GetMonoBaseField(this, inst, info, managedPath);
                inst.templateFieldCache[scriptIndex] = baseValueField.templateField;
                return(baseValueField);
            }
        }
Esempio n. 5
0
        public AssetTypeInstance GetATI(AssetsFile file, AssetFileInfoEx info)
        {
            //do we still need pooling?
            //(it accumulates memory over time and we don't
            // really need to read the same ati twice)

            //unity is wack
            uint fixedId = info.curFileType;

            if (fixedId == 0xf1)      //AudioMixerController
            {
                fixedId = 0xf0;       //AudioMixer
            }
            else if (fixedId == 0xf3) //AudioMixerGroupController
            {
                fixedId = 0x111;      //AudioMixerGroup
            }
            else if (fixedId == 0xf5) //AudioMixerSnapshotController
            {
                fixedId = 0x110;      //AudioMixerSnapshot
            }
            AssetTypeTemplateField pBaseField = null;

            if (useTemplateFieldCache)
            {
                if (templateFieldCache.ContainsKey(fixedId))
                {
                    pBaseField = templateFieldCache[fixedId];
                }
                else
                {
                    pBaseField = new AssetTypeTemplateField();
                    pBaseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0);
                    templateFieldCache[fixedId] = pBaseField;
                }
            }
            else
            {
                pBaseField = new AssetTypeTemplateField();
                pBaseField.FromClassDatabase(classFile, AssetHelper.FindAssetClassByID(classFile, fixedId), 0);
            }

            return(new AssetTypeInstance(pBaseField, file.reader, false, info.absoluteFilePos));
        }
Esempio n. 6
0
        public static Type_0D Cldb2TypeTree(ClassDatabaseFile classes, string name)
        {
            ClassDatabaseType type = AssetHelper.FindAssetClassByName(classes, name);

            return(Cldb2TypeTree(classes, type));
        }
Esempio n. 7
0
        public static Type_0D Cldb2TypeTree(ClassDatabaseFile classes, int id)
        {
            ClassDatabaseType type = AssetHelper.FindAssetClassByID(classes, (uint)id);

            return(Cldb2TypeTree(classes, type));
        }
 public override ushort GetMonoScriptID()
 {
     return(AssetHelper.GetScriptIndex(assetsFile, asset));
 }