internal void ConfigButton() { if (GadgetModConfigs.IsConfigMenuOpen((modIndex << 16) + (gadgetIndex & 0xFFFF))) { GadgetModConfigs.CloseConfigMenu((modIndex << 16) + (gadgetIndex & 0xFFFF)); } else { GadgetModConfigs.OpenConfigMenu((modIndex << 16) + (gadgetIndex & 0xFFFF)); } }
internal void UMFConfigButton() { if (GadgetModConfigs.IsConfigMenuOpen(-1)) { GadgetModConfigs.CloseConfigMenu(-1); } else { GadgetModConfigs.OpenConfigMenu(-1); } }
internal void ConfigButton() { if (GadgetModConfigs.IsConfigMenuOpen(modIndex)) { GadgetModConfigs.CloseConfigMenu(modIndex); } else { GadgetModConfigs.OpenConfigMenu(modIndex); } /*string filePath; * if (modIndex < GadgetMods.CountMods()) * { * filePath = UMFData.ConfigsPath + "/" + GadgetMods.GetModInfo(modIndex).UMFName + ".ini"; * } * else if (modIndex - GadgetMods.CountMods() < GadgetCore.nonGadgetMods.Count) * { * filePath = UMFData.ConfigsPath + "/" + GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()] + ".ini"; * } * else if (modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count < GadgetCore.disabledMods.Count) * { * filePath = UMFData.ConfigsPath + "/" + GadgetCore.disabledMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count] + ".ini"; * } * else * { * filePath = UMFData.ConfigsPath + "/" + GadgetCore.disabledMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count] + ".ini"; * } * try * { * if (!originalConfig.ContainsKey(modIndex)) * { * originalConfig.Add(modIndex, File.ReadAllText(filePath)); * } * ConfigHandles.Add(Process.Start(filePath)); * } * catch (Exception e) { GadgetCore.Log(e.ToString()); }*/ }
public void UpdateInfo(Toggle toggle, int modIndex, int gadgetIndex = -1) { try { if (GadgetModConfigs.IsConfigMenuOpen((this.modIndex << 16) + (this.gadgetIndex & 0xFFFF))) { GadgetModConfigs.CloseConfigMenu((this.modIndex << 16) + (this.gadgetIndex & 0xFFFF)); } this.toggle = toggle; this.modIndex = modIndex; this.gadgetIndex = gadgetIndex; string[] disabledMods = GadgetCoreConfig.enabledMods.Where(x => !x.Value).Select(x => x.Key).ToArray(); StringBuilder descTextBuilder = new StringBuilder(); bool modEnabled = modEntries[modIndex].Type == ModMenuEntryType.GADGET || modEntries[modIndex].Type == ModMenuEntryType.UMF; if (gadgetIndex >= 0) { GadgetInfo mod = modEntries[modIndex].Gadgets[gadgetIndex]; enableButton.interactable = modEnabled; reloadButton.interactable = mod.Attribute.AllowRuntimeReloading; configButton.interactable = GadgetModConfigs.GetConfigMenuObject((modIndex << 16) + (gadgetIndex & 0xFFFF)) != null; enableButton.GetComponentInChildren <Text>().text = mod.Gadget.Enabled ? "Disable" : "Enable"; descTextBuilder.Append((mod.Gadget.Enabled ? "Gadget Enabled" : "Gadget Disabled") + (modEnabled ? "" : " (Disabled by mod) ") + '\n'); Dictionary <string, string> gadgetInfo = new Dictionary <string, string> { ["Name"] = mod.Attribute.Name, ["Version"] = mod.Mod.Version.ToString(), ["Required On Clients"] = mod.Attribute.RequiredOnClients ? "Yes" : "No", ["Dependencies"] = mod.Attribute.Dependencies.Length > 0 ? mod.Attribute.Dependencies.Aggregate(new StringBuilder(), (a, b) => { if (a.Length == 0) { a.Append(", "); } a.Append(b); return(a); }).ToString() : "None" }; foreach (KeyValuePair <string, string> info in gadgetInfo) { descTextBuilder.Append('\n'); descTextBuilder.Append(info.Key + ": " + info.Value); } string gadgetDesc = mod.Gadget.GetModDescription(); descTextBuilder.Append("\n\n" + (!string.IsNullOrEmpty(gadgetDesc) ? gadgetDesc : modEntries[modIndex].Description)); } else { enableButton.interactable = modEntries[modIndex].Name != "GadgetCore" && (modEnabled || modEntries[modIndex].Type == ModMenuEntryType.DISABLED_UMF); reloadButton.interactable = modEntries[modIndex].Name != "GadgetCore" && (modEntries[modIndex].Type == ModMenuEntryType.GADGET || modEntries[modIndex].Type == ModMenuEntryType.UMF); configButton.interactable = GadgetModConfigs.GetConfigMenuObject((modIndex << 16) + (gadgetIndex & 0xFFFF)) != null; enableButton.GetComponentInChildren <Text>().text = (modEnabled ^ modsToToggle.Contains(modEntries[modIndex].Name)) ? "Disable" : "Enable"; descTextBuilder.Append((modEnabled ? "Mod Enabled" : "Mod Disabled") + (modsToToggle.Contains(modEntries[modIndex].Name) ? (modEnabled ? " (Will disable after restart)" : " (Will enable after restart)") : "") + '\n'); foreach (KeyValuePair <string, string> info in modEntries[modIndex].Info) { descTextBuilder.Append('\n'); descTextBuilder.Append(info.Key + ": " + info.Value); } descTextBuilder.Append("\n\n" + modEntries[modIndex].Description); } descText.text = descTextBuilder.ToString(); } catch (Exception e) { descText.text = "An error occured while populating the info panel for this mod! Check GadgetCore.log for details."; if (gadgetIndex >= 0) { GadgetCore.CoreLogger.LogError("An error occured while populating the info panel for the gadget with the mod index " + modIndex + " and gadget index " + gadgetIndex + ": " + e.ToString(), false); } else { GadgetCore.CoreLogger.LogError("An error occured while populating the info panel for the mod with the index " + modIndex + ": " + e.ToString(), false); } } }
public void UpdateInfo(Toggle toggle, int modIndex) { try { if (GadgetModConfigs.IsConfigMenuOpen(this.modIndex)) { GadgetModConfigs.CloseConfigMenu(this.modIndex); } if (!File.Exists(UMFData.DisabledModsFile)) { File.Create(UMFData.DisabledModsFile).Dispose(); } this.toggle = toggle; this.modIndex = modIndex; string[] disabledMods = File.ReadAllLines(UMFData.DisabledModsFile).Where(x => !string.IsNullOrEmpty(x)).ToArray(); if (modIndex < GadgetMods.CountMods()) { GadgetModInfo mod = GadgetMods.GetModInfo(modIndex); unpackButton.gameObject.SetActive(Directory.GetFiles(UMFData.ModsPath, mod.UMFName + "*.zip").Length > 0); enableUMFButton.interactable = !GadgetCore.dependencies.Any(x => !disabledMods.Contains(x.Key) && x.Value.Any(d => { string[] split = d.Split(' '); return(split[split.Length - 2].Equals(mod.UMFName)); })); if (mod.Attribute.Dependencies.All(x => GadgetMods.ListAllModInfos().Where(y => y.Mod.Enabled).Select(y => y.Attribute.Name).Contains(x) || GadgetMods.ListAllModInfos().Where(y => y.Mod.Enabled).Select(y => y.Mod.GetPreviousModNames()).Any(y => y.Contains(x)))) { enableButton.interactable = true; string[][] splitDependencies = mod.Attribute.Dependencies.Select(x => x.Split(' ')).Where(x => x.Length == 2).ToArray(); GadgetModInfo[] dependencies = splitDependencies.Select(x => GadgetMods.ListAllModInfos().Where(y => y.Mod.Enabled).FirstOrDefault(y => y.Attribute.Name.Equals(x[0])) ?? GadgetMods.ListAllModInfos().Where(y => y.Mod.Enabled).First(y => y.Mod.GetPreviousModNames().Contains(x[0]))).ToArray(); for (int i = 0; i < dependencies.Length; i++) { int[] currentVersionNums = dependencies[i].Mod.GetModVersionString().Split('.').Select(x => int.Parse(x)).ToArray(); int[] targetVersionNums = splitDependencies[i][1].TrimStart('v').Split('.').Select(x => int.Parse(x)).ToArray(); VersionSpecificity versionSpecificity = (VersionSpecificity)targetVersionNums.Length; if (!((versionSpecificity == VersionSpecificity.MAJOR && currentVersionNums[0] == targetVersionNums[0] && (currentVersionNums[1] > targetVersionNums[1] || (currentVersionNums[1] == targetVersionNums[1] && (currentVersionNums[2] > targetVersionNums[2] || (currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] >= targetVersionNums[3]))))) || (versionSpecificity == VersionSpecificity.MINOR && currentVersionNums[0] == targetVersionNums[0] && currentVersionNums[1] == targetVersionNums[1] && (currentVersionNums[2] > targetVersionNums[2] || (currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] >= targetVersionNums[3]))) || (versionSpecificity == VersionSpecificity.NONBREAKING && currentVersionNums[0] == targetVersionNums[0] && currentVersionNums[1] == targetVersionNums[1] && currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] >= targetVersionNums[3]) || (versionSpecificity == VersionSpecificity.BUGFIX && currentVersionNums[0] == targetVersionNums[0] && currentVersionNums[1] == targetVersionNums[1] && currentVersionNums[2] == targetVersionNums[2] && currentVersionNums[3] == targetVersionNums[3]))) { enableButton.interactable = false; break; } } } else { enableButton.interactable = false; } configButton.interactable = GadgetModConfigs.GetConfigMenuObject(modIndex) != null; enableButton.GetComponentInChildren <Text>().text = mod.Mod.Enabled ? "Disable Gadget" : "Enable Gadget"; enableUMFButton.GetComponentInChildren <Text>().text = File.ReadAllLines(UMFData.DisabledModsFile).Any(x => x.Equals(mod.UMFName)) ? "Enable Mod" : "Disable Mod"; string desc = mod.Mod.GetModDescription(); bool isDescNull = desc == null; bool isModInfo = false; if (string.IsNullOrEmpty(desc)) { try { desc = File.ReadAllText(UMFData.ModInfosPath + "/" + mod.UMFName + "_v" + UMFMod.GetModVersion(mod.UMFName) + "_ModInfo.txt"); } catch (Exception) { } finally { if (string.IsNullOrEmpty(desc) || desc == "A UMF Mod(umodframework.com) for Roguelands") { desc = "This mod does not have a description, or a ModInfo file." + Environment.NewLine + (isDescNull ? "You should suggest to the mod author that they add a description." : ""); } else { isModInfo = true; } } } descText.text = mod.Attribute.Name + " v" + UMFMod.GetModVersion(mod.UMFName).ToString() + (mod.Mod.Enabled ? " (Enabled)" : " (Disabled)") + Environment.NewLine + "UMF Mod: " + mod.UMFName + Environment.NewLine + (GadgetCore.dependencies.ContainsKey(mod.UMFName) ? ("Dependencies: " + GadgetCore.dependencies[mod.UMFName].Aggregate((x, y) => x + ", " + y) + Environment.NewLine) : "") + "Required on clients: " + (mod.Attribute.RequiredOnClients ? "Yes" : "No") + Environment.NewLine + (isModInfo ? "UMF Mod Info: " : "Description: ") + UMFMod.GetModDescription(mod.UMFName) + Environment.NewLine + Environment.NewLine + desc; } else if (modIndex < GadgetMods.CountMods() + GadgetCore.nonGadgetMods.Count + GadgetCore.disabledMods.Count + GadgetCore.incompatibleMods.Count) { bool enabled = !File.ReadAllLines(UMFData.DisabledModsFile).Any(x => x.Equals(modIndex - GadgetMods.CountMods() < GadgetCore.nonGadgetMods.Count ? GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()] : modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count < GadgetCore.disabledMods.Count ? GadgetCore.disabledMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count] : GadgetCore.incompatibleMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count])); enableButton.GetComponentInChildren <Text>().text = modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count >= 0 && modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count < GadgetCore.disabledMods.Count ? "Disabled" : "Not Gadget"; enableUMFButton.GetComponentInChildren <Text>().text = enabled ? "Disable Mod" : "Enable Mod"; string mod = modIndex - GadgetMods.CountMods() < GadgetCore.nonGadgetMods.Count ? GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()] : modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count < GadgetCore.disabledMods.Count ? GadgetCore.disabledMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count] : GadgetCore.incompatibleMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count]; unpackButton.gameObject.SetActive(Directory.GetFiles(UMFData.ModsPath, mod + "*.zip").Length > 0); if (modIndex - GadgetMods.CountMods() < GadgetCore.nonGadgetMods.Count && GadgetCore.nonGadgetMods[modIndex - GadgetMods.CountMods()].Equals("GadgetCore")) { enableUMFButton.interactable = false; } else { enableUMFButton.interactable = !GadgetCore.dependencies.Any(x => !disabledMods.Contains(x.Key) && x.Value.Any(d => { string[] split = d.Split(' '); return(split[split.Length - 2].Equals(mod)); })); } enableButton.interactable = false; configButton.interactable = GadgetModConfigs.GetConfigMenuObject(modIndex) != null; string desc = null; try { desc = File.ReadAllText(UMFData.ModInfosPath + "/" + mod + "_v" + UMFMod.GetModVersion(mod) + "_ModInfo.txt"); } catch (Exception) { } finally { if (string.IsNullOrEmpty(desc) || desc == "A UMF Mod(umodframework.com) for Roguelands") { desc = "This mod does not have a ModInfo file."; } descText.text = mod + " v" + UMFMod.GetModVersion(mod).ToString() + (enabled ? " (Enabled)" : " (Disabled)") + Environment.NewLine + (GadgetCore.dependencies.ContainsKey(mod) ? ("Dependencies: " + GadgetCore.dependencies[mod].Aggregate((x, y) => x + ", " + y) + Environment.NewLine) : "") + "UMF Mod Info: " + UMFMod.GetModDescription(mod) + Environment.NewLine + Environment.NewLine + desc; } } else { string mod = GadgetCore.packedMods[modIndex - GadgetMods.CountMods() - GadgetCore.nonGadgetMods.Count - GadgetCore.disabledMods.Count - GadgetCore.incompatibleMods.Count]; enableButton.interactable = false; enableUMFButton.interactable = false; configButton.interactable = false; unpackButton.interactable = !unpackedMods.Contains(mod); unpackButton.gameObject.SetActive(true); descText.text = Path.GetFileName(mod) + Environment.NewLine + Environment.NewLine + "This mod is still packed in its .zip, and needs to be unpacked to run!"; } } catch (Exception e) { descText.text = "An error occured while populating the info panel for this mod! Check GadgetCore.log for details."; GadgetCore.Log("An error occured while populating the info panel for the mod with the index " + modIndex + ": " + e.ToString()); } }