Beispiel #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();
            }
        }
Beispiel #2
0
        // Save keybind for a single mod to config file.
        public static void SaveModBinds(Mod mod)
        {
            KeybindList list = new KeybindList();
            string      path =
                Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json");

            Keybind[] binds = Keybind.Get(mod).ToArray();
            for (int i = 0; i < binds.Length; i++)
            {
                if (binds[i].ID == null || binds[i].Vals != null)
                {
                    continue;
                }
                Keybinds keybinds = new Keybinds {
                    ID       = binds[i].ID, Key = binds[i].Key,
                    Modifier = binds[i].Modifier
                };

                list.keybinds.Add(keybinds);
            }

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

            File.WriteAllText(path, serializedData);
        }
Beispiel #3
0
        public void LoadConsoleSize()
        {
            string path = ModLoader.GetModSettingsFolder(new ModConsole());

            if (File.Exists(Path.Combine(path, "console.data")))
            {
                try
                {
                    m_transform = GetComponent <RectTransform>();
                    m_logview   = logview.GetComponent <RectTransform>();
                    m_scrollbar = scrollbar.GetComponent <RectTransform>();
                    string   data   = File.ReadAllText(Path.Combine(path, "console.data"));
                    string[] values = data.Trim().Split(',');
                    m_transform.anchoredPosition = new Vector3(0f, float.Parse(values[0], CultureInfo.InvariantCulture));
                    m_logview.anchoredPosition   = new Vector3(0f, float.Parse(values[1], CultureInfo.InvariantCulture));
                    m_scrollbar.anchoredPosition = new Vector3(0f, float.Parse(values[2], CultureInfo.InvariantCulture));
                    m_logview.sizeDelta          = new Vector2(333f, float.Parse(values[3], CultureInfo.InvariantCulture));
                    m_scrollbar.sizeDelta        = new Vector2(13f, float.Parse(values[4], CultureInfo.InvariantCulture));
                }
                catch (Exception e)
                {
                    if (ModLoader.devMode)
                    {
                        ModConsole.Error(e.ToString());
                    }
                    Debug.Log(e);
                    File.Delete(Path.Combine(path, "console.data"));
                }
            }
        }
Beispiel #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);
                }
            }
        }
        // Load all keybinds.
        public static void LoadBinds()
        {
            foreach (Mod mod in ModLoader.LoadedMods.Where(mod => Keybind.Get(mod).Count > 0))
            {
                // Check if there is custom keybinds file (if not, create)
                string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json");
                if (!File.Exists(path))
                {
                    SaveModBinds(mod);
                    continue;
                }

                //Load and deserialize
                KeybindList keybinds = Newtonsoft.Json.JsonConvert.DeserializeObject <KeybindList>(File.ReadAllText(path));

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

                foreach (Keybinds kb in keybinds.keybinds)
                {
                    Keybind bind = Keybind.Keybinds.Find(x => x.Mod == mod && x.ID == kb.ID);

                    if (bind == null)
                    {
                        continue;
                    }

                    bind.Key      = kb.Key;
                    bind.Modifier = kb.Modifier;
                }
            }
        }
