public static void ParseAndProcessXML(XmlDocument xmlDoc, Dictionary <XmlNode, LoadableXmlAsset> assetlookup)
        {
            XmlNodeList childNodes = xmlDoc.DocumentElement.ChildNodes;

            for (int i = 0; i < childNodes.Count; i++)
            {
                if (childNodes[i].NodeType == XmlNodeType.Element)
                {
                    LoadableXmlAsset loadableXmlAsset = assetlookup.TryGetValue(childNodes[i], null);
                    XmlInheritance.TryRegister(childNodes[i], (loadableXmlAsset == null) ? null : loadableXmlAsset.mod);
                }
            }
            XmlInheritance.Resolve();
            DefPackage     defPackage     = new DefPackage("Unknown", string.Empty);
            ModContentPack modContentPack = LoadedModManager.runningMods.FirstOrDefault <ModContentPack>();

            modContentPack.AddDefPackage(defPackage);
            foreach (XmlNode xmlNode in xmlDoc.DocumentElement.ChildNodes)
            {
                LoadableXmlAsset loadableXmlAsset2 = assetlookup.TryGetValue(xmlNode, null);
                DefPackage       defPackage2       = (loadableXmlAsset2 == null) ? defPackage : loadableXmlAsset2.defPackage;
                Def def = DirectXmlLoader.DefFromNode(xmlNode, loadableXmlAsset2);
                if (def != null)
                {
                    def.modContentPack = ((loadableXmlAsset2 == null) ? modContentPack : loadableXmlAsset2.mod);
                    defPackage2.AddDef(def);
                }
            }
        }
Beispiel #2
0
 public static IEnumerable <T> AllGameItemsFromAsset <T>(LoadableXmlAsset asset) where T : new()
 {
     if (asset.xmlDoc != null)
     {
         XmlNodeList xmlNodeList = asset.xmlDoc.DocumentElement.SelectNodes(typeof(T).Name);
         bool        gotData     = false;
         foreach (XmlNode item in xmlNodeList)
         {
             XmlAttribute xmlAttribute = item.Attributes["Abstract"];
             if (xmlAttribute == null || !(xmlAttribute.Value.ToLower() == "true"))
             {
                 T val;
                 try
                 {
                     val     = DirectXmlToObject.ObjectFromXml <T>(item, doPostLoad: true);
                     gotData = true;
                 }
                 catch (Exception ex)
                 {
                     Log.Error("Exception loading data from file " + asset.name + ": " + ex);
                     continue;
                 }
                 yield return(val);
             }
         }
         if (!gotData)
         {
             Log.Error("Found no usable data when trying to get " + typeof(T) + "s from file " + asset.name);
         }
     }
 }
Beispiel #3
0
        public static IEnumerable <T> AllGameItemsFromAsset <T>(LoadableXmlAsset asset) where T : new()
        {
            if (asset.xmlDoc == null)
            {
                yield break;
            }
            XmlNodeList assetNodes = asset.xmlDoc.DocumentElement.SelectNodes(typeof(T).Name);
            bool        gotData    = false;
            IEnumerator enumerator = assetNodes.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object       obj         = enumerator.Current;
                    XmlNode      node        = (XmlNode)obj;
                    XmlAttribute abstractAtt = node.Attributes["Abstract"];
                    if (abstractAtt == null || !(abstractAtt.Value.ToLower() == "true"))
                    {
                        T item;
                        try
                        {
                            item    = DirectXmlToObject.ObjectFromXml <T>(node, true);
                            gotData = true;
                        }
                        catch (Exception ex)
                        {
                            Log.Error(string.Concat(new object[]
                            {
                                "Exception loading data from file ",
                                asset.name,
                                ": ",
                                ex
                            }), false);
                            continue;
                        }
                        yield return(item);
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            if (!gotData)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Found no usable data when trying to get ",
                    typeof(T),
                    "s from file ",
                    asset.name
                }), false);
            }
            yield break;
        }
