private IEnumerable <ModMetaData> ModsInListOrder() { using (IEnumerator <ModMetaData> enumerator = ModsConfig.ActiveModsInLoadOrder.GetEnumerator()) { if (enumerator.MoveNext()) { ModMetaData mod2 = enumerator.Current; yield return(mod2); /*Error: Unable to find new state assignment for yield return*/; } } using (IEnumerator <ModMetaData> enumerator2 = (from x in ModLister.AllInstalledMods where !x.Active select x into m orderby m.VersionCompatible descending select m).GetEnumerator()) { if (enumerator2.MoveNext()) { ModMetaData mod = enumerator2.Current; yield return(mod); /*Error: Unable to find new state assignment for yield return*/; } } yield break; IL_0182: /*Error near IL_0183: Unexpected return in MoveNext()*/; }
private static void LoadNotPresentPatchesFor(ModMetaData modMetaData) //Adapted from Verse.ModContentPack.LoadPatches() { ModContentPack mod = new ModContentPack(modMetaData.RootDir, -1, "Loadable"); List <LoadableXmlAsset> list = DirectXmlLoader.XmlAssetsInModFolder(mod, "NotPresentPatches/").ToList <LoadableXmlAsset>(); for (int i = 0; i < list.Count; i++) { XmlElement documentElement = list[i].xmlDoc.DocumentElement; if (documentElement.Name != "Patch") { Log.Error(string.Format("Unexpected document element in patch XML; got {0}, expected 'Patch'", documentElement.Name)); } else { for (int j = 0; j < documentElement.ChildNodes.Count; j++) { XmlNode xmlNode = documentElement.ChildNodes[j]; if (xmlNode.NodeType == XmlNodeType.Element) { if (xmlNode.Name != "Operation") { Log.Error(string.Format("Unexpected element in patch XML; got {0}, expected 'Operation'", documentElement.ChildNodes[j].Name)); } else { PatchOperation patchOperation = DirectXmlToObject.ObjectFromXml <PatchOperation>(xmlNode, false); patchOperation.sourceFile = list[i].FullFilePath; SaveGamePatches.notPresentPatches.Add(patchOperation); } } } } } }
protected override bool isTestPassed() { int index = getModLoadIndex(modName); if (index != -1) { ModMetaData MetaData = ModsConfig.ActiveModsInLoadOrder.ElementAt(index); string ModVersion = RimWorld_ModSyncNinja.FileUtil.GetModSyncVersionForMod(MetaData.RootDir); Version current; try { current = new Version(ModVersion); } catch { throw new ArgumentException("CurrentVersionUnreadable"); } Version min; try { min = new Version(version); } catch { throw new ArgumentException("MinVersionUnreadable"); } return(current.CompareTo(min) > -1); } return(true); }
public static bool TryCreateLocalCopy(ModMetaData mod, out ModMetaData copy) { copy = null; if (mod.Source != ContentSource.SteamWorkshop) { Log.Error("Can only create local copies of steam workshop mods."); return(false); } var baseTargetDir = mod.GetLocalCopyFolder(); var targetDir = baseTargetDir; var i = 2; while (Directory.Exists(targetDir)) { targetDir = $"{baseTargetDir} ({i++})"; } try { mod.RootDir.Copy(targetDir, true); copy = new ModMetaData(targetDir); (ModLister.AllInstalledMods as List <ModMetaData>)?.Add(copy); return(true); } catch (Exception e) { Log.Error("Creating local copy failed: " + e.Message); return(false); } }
public override void PreOpen() { base.PreOpen(); ModLister.RebuildModList(); selectedMod = ModsInListOrder().FirstOrDefault(); activeModsWhenOpenedHash = ModLister.InstalledModsListHash(activeOnly: true); }
private static void UpdatePackageId_ModMetaData(ModMetaData mod, string id) { var traverse = Traverse.Create(mod); traverse.Field("meta").Field("traverse").SetValue(id); traverse.Field("packageIdLowerCase").SetValue(id.ToLower()); }
public static bool TryUpdateLocalCopy(ModMetaData source, ModMetaData local) { // delete and re-copy mod. var removedResult = TryRemoveLocalCopy(local); if (!removedResult) { return(false); } var updateResult = TryCopyMod(source, out var updated, local.RootDir.FullName, false); if (!updateResult) { return(false); } // update version var button = ModButton_Installed.For(updated); button.Notify_VersionRemoved(local); button.Notify_VersionAdded(updated, true); return(true); }
private static void SetUniquePackageId(ModMetaData mod) { var id = GetUniquePackageId(mod); UpdatePackageId_ModMetaData(mod, id); UpdatePackageId_Xml(mod, id); }
private static bool TryCopyUserData(ModMetaData source, ModMetaData target, bool deleteOld = false) { try { var sourcePath = UserData.GetModAttributesPath(source); if (!File.Exists(sourcePath)) { return(true); } File.Copy(sourcePath, UserData.GetModAttributesPath(target), true); if (deleteOld) { File.Delete(sourcePath); } return(true); } catch (Exception err) { Debug.Error($"Error copying user settings: " + $"\n\tsource: {source.Name}" + $"\n\ttarget: {target.Name}" + $"\n\terror: {err}"); } return(false); }
public VersionStatus(ModMetaData mod) { version = mod.TargetVersion; if (!VersionControl.IsWellFormattedVersionString(mod.TargetVersion)) { match = VersionMatch.InvalidVersion; tip = I18n.InvalidVersion(version); return; } var _version = VersionControl.VersionFromString(version); if (_version.Major != VersionControl.CurrentMajor || _version.Minor != VersionControl.CurrentMinor) { match = VersionMatch.DifferentVersion; tip = I18n.DifferentVersion(mod); return; } if (_version.Build != VersionControl.CurrentBuild) { match = VersionMatch.DifferentBuild; tip = I18n.DifferentBuild(mod); return; } match = VersionMatch.CurrentVersion; tip = I18n.CurrentVersion; }
private static void Postfix(ref Dialog_ConfirmModUpload __instance, ModMetaData ___mod) { void Action() => Find.WindowStack.Add(new Dialog_Publish(___mod.GetWorkshopItemHook())); __instance.buttonAAction = Action; __instance.acceptAction = Action; }
public static bool MatchesVersion(ModMetaData mod, EqualityOperator op, Version version, bool unknownResult = false) { var modVersion = Manifest.For(mod)?.Version; if (modVersion == null || version == null) { return(unknownResult); } switch (op) { case EqualityOperator.Equal: return(version == modVersion); case EqualityOperator.Exists: return(mod != null); case EqualityOperator.GreaterEqual: return(modVersion >= version); case EqualityOperator.LesserEqual: return(modVersion <= version); default: return(unknownResult); } }
public static void Upload(ModMetaData mod) { if (!VersionControl.IsWellFormattedVersionString(mod.TargetVersion)) { Messages.Message(I18n.NeedsWellFormattedTargetVersion, MessageTypeDefOf.RejectInput, false); } else { Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(I18n.ConfirmSteamWorkshopUpload, delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); Dialog_MessageBox dialog_MessageBox = Dialog_MessageBox.CreateConfirmation( I18n.ConfirmContentAuthor, delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); AccessTools.Method(typeof(Verse.Steam.Workshop), "Upload") .Invoke(null, new object[] { mod }); }, true); dialog_MessageBox.buttonAText = I18n.Yes; dialog_MessageBox.buttonBText = I18n.No; dialog_MessageBox.interactionDelay = 6f; Find.WindowStack.Add(dialog_MessageBox); }, true)); } }
public static void Notify_DownloadCompleted(ModMetaData mod) { var downloading = AllButtons.OfType <ModButton_Downloading>() .FirstOrDefault(b => b.Identifier == mod.Identifier); var missing = AllButtons.OfType <ModButton_Missing>() .FirstOrDefault(b => b.Identifier == mod.Identifier); // add installed item to MBM var installed = ModButton_Installed.For(mod); if (missing != null && missing.Active) { Insert(installed, ActiveButtons.IndexOf(missing)); } else { TryAdd(installed); } Page_BetterModConfig.Instance.Selected = installed; TryRemove(downloading); TryRemove(missing); Page_BetterModConfig.Instance.Notify_ModsListChanged(); }
public static bool Prefix(PublishedFileId_t pfid) { // TODO: display some sort of in-progress indicator Debug.Log("Notify_Subscribed"); // check if item was already present. var item = WorkshopItem.MakeFrom(pfid); if (item is WorkshopItem_Mod item_installed) { // register item in WorkshopItems workshopitems.Add(item_installed); // register item in ModLister var mod = new ModMetaData(item_installed); modlister.Add(mod); // show a message Messages.Message(I18n.ModInstalled(mod.Name), MessageTypeDefOf.PositiveEvent, false); // notify button manager that we done stuff. ModButtonManager.Notify_DownloadCompleted(mod); } else { // add dowloading item to MBM var button = new ModButton_Downloading(pfid); ModButtonManager.TryAdd(button); Page_BetterModConfig.Instance.Selected = button; } // do whatever needs doing for ScenarioLister. ScenarioLister.MarkDirty(); return(false); }
public static string GetVersionFromDll(ModMetaData mod) { string assemblyDirectory = mod.RootDir + "/" + ASSEMBLIES_DIRECTORY; if (!Directory.Exists(assemblyDirectory)) { return(null); } string foundDll = null; foreach (string dll in Directory.GetFiles(assemblyDirectory)) { if (!DllsToExclude.Contains(Path.GetFileName(dll))) { foundDll = dll; break; } } if (!String.IsNullOrEmpty(foundDll)) { FileVersionInfo info = FileVersionInfo.GetVersionInfo(@foundDll); return(info.FileVersion); } return(null); }
public override void PreOpen() { base.PreOpen(); ModLister.RebuildModList(); modsInListOrderDirty = true; selectedMod = ModsInListOrder().FirstOrDefault(); activeModsWhenOpenedHash = ModLister.InstalledModsListHash(activeOnly: true); RecacheSelectedModRequirements(); foreach (ModMetaData mod in ModLister.AllInstalledMods) { ModContentPack modContentPack = LoadedModManager.RunningModsListForReading.FirstOrDefault((ModContentPack p) => mod.SamePackageId(p.PackageId)); if (modContentPack != null) { mod.translationMod = !modContentPack.AnyNonTranslationContentLoaded() && modContentPack.AnyTranslationsLoaded(); continue; } List <string> list = (from d in mod.RootDir.EnumerateDirectories() select d.Name).ToList(); for (int i = 0; i < translationOnlyModFolders.Count; i++) { if (list.Count == translationOnlyModFolders[i].Count && list.ListsEqualIgnoreOrder(translationOnlyModFolders[i])) { mod.translationMod = true; break; } } } }
public static string DifferentVersion(ModMetaData mod) { var version = new Version(mod.TargetVersion); return(Key("DifferentVersion").Translate(mod.Name, version.Major + "." + version.Minor, VersionControl.CurrentMajor + "." + VersionControl.CurrentMinor)); }
public override void PreOpen() { base.PreOpen(); ModLister.RebuildModList(); this.selectedMod = this.ModsInListOrder().FirstOrDefault <ModMetaData>(); this.activeModsWhenOpenedHash = ModLister.InstalledModsListHash(true); }
internal static void DeleteLocal(ModMetaData mod, bool force = false) { if (force) { LongEventHandler.QueueLongEvent(() => { LongEventHandler.SetCurrentEventText(I18n.RemovingLocal(mod.Name)); if (TryRemoveLocalCopy(mod)) { Messages.Message(I18n.RemoveLocalSucceeded(mod.Name), MessageTypeDefOf.NeutralEvent, false); } else { Messages.Message(I18n.RemoveLocalFailed(mod.Name), MessageTypeDefOf.RejectInput, false); } // remove this version either way, as it's likely to be borked. ModButton_Installed.For(mod).Notify_VersionRemoved(mod); }, null, true, null); return; } Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation( I18n.ConfirmRemoveLocal(mod.Name), () => DeleteLocal(mod, true), true)); }
private static bool TryCopyMod(ModMetaData mod, ref ModMetaData copy, string targetDir, bool copySettings = true) { try { // copy mod mod.RootDir.Copy(targetDir, true); copy = new ModMetaData(targetDir); (ModLister.AllInstalledMods as List <ModMetaData>)?.Add(copy); // copy settings and color attribute if (copySettings) { TryCopySettings(mod, copy); ModManager.Settings[copy].Color = ModManager.Settings[mod].Color; } // set source attribute ModManager.Settings[copy].Source = mod; return(true); } catch (Exception e) { Log.Error($"Creating local copy failed: {e.Message} \n\n{e.StackTrace}"); return(false); } }
private static void TryCopySettings(ModMetaData source, ModMetaData target, bool deleteOld = false) { // find any settings files that belong to the source mod var mask = SettingsMask(source.Identifier); var settings = Directory.GetFiles(GenFilePaths.ConfigFolderPath) .Where(f => mask.IsMatch(f)) .Select(f => new { source = f, target = NewSettingsFilePath(f, mask, target.Identifier) }); // copy settings files, overwriting existing - if any. foreach (var setting in settings) { Debug.Log($"Copying settings :: {setting.source} => {setting.target}"); if (deleteOld) { File.Move(setting.source, setting.target); } else { File.Copy(setting.source, setting.target, true); } } }
internal static void CreateLocalCopy(ModMetaData mod, bool batch = false) { LongEventHandler.QueueLongEvent(() => { ModMetaData copy; LongEventHandler.SetCurrentEventText(I18n.CreatingLocal(mod.Name)); if (TryCreateLocalCopy(mod, out copy)) { var button = ModButton_Installed.For(copy); if (batch) { _batchCreatedCopies.Add(new Pair <ModButton_Installed, ModMetaData>(button, copy)); } else { Messages.Message(I18n.CreateLocalSucceeded(mod.Name), MessageTypeDefOf.NeutralEvent, false); LongEventHandler.QueueLongEvent(() => button.Notify_VersionAdded(copy, true), "", true, null); } } else { Messages.Message(I18n.CreateLocalFailed(mod.Name), MessageTypeDefOf.RejectInput, false); } }, null, true, null); }
public static void ModManager_ButtonPrefix(object __instance, ModMetaData ____selected, Rect rect, Dictionary <string, string> ____modNameTruncationCache) { if (!MultiplayerMod.settings.showModCompatibility) { return; } var tooltip = ""; var mod = ____selected; currentModName = __instance == null ? mod.Name : (string)__instance.GetPropertyOrField("TrimmedName"); truncatedStrings = ____modNameTruncationCache; if (mod.IsCoreMod || mod.Official || mod.Name == "Harmony") { currentModCompat = "<color=green>4</color>"; tooltip = "4 = Everything works (official content)"; } else if (Multiplayer.xmlMods.Contains(mod.RootDir.FullName)) { currentModCompat = "<color=green>4</color>"; tooltip = "4 = Everything works (XML-only mod)"; } if (Multiplayer.modsCompatibility.ContainsKey(mod.publishedFileIdInt.ToString())) { var compat = Multiplayer.modsCompatibility[mod.publishedFileIdInt.ToString()]; if (compat == 1) { currentModCompat = $"<color=red>{compat}</color>"; tooltip = "1 = Does not work"; } else if (compat == 2) { currentModCompat = $"<color=orange>{compat}</color>"; tooltip = "2 = Partially works, but major features don't work"; } else if (compat == 3) { currentModCompat = $"<color=yellow>{compat}</color>"; tooltip = "3 = Mostly works, some minor features don't work"; } else if (compat == 4) { currentModCompat = $"<color=green>{compat}</color>"; tooltip = "4 = Everything works"; } else { currentModCompat = $"<color=grey>{compat}</color>"; tooltip = "0 = Unknown; please report findings to #mod-report in our Discord"; } } if (tooltip != "") { var tooltipRect = new Rect(rect); tooltipRect.xMax = tooltipRect.xMin + 50f; TooltipHandler.TipRegion(tooltipRect, new TipSignal($"Multiplayer Compatibility: {tooltip}", mod.GetHashCode() * 3312)); } }
static void Postfix(Page_ModsConfig __instance, Rect rect) { ModMetaData selectedMod = __instance.selectedMod; if (Prefs.DevMode && selectedMod != null && !selectedMod.IsCoreMod && selectedMod.Source == ContentSource.LocalFolder) { Rect buttonRect = new Rect(580f, rect.height - 95f, 200f, 40f); string version = FileUtil.GetModSyncVersionForMod(selectedMod.RootDir); if (!String.IsNullOrEmpty(version)) { // Add the ModSync verion on the top left of the window GameFont origFont = Text.Font; Text.Font = GameFont.Tiny; Widgets.Label(new Rect(350f, 23f, 250f, 40f), "ModSync.ModSyncVersion".Translate().Replace("{version}", version)); Text.Font = origFont; // Draw the "Update on ModSync.ninja" button string label = (isSubmitting) ? "ModSync.PleaseWait".Translate() + "..." : "ModSync.UpdateOnModSync".Translate(); if (Widgets.ButtonText(buttonRect, label, true, false, !isSubmitting)) { HandleUpdateOnModSync(selectedMod, version); } } else // No ModSync.xml for the mod { // Draw the "Upload to ModSync.ninja" button if (Widgets.ButtonText(buttonRect, "ModSync.UploadToModSync".Translate())) { NetworkManager.OpenModSyncUrl(); } } } }
public static void ResolveUpdateLocalCopy(ModMetaData source, ModMetaData local) { var options = NewOptions; options.Add(new FloatMenuOption(I18n.UpdateLocalCopy(TrimModName(local.Name)), () => IO.TryUpdateLocalCopy(source, local))); FloatMenu(options); }
internal void Notify_SteamItemUnsubscribed(PublishedFileId_t pfid) { if (this.selectedMod != null && this.selectedMod.Identifier == pfid.ToString()) { this.selectedMod = null; } }
public static string MakeXMLfromJobMeta(ModMetaData meta) { XMLHelper.Node root = new XMLHelper.Node(); root.name = "daimod"; root.properties = new List <XMLHelper.NodeProp>(); root.properties.Add(new XMLHelper.NodeProp("version", meta.version.ToString())); root.properties.Add(new XMLHelper.NodeProp("id", meta.id)); root.childs = new List <XMLHelper.Node>(); XMLHelper.Node details = new XMLHelper.Node(); details.name = "details"; details.childs = new List <XMLHelper.Node>(); details.childs.Add(new XMLHelper.Node("name", meta.details.name)); details.childs.Add(new XMLHelper.Node("version", meta.details.version.ToString())); details.childs.Add(new XMLHelper.Node("author", meta.details.author)); details.childs.Add(new XMLHelper.Node("description", meta.details.description)); root.childs.Add(details); XMLHelper.Node req = new XMLHelper.Node(); req.name = "requirements"; req.childs = new List <XMLHelper.Node>(); foreach (ModReq r in meta.requirements) { XMLHelper.Node rn = new XMLHelper.Node("requires", ""); rn.properties = new List <XMLHelper.NodeProp>(); rn.properties.Add(new XMLHelper.NodeProp("id", r.id)); if (r.minVersion != "") { rn.properties.Add(new XMLHelper.NodeProp("minVersion", r.minVersion)); } req.childs.Add(rn); } root.childs.Add(req); XMLHelper.Node bundles = new XMLHelper.Node(); bundles.name = "bundles"; bundles.childs = new List <XMLHelper.Node>(); foreach (ModBundle b in meta.bundles) { XMLHelper.Node bn = new XMLHelper.Node("bundle", ""); bn.properties = new List <XMLHelper.NodeProp>(); bn.properties.Add(new XMLHelper.NodeProp("name", b.name)); bn.properties.Add(new XMLHelper.NodeProp("action", b.action)); bn.childs = new List <XMLHelper.Node>(); XMLHelper.Node eln = new XMLHelper.Node("entries", ""); eln.childs = new List <XMLHelper.Node>(); foreach (ModBundleEntry e in b.entries) { XMLHelper.Node en = new XMLHelper.Node("entry", ""); en.properties = new List <XMLHelper.NodeProp>(); en.properties.Add(new XMLHelper.NodeProp("name", e.name)); en.properties.Add(new XMLHelper.NodeProp("action", e.action)); en.properties.Add(new XMLHelper.NodeProp("originalSha1", e.orgSHA1)); en.properties.Add(new XMLHelper.NodeProp("resourceId", e.resId.ToString())); eln.childs.Add(en); } bn.childs.Add(eln); bundles.childs.Add(bn); } root.childs.Add(bundles); return(XMLHelper.MakeXML(root, 0)); }
public void Notify_ModsListChanged() { string selModId = selectedMod.PackageId; selectedMod = ModLister.AllInstalledMods.FirstOrDefault((ModMetaData m) => m.SamePackageId(selModId)); RecacheSelectedModRequirements(); modsInListOrderDirty = true; }
public static bool MatchesIdentifier(this ModMetaData mod, string identifier) { identifier = identifier.StripSpaces(); return(!identifier.NullOrEmpty() && (mod.Identifier.StripSpaces() == identifier || mod.Name.StripSpaces() == identifier || Manifest.For(mod)?.identifier == identifier)); }
protected Mod(Guid id, ModMetaData metaData) : base(id) { MetaData = metaData; }