Exemple #1
0
        static ModsConfig()
        {
            bool flag = false;

            ModsConfig.data = DirectXmlLoader.ItemFromXmlFile <ModsConfig.ModsConfigData>(GenFilePaths.ModsConfigFilePath, true);
            if (ModsConfig.data.buildNumber < VersionControl.CurrentBuild)
            {
                Log.Message(string.Concat(new object[]
                {
                    "Mods config data is from build ",
                    ModsConfig.data.buildNumber,
                    " while we are at build ",
                    VersionControl.CurrentBuild,
                    ". Resetting."
                }), false);
                ModsConfig.data = new ModsConfig.ModsConfigData();
                flag            = true;
            }
            ModsConfig.data.buildNumber = VersionControl.CurrentBuild;
            bool flag2 = File.Exists(GenFilePaths.ModsConfigFilePath);

            if (!flag2 || flag)
            {
                ModsConfig.data.activeMods.Add(ModContentPack.CoreModIdentifier);
                ModsConfig.Save();
            }
        }
        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);
                }
            }
        }
Exemple #3
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()*/;
        }
Exemple #4
0
        private void LoadPatches()
        {
            DeepProfiler.Start("Loading all patches");
            patches          = new List <PatchOperation>();
            loadedAnyPatches = false;
            List <LoadableXmlAsset> list = DirectXmlLoader.XmlAssetsInModFolder(this, "Patches/").ToList();

            for (int i = 0; i < list.Count; i++)
            {
                XmlElement documentElement = list[i].xmlDoc.DocumentElement;
                if (documentElement.Name != "Patch")
                {
                    Log.Error($"Unexpected document element in patch XML; got {documentElement.Name}, expected 'Patch'");
                    continue;
                }
                foreach (XmlNode childNode in documentElement.ChildNodes)
                {
                    if (childNode.NodeType == XmlNodeType.Element)
                    {
                        if (childNode.Name != "Operation")
                        {
                            Log.Error($"Unexpected element in patch XML; got {childNode.Name}, expected 'Operation'");
                            continue;
                        }
                        PatchOperation patchOperation = DirectXmlToObject.ObjectFromXml <PatchOperation>(childNode, doPostLoad: false);
                        patchOperation.sourceFile = list[i].FullFilePath;
                        patches.Add(patchOperation);
                        loadedAnyPatches = true;
                    }
                }
            }
            DeepProfiler.End();
        }
Exemple #5
0
        public static void Init()
        {
            bool flag = !new FileInfo(GenFilePaths.KeyPrefsFilePath).Exists;
            Dictionary <string, KeyBindingData> dictionary = DirectXmlLoader.ItemFromXmlFile <Dictionary <string, KeyBindingData> >(GenFilePaths.KeyPrefsFilePath, true);

            KeyPrefs.data = new KeyPrefsData();
            KeyPrefs.unresolvedBindings = new Dictionary <string, KeyBindingData>();
            foreach (KeyValuePair <string, KeyBindingData> current in dictionary)
            {
                KeyBindingDef namedSilentFail = DefDatabase <KeyBindingDef> .GetNamedSilentFail(current.Key);

                if (namedSilentFail != null)
                {
                    KeyPrefs.data.keyPrefs[namedSilentFail] = current.Value;
                }
                else
                {
                    KeyPrefs.unresolvedBindings[current.Key] = current.Value;
                }
            }
            if (flag)
            {
                KeyPrefs.data.ResetToDefaults();
            }
            KeyPrefs.data.AddMissingDefaultBindings();
            KeyPrefs.data.ErrorCheck();
            if (flag)
            {
                KeyPrefs.Save();
            }
        }