Beispiel #4
0
        public static IEnumerable <T> LoadXmlDataInResourcesFolder <T>(string folderPath) where T : new()
        {
            XmlInheritance.Clear();
            List <LoadableXmlAsset> assets = new List <LoadableXmlAsset>();

            object[] textObjects = Resources.LoadAll <TextAsset>(folderPath);
            object[] array       = textObjects;
            for (int j = 0; j < array.Length; j++)
            {
                TextAsset        textAsset        = (TextAsset)array[j];
                LoadableXmlAsset loadableXmlAsset = new LoadableXmlAsset(textAsset.name, string.Empty, textAsset.text);
                XmlInheritance.TryRegisterAllFrom(loadableXmlAsset, null);
                assets.Add(loadableXmlAsset);
            }
            XmlInheritance.Resolve();
            for (int i = 0; i < assets.Count; i++)
            {
                using (IEnumerator <T> enumerator = DirectXmlLoader.AllGameItemsFromAsset <T>(assets[i]).GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        T item = enumerator.Current;
                        yield return(item);

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                }
            }
            XmlInheritance.Clear();
            yield break;
IL_0195:
            /*Error near IL_0196: Unexpected return in MoveNext()*/;
        }
Beispiel #5
0
        public static Def DefFromNode(XmlNode node, LoadableXmlAsset loadingAsset)
        {
            Def result;

            if (node.NodeType != XmlNodeType.Element)
            {
                result = null;
            }
            else
            {
                XmlAttribute xmlAttribute = node.Attributes["Abstract"];
                if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true")
                {
                    result = null;
                }
                else
                {
                    Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(node.Name);
                    if (typeInAnyAssembly == null)
                    {
                        result = null;
                    }
                    else if (!typeof(Def).IsAssignableFrom(typeInAnyAssembly))
                    {
                        result = null;
                    }
                    else
                    {
                        MethodInfo method     = typeof(DirectXmlToObject).GetMethod("ObjectFromXml");
                        MethodInfo methodInfo = method.MakeGenericMethod(new Type[]
                        {
                            typeInAnyAssembly
                        });
                        Def def = null;
                        try
                        {
                            def = (Def)methodInfo.Invoke(null, new object[]
                            {
                                node,
                                true
                            });
                        }
                        catch (Exception ex)
                        {
                            Log.Error(string.Concat(new object[]
                            {
                                "Exception loading def from file ",
                                (loadingAsset == null) ? "(unknown)" : loadingAsset.name,
                                ": ",
                                ex
                            }), false);
                        }
                        result = def;
                    }
                }
            }
            return(result);
        }
Beispiel #6
0
        public static IEnumerable <T> AllGameItemsFromAsset <T>(LoadableXmlAsset asset) where T : new()
        {
            if (DirectXmlLoader.loadingAsset != null)
            {
                Log.Error("Tried to load " + asset + " while loading " + DirectXmlLoader.loadingAsset + ". This will corrupt the internal state of DataLoader.");
            }
            if (asset.xmlDoc != null)
            {
                DirectXmlLoader.loadingAsset = asset;
                XmlNodeList assetNodes = asset.xmlDoc.DocumentElement.SelectNodes(typeof(T).Name);
                bool        gotData    = false;
                IEnumerator enumerator = assetNodes.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        XmlNode      node        = (XmlNode)enumerator.Current;
                        XmlAttribute abstractAtt = node.Attributes["Abstract"];
                        if (abstractAtt != null && abstractAtt.Value.ToLower() == "true")
                        {
                            continue;
                        }
                        T item;
                        try
                        {
                            item    = DirectXmlToObject.ObjectFromXml <T>(node, true);
                            gotData = true;
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Exception loading data from file " + asset.name + ": " + ex);
                            continue;
                        }
                        yield return(item);

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                }
                finally
                {
                    IDisposable disposable;
                    IDisposable disposable2 = disposable = (enumerator as IDisposable);
                    if (disposable != null)
                    {
                        disposable2.Dispose();
                    }
                }
                if (!gotData)
                {
                    Log.Error("Found no usable data when trying to get " + typeof(T) + "s from file " + asset.name);
                }
                DirectXmlLoader.loadingAsset = null;
            }
            yield break;
