// Handle the reloading of mods when the Mods screen is closed.
        public override void PostClose()
        {
            base.PostClose();

            // Only reloads mods if the user actually made changes to the mod configuration.
            if (HasConfigurationChanged)
            {
                // Deactivate all of the mods...
                foreach (InstalledMod mod in InstalledModLister.AllInstalledMods)
                {
                    mod.Active = false;
                }
                // ...and then activate them in the selected order
                foreach (InstalledMod mod in activeMods)
                {
                    mod.Active = true;
                }

                ModsConfig.Save();
                PlayDataLoader.ClearAllPlayData();
                PlayDataLoader.LoadAllPlayData(false);
            }
            else
            {
                Log.Message("Mod selection did not change.  Skipping mod reload.");
            }

            // TODO: Alpha 12
            //Find.WindowStack.Add(new Page_MainMenu());
        }
Exemplo n.º 2
0
        private static void CorrectLoadOrderBeforeRestart()
        {
            var allMods = LoadedModManager.LoadedMods.ToList();

            // Deactivate all mods
            foreach (var mod in allMods)
            {
                ModsConfig.SetActive(mod.name, false);
            }
            // Activate core first
            ModsConfig.SetActive("Core", true);
            if (cclModIndex != -1)
            { // Activate CCL second
                ModsConfig.SetActive(Controller.Data.UnityObjectName, true);
            }
            // Activate everything else in the same order
            foreach (var mod in allMods)
            {
                if (
                    (mod.name != "Core") &&
                    (mod.name != Controller.Data.UnityObjectName)
                    )
                {
                    ModsConfig.SetActive(mod.name, true);
                }
            }
            // Now save the config
            ModsConfig.Save();
        }