Exemple #6
0
        static ModsConfig()
        {
            bool flag = false;

            data = DirectXmlLoader.ItemFromXmlFile <ModsConfigData>(GenFilePaths.ModsConfigFilePath);
            if (data.version != null)
            {
                bool flag2 = false;
                int  result;
                if (data.version.Contains("."))
                {
                    int num  = VersionControl.MinorFromVersionString(data.version);
                    int num2 = VersionControl.MajorFromVersionString(data.version);
                    if (num2 != VersionControl.CurrentMajor || num != VersionControl.CurrentMinor)
                    {
                        flag2 = true;
                    }
                }
                else if (data.version.Length > 0 && data.version.All(char.IsNumber) && int.TryParse(data.version, out result) && result <= 2009)
                {
                    flag2 = true;
                }
                if (flag2)
                {
                    Log.Message("Mods config data is from version " + data.version + " while we are running " + VersionControl.CurrentVersionStringWithRev + ". Resetting.");
                    data = new ModsConfigData();
                    flag = true;
                }
            }
            if (!File.Exists(GenFilePaths.ModsConfigFilePath) || flag)
            {
                data.activeMods.Add(ModContentPack.CoreModIdentifier);
                Save();
            }
        }
        private void Init()
        {
            meta        = DirectXmlLoader.ItemFromXmlFile <ModMetaDataInternal>(RootDir.FullName + Path.DirectorySeparatorChar + "About" + Path.DirectorySeparatorChar + "About.xml");
            loadFolders = DirectXmlLoader.ItemFromXmlFile <ModLoadFolders>(RootDir.FullName + Path.DirectorySeparatorChar + "LoadFolders.xml");
            bool shouldLogIssues = ModLister.ShouldLogIssues;

            HadIncorrectlyFormattedVersionInMetadata = !meta.TryParseSupportedVersions(!OnSteamWorkshop && shouldLogIssues);
            if (meta.name.NullOrEmpty())
            {
                if (OnSteamWorkshop)
                {
                    meta.name = "Workshop mod " + FolderName;
                }
                else
                {
                    meta.name = FolderName;
                }
            }
            HadIncorrectlyFormattedPackageId = !meta.TryParsePackageId(Official, !OnSteamWorkshop && shouldLogIssues);
            packageIdLowerCase = meta.packageId.ToLower();
            meta.InitVersionedData();
            meta.ValidateDependencies_NewTmp(shouldLogIssues);
            string publishedFileIdPath = PublishedFileIdPath;

            if (File.Exists(PublishedFileIdPath) && ulong.TryParse(File.ReadAllText(publishedFileIdPath), out var result))
            {
                publishedFileIdInt = new PublishedFileId_t(result);
            }
        }
Exemple #8
0
        private void Init()
        {
            this.meta = DirectXmlLoader.ItemFromXmlFile <ModMetaData.ModMetaDataInternal>(string.Concat(new object[]
            {
                this.RootDir.FullName,
                Path.DirectorySeparatorChar,
                "About",
                Path.DirectorySeparatorChar,
                "About.xml"
            }), true);
            if (this.meta.name.NullOrEmpty())
            {
                if (this.OnSteamWorkshop)
                {
                    this.meta.name = "Workshop mod " + this.Identifier;
                }
                else
                {
                    this.meta.name = this.Identifier;
                }
            }
            if (!this.IsCoreMod && !this.OnSteamWorkshop && !VersionControl.IsWellFormattedVersionString(this.meta.targetVersion))
            {
                Log.ErrorOnce(string.Concat(new string[]
                {
                    "Mod ",
                    this.meta.name,
                    " has incorrectly formatted target version '",
                    this.meta.targetVersion,
                    "'. For the current version, write: <targetVersion>",
                    VersionControl.CurrentVersionString,
                    "</targetVersion>"
                }), this.Identifier.GetHashCode(), false);
            }
            LongEventHandler.ExecuteWhenFinished(delegate
            {
                string url = GenFilePaths.SafeURIForUnityWWWFromPath(this.PreviewImagePath);
                using (WWW www = new WWW(url))
                {
                    www.threadPriority = UnityEngine.ThreadPriority.High;
                    while (!www.isDone)
                    {
                        Thread.Sleep(1);
                    }
                    if (www.error == null)
                    {
                        this.previewImage = www.textureNonReadable;
                    }
                }
            });
            string publishedFileIdPath = this.PublishedFileIdPath;

            if (File.Exists(this.PublishedFileIdPath))
            {
                string s = File.ReadAllText(publishedFileIdPath);
                this.publishedFileIdInt = new PublishedFileId_t(ulong.Parse(s));
            }
        }
            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);
            }
