예제 #1
0
        // Load all settings.
        public static void LoadSettings()
        {
            foreach (Mod mod in ModLoader.LoadedMods)
            {
                // Check if there is custom settings file (if not, ignore)
                string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "settings.json");
                if (!File.Exists(path))
                {
                    continue;
                }

                //Load and deserialize
                SettingsList settings       = new SettingsList();
                string       serializedData = File.ReadAllText(path);
                settings       = JsonConvert.DeserializeObject <SettingsList>(serializedData);
                mod.isDisabled = settings.isDisabled;
                if (settings.settings.Count == 0)
                {
                    continue;
                }

                foreach (var kb in settings.settings)
                {
                    Settings set = Settings.modSettings.Find(x => x.Mod == mod && x.ID == kb.ID);
                    if (set == null)
                    {
                        continue;
                    }
                    set.Value = kb.Value;
                }

                mod.ModSettingsLoaded();
            }
        }
예제 #2
0
        // Save settings for a single mod to config file.
        public static void SaveSettings(Mod mod)
        {
            SettingsList list = new SettingsList();

            list.isDisabled = mod.isDisabled;
            string path =
                Path.Combine(ModLoader.GetModSettingsFolder(mod), "settings.json");

            Settings[] set = Settings.Get(mod).ToArray();
            for (int i = 0; i < set.Length; i++)
            {
                if (set[i].type == SettingsType.Button ||
                    set[i].type == SettingsType.RButton ||
                    set[i].type == SettingsType.Header || set[i].type == SettingsType.Text)
                {
                    continue;
                }

                Setting sets = new Setting {
                    ID = set[i].ID, Value = set[i].Value
                };

                list.settings.Add(sets);
            }

            string serializedData = JsonConvert.SerializeObject(list, Formatting.Indented);

            File.WriteAllText(path, serializedData);
        }
예제 #3
0
        // Save settings for a single mod to config file.
        public static void SaveSettings(Mod mod)
        {
            SettingsList list = new SettingsList();

            list.isDisabled = mod.isDisabled;
            string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "settings.json");

            foreach (Settings set in Settings.Get(mod))
            {
                if (set.type == SettingsType.Button || set.type == SettingsType.Header)
                {
                    continue;
                }

                Setting sets = new Setting
                {
                    ID    = set.ID,
                    Value = set.Value
                };

                list.settings.Add(sets);
            }

            string serializedData = JsonConvert.SerializeObject(list, Formatting.Indented);

            File.WriteAllText(path, serializedData);
        }
예제 #4
0
        // Load all settings.
        public static void LoadSettings()
        {
            for (int i = 0; i < ModLoader.LoadedMods.Count; i++)
            {
                // Check if there is custom settings file (if not, ignore)
                string path = Path.Combine(ModLoader.GetModSettingsFolder(ModLoader.LoadedMods[i]), "settings.json");
                if (!File.Exists(path))
                {
                    SaveSettings(ModLoader.LoadedMods[i]); //create settings file if not exists.
                }
                //Load and deserialize
                SettingsList settings = JsonConvert.DeserializeObject <SettingsList>(File.ReadAllText(path));
                ModLoader.LoadedMods[i].isDisabled = settings.isDisabled;
                try
                {
                    if (ModLoader.LoadedMods[i].LoadInMenu && !ModLoader.LoadedMods[i].isDisabled && ModLoader.LoadedMods[i].fileName != null)
                    {
                        ModLoader.LoadedMods[i].OnMenuLoad();
                    }
                }
                catch (Exception e)
                {
                    string errorDetails = string.Format("{2}<b>Details: </b>{0} in <b>{1}</b>", e.Message, new StackTrace(e, true).GetFrame(0).GetMethod(), Environment.NewLine);
                    ModConsole.Error(string.Format("Mod <b>{0}</b> throw an error!{1}", ModLoader.LoadedMods[i].ID, errorDetails));
                    if (ModLoader.devMode)
                    {
                        ModConsole.Error(e.ToString());
                    }
                    System.Console.WriteLine(e);
                }
                if (Settings.Get(ModLoader.LoadedMods[i]).Count == 0)
                {
                    continue;
                }

                for (int j = 0; j < settings.settings.Count; j++)
                {
                    Settings set = Settings.modSettings.Find(x => x.Mod == ModLoader.LoadedMods[i] && x.ID == settings.settings[j].ID);
                    if (set == null)
                    {
                        continue;
                    }
                    set.Value = settings.settings[j].Value;
                }
                try
                {
                    ModLoader.LoadedMods[i].ModSettingsLoaded();
                }
                catch (Exception e)
                {
                    string errorDetails = string.Format("{2}<b>Details: </b>{0} in <b>{1}</b>", e.Message, new StackTrace(e, true).GetFrame(0).GetMethod(), Environment.NewLine);
                    ModConsole.Error(string.Format("Mod <b>{0}</b> throw an error!{1}", ModLoader.LoadedMods[i].ID, errorDetails));
                    if (ModLoader.devMode)
                    {
                        ModConsole.Error(e.ToString());
                    }
                    System.Console.WriteLine(e);
                }
            }
        }