Exemplo n.º 3
0
        public static void DeactivateMod()
        {
            _isDeactivating = true;

            ModsConfig.SetActive(Mod.ContentPack.Identifier, false);

            var runningMods = PrivateAccess.Verse_LoadedModManager_RunningMods();

            runningMods.Remove(Mod.ContentPack);

            var addonMods = new StringBuilder();

            foreach (var mod in AddonManager.Mods)
            {
                addonMods.AppendLine(mod.Name);
                ModsConfig.SetActive(mod.Identifier, false);
                runningMods.Remove(mod);
            }

            ModsConfig.Save();

            if (Find.WorldObjects.Contains(Instance))
            {
                Find.WorldObjects.Remove(Instance);
            }

            const string saveName = "PawnRules_Removed";

            GameDataSaveLoader.SaveGame(saveName);

            var message = addonMods.Length > 0 ? Lang.Get("Button.RemoveModAndAddonsComplete", saveName.Bold(), addonMods.ToString()) : Lang.Get("Button.RemoveModComplete", saveName.Bold());

            Find.WindowStack.Add(new Dialog_Alert(message, Dialog_Alert.Buttons.Ok, GenCommandLine.Restart));
        }
        private static void PostCloseDetour(this Page_ModsConfig self)
        {
            if (SettingsHandler.LastRestartOnClose.Value != RestartOnClose)
            {
                SettingsHandler.LastRestartOnClose.Value = RestartOnClose;
                HugsLibController.Instance.Settings.SaveChanges();
            }

            ModsConfig.Save();
            int activeModsWhenOpenedHash = (int)typeof(Page_ModsConfig).GetField("activeModsWhenOpenedHash", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(self);

            if (activeModsWhenOpenedHash != ModLister.InstalledModsListHash(true))
            {
                if (RestartOnClose)
                {
                    PlatformHandler.RestartRimWorld();
                }

                //Copy of source from here
                bool assemblyWasLoaded = LoadedModManager.RunningMods.Any((ModContentPack m) => m.LoadedAnyAssembly);
                LongEventHandler.QueueLongEvent(delegate
                {
                    PlayDataLoader.ClearAllPlayData();
                    PlayDataLoader.LoadAllPlayData(false);
                    if (assemblyWasLoaded)
                    {
                        LongEventHandler.ExecuteWhenFinished(delegate
                        {
                            Find.WindowStack.Add(new Dialog_MessageBox("ModWithAssemblyWasUnloaded".Translate(), null, null, null, null, null, false));
                        });
                    }
                }, "LoadingLongEvent", true, null);
            }
        }
        private static void CorrectLoadOrderBeforeRestart()
        {
            var allMods = LoadedModManager.RunningMods.ToList();

            // Deactivate all mods
            foreach (var mod in allMods)
            {
                ModsConfig.SetActive(mod.Name, false);
            }
            // Activate core first
            ModsConfig.SetActive(ModContentPack.CoreModIdentifier, true);
            if (cclModIndex != -1)
            { // Activate CCL second
                ModsConfig.SetActive(Controller.Data.cclModIdentifier, true);
            }
            // Activate everything else in the same order
            foreach (var mod in allMods)
            {
                if (
                    (mod.Name != ModContentPack.CoreModIdentifier) &&
                    (mod.Name != Controller.Data.cclModIdentifier)
                    )
                {
                    ModsConfig.SetActive(mod.Name, true);
                }
            }
            // Now save the config
            ModsConfig.Save();
        }
Exemplo n.º 6
0
 public override void PostClose()
 {
     ModsConfig.Save();
     if (this.activeModsWhenOpenedHash != ModLister.InstalledModsListHash(true))
     {
         ModsConfig.RestartFromChangedMods();
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Set the current active mods
 /// </summary>
 /// <param name="modsToActivate">The mods to set as active</param>
 internal static void SetActiveMods(List <string> modsToActivate)
 {
     ClearLoadedMods(true);
     foreach (string modID in modsToActivate)
     {
         ModsConfig.SetActive(modID, true);
     }
     ModsConfig.Save();
 }
 public override void PostClose()
 {
     ModsConfig.Save();
     foreach (ModMetaData item in ModsConfig.ActiveModsInLoadOrder)
     {
         item.UnsetPreviewImage();
     }
     Resources.UnloadUnusedAssets();
     if (activeModsWhenOpenedHash != ModLister.InstalledModsListHash(activeOnly: true))
     {
         ModsConfig.RestartFromChangedMods();
     }
 }
Exemplo n.º 9
0
        public override void DrawButtons(Rect inRect)
        {
            var btnWidth = 90f;
            var gap      = 10f;

            Rect btnRect = new Rect(gap, inRect.height - ButtonHeight - 10f, btnWidth, ButtonHeight);

            if (Widgets.ButtonText(btnRect, "Details".Translate()))
            {
                var defs = mods.defInfo.Where(kv => kv.Value.status != DefCheckStatus.OK).Join(kv => $"{kv.Key}: {kv.Value.status}", delimiter: "\n");

                Find.WindowStack.Add(new TextAreaWindow($"Mismatches:\n\n{defs}"));
            }

            btnRect.x += btnWidth + gap;

            if (Widgets.ButtonText(btnRect, "MpModList".Translate()))
            {
                ShowModList(mods);
            }
            btnRect.x += btnWidth + gap;

            btnRect.width = 140f;
            if (Widgets.ButtonText(btnRect, "MpSyncModList".Translate()))
            {
                Log.Message("MP remote host's modIds: " + string.Join(", ", mods.remoteModIds));
                Log.Message("MP remote host's workshopIds: " + string.Join(", ", mods.remoteWorkshopModIds));

                LongEventHandler.QueueLongEvent(() => {
                    ModManagement.DownloadWorkshopMods(mods.remoteWorkshopModIds);
                    try {
                        ModManagement.RebuildModsList();
                        ModsConfig.SetActiveToList(mods.remoteModIds.ToList());
                        ModsConfig.Save();
                        ModManagement.PromptRestartAndReconnect(mods.remoteAddress, mods.remotePort);
                    }
                    catch (Exception e) {
                        Log.Error($"MP mod sync error: {e.GetType()} {e.Message}");
                    }
                }, "MpDownloadingWorkshopMods", true, null);
            }

            btnRect.x    += btnRect.width + gap;
            btnRect.width = btnWidth;

            if (Widgets.ButtonText(btnRect, "CloseButton".Translate()))
            {
                Close();
            }
        }
        private void SyncModsAndConfigs(bool syncConfigs)
        {
            Log.Message("MP remote host's modIds: " + string.Join(", ", mods.remoteModIds));
            Log.Message("MP remote host's workshopIds: " + string.Join(", ", mods.remoteWorkshopModIds));

            LongEventHandler.QueueLongEvent(() => {
                try {
                    ModManagement.DownloadWorkshopMods(mods.remoteWorkshopModIds);
                }
                catch (InvalidOperationException e) {
                    Log.Warning($"MP Workshop mod download error: {e.Message}");
                    var missingMods = ModManagement.GetNotInstalledMods(mods.remoteModIds).ToList();
                    if (missingMods.Any())
                    {
                        Find.WindowStack.Add(new DebugTextWindow(
                                                 $"Failed to connect to Workshop.\nThe following mods are missing, please install them:\n"
                                                 + missingMods.Join(s => $"- {s}", "\n")
                                                 ));
                        return;
                    }
                }

                try {
                    ModManagement.RebuildModsList();
                    ModsConfig.SetActiveToList(mods.remoteModIds.ToList());
                    ModsConfig.Save();
                    if (syncConfigs)
                    {
                        ModManagement.ApplyHostModConfigFiles(mods.remoteModConfigs);
                    }
                    ModManagement.PromptRestartAndReconnect(mods.remoteAddress, mods.remotePort);
                }
                catch (Exception e) {
                    Log.Error($"MP mod sync error: {e.GetType()} {e.Message}");
                    Find.WindowStack.Add(new DebugTextWindow($"Failed to sync mods: {e.GetType()} {e.Message}"));
                }
            }, "MpDownloadingWorkshopMods", true, null);
        }
Exemplo n.º 11
0
        static void WorkshopItems_Notify_Subscribed_Postfix(PublishedFileId_t pfid)
        {
            var longID = pfid.m_PublishedFileId;

            if (subscribingMods.Contains(longID) == false)
            {
                return;
            }
            subscribingMods.Remove(longID);

            LongEventHandler.ExecuteWhenFinished(() =>
            {
                var mod = ModLister.AllInstalledMods.FirstOrDefault(meta => meta.GetPublishedFileId().m_PublishedFileId == longID);
                if (mod == null)
                {
                    return;
                }

                ModsConfig.SetActive(mod, true);
                ModsConfig.Save();
                Find.WindowStack.Add(new MiniDialog(mod.Name + " added"));
            });
        }
Exemplo n.º 12
0
 /// <summary>
 /// Saves the current active mods
 /// </summary>
 public static void Save()
 {
     ModsConfig.Save();
 }
Exemplo n.º 13
0
        static void PromotionPart(Rect mainRect, float leftColumn, float rightColumn, ModMetaData mod, Page_ModsConfig page)
        {
            var mainModID = mod.GetPublishedFileId();

            Text.Font = GameFont.Tiny;
            var headerHeight = 30f;
            var headerRect   = new Rect(leftColumn + 10f, -4f, rightColumn - 20f, headerHeight);

            Text.Anchor = TextAnchor.UpperCenter;
            Widgets.Label(headerRect, "Mods of " + mod.Author.Replace("Andreas Pardeike", "Brrainz") + ":".Truncate(headerRect.width, null));
            Text.Anchor = TextAnchor.UpperLeft;

            var outRect       = new Rect(leftColumn + 10f, headerHeight - 4f, rightColumn, mainRect.height - (headerHeight - 4f));
            var width         = outRect.width - 20f;
            var previewHeight = width * 319f / 588f;
            var promoMods     = CrossPromotion.promotionMods.ToArray().Where(m => m.m_nPublishedFileId != mainModID);
            var workshopMods  = WorkshopItems.AllSubscribedItems.Select(wi => wi.PublishedFileId.m_PublishedFileId).ToList();
            var activeMods    = ModLister.AllInstalledMods.Where(meta => meta.Active).Select(meta => meta.GetPublishedFileId().m_PublishedFileId).ToList();

            var height = 0f;

            foreach (var promoMod in promoMods)
            {
                var myModID     = promoMod.m_nPublishedFileId.m_PublishedFileId;
                var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID && meta.Source == ContentSource.LocalFolder);
                var isSubbed    = workshopMods.Contains(myModID);
                CrossPromotion.allVoteStati.TryGetValue(myModID, out var voteStatus);

                if (height > 0)
                {
                    height += 10f;
                }
                var preview = CrossPromotion.PreviewForMod(promoMod.m_nPublishedFileId.m_PublishedFileId);
                if (preview != null)
                {
                    height += width * preview.height / preview.width + 2f;
                    if (isLocalFile == false && (isSubbed == false || (voteStatus == false)))
                    {
                        height += 16f;
                    }
                }
            }

            Widgets.BeginScrollView(outRect, ref rightScroll, new Rect(0f, 0f, width, height), true);
            var firstTime = true;
            var modRect   = new Rect(0f, 0f, width, 0f);

            foreach (var promoMod in promoMods)
            {
                var myModID     = promoMod.m_nPublishedFileId.m_PublishedFileId;
                var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID && meta.Source == ContentSource.LocalFolder);
                var isSubbed    = workshopMods.Contains(myModID);
                var isActive    = activeMods.Contains(myModID);
                CrossPromotion.allVoteStati.TryGetValue(myModID, out var voteStatus);

                if (firstTime == false)
                {
                    modRect.y += 10f;
                }

                var preview = CrossPromotion.PreviewForMod(promoMod.m_nPublishedFileId.m_PublishedFileId);
                if (preview != null)
                {
                    modRect.height = width * preview.height / preview.width;
                    GUI.DrawTexture(modRect, preview, ScaleMode.ScaleToFit);

                    var checkRect = modRect;
                    checkRect.xMax -= 4f;
                    checkRect.yMax -= 4f;
                    checkRect.xMin  = checkRect.xMax - 18f;
                    checkRect.yMin  = checkRect.yMax - 18f;
                    var active = isActive;
                    GUI.DrawTexture(checkRect.ContractedBy(-2f), CheckboxBackground);
                    Widgets.Checkbox(checkRect.xMin, checkRect.yMin, ref active, checkRect.width);
                    if (active != isActive)
                    {
                        var clickedMod = ModLister.AllInstalledMods.FirstOrDefault(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID);
                        if (clickedMod != null)
                        {
                            ModsConfig.SetActive(clickedMod, active);
                            ModsConfig.Save();
                        }
                    }

                    if (Mouse.IsOver(checkRect) == false)
                    {
                        Widgets.DrawHighlightIfMouseover(modRect);
                        if (Widgets.ButtonInvisible(modRect, true))
                        {
                            var description  = promoMod.m_rgchTitle + "\n\n" + promoMod.m_rgchDescription;
                            var actionButton = isSubbed || isLocalFile ? "Select" : "Subscribe";
                            void actionButtonAction()
                            {
                                if (isSubbed || isLocalFile)
                                {
                                    var orderedMods = (IEnumerable <ModMetaData>)AccessTools.Method(typeof(Page_ModsConfig), "ModsInListOrder").Invoke(page, new object[0]);
                                    page.selectedMod = orderedMods.FirstOrDefault(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID);
                                    var modsBefore = orderedMods.FirstIndexOf(m => m == page.selectedMod);
                                    if (modsBefore >= 0)
                                    {
                                        Traverse.Create(page).Field("modListScrollPosition").SetValue(new Vector2(0f, modsBefore * 26f + 4f));
                                    }
                                }
                                else
                                {
                                    new Thread(() =>
                                    {
                                        CrossPromotion.subscribingMods.Add(myModID);
                                        SteamUGC.SubscribeItem(new PublishedFileId_t(myModID));
                                    }).Start();
                                }
                            }

                            var infoWindow = new Dialog_MessageBox(description, "Close".Translate(), null, actionButton, actionButtonAction, null, false, null, null);
                            Find.WindowStack.Add(infoWindow);
                        }
                    }
                    modRect.y += modRect.height + 2f;

                    modRect.height = 0f;
                    if (isLocalFile == false)
                    {
                        if (isSubbed == false)
                        {
                            modRect.height = 16f;
                            if (CrossPromotion.subscribingMods.Contains(myModID))
                            {
                                Widgets.Label(modRect, WaitingString);
                            }
                            else if (Widgets.ButtonText(modRect, "Subscribe", false, true, true))
                            {
                                new Thread(() =>
                                {
                                    CrossPromotion.subscribingMods.Add(myModID);
                                    SteamUGC.SubscribeItem(new PublishedFileId_t(myModID));
                                }).Start();
                            }
                        }
                        else if (voteStatus != null && voteStatus == false)
                        {
                            modRect.height = 16f;
                            if (Widgets.ButtonText(modRect, "Like", false, true, true))
                            {
                                new Thread(() =>
                                {
                                    CrossPromotion.allVoteStati[myModID] = true;
                                    SteamUGC.SetUserItemVote(new PublishedFileId_t(myModID), true);
                                }).Start();
                            }
                        }
                    }
                    modRect.y += modRect.height;
                }

                firstTime = false;
            }
            Widgets.EndScrollView();
        }