Exemple #10
0
        public static void Init()
        {
            bool flag = !new FileInfo(GenFilePaths.PrefsFilePath).Exists;

            Prefs.data = new PrefsData();
            Prefs.data = DirectXmlLoader.ItemFromXmlFile <PrefsData>(GenFilePaths.PrefsFilePath, true);
            if (flag)
            {
                Prefs.data.langFolderName = LanguageDatabase.SystemLanguageFolderName();
            }
        }
Exemple #11
0
 public IEnumerable <LoadableXmlAsset> LoadDefs()
 {
     if (this.defPackages.Count != 0)
     {
         Log.ErrorOnce("LoadDefs called with already existing def packages", 39029405, false);
     }
     foreach (LoadableXmlAsset asset in DirectXmlLoader.XmlAssetsInModFolder(this, "Defs/"))
     {
         DefPackage defPackage = new DefPackage(asset.name, GenFilePaths.FolderPathRelativeToDefsFolder(asset.fullFolderPath, this));
         this.AddDefPackage(defPackage);
         asset.defPackage = defPackage;
         yield return(asset);
     }
 }
Exemple #12
0
        private static void LoadedFilesForMod()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (ModContentPack item in LoadedModManager.RunningModsListForReading)
            {
                ModContentPack mod = item;
                list.Add(new DebugMenuOption(mod.Name, DebugMenuOptionMode.Action, delegate
                {
                    ModMetaData metaData = ModLister.GetModWithIdentifier(mod.PackageId);
                    if (metaData.loadFolders != null && metaData.loadFolders.DefinedVersions().Count != 0)
                    {
                        Find.WindowStack.Add(new Dialog_DebugOptionListLister(from ver in metaData.loadFolders.DefinedVersions()
                                                                              select new DebugMenuOption(ver, DebugMenuOptionMode.Action, delegate
                        {
                            ShowTable((from f in metaData.loadFolders.FoldersForVersion(ver)
                                       select Path.Combine(mod.RootDir, f.folderName)).Reverse().ToList());
                        })));
                    }
                    else
                    {
                        ShowTable(null);
                    }
                }));
                void ShowTable(List <string> loadFolders)
                {
                    List <Pair <string, string> > list2 = new List <Pair <string, string> >();

                    list2.AddRange(from f in DirectXmlLoader.XmlAssetsInModFolder(mod, "Defs/", loadFolders)
                                   select new Pair <string, string>(f.FullFilePath, "-"));
                    list2.AddRange(from f in DirectXmlLoader.XmlAssetsInModFolder(mod, "Patches/", loadFolders)
                                   select new Pair <string, string>(f.FullFilePath, "-"));
                    list2.AddRange(from f in ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <Texture2D>(), ModContentLoader <Texture2D> .IsAcceptableExtension, loadFolders)
                                   select new Pair <string, string>(f.Value.FullName, f.Key));
                    list2.AddRange(from f in ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <AudioClip>(), ModContentLoader <AudioClip> .IsAcceptableExtension, loadFolders)
                                   select new Pair <string, string>(f.Value.FullName, f.Key));
                    list2.AddRange(from f in ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <string>(), ModContentLoader <string> .IsAcceptableExtension, loadFolders)
                                   select new Pair <string, string>(f.Value.FullName, f.Key));
                    list2.AddRange(from f in ModContentPack.GetAllFilesForModPreserveOrder(mod, "Assemblies/", (string e) => e.ToLower() == ".dll", loadFolders)
                                   select new Pair <string, string>(f.Item2.FullName, f.Item1));
                    DebugTables.MakeTablesDialog(list2, new List <TableDataGetter <Pair <string, string> > >
                    {
                        new TableDataGetter <Pair <string, string> >("full path", (Pair <string, string> f) => f.First),
                        new TableDataGetter <Pair <string, string> >("internal path", (Pair <string, string> f) => f.Second)
                    }.ToArray());
                }
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
Exemple #13
0
        public IEnumerable <LoadableXmlAsset> LoadDefs()
        {
            if (defs.Count != 0)
            {
                Log.ErrorOnce("LoadDefs called with already existing def packages", 39029405);
            }
            DeepProfiler.Start("Load Assets");
            List <LoadableXmlAsset> list = DirectXmlLoader.XmlAssetsInModFolder(this, "Defs/").ToList();

            DeepProfiler.End();
            DeepProfiler.Start("Parse Assets");
            foreach (LoadableXmlAsset item in list)
            {
                yield return(item);
            }
            DeepProfiler.End();
        }
        public static void Init()
        {
            bool num = !new FileInfo(GenFilePaths.PrefsFilePath).Exists;

            data = new PrefsData();
            data = DirectXmlLoader.ItemFromXmlFile <PrefsData>(GenFilePaths.PrefsFilePath);
            BackCompatibility.PrefsDataPostLoad(data);
            if (num)
            {
                data.langFolderName = LanguageDatabase.SystemLanguageFolderName();
                data.uiScale        = ResolutionUtility.GetRecommendedUIScale(data.screenWidth, data.screenHeight);
            }
            if (DevModePermanentlyDisabledUtility.Disabled)
            {
                DevMode = false;
            }
            Apply();
        }
        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();
                }
            }
        }
