Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
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()*/;
        }
        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();
                }
            }
        }
Exemplo n.º 4
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();
        }
        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;
        }
Exemplo n.º 6
0
        public void LoadDefs(IEnumerable <PatchOperation> patches)
        {
            DeepProfiler.Start("Loading all defs");
            List <LoadableXmlAsset> list = DirectXmlLoader.XmlAssetsInModFolder(this, "Defs/").ToList <LoadableXmlAsset>();

            foreach (LoadableXmlAsset current in list)
            {
                foreach (PatchOperation current2 in patches)
                {
                    current2.Apply(current.xmlDoc);
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i] == null || list[i].xmlDoc == null || list[i].xmlDoc.DocumentElement == null)
                {
                    Log.Error(string.Format("{0}: unknown parse failure", list[i].fullFolderPath + "/" + list[i].name));
                }
                else if (list[i].xmlDoc.DocumentElement.Name != "Defs")
                {
                    Log.Error(string.Format("{0}: root element named {1}; should be named Defs", list[i].fullFolderPath + "/" + list[i].name, list[i].xmlDoc.DocumentElement.Name));
                }
                XmlInheritance.TryRegisterAllFrom(list[i], this);
            }
            XmlInheritance.Resolve();
            for (int j = 0; j < list.Count; j++)
            {
                string     relFolder  = GenFilePaths.FolderPathRelativeToDefsFolder(list[j].fullFolderPath, this);
                DefPackage defPackage = new DefPackage(list[j].name, relFolder);
                foreach (Def current3 in DirectXmlLoader.AllDefsFromAsset(list[j]))
                {
                    defPackage.defs.Add(current3);
                }
                this.defPackages.Add(defPackage);
            }
            DeepProfiler.End();
        }
Exemplo n.º 7
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();
            }
        }