Ejemplo n.º 1
0
        public static bool LoadSettings(string configPath)
        {
            //Load Settings
            try
            {
                var  overridefile     = System.IO.Path.Combine(configPath, "override.txt");
                bool overrideSettings = false;
                bool forceDebug       = false;


                if (File.Exists(overridefile))
                {
                    string overridetext = File.ReadAllText(overridefile);
                    if (overridetext.IndexOf("force local settings", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        overrideSettings = true;
                    }
                    if (overridetext.IndexOf("force debug on", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        forceDebug = true;
                    }
                    if (overridetext.IndexOf("force disabled on", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    File.WriteAllText(overridefile, "");
                }

                bool modLibLoaded = false;

                if (!modLibLoaded)
                {
                    string configFilePath         = System.IO.Path.Combine(configPath, "tournamentxpsettings.json");
                    TournamentXPSettings settings = GetFromFile(configFilePath);

                    if (forceDebug)
                    {
                        settings.DebugMode = true;
                    }
#if DEBUG
                    settings.DebugMode = true;
#endif
                    TournamentXPSettings.SetSettings(settings);
                }
            }
            catch
            {
                // ErrorLog.Log("Error Loading Settings\n" + ex.ToStringFull());
                return(false);
            }
            return(true);
        }
        public static bool GetModLibSettings(bool forceDebug = false, bool forceMenu = false)
        {
            var modnames = Utilities.GetModulesNames().ToList();

            if (modnames.Contains("Bannerlord.MBOptionScreen"))
            {
                if (forceMenu)
                {
                    //Reenable ModLib settings menu option
                    Module.CurrentModule.AddInitialStateOption(new InitialStateOption("ModOptionsMenu", new TextObject("ModLib Options"), 9990, () =>
                    {
                        ScreenManager.PushScreen(new ModOptionsGauntletScreen());
                    }, false));
                }
            }

            try
            {
                FileDatabase.Initialise(SettingsHelper.ModuleFolderName);
                TournamentXPSettingsModLib settings = FileDatabase.Get <TournamentXPSettingsModLib>(TournamentXPSettingsModLib.InstanceID);
                if (settings == null)
                {
                    settings = new TournamentXPSettingsModLib();
                }
                SettingsDatabase.RegisterSettings(settings);
                if (forceDebug)
                {
                    settings.DebugMode = true;
                }
                TournamentXPSettings.SetSettings(settings.GetSettings());
            }
            catch (Exception ex)
            {
                ErrorLog.Log("TournamentsXPanded failed to initialize settings data.\n\n" + ex.ToStringFull());
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public static bool GetSettings()
        {
            //Load Settings
            try
            {
                var  overridefile     = System.IO.Path.Combine(TaleWorlds.Engine.Utilities.GetConfigsPath(), ModuleFolderName, "override.txt");
                bool overrideSettings = false;
                bool forceDebug       = false;
                bool forceMenu        = false;
                if (File.Exists(overridefile))
                {
                    string overridetext = File.ReadAllText(overridefile);
                    if (overridetext.IndexOf("force local settings", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        overrideSettings = true;
                    }
                    if (overridetext.IndexOf("force debug on", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        forceDebug = true;
                    }
                    if (overridetext.IndexOf("force modlib on", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        forceMenu = true;
                    }
                }

                var  modnames     = Utilities.GetModulesNames().ToList();
                bool modLibLoaded = false;
                if (modnames.Contains("ModLib") && !overrideSettings)
                {
                    //    modLibLoaded =  SettingsHelperModLib.GetModLibSettings(forceDebug, forceMenu);

                    var modlibsettingsdll = System.IO.Path.Combine(TaleWorlds.Engine.Utilities.GetBasePath(), "Modules", ModuleFolderName, "bin", "Win64_Shipping_Client", "TournamentsXPanded.Settings.ModLib.dll");
                    modlibsettingsdll = System.IO.Path.GetFullPath(modlibsettingsdll);
                    Assembly assembly = Assembly.LoadFile(modlibsettingsdll);
                    Type     settingsHelperModLibType = assembly.GetType("TournamentsXPanded.Settings.SettingsHelperModLib");

                    Type TournamentXPSettingsModLib = assembly.GetType("TournamentsXPanded.Settings.SettingsHelperModLib.TournamentXPSettingsModLib");

                    TournamentXPSettings osettings = (TournamentXPSettings)settingsHelperModLibType.GetMethod("GetModLibSettings", BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly).Invoke(null, new object[] { forceDebug, forceMenu });
                    if (osettings != null)
                    {
                        TournamentXPSettings.SetSettings(osettings);
                        modLibLoaded = true;
                    }
                }
                if (!modLibLoaded)
                {
                    TournamentXPSettings settings = new TournamentXPSettings();
                    string configPath             = System.IO.Path.Combine(TaleWorlds.Engine.Utilities.GetConfigsPath(), ModuleFolderName, "tournamentxpsettings.json");
                    if (File.Exists(configPath))
                    {
                        var settingsjson = File.ReadAllText(configPath);
                        settings = JsonConvert.DeserializeObject <TournamentXPSettings>(settingsjson);
                    }
                    else
                    {
                        JsonSerializerSettings serializerSettings = new JsonSerializerSettings();
                        serializerSettings.Formatting = Formatting.Indented;

                        var settingsjson = JsonConvert.SerializeObject(settings, serializerSettings);
                        File.WriteAllText(configPath, settingsjson);
                    }

                    if (forceDebug)
                    {
                        settings.DebugMode = true;
                    }
                    TournamentXPSettings.SetSettings(settings);
                }
            }
            catch (Exception ex)
            {
                ErrorLog.Log("Error Loading Settings\n" + ex.ToStringFull());
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        public static bool LoadSettings()
        {
            //Load Settings
            try
            {
                var  overridefile     = System.IO.Path.Combine(TaleWorlds.Engine.Utilities.GetConfigsPath(), ModuleFolderName, "override.txt");
                bool overrideSettings = false;
                bool forceDebug       = false;
                bool forceMenu        = false;
                if (File.Exists(overridefile))
                {
                    string overridetext = File.ReadAllText(overridefile);
                    if (overridetext.IndexOf("force local settings", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        overrideSettings = true;
                    }
                    if (overridetext.IndexOf("force debug on", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        forceDebug = true;
                    }
                }
                else
                {
                    File.WriteAllText(overridefile, "");
                }
                var  modnames     = Utilities.GetModulesNames().ToList();
                bool modLibLoaded = false;
                if (
                    (modnames.Contains("ModLib")
                     //  || modnames.Contains("Bannerlord.MBOptionScreen")
                    ) && !overrideSettings)
                {
                    Type     settingsHelperModLibType = null;
                    Assembly modlibassembly           = null;
                    Assembly modlibSettingsAssembly   = null;

                    try
                    {
                        modlibassembly = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.GetName().Name == "ModLib").FirstOrDefault();
                    }
                    catch { }

                    //try
                    //{
                    //    if (!AppDomain.CurrentDomain.GetAssemblies().Select(x => x.GetName().Name).ToList().Contains("ModLib"))
                    //    {
                    //        var modlibdllpath = System.IO.Path.Combine(TaleWorlds.Engine.Utilities.GetBasePath(), "Modules", "Bannerlord.MBOptionScreen", "bin", "Win64_Shipping_Client", "ModLib.dll");
                    //        modlibdllpath = System.IO.Path.GetFullPath(modlibdllpath);
                    //        if (File.Exists(modlibdllpath))
                    //            modlibassembly = Assembly.LoadFile(modlibdllpath);
                    //    }
                    //}
                    //catch (Exception ex)
                    //{
                    //    ErrorLog.Log("Error Loading ModLib Assembly\n" + ex.ToStringFull());
                    //}

                    if (modlibassembly != null)
                    {
                        var modlibsettingsdll = System.IO.Path.Combine(TaleWorlds.Engine.Utilities.GetBasePath(), "Modules", ModuleFolderName, "bin", "Win64_Shipping_Client", "TournamentsXPanded.Settings.ModLib.dll");
                        modlibsettingsdll        = System.IO.Path.GetFullPath(modlibsettingsdll);
                        modlibSettingsAssembly   = Assembly.LoadFile(modlibsettingsdll);
                        settingsHelperModLibType = modlibSettingsAssembly.GetType("TournamentsXPanded.Settings.SettingsHelperModLib");
                    }

                    if (settingsHelperModLibType != null)
                    {
                        try
                        {
                            TournamentXPSettings osettings = (TournamentXPSettings)settingsHelperModLibType.GetMethod("GetModLibSettings", BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly).Invoke(null, new object[] { forceDebug });
                            if (osettings != null)
                            {
                                TournamentXPSettings.SetSettings(osettings);
                                modLibLoaded = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrorLog.Log("Error getting ModLib settings\n" + ex.ToStringFull());
                        }
                    }
                }
                if (!modLibLoaded)
                {
                    JsonSerializerSettings serializerSettings = new JsonSerializerSettings
                    {
                        Formatting = Formatting.Indented
                    };
                    TournamentXPSettings settings = new TournamentXPSettings();
                    string configPath             = System.IO.Path.Combine(TaleWorlds.Engine.Utilities.GetConfigsPath(), ModuleFolderName, "tournamentxpsettings.json");
                    if (File.Exists(configPath))
                    {
                        var settingsjson = File.ReadAllText(configPath);
                        settings = JsonConvert.DeserializeObject <TournamentXPSettings>(settingsjson);
                        //write new file to get latest updates
                        File.WriteAllText(configPath, settingsjson);
                    }
                    else
                    {
                        var settingsjson = JsonConvert.SerializeObject(settings, serializerSettings);
                        File.WriteAllText(configPath, settingsjson);
                    }

                    if (forceDebug)
                    {
                        settings.DebugMode = true;
                    }

                    TournamentXPSettings.SetSettings(settings);
                }
            }
            catch (Exception ex)
            {
                ErrorLog.Log("Error Loading Settings\n" + ex.ToStringFull());
                return(false);
            }
            return(true);
        }