IL_0247:
            /*Error near IL_0248: Unexpected return in MoveNext()*/;
        }
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                bool flag = false;

                switch (num)
                {
                case 0u:
                    if (this.defPackages.Count != 0)
                    {
                        Log.ErrorOnce("LoadDefs called with already existing def packages", 39029405, false);
                    }
                    enumerator = DirectXmlLoader.XmlAssetsInModFolder(this, "Defs/").GetEnumerator();
                    num        = 4294967293u;
                    break;

                case 1u:
                    break;

                default:
                    return(false);
                }
                try
                {
                    switch (num)
                    {
                    }
                    if (enumerator.MoveNext())
                    {
                        asset      = enumerator.Current;
                        defPackage = new DefPackage(asset.name, GenFilePaths.FolderPathRelativeToDefsFolder(asset.fullFolderPath, this));
                        base.AddDefPackage(defPackage);
                        asset.defPackage = defPackage;
                        this.$current    = asset;
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        flag = true;
                        return(true);
                    }
                }
                finally
                {
                    if (!flag)
                    {
                        if (enumerator != null)
                        {
                            enumerator.Dispose();
                        }
                    }
                }
                this.$PC = -1;
                return(false);
            }
 public static IEnumerable <T> AllGameItemsFromAsset <T>(LoadableXmlAsset asset) where T : new()
 {
     if (DirectXmlLoader.loadingAsset != null)
     {
         Log.Error(string.Concat(new object[]
         {
             "Tried to load ",
             asset,
             " while loading ",
             DirectXmlLoader.loadingAsset,
             ". This will corrupt the internal state of DataLoader."
         }));
     }
     if (asset.xmlDoc != null)
     {
         DirectXmlLoader.loadingAsset = asset;
         XmlNodeList assetNodes = asset.xmlDoc.DocumentElement.SelectNodes(typeof(T).Name);
         bool        gotData    = false;
         foreach (XmlNode node in assetNodes)
         {
             XmlAttribute abstractAtt = node.Attributes["Abstract"];
             if (abstractAtt == null || !(abstractAtt.Value.ToLower() == "true"))
             {
                 T item;
                 try
                 {
                     item    = DirectXmlToObject.ObjectFromXml <T>(node, true);
                     gotData = true;
                 }
                 catch (Exception ex)
                 {
                     Log.Error(string.Concat(new object[]
                     {
                         "Exception loading data from file ",
                         asset.name,
                         ": ",
                         ex
                     }));
                     continue;
                 }
                 yield return(item);
             }
         }
         if (!gotData)
         {
             Log.Error(string.Concat(new object[]
             {
                 "Found no usable data when trying to get ",
                 typeof(T),
                 "s from file ",
                 asset.name
             }));
         }
         DirectXmlLoader.loadingAsset = null;
     }
 }
Beispiel #9
0
 public static void TryRegisterAllFrom(LoadableXmlAsset xmlAsset, ModContentPack mod)
 {
     if (xmlAsset.xmlDoc != null)
     {
         XmlNodeList childNodes = xmlAsset.xmlDoc.DocumentElement.ChildNodes;
         for (int i = 0; i < childNodes.Count; i++)
         {
             if (childNodes[i].NodeType == XmlNodeType.Element)
             {
                 XmlInheritance.TryRegister(childNodes[i], mod);
             }
         }
     }
 }