Exemple #16
0
        public static void Init()
        {
            bool flag = !new FileInfo(GenFilePaths.PrefsFilePath).Exists;

            Prefs.data = new PrefsData();
            Prefs.data = DirectXmlLoader.ItemFromXmlFile <PrefsData>(GenFilePaths.PrefsFilePath, true);
            if (flag)
            {
                Prefs.data.langFolderName = LanguageDatabase.SystemLanguageFolderName();
                if (UnityData.isDebugBuild && !DevModePermanentlyDisabledUtility.Disabled)
                {
                    Prefs.DevMode = true;
                }
            }
            if (DevModePermanentlyDisabledUtility.Disabled)
            {
                Prefs.DevMode = false;
            }
        }
        static ModsConfig()
        {
            bool flag = false;

            ModsConfig.data = DirectXmlLoader.ItemFromXmlFile <ModsConfigData>(GenFilePaths.ModsConfigFilePath, true);
            if (ModsConfig.data.buildNumber < VersionControl.CurrentBuild)
            {
                Log.Message("Mods config data is from build " + ModsConfig.data.buildNumber + " while we are at build " + VersionControl.CurrentBuild + ". Resetting.");
                ModsConfig.data = new ModsConfigData();
                flag            = true;
            }
            ModsConfig.data.buildNumber = VersionControl.CurrentBuild;
            if (File.Exists(GenFilePaths.ModsConfigFilePath) && !flag)
            {
                return;
            }
            ModsConfig.data.activeMods.Add(ModContentPack.CoreModIdentifier);
            ModsConfig.Save();
        }
