public static void UpdateManifest(Mod mod) { if (!File.Exists(ModLoader.GetMetadataFolder(string.Format("{0}.json", mod.ID)))) { ModConsole.Error("Metadata file doesn't exists, to create use create command"); return; } if (mod.RemMetadata == null) { ModConsole.Error(string.Format("Your metadata file doesn't seem to be public, you need to upload first before you can update file.{0}If you want to just recreate metadata, delete old file and use create command", Environment.NewLine)); return; } string steamID; if (ModLoader.CheckSteam()) { try { new Version(mod.Version); } catch { ModConsole.Error(string.Format("Invalid version: {0}{1}Please use proper version format: (0.0 or 0.0.0 or 0.0.0.0)", mod.Version, Environment.NewLine)); return; } steamID = Steamworks.SteamUser.GetSteamID().ToString(); if (mod.RemMetadata.sid_sign != ModLoader.MurzynskaMatematyka(steamID + mod.ID)) { ModConsole.Error("This mod doesn't belong to you, can't continue"); return; } try { ModsManifest umm = mod.metadata; Version v1 = new Version(mod.Version); Version v2 = new Version(mod.metadata.version); switch (v1.CompareTo(v2)) { case 0: ModConsole.Error(string.Format("Mod version {0} is same as current metadata version {1}, nothing to update.", mod.Version, mod.metadata.version)); break; case 1: umm.version = mod.Version; umm.sign = AzjatyckaMatematyka(mod.fileName); string msad = ModLoader.GetMetadataFolder(string.Format("{0}.json", mod.ID)); string serializedData = JsonConvert.SerializeObject(umm, Formatting.Indented); File.WriteAllText(msad, serializedData); ModConsole.Print("<color=green>Metadata file updated successfully, you can upload it now!</color>"); break; case -1: ModConsole.Error(string.Format("Mod version {0} is <b>earlier</b> than current metadata version {1}, cannot update.", mod.Version, mod.metadata.version)); break; } } catch (Exception e) { ModConsole.Error(e.Message); System.Console.WriteLine(e); } } else { ModConsole.Error("No valid steam detected"); } }
void CreateList() { if ((bool)ModSettings_menu.showCoreModsDf.GetValue() && !coreModCheckbox.isOn) { coreModCheckbox.isOn = true; return; } Mod[] coreMods = ModLoader.LoadedMods.Where(x => x.ID.StartsWith("MSCLoader_")).ToArray(); Mod[] modList = ModLoader.LoadedMods.Where(x => !x.ID.StartsWith("MSCLoader_")).ToArray(); Mod[] updateMods = modList.Where(x => x.hasUpdate).ToArray(); Mod[] menuMods = modList.Where(x => x.LoadInMenu).ToArray(); RemoveChildren(modView.transform); if (coreModCheckbox.isOn) { ModListHeader("Core Mods", new Color32(101, 34, 18, 255), new Color32(254, 254, 0, 255)); for (int i = 0; i < coreMods.Length; i++) { ModButton(coreMods[i].Name, coreMods[i].Version, coreMods[i].Author, coreMods[i]); } } if (modList.Length == 0) { ModListHeader("No mods installed", Color.blue, Color.white); if (ModLoader.InvalidMods.Count == 0) { return; } ModListHeader("Invalid/Broken Mods", new Color32(101, 34, 18, 255), new Color32(254, 254, 0, 255)); for (int i = 0; i < ModLoader.InvalidMods.Count; i++) { GameObject invMod = Instantiate(ms.ModButton_Invalid); invMod.transform.GetChild(0).GetComponent <Text>().text = ModLoader.InvalidMods[i]; invMod.transform.SetParent(modView.transform, false); } return; } if (updateMods.Length > 0) { ModListHeader("Mods with updates", new Color32(57, 57, 57, 255), new Color32(0, 255, 255, 255)); for (int i = 0; i < updateMods.Length; i++) { ModButton(updateMods[i].Name, updateMods[i].Version, updateMods[i].Author, updateMods[i]); } } if (ModLoader.GetCurrentScene() == CurrentScene.MainMenu) { if (menuMods.Length > 0) { ModListHeader("Loaded Mods", new Color32(57, 57, 57, 255), new Color32(0, 255, 255, 255)); for (int i = 0; i < menuMods.Length; i++) { if (!menuMods[i].isDisabled && !menuMods[i].hasUpdate) { ModButton(menuMods[i].Name, menuMods[i].Version, menuMods[i].Author, menuMods[i]); } } } ModListHeader("Ready to load", new Color32(57, 57, 57, 255), new Color32(0, 255, 255, 255)); for (int i = 0; i < modList.Length; i++) { if (!modList[i].LoadInMenu && !modList[i].isDisabled && !modList[i].hasUpdate) { ModButton(modList[i].Name, modList[i].Version, modList[i].Author, modList[i]); } } } else { ModListHeader("Loaded Mods", new Color32(57, 57, 57, 255), new Color32(0, 255, 255, 255)); for (int i = 0; i < modList.Length; i++) { if (!modList[i].isDisabled && !modList[i].hasUpdate) { ModButton(modList[i].Name, modList[i].Version, modList[i].Author, modList[i]); } } } Mod[] disMods = modList.Where(x => x.isDisabled).ToArray(); if (disMods.Length > 0) { ModListHeader("Disabled mods", new Color32(101, 34, 18, 255), new Color32(254, 254, 0, 255)); for (int i = 0; i < disMods.Length; i++) { ModButton(disMods[i].Name, disMods[i].Version, disMods[i].Author, disMods[i]); } } if (ModLoader.InvalidMods.Count > 0) { ModListHeader("Invalid/Broken Mods", new Color32(101, 34, 18, 255), new Color32(254, 254, 0, 255)); for (int i = 0; i < ModLoader.InvalidMods.Count; i++) { GameObject invMod = Instantiate(ms.ModButton_Invalid); invMod.transform.GetChild(0).GetComponent <Text>().text = ModLoader.InvalidMods[i]; invMod.transform.SetParent(modView.transform, false); } } }
// Load all keybinds. public static void LoadBinds() { foreach (Mod mod in ModLoader.LoadedMods) { // Check if there are custom keybinds string path = Path.Combine(ModLoader.GetModConfigFolder(mod), "keybinds.xml"); if (!File.Exists(path)) { SaveModBinds(mod); continue; } // Load XML XmlDocument doc = new XmlDocument(); doc.Load(path); foreach (XmlNode keybind in doc.GetElementsByTagName("Keybind")) { XmlNode id = keybind.SelectSingleNode("ID"); XmlNode key = keybind.SelectSingleNode("Key"); XmlNode modifier = keybind.SelectSingleNode("Modifier"); // Check if its valid and fetch if (id == null || key == null || modifier == null) { continue; } Keybind bind = Keybind.Keybinds.Find(x => x.Mod == mod && x.ID == id.InnerText); if (bind == null) { continue; } // Set bind try { KeyCode code = (KeyCode)Enum.Parse(typeof(KeyCode), key.InnerText); bind.Key = code; } catch (Exception e) { bind.Key = KeyCode.None; ModConsole.Error(e.Message); } try { KeyCode code = (KeyCode)Enum.Parse(typeof(KeyCode), modifier.InnerText); bind.Modifier = code; } catch (Exception e) { bind.Modifier = KeyCode.None; ModConsole.Error(e.Message); } } } }
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 } }