Beispiel #10
0
 public static void TryRegisterAllFrom(LoadableXmlAsset xmlAsset, ModContentPack mod)
 {
     if (xmlAsset.xmlDoc != null)
     {
         DeepProfiler.Start("XmlInheritance.TryRegisterAllFrom");
         foreach (XmlNode childNode in xmlAsset.xmlDoc.DocumentElement.ChildNodes)
         {
             if (childNode.NodeType == XmlNodeType.Element)
             {
                 TryRegister(childNode, mod);
             }
         }
         DeepProfiler.End();
     }
 }
        public static IEnumerable <LoadableXmlAsset> XmlAssetsInModFolder(ModContentPack mod, string folderPath)
        {
            DirectoryInfo di = new DirectoryInfo(Path.Combine(mod.RootDir, folderPath));

            if (di.Exists)
            {
                FileInfo[] files = di.GetFiles("*.xml", SearchOption.AllDirectories);
                FileInfo[] array = files;
                for (int i = 0; i < array.Length; i++)
                {
                    FileInfo         file  = array[i];
                    LoadableXmlAsset asset = new LoadableXmlAsset(file.Name, file.Directory.FullName, File.ReadAllText(file.FullName));
                    yield return(asset);
                }
            }
        }
        public static void ParseAndProcessXML(XmlDocument xmlDoc, Dictionary <XmlNode, LoadableXmlAsset> assetlookup)
        {
            XmlNodeList childNodes = xmlDoc.DocumentElement.ChildNodes;

            for (int i = 0; i < childNodes.Count; i++)
            {
                if (childNodes[i].NodeType == XmlNodeType.Element)
                {
                    LoadableXmlAsset loadableXmlAsset = assetlookup.TryGetValue(childNodes[i], null);
                    XmlInheritance.TryRegister(childNodes[i], (loadableXmlAsset == null) ? null : loadableXmlAsset.mod);
                }
            }
            XmlInheritance.Resolve();
            DefPackage     defPackage     = new DefPackage("(unknown)", "(unknown)");
            ModContentPack modContentPack = LoadedModManager.runningMods.FirstOrDefault <ModContentPack>();

            modContentPack.AddDefPackage(defPackage);
            IEnumerator enumerator = xmlDoc.DocumentElement.ChildNodes.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object           obj               = enumerator.Current;
                    XmlNode          xmlNode           = (XmlNode)obj;
                    LoadableXmlAsset loadableXmlAsset2 = assetlookup.TryGetValue(xmlNode, null);
                    DefPackage       defPackage2       = (loadableXmlAsset2 == null) ? defPackage : loadableXmlAsset2.defPackage;
                    Def def = DirectXmlLoader.DefFromNode(xmlNode, loadableXmlAsset2);
                    if (def != null)
                    {
                        def.modContentPack = ((loadableXmlAsset2 == null) ? modContentPack : loadableXmlAsset2.mod);
                        defPackage2.AddDef(def);
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
        }
Beispiel #13
0
        public static LoadableXmlAsset[] XmlAssetsInModFolder(ModContentPack mod, string folderPath, List <string> foldersToLoadDebug = null)
        {
            List <string> list = foldersToLoadDebug ?? mod.foldersToLoadDescendingOrder;
            Dictionary <string, FileInfo> dictionary = new Dictionary <string, FileInfo>();

            for (int j = 0; j < list.Count; j++)
            {
                string        text          = list[j];
                DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(text, folderPath));
                if (!directoryInfo.Exists)
                {
                    continue;
                }
                FileInfo[] files = directoryInfo.GetFiles("*.xml", SearchOption.AllDirectories);
                foreach (FileInfo fileInfo in files)
                {
                    string key = fileInfo.FullName.Substring(text.Length + 1);
                    if (!dictionary.ContainsKey(key))
                    {
                        dictionary.Add(key, fileInfo);
                    }
                }
            }
            if (dictionary.Count == 0)
            {
                return(emptyXmlAssetsArray);
            }
            List <FileInfo> fileList = dictionary.Values.ToList();

            LoadableXmlAsset[] assets = new LoadableXmlAsset[fileList.Count];
            GenThreading.ParallelFor(0, fileList.Count, delegate(int i)
            {
                FileInfo fileInfo2 = fileList[i];
                LoadableXmlAsset loadableXmlAsset = new LoadableXmlAsset(fileInfo2.Name, fileInfo2.Directory.FullName, File.ReadAllText(fileInfo2.FullName))
                {
                    mod = mod
                };
                assets[i] = loadableXmlAsset;
            });
            return(assets);
        }
