public void ToggleModEnabled(CustomDGVCheckBoxCell cb) { ModIncompatibilityWarning warningLevel = GameManager.CheckForModIncompatibilities(cb.ModMeta); string fileName = Path.GetFileName(cb.ModMeta.modPath); if (cb.ModMeta.isStandalone && !cb.ModMeta.isEnabled) { foreach (DataGridViewRow row in modList.Rows) { var ocb = (CustomDGVCheckBoxCell)row.Cells[1]; if (ocb.ModMeta != cb.ModMeta && ocb.ModMeta.isStandalone) { ocb.ModMeta.isStandalone = false; CustomDGVCheckBoxCell.ToggleProgrammatically = true; ocb.Value = false; ocb.ModMeta.isEnabled = false; CustomDGVCheckBoxCell.ToggleProgrammatically = false; } } } if (cb.ModMeta.isEnabled == false) { if (warningLevel.warningLevel == 1) { MessageBox.Show(string.Format("The mod {0} might not work with the following mods:{1}{2}", fileName, Environment.NewLine, warningLevel.sameClassMods)); } else if (warningLevel.warningLevel == 2) { string msg = string.Format("The mod {0} is incompatible with the following mods:{1}{2}{1}Don't expect them both to work together, but you can still launch the game.", fileName, Environment.NewLine, warningLevel.sameFunctionMods); if (warningLevel.sameClassMods.Length > 0) { msg += string.Format("It also might not work with these mods:{0}{1}", Environment.NewLine, warningLevel.sameClassMods); } MessageBox.Show(msg); } } CustomDGVCheckBoxCell.ToggleProgrammatically = true; cb.ModMeta.isEnabled = !cb.ModMeta.isEnabled; cb.Value = cb.ModMeta.isEnabled; CustomDGVCheckBoxCell.ToggleProgrammatically = false; }
public void SetModEnabled(CheckBox box, int index) { ModIncompatibilityWarning warningLevel = GameManager.CheckForModIncompatibilities(index); ModMetadata md = GameManager.modMetas[index]; string fileName = Path.GetFileName(md.modPath); if (md.isStandalone) { int i = 0; foreach (ModMetadata oMD in GameManager.modMetas) { if (oMD != md && oMD.isStandalone) { oMD.isStandalone = false; ((modList.Items[i].Control as StackLayout).Items[1].Control as CheckBox).Checked = false; } i++; } } if (md.isEnabled == false) { if (warningLevel.warningLevel == 1) { MessageBox.Show(string.Format("The mod {0} might not work with the following mods:{1}{2}", fileName, Environment.NewLine, warningLevel.sameClassMods)); } else if (warningLevel.warningLevel == 2) { string msg = string.Format("The mod {0} is incompatible with the following mods:{1}{2}{1}Don't expect them both to work together, but you can still launch the game.", fileName, Environment.NewLine, warningLevel.sameFunctionMods); if (warningLevel.sameClassMods.Length > 0) { msg += string.Format("It also might not work with these mods:{0}{1}", Environment.NewLine, warningLevel.sameClassMods); } MessageBox.Show(msg); } } md.isEnabled = !md.isEnabled; }
public static ModIncompatibilityWarning CheckForModIncompatibilities(int modIndex) { ModIncompatibilityWarning warning = new ModIncompatibilityWarning(); ModMetadata checkMod = modMetas[modIndex]; StringBuilder warningBuilder = new StringBuilder(); StringBuilder incompatibleBuilder = new StringBuilder(); //If the mod's not a patch, we don't have to care what it messes with. if (!checkMod.isPatch) { return(warning); } int warnType = 0; //Compare the mod to all other mods for (int i = 0; i < modMetas.Count; i++) { if (i == modIndex) { continue; } //Get the other mod we're comparing to ModMetadata otherMod = modMetas[i]; if (!otherMod.isPatch || !otherMod.isEnabled) { continue; } //The warning type will be nothing by default //Check all the classes the other mod modifies foreach (KeyValuePair <string, HashSet <string> > otherModClass in otherMod.modifiedClasses) { //If the other mod modifies a class that this mod does if (checkMod.modifiedClasses.ContainsKey(otherModClass.Key)) { //Store this mod's compares for later HashSet <string> classCompare = checkMod.modifiedClasses[otherModClass.Key]; bool isHighWarning = false; //Set warning type to 1 if (warnType == 0) { warnType = 1; } //Check all the functions the other mod changes foreach (string s in otherModClass.Value) { //If both mods change the same function, it as incompatible. if (classCompare.Contains(s)) { warnType = 2; isHighWarning = true; break; } } if (isHighWarning) { incompatibleBuilder.AppendLine(Path.GetFileName(otherMod.modPath)); } else { warningBuilder.AppendLine(Path.GetFileName(otherMod.modPath)); } break; } } } warning.warningLevel = warnType; warning.sameClassMods = warningBuilder.ToString(); warning.sameFunctionMods = incompatibleBuilder.ToString(); return(warning); }