Beispiel #6
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);
        }
        // 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));
                }
            }
        }
        // Save keybind for a single mod to config file.
        public static void SaveModBinds(Mod mod)
        {
            KeybindList list = new KeybindList();

            foreach (Keybind bind in Keybind.Get(mod))
            {
                if (bind.ID == null || bind.Vals != null)
                {
                    continue;
                }

                Keybinds keybinds = new Keybinds
                {
                    ID       = bind.ID,
                    Key      = bind.Key,
                    Modifier = bind.Modifier
                };

                list.keybinds.Add(keybinds);
            }

            if (list.keybinds.Count > 0)
            {
                File.WriteAllText(Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json"), Newtonsoft.Json.JsonConvert.SerializeObject(list, Newtonsoft.Json.Formatting.Indented));
            }
        }
Beispiel #9
0
        public void SaveConsoleSize()
        {
            string path = ModLoader.GetModSettingsFolder(new ModConsole());
            string data = string.Format("{0},{1},{2},{3},{4}", m_transform.anchoredPosition.y, m_logview.anchoredPosition.y, m_scrollbar.anchoredPosition.y, m_logview.sizeDelta.y, m_scrollbar.sizeDelta.y);

            File.WriteAllText(Path.Combine(path, "console.data"), data);
        }
Beispiel #10
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);
        }
        public void SaveConsoleSize()
        {
            string path = ModLoader.GetModSettingsFolder(new ModConsole());

            if (Xresizer)
            {
                ConsoleSizeSave css = new ConsoleSizeSave()
                {
                    otherResizerPos = new float[] { m_otherResizer.anchoredPosition.x,
                                                    m_otherResizer.anchoredPosition.y },
                    otherResizerSize =
                        new float[] { m_otherResizer.sizeDelta.x, m_otherResizer.sizeDelta.y },
                    ResizerPos = new float[] { m_transform.anchoredPosition.x,
                                               m_transform.anchoredPosition.y },
                    ResizerSize =
                        new float[] { m_transform.sizeDelta.x, m_transform.sizeDelta.y },
                    ScrollbarPos = new float[] { m_scrollbar.anchoredPosition.x,
                                                 m_scrollbar.anchoredPosition.y },
                    ScrollbarSize =
                        new float[] { m_scrollbar.sizeDelta.x, m_scrollbar.sizeDelta.y },
                    LogviewPos = new float[] { m_logview.anchoredPosition.x,
                                               m_logview.anchoredPosition.y },
                    LogviewSize    = new float[] { m_logview.sizeDelta.x, m_logview.sizeDelta.y },
                    InputFieldSize =
                        new float[] { m_inputField.sizeDelta.x, m_inputField.sizeDelta.y },
                    SubmitBtnPos = new float[] { m_submitBtn.anchoredPosition.x,
                                                 m_submitBtn.anchoredPosition.y }
                };
                string serializedData =
                    JsonConvert.SerializeObject(css, Formatting.Indented);
                File.WriteAllText(Path.Combine(path, "consoleSize.data"), serializedData);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Serialize custom save class (see example)
        /// Call Only in <see cref="Mod.OnSave"/>
        /// </summary>
        /// <typeparam name="T">Your class</typeparam>
        /// <param name="mod">Mod Instance</param>
        /// <param name="saveDataClass">Your class</param>
        /// <param name="fileName">Name of the save file</param>
        /// <example><code source="SaveExamples.cs" region="Serializer" lang="C#"
        /// title="Example of save class" /></example>
        public static void SerializeSaveFile <T>(Mod mod, T saveDataClass, string fileName)
        {
            var config = new JsonSerializerSettings();

            config.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            config.Formatting            = Formatting.Indented;
            string path           = Path.Combine(ModLoader.GetModSettingsFolder(mod), fileName);
            string serializedData = JsonConvert.SerializeObject(saveDataClass, config);

            File.WriteAllText(path, serializedData);
        }
Beispiel #13
0
        /// <summary>
        /// Deserialize custom save class (see example)
        /// </summary>
        /// <typeparam name="T">Your save class</typeparam>
        /// <param name="mod">Mod Instance</param>
        /// <param name="fileName">Name of the save file</param>
        /// <returns>Deserialized class</returns>
        /// <example><code source="SaveExamples.cs" region="Deserializer" lang="C#"
        /// title="Example of loading class" /></example>
        public static T DeserializeSaveFile <T>(Mod mod, string fileName) where T : new()
        {
            string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), fileName);

            if (File.Exists(path))
            {
                string serializedData = File.ReadAllText(path);
                return(JsonConvert.DeserializeObject <T>(serializedData));
            }
            return(default(T));
        }
        // 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();
            }
        }
        // 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);
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Save position and rotation of single gameobject to file (DO NOT loop this for
        /// multiple gameobjects) Call this in <see cref="Mod.OnSave"/>  function
        /// </summary>
        /// <param name="mod">Mod instance</param>
        /// <param name="g">Your GameObject to save</param>
        /// <param name="fileName">Name of the save file</param>
        public static void SaveGameObject(Mod mod, GameObject g, string fileName)
        {
            string       path = Path.Combine(ModLoader.GetModSettingsFolder(mod), fileName);
            SaveData     save = new SaveData();
            SaveDataList s    = new SaveDataList {
                name = g.name, pos = g.transform.position,
                rotX = g.transform.localEulerAngles.x, rotY = g.transform.localEulerAngles.y,
                rotZ = g.transform.localEulerAngles.z
            };

            save.save.Add(s);
            string serializedData = JsonConvert.SerializeObject(save, Formatting.Indented);

            File.WriteAllText(path, serializedData);
        }
        public void LoadConsoleSize()
        {
            if (!Xresizer)
            {
                return;
            }
            Start();
            string path = ModLoader.GetModSettingsFolder(new ModConsole());

            if (File.Exists(Path.Combine(path, "consoleSize.data")))
            {
                try {
                    ConsoleSizeSave css = JsonConvert.DeserializeObject <ConsoleSizeSave>(
                        File.ReadAllText(Path.Combine(path, "consoleSize.data")));
                    m_transform.anchoredPosition =
                        new Vector2(css.ResizerPos[0], css.ResizerPos[1]);
                    m_transform.sizeDelta =
                        new Vector2(css.ResizerSize[0], css.ResizerSize[1]);
                    m_otherResizer.anchoredPosition =
                        new Vector2(css.otherResizerPos[0], css.otherResizerPos[1]);
                    m_otherResizer.sizeDelta =
                        new Vector2(css.otherResizerSize[0], css.otherResizerSize[1]);
                    m_scrollbar.anchoredPosition =
                        new Vector2(css.ScrollbarPos[0], css.ScrollbarPos[1]);
                    m_scrollbar.sizeDelta =
                        new Vector2(css.ScrollbarSize[0], css.ScrollbarSize[1]);
                    m_logview.anchoredPosition =
                        new Vector2(css.LogviewPos[0], css.LogviewPos[1]);
                    m_logview.sizeDelta    = new Vector2(css.LogviewSize[0], css.LogviewSize[1]);
                    m_inputField.sizeDelta =
                        new Vector2(css.InputFieldSize[0], css.InputFieldSize[1]);
                    m_submitBtn.anchoredPosition =
                        new Vector2(css.SubmitBtnPos[0], css.SubmitBtnPos[1]);
                } catch (Exception e) {
                    if (ModLoader.devMode)
                    {
                        ModConsole.Error(e.ToString());
                    }
                    System.Console.WriteLine(e);
                    File.Delete(Path.Combine(path, "consoleSize.data"));
                }
            }
        }
Beispiel #18
0
        // Load all keybinds.
        public static void LoadBinds()
        {
            Mod[] binds =
                ModLoader.LoadedMods.Where(mod => Keybind.Get(mod).Count > 0).ToArray();
            for (int i = 0; i < binds.Length; i++)
            {
                // delete old xml file (if exists)
                string path =
                    Path.Combine(ModLoader.GetModSettingsFolder(binds[i]), "keybinds.xml");
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                // Check if there is custom keybinds file (if not, create)
                path =
                    Path.Combine(ModLoader.GetModSettingsFolder(binds[i]), "keybinds.json");
                if (!File.Exists(path))
                {
                    SaveModBinds(binds[i]);
                    continue;
                }

                // Load and deserialize
                KeybindList keybinds =
                    JsonConvert.DeserializeObject <KeybindList>(File.ReadAllText(path));
                if (keybinds.keybinds.Count == 0)
                {
                    continue;
                }
                for (int k = 0; k < keybinds.keybinds.Count; k++)
                {
                    Keybind bind = Keybind.Keybinds.Find(
                        x => x.Mod == binds[i] && x.ID == keybinds.keybinds[k].ID);
                    if (bind == null)
                    {
                        continue;
                    }
                    bind.Key      = keybinds.keybinds[k].Key;
                    bind.Modifier = keybinds.keybinds[k].Modifier;
                }
            }
        }
Beispiel #19
0
        // Save keybind for a single mod to config file.
        public static void SaveModBinds(Mod mod)
        {
            KeybindList list = new KeybindList();
            string      path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json");

            foreach (Keybind bind in Keybind.Get(mod))
            {
                Keybinds keybinds = new Keybinds
                {
                    ID       = bind.ID,
                    Key      = bind.Key,
                    Modifier = bind.Modifier
                };

                list.keybinds.Add(keybinds);
            }

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

            File.WriteAllText(path, serializedData);
        }
Beispiel #20
0
        // Load all keybinds.
        public static void LoadBinds()
        {
            foreach (Mod mod in ModLoader.LoadedMods)
            {
                //delete old xml file (if exists)
                string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.xml");
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                // Check if there is custom keybinds file (if not, create)
                path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json");
                if (!File.Exists(path))
                {
                    SaveModBinds(mod);
                    continue;
                }

                //Load and deserialize
                KeybindList keybinds       = new KeybindList();
                string      serializedData = File.ReadAllText(path);
                keybinds = JsonConvert.DeserializeObject <KeybindList>(serializedData);
                if (keybinds.keybinds.Count == 0)
                {
                    continue;
                }
                foreach (var kb in keybinds.keybinds)
                {
                    Keybind bind = Keybind.Keybinds.Find(x => x.Mod == mod && x.ID == kb.ID);
                    if (bind == null)
                    {
                        continue;
                    }
                    bind.Key      = kb.Key;
                    bind.Modifier = kb.Modifier;
                }
            }
        }
Beispiel #21
0
        // Reset keybinds
        public void ResetBinds(Mod mod)
        {
            if (mod != null)
            {
                // Delete file
                string path = Path.Combine(ModLoader.GetModSettingsFolder(mod), "keybinds.json");

                // Revert binds
                foreach (Keybind bind in Keybind.Get(mod))
                {
                    Keybind original = Keybind.DefaultKeybinds.Find(x => x.Mod == mod && x.ID == bind.ID);

                    if (original != null)
                    {
                        ModConsole.Print(original.Key.ToString() + " -> " + bind.Key.ToString());
                        bind.Key      = original.Key;
                        bind.Modifier = original.Modifier;
                    }
                }

                // Save binds
                SaveModBinds(mod);
            }
        }