Beispiel #14
0
        public static Def DefFromNode(XmlNode node, LoadableXmlAsset loadingAsset)
        {
            if (node.NodeType != XmlNodeType.Element)
            {
                return(null);
            }
            XmlAttribute xmlAttribute = node.Attributes["Abstract"];

            if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true")
            {
                return(null);
            }
            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(node.Name);

            if (typeInAnyAssembly == null)
            {
                return(null);
            }
            if (typeof(Def).IsAssignableFrom(typeInAnyAssembly))
            {
                MethodInfo method     = typeof(DirectXmlToObject).GetMethod("ObjectFromXml");
                MethodInfo methodInfo = method.MakeGenericMethod(typeInAnyAssembly);
                Def        result     = null;
                try
                {
                    result = (Def)methodInfo.Invoke(null, new object[2]
                    {
                        node,
                        true
                    });
                    return(result);
                }
                catch (Exception ex)
                {
                    Log.Error("Exception loading def from file " + ((loadingAsset == null) ? "(unknown)" : loadingAsset.name) + ": " + ex);
                    return(result);
                }
            }
            return(null);
        }
        public static IEnumerable <T> LoadXmlDataInResourcesFolder <T>(string folderPath) where T : new()
        {
            XmlInheritance.Clear();
            List <LoadableXmlAsset> assets = new List <LoadableXmlAsset>();

            object[] textObjects = Resources.LoadAll <TextAsset>(folderPath);
            foreach (TextAsset textAsset in textObjects)
            {
                LoadableXmlAsset loadableXmlAsset = new LoadableXmlAsset(textAsset.name, string.Empty, textAsset.text);
                XmlInheritance.TryRegisterAllFrom(loadableXmlAsset, null);
                assets.Add(loadableXmlAsset);
            }
            XmlInheritance.Resolve();
            for (int i = 0; i < assets.Count; i++)
            {
                foreach (T item in DirectXmlLoader.AllGameItemsFromAsset <T>(assets[i]))
                {
                    yield return(item);
                }
            }
            XmlInheritance.Clear();
            yield break;
        }
Beispiel #16
0
        public static IEnumerable <T> LoadXmlDataInResourcesFolder <T>(string folderPath) where T : new()
        {
            XmlInheritance.Clear();
            List <LoadableXmlAsset> assets = new List <LoadableXmlAsset>();

            object[] array = Resources.LoadAll <TextAsset>(folderPath);
            for (int j = 0; j < array.Length; j++)
            {
                TextAsset        textAsset        = (TextAsset)array[j];
                LoadableXmlAsset loadableXmlAsset = new LoadableXmlAsset(textAsset.name, "", textAsset.text);
                XmlInheritance.TryRegisterAllFrom(loadableXmlAsset, null);
                assets.Add(loadableXmlAsset);
            }
            XmlInheritance.Resolve();
            for (int i = 0; i < assets.Count; i++)
            {
                foreach (T item in AllGameItemsFromAsset <T>(assets[i]))
                {
                    yield return(item);
                }
            }
            XmlInheritance.Clear();
        }