예제 #5
0
        // Save settings for a single mod to config file.
        public static void SaveSettings(Mod mod)
        {
            SettingsList list = new SettingsList {
                isDisabled = mod.isDisabled
            };

            foreach (Settings set in Settings.Get(mod).Where(set =>
                                                             set.type != SettingsType.Button && set.type != SettingsType.RButton && set.type != SettingsType.Header && set.type != SettingsType.Text))
            {
                Setting sets = new Setting
                {
                    ID    = set.ID,
                    Value = set.Value
                };

                list.settings.Add(sets);
            }

            if (list.isDisabled || list.settings.Count > 0)
            {
                File.WriteAllText(Path.Combine(ModLoader.GetModSettingsFolder(mod), "settings.json"), Newtonsoft.Json.JsonConvert.SerializeObject(list, Newtonsoft.Json.Formatting.Indented));
            }
            else if (Directory.Exists(Path.Combine(ModLoader.SettingsFolder, mod.ID)))
            {
                if (File.Exists(Path.Combine(ModLoader.SettingsFolder, mod.ID + "/settings.json")))
                {
                    File.Delete(Path.Combine(ModLoader.SettingsFolder, mod.ID + "/settings.json"));
                }

                if (Directory.GetDirectories(Path.Combine(ModLoader.SettingsFolder, mod.ID)).Length == 0 && Directory.GetFiles(Path.Combine(ModLoader.SettingsFolder, mod.ID)).Length == 0)
                {
                    Directory.Delete(Path.Combine(ModLoader.SettingsFolder, mod.ID));
                }
            }
        }
예제 #6
0
        // Load all settings.
        public static void LoadSettings()
        {
            foreach (Mod mod in ModLoader.LoadedMods)
            {
                // Check if there is custom settings file (if not, ignore)
                string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "settings.json");
                if (!File.Exists(path))
                {
                    SaveSettings(mod); //create settings file if not exists.
                }
                //Load and deserialize
                SettingsList settings       = new SettingsList();
                string       serializedData = File.ReadAllText(path);
                settings       = JsonConvert.DeserializeObject <SettingsList>(serializedData);
                mod.isDisabled = settings.isDisabled;
                try
                {
                    if (mod.LoadInMenu && !mod.isDisabled && mod.fileName != null)
                    {
                        mod.OnMenuLoad();
                    }
                }
                catch (Exception e)
                {
                    StackFrame frame = new StackTrace(e, true).GetFrame(0);

                    string errorDetails = string.Format("{2}<b>Details: </b>{0} in <b>{1}</b>", e.Message, frame.GetMethod(), Environment.NewLine);
                    ModConsole.Error(string.Format("Mod <b>{0}</b> throw an error!{1}", mod.ID, errorDetails));
                    if (ModLoader.devMode)
                    {
                        ModConsole.Error(e.ToString());
                    }
                    UnityEngine.Debug.Log(e);
                }

                if (settings.settings.Count == 0)
                {
                    continue;
                }

                foreach (var kb in settings.settings)
                {
                    Settings set = Settings.modSettings.Find(x => x.Mod == mod && x.ID == kb.ID);
                    if (set == null)
                    {
                        continue;
                    }
                    set.Value = kb.Value;
                }
                mod.ModSettingsLoaded();
            }
        }
예제 #7
0
        // Load all settings.
        public static void LoadSettings()
        {
            foreach (Mod mod in ModLoader.LoadedMods)
            {
                // Check if there is custom settings file (if not, ignore)
                if (true)//Settings.Get(mod).Where(set => set.type != SettingsType.Button && set.type != SettingsType.Header && set.type != SettingsType.Text).ToList().Count > 0)
                {
                    string path = Path.Combine(ModLoader.GetModSettingsFolder(mod, false), "settings.json");
                    if (!File.Exists(path))
                    {
                        SaveSettings(mod);
                    }

                    if (File.Exists(path))
                    {
                        SettingsList settings = Newtonsoft.Json.JsonConvert.DeserializeObject <SettingsList>(File.ReadAllText(path));
                        mod.isDisabled = settings.isDisabled;

                        foreach (Setting kb in settings.settings)
                        {
                            Settings set = Settings.modSettings.Find(x => x.Mod == mod && x.ID == kb.ID);

                            if (set == null)
                            {
                                continue;
                            }

                            set.Value = kb.Value;
                        }
                        mod.ModSettingsLoaded();
                    }
                }

                try
                {
                    if (mod.LoadInMenu && !mod.isDisabled && mod.fileName != null)
                    {
                        mod.OnMenuLoad();
                    }
                }
                catch (Exception e)
                {
                    StackFrame frame = new StackTrace(e, true).GetFrame(0);

                    string errorDetails = string.Format("{2}<b>Details: </b>{0} in <b>{1}</b>", e.Message, frame.GetMethod(), Environment.NewLine);
                    ModConsole.Error(string.Format("Mod <b>{0}</b> throw an error!{1}", mod.ID, errorDetails));
                    ModConsole.Error(e.ToString());
                    System.Console.WriteLine(e);
                }
            }
        }