Exemple #18
0
        private void Init()
        {
            meta = DirectXmlLoader.ItemFromXmlFile <ModMetaDataInternal>(RootDir.FullName + Path.DirectorySeparatorChar + "About" + Path.DirectorySeparatorChar + "About.xml");
            if (meta.name.NullOrEmpty())
            {
                if (OnSteamWorkshop)
                {
                    meta.name = "Workshop mod " + Identifier;
                }
                else
                {
                    meta.name = Identifier;
                }
            }
            if (!IsCoreMod && !OnSteamWorkshop && !VersionControl.IsWellFormattedVersionString(meta.targetVersion))
            {
                Log.ErrorOnce("Mod " + meta.name + " has incorrectly formatted target version '" + meta.targetVersion + "'. For the current version, write: <targetVersion>" + VersionControl.CurrentVersionString + "</targetVersion>", Identifier.GetHashCode());
            }
            LongEventHandler.ExecuteWhenFinished(delegate
            {
                string url = GenFilePaths.SafeURIForUnityWWWFromPath(PreviewImagePath);
                using (WWW wWW = new WWW(url))
                {
                    wWW.threadPriority = UnityEngine.ThreadPriority.High;
                    while (!wWW.isDone)
                    {
                        Thread.Sleep(1);
                    }
                    if (wWW.error == null)
                    {
                        previewImage = wWW.textureNonReadable;
                    }
                }
            });
            string publishedFileIdPath = PublishedFileIdPath;

            if (File.Exists(PublishedFileIdPath))
            {
                string s = File.ReadAllText(publishedFileIdPath);
                publishedFileIdInt = new PublishedFileId_t(ulong.Parse(s));
            }
        }
 public void LoadMetadata()
 {
     if (info != null && infoIsRealMetadata)
     {
         return;
     }
     infoIsRealMetadata = true;
     foreach (ModContentPack runningMod in LoadedModManager.RunningMods)
     {
         foreach (string item in runningMod.foldersToLoadDescendingOrder)
         {
             string text = Path.Combine(item, "Languages");
             if (!new DirectoryInfo(text).Exists)
             {
                 continue;
             }
             foreach (VirtualDirectory directory in AbstractFilesystem.GetDirectories(text, "*", SearchOption.TopDirectoryOnly))
             {
                 if (directory.Name == folderName || directory.Name == legacyFolderName)
                 {
                     info = DirectXmlLoader.ItemFromXmlFile <LanguageInfo>(directory, "LanguageInfo.xml", resolveCrossRefs: false);
                     if (info.friendlyNameNative.NullOrEmpty() && directory.FileExists("FriendlyName.txt"))
                     {
                         info.friendlyNameNative = directory.ReadAllText("FriendlyName.txt");
                     }
                     if (info.friendlyNameNative.NullOrEmpty())
                     {
                         info.friendlyNameNative = folderName;
                     }
                     if (info.friendlyNameEnglish.NullOrEmpty())
                     {
                         info.friendlyNameEnglish = folderName;
                     }
                     return;
                 }
             }
         }
     }
 }
Exemple #20
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()*/;
        }
Exemple #21
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);
            foreach (TextAsset textAsset in textObjects)
            {
                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 DirectXmlLoader.AllGameItemsFromAsset <T>(assets[i]))
                {
                    yield return(item);
                }
            }
            XmlInheritance.Clear();
            yield break;
        }
        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();
        }
 public void TryLoadMetadataFrom(string folderPath)
 {
     if (this.info == null)
     {
         string filePath = Path.Combine(folderPath.ToString(), "LanguageInfo.xml");
         this.info = DirectXmlLoader.ItemFromXmlFile <LanguageInfo>(filePath, false);
         if (this.info.friendlyNameNative.NullOrEmpty())
         {
             FileInfo fileInfo = new FileInfo(Path.Combine(folderPath.ToString(), "FriendlyName.txt"));
             if (fileInfo.Exists)
             {
                 this.info.friendlyNameNative = GenFile.TextFromRawFile(fileInfo.ToString());
             }
         }
         if (this.info.friendlyNameNative.NullOrEmpty())
         {
             this.info.friendlyNameNative = this.folderName;
         }
         if (this.info.friendlyNameEnglish.NullOrEmpty())
         {
             this.info.friendlyNameEnglish = this.folderName;
         }
     }
 }
        private void LoadPatches()
        {
            DeepProfiler.Start("Loading all patches");
            this.patches = new List <PatchOperation>();
            List <LoadableXmlAsset> list = DirectXmlLoader.XmlAssetsInModFolder(this, "Patches/").ToList <LoadableXmlAsset>();

            for (int i = 0; i < list.Count; i++)
            {
                XmlElement documentElement = list[i].xmlDoc.DocumentElement;
                if (documentElement.Name != "Patch")
                {
                    Log.Error(string.Format("Unexpected document element in patch XML; got {0}, expected 'Patch'", documentElement.Name));
                }
                else
                {
                    for (int j = 0; j < documentElement.ChildNodes.Count; j++)
                    {
                        XmlNode xmlNode = documentElement.ChildNodes[j];
                        if (xmlNode.NodeType == XmlNodeType.Element)
                        {
                            if (xmlNode.Name != "Operation")
                            {
                                Log.Error(string.Format("Unexpected element in patch XML; got {0}, expected 'Operation'", documentElement.ChildNodes[j].Name));
                            }
                            else
                            {
                                PatchOperation patchOperation = DirectXmlToObject.ObjectFromXml <PatchOperation>(xmlNode, false);
                                patchOperation.sourceFile = list[i].FullFilePath;
                                this.patches.Add(patchOperation);
                            }
                        }
                    }
                }
            }
            DeepProfiler.End();
        }