Beispiel #17
0
        public IEnumerable <LoadableXmlAsset> LoadDefs()
        {
            if (defPackages.Count != 0)
            {
                Log.ErrorOnce("LoadDefs called with already existing def packages", 39029405);
            }
            using (IEnumerator <LoadableXmlAsset> enumerator = DirectXmlLoader.XmlAssetsInModFolder(this, "Defs/").GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    LoadableXmlAsset asset      = enumerator.Current;
                    DefPackage       defPackage = new DefPackage(asset.name, GenFilePaths.FolderPathRelativeToDefsFolder(asset.fullFolderPath, this));
                    AddDefPackage(defPackage);
                    asset.defPackage = defPackage;
                    yield return(asset);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            yield break;
IL_0131:
            /*Error near IL_0132: Unexpected return in MoveNext()*/;
        }
Beispiel #18
0
        public static Def DefFromNode(XmlNode node, LoadableXmlAsset loadingAsset)
        {
            if (node.NodeType != XmlNodeType.Element)
            {
                return(null);
            }
            XmlAttribute xmlAttribute = node.Attributes["Abstract"];

            if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true")
            {
                return(null);
            }
            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(node.Name);

            if (typeInAnyAssembly == null)
            {
                return(null);
            }
            if (!typeof(Def).IsAssignableFrom(typeInAnyAssembly))
            {
                return(null);
            }
            Func <XmlNode, bool, object> objectFromXmlMethod = DirectXmlToObject.GetObjectFromXmlMethod(typeInAnyAssembly);
            Def result = null;

            try
            {
                result = (Def)objectFromXmlMethod(node, arg2: true);
                return(result);
            }
            catch (Exception ex)
            {
                Log.Error("Exception loading def from file " + ((loadingAsset != null) ? loadingAsset.name : "(unknown)") + ": " + ex);
                return(result);
            }
        }
Beispiel #19
0
        public static IEnumerable <Def> AllDefsFromAsset(LoadableXmlAsset asset)
        {
            if (DirectXmlLoader.loadingAsset != null)
            {
                Log.Error("Tried to load " + asset + " while loading " + DirectXmlLoader.loadingAsset + ". This will corrupt the internal state of DataLoader.");
            }
            if (asset.xmlDoc != null)
            {
                DirectXmlLoader.loadingAsset = asset;
                XmlNodeList assetNodes = asset.xmlDoc.DocumentElement.ChildNodes;
                bool        gotData    = false;
                IEnumerator enumerator = assetNodes.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        XmlNode node = (XmlNode)enumerator.Current;
                        if (node.NodeType == XmlNodeType.Element)
                        {
                            XmlAttribute abstractAtt = node.Attributes["Abstract"];
                            if (abstractAtt != null && abstractAtt.Value.ToLower() == "true")
                            {
                                gotData = true;
                            }
                            else
                            {
                                Type defType = GenTypes.GetTypeInAnyAssembly(node.Name);
                                if (defType != null && typeof(Def).IsAssignableFrom(defType))
                                {
                                    MethodInfo method = typeof(DirectXmlToObject).GetMethod("ObjectFromXml");
                                    MethodInfo gen    = method.MakeGenericMethod(defType);
                                    Def        def    = null;
                                    try
                                    {
                                        def = (Def)gen.Invoke(null, new object[2]
                                        {
                                            node,
                                            true
                                        });
                                        gotData = true;
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error("Exception loading def from file " + asset.name + ": " + ex);
                                    }
                                    if (def != null)
                                    {
                                        yield return(def);

                                        /*Error: Unable to find new state assignment for yield return*/;
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    IDisposable disposable;
                    IDisposable disposable2 = disposable = (enumerator as IDisposable);
                    if (disposable != null)
                    {
                        disposable2.Dispose();
                    }
                }
                if (!gotData)
                {
                    Log.Error("Found no usable data when trying to get defs from file " + asset.name);
                }
                DirectXmlLoader.loadingAsset = null;
            }
            yield break;
IL_02e2:
            /*Error near IL_02e3: Unexpected return in MoveNext()*/;
        }
Beispiel #20
0
        public static void ParseAndProcessXML(XmlDocument xmlDoc, Dictionary <XmlNode, LoadableXmlAsset> assetlookup)
        {
            XmlNodeList    childNodes = xmlDoc.DocumentElement.ChildNodes;
            List <XmlNode> list       = new List <XmlNode>();

            foreach (object item in childNodes)
            {
                list.Add(item as XmlNode);
            }
            DeepProfiler.Start("Loading asset nodes " + list.Count);
            try
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].NodeType == XmlNodeType.Element)
                    {
                        LoadableXmlAsset value = null;
                        DeepProfiler.Start("assetlookup.TryGetValue");
                        try
                        {
                            assetlookup.TryGetValue(list[i], out value);
                        }
                        finally
                        {
                            DeepProfiler.End();
                        }
                        DeepProfiler.Start("XmlInheritance.TryRegister");
                        try
                        {
                            XmlInheritance.TryRegister(list[i], value?.mod);
                        }
                        finally
                        {
                            DeepProfiler.End();
                        }
                    }
                }
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("XmlInheritance.Resolve()");
            try
            {
                XmlInheritance.Resolve();
            }
            finally
            {
                DeepProfiler.End();
            }
            runningMods.FirstOrDefault();
            DeepProfiler.Start("Loading defs for " + list.Count + " nodes");
            try
            {
                foreach (XmlNode item2 in list)
                {
                    LoadableXmlAsset loadableXmlAsset = assetlookup.TryGetValue(item2);
                    Def def = DirectXmlLoader.DefFromNode(item2, loadableXmlAsset);
                    if (def != null)
                    {
                        ModContentPack modContentPack = loadableXmlAsset?.mod;
                        if (modContentPack != null)
                        {
                            modContentPack.AddDef(def, loadableXmlAsset.name);
                        }
                        else
                        {
                            patchedDefs.Add(def);
                        }
                    }
                }
            }
            finally
            {
                DeepProfiler.End();
            }
        }
 public static IEnumerable <Def> AllDefsFromAsset(LoadableXmlAsset asset)
 {
     if (DirectXmlLoader.loadingAsset != null)
     {
         Log.Error(string.Concat(new object[]
         {
             "Tried to load ",
             asset,
             " while loading ",
             DirectXmlLoader.loadingAsset,
             ". This will corrupt the internal state of DataLoader."
         }));
     }
     if (asset.xmlDoc != null)
     {
         DirectXmlLoader.loadingAsset = asset;
         XmlNodeList assetNodes = asset.xmlDoc.DocumentElement.ChildNodes;
         bool        gotData    = false;
         foreach (XmlNode node in assetNodes)
         {
             if (node.NodeType == XmlNodeType.Element)
             {
                 XmlAttribute abstractAtt = node.Attributes["Abstract"];
                 if (abstractAtt != null && abstractAtt.Value.ToLower() == "true")
                 {
                     gotData = true;
                 }
                 else
                 {
                     Type defType = GenTypes.GetTypeInAnyAssembly(node.Name);
                     if (defType != null)
                     {
                         if (typeof(Def).IsAssignableFrom(defType))
                         {
                             MethodInfo method = typeof(DirectXmlToObject).GetMethod("ObjectFromXml");
                             MethodInfo gen    = method.MakeGenericMethod(new Type[]
                             {
                                 defType
                             });
                             Def def = null;
                             try
                             {
                                 def = (Def)gen.Invoke(null, new object[]
                                 {
                                     node,
                                     true
                                 });
                                 gotData = true;
                             }
                             catch (Exception ex)
                             {
                                 Log.Error(string.Concat(new object[]
                                 {
                                     "Exception loading def from file ",
                                     asset.name,
                                     ": ",
                                     ex
                                 }));
                             }
                             if (def != null)
                             {
                                 yield return(def);
                             }
                         }
                     }
                 }
             }
         }
         if (!gotData)
         {
             Log.Error("Found no usable data when trying to get defs from file " + asset.name);
         }
         DirectXmlLoader.loadingAsset = null;
     }
 }