// Reset keybinds private void resetBinds() { if (selectedMod != null) { // Delete file string path = ModLoader.ConfigFolder + selectedMod.ID + "\\keybinds.xml"; File.WriteAllText(path, ""); // Revert binds foreach (Keybind bind in Keybind.Get(selectedMod)) { Keybind original = Keybind.DefaultKeybinds.Find(x => x.Mod == selectedMod && x.ID == bind.ID); if (original != null) { bind.Key = original.Key; bind.Modifier = original.Modifier; ModConsole.Print(original.Key.ToString() + " -> " + bind.Key.ToString()); } } // Save binds SaveModBinds(selectedMod); } }
/// <summary> /// Save keybind for a single mod to config file. /// </summary> /// <param name="mod">The mod to save the config for.</param> public static void SaveModBinds(Mod mod) { string path = ModLoader.ConfigFolder + mod.ID + "\\keybinds.xml"; // Clear file File.WriteAllText(path, ""); // Write XML XmlDocument doc = new XmlDocument(); XmlElement keybinds = doc.CreateElement(string.Empty, "Keybinds", string.Empty); foreach (Keybind bind in Keybind.Get(mod)) { XmlElement keybind = doc.CreateElement(string.Empty, "Keybind", string.Empty); XmlElement name = doc.CreateElement(string.Empty, "ID", string.Empty); name.AppendChild(doc.CreateTextNode(bind.ID)); keybind.AppendChild(name); XmlElement key = doc.CreateElement(string.Empty, "Key", string.Empty); key.AppendChild(doc.CreateTextNode(bind.Key.ToString())); keybind.AppendChild(key); XmlElement modifier = doc.CreateElement(string.Empty, "Modifier", string.Empty); modifier.AppendChild(doc.CreateTextNode(bind.Modifier.ToString())); keybind.AppendChild(modifier); keybinds.AppendChild(keybind); } doc.AppendChild(keybinds); doc.Save(path); }
// 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); }
// 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; } } }
// 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)); } }
// 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; } } }
// Reset keybinds public static void ResetBinds(Mod mod) { if (mod != null) { // Revert binds foreach (Keybind bind in Keybind.Get(mod)) { Keybind original = Keybind.GetDefault(mod).Find(x => x.ID == bind.ID); if (original != null) { bind.Key = original.Key; bind.Modifier = original.Modifier; } } // Save binds SaveModBinds(mod); } }
// Reset keybinds public static void ResetBinds(Mod mod) { if (mod != null) { // Revert binds Keybind[] bind = Keybind.Get(mod).ToArray(); for (int i = 0; i < bind.Length; i++) { Keybind original = Keybind.GetDefault(mod).Find(x => x.ID == bind[i].ID); if (original != null) { bind[i].Key = original.Key; bind[i].Modifier = original.Modifier; } } // Save binds SaveModBinds(mod); } }
// 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); }
// 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); } }
public void ModButton(string name, string version, string author, Mod mod) { GameObject modButton = Instantiate(ms.ModButton); if (mod.ID.StartsWith("MSCLoader_")) { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.cyan; modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text = "<color=cyan>Core Module!</color>"; modButton.transform.GetChild(1) .GetChild(4) .GetChild(0) .GetComponent <Button>() .interactable = false; } else if (mod.isDisabled) { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.red; modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text = "<color=red>Mod is disabled!</color>"; modButton.transform.GetChild(2).GetChild(1).gameObject.SetActive( true); // Add plugin Disabled icon modButton.transform.GetChild(2).GetChild(1).GetComponent <Image>().color = Color.red; } else if (!mod.LoadInMenu && ModLoader.GetCurrentScene() == CurrentScene.MainMenu) { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.yellow; modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text = "<color=yellow>Ready to load</color>"; } else { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.green; } modButton.transform.GetChild(1) .GetChild(4) .GetChild(0) .GetComponent <Button>() .onClick.AddListener(() => ms.settings.ModDetailsShow(mod)); if (Settings.Get(mod).Count > 0) { modButton.transform.GetChild(1) .GetChild(4) .GetChild(1) .GetComponent <Button>() .interactable = true; modButton.transform.GetChild(1) .GetChild(4) .GetChild(1) .GetComponent <Button>() .onClick.AddListener(() => ms.settings.ModSettingsShow(mod)); } if (Keybind.Get(mod).Count > 0) { modButton.transform.GetChild(1) .GetChild(4) .GetChild(2) .GetComponent <Button>() .interactable = true; modButton.transform.GetChild(1) .GetChild(4) .GetChild(2) .GetComponent <Button>() .onClick.AddListener(() => ms.settings.ModKeybindsShow(mod)); } if (name.Length > 24) { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().text = string.Format("{0}...", name.Substring(0, 22)); } else { modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().text = name; } modButton.transform.GetChild(1).GetChild(1).GetComponent <Text>().text = string.Format("by <color=orange>{0}</color>", author); modButton.transform.GetChild(1).GetChild(2).GetComponent <Text>().text = version; modButton.transform.SetParent(modView.transform, false); if (mod.metadata != null && mod.metadata.icon.iconFileName != null && mod.metadata.icon.iconFileName != string.Empty) { if (mod.metadata.icon.isIconRemote) { if (File.Exists(Path.Combine(ModLoader.ManifestsFolder, @"Mod Icons\" + mod.metadata.icon.iconFileName))) { try { Texture2D t2d = new Texture2D(1, 1); t2d.LoadImage(File.ReadAllBytes(Path.Combine(ModLoader.ManifestsFolder, @"Mod Icons\" + mod.metadata.icon.iconFileName))); modButton.transform.GetChild(0) .GetChild(0) .GetComponent <RawImage>() .texture = t2d; } catch (Exception e) { ModConsole.Error(e.Message); System.Console.WriteLine(e); } } } else if (mod.metadata.icon.isIconUrl) { try { WWW www = new WWW(mod.metadata.icon.iconFileName); modButton.transform.GetChild(0) .GetChild(0) .GetComponent <RawImage>() .texture = www.texture; } catch (Exception e) { ModConsole.Error(e.Message); System.Console.WriteLine(e); } } else { if (File.Exists(Path.Combine(ModLoader.GetModAssetsFolder(mod), mod.metadata.icon.iconFileName))) { try { Texture2D t2d = new Texture2D(1, 1); t2d.LoadImage( File.ReadAllBytes(Path.Combine(ModLoader.GetModAssetsFolder(mod), mod.metadata.icon.iconFileName))); modButton.transform.GetChild(0) .GetChild(0) .GetComponent <RawImage>() .texture = t2d; } catch (Exception e) { ModConsole.Error(e.Message); System.Console.WriteLine(e); } } } } if (mod.hasUpdate) { modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text = "<color=lime>UPDATE AVAILABLE!</color>"; } if (mod.UseAssetsFolder) { modButton.transform.GetChild(2).GetChild(2).gameObject.SetActive( true); // Add assets icon } if (!mod.isDisabled) { modButton.transform.GetChild(2).GetChild(1).gameObject.SetActive( true); // Add plugin OK icon } if (mod.LoadInMenu) { modButton.transform.GetChild(2).GetChild(0).gameObject.SetActive( true); // Add Menu Icon } }