Exemple #25
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();
            }
        }
Exemple #26
0
        static ModsConfig()
        {
            activeModsHashSet           = new HashSet <string>();
            activeModsInLoadOrderCached = new List <ModMetaData>();
            bool flag  = false;
            bool flag2 = false;

            data = DirectXmlLoader.ItemFromXmlFile <ModsConfigData>(GenFilePaths.ModsConfigFilePath);
            if (data.version != null)
            {
                bool flag3 = false;
                int  result;
                if (data.version.Contains("."))
                {
                    int num = VersionControl.MinorFromVersionString(data.version);
                    if (VersionControl.MajorFromVersionString(data.version) != VersionControl.CurrentMajor || num != VersionControl.CurrentMinor)
                    {
                        flag3 = true;
                    }
                }
                else if (data.version.Length > 0 && data.version.All((char x) => char.IsNumber(x)) && int.TryParse(data.version, out result) && result <= 2009)
                {
                    flag3 = true;
                }
                if (flag3)
                {
                    Log.Message("Mods config data is from version " + data.version + " while we are running " + VersionControl.CurrentVersionStringWithRev + ". Resetting.");
                    data = new ModsConfigData();
                    flag = true;
                }
            }
            for (int i = 0; i < data.activeMods.Count; i++)
            {
                string packageId = data.activeMods[i];
                if (ModLister.GetModWithIdentifier(packageId) == null)
                {
                    ModMetaData modMetaData = ModLister.AllInstalledMods.FirstOrDefault((ModMetaData m) => m.FolderName == packageId);
                    if (modMetaData != null)
                    {
                        data.activeMods[i] = modMetaData.PackageId;
                        flag2 = true;
                    }
                    if (TryGetPackageIdWithoutExtraSteamPostfix(packageId, out var nonSteamPackageId) && ModLister.GetModWithIdentifier(nonSteamPackageId) != null)
                    {
                        data.activeMods[i] = nonSteamPackageId;
                    }
                }
            }
            HashSet <string> hashSet = new HashSet <string>();

            foreach (ModMetaData allInstalledMod in ModLister.AllInstalledMods)
            {
                if (allInstalledMod.Active)
                {
                    if (hashSet.Contains(allInstalledMod.PackageIdNonUnique))
                    {
                        allInstalledMod.Active = false;
                        Log.Warning("There was more than one enabled instance of mod with PackageID: " + allInstalledMod.PackageIdNonUnique + ". Disabling the duplicates.");
                        continue;
                    }
                    hashSet.Add(allInstalledMod.PackageIdNonUnique);
                }
                if (!allInstalledMod.IsCoreMod && allInstalledMod.Official && IsExpansionNew(allInstalledMod.PackageId))
                {
                    SetActive(allInstalledMod.PackageId, active: true);
                    AddKnownExpansion(allInstalledMod.PackageId);
                    flag2 = true;
                }
            }
            if (!File.Exists(GenFilePaths.ModsConfigFilePath) || flag)
            {
                Reset();
            }
            else if (flag2)
            {
                Save();
            }
            RecacheActiveMods();
        }