Esempio n. 1
0
        internal static void UnloadMod(ITogglableMod mod)
        {
            try
            {
                ModHooks.Instance.GlobalSettings.ModEnabledSettings[mod.GetName()] = false;
                ModHooks.Instance.LoadedModsWithVersions.Remove(mod.GetType().Name);
                ModHooks.Instance.LoadedMods.Remove(mod.GetType().Name);

                mod.Unload();
            }
            catch (Exception ex)
            {
                Logger.LogError($"[API] - Failed to unload Mod - {mod.GetName()} - {Environment.NewLine} - {ex} ");
            }

            UpdateModText();
        }
Esempio n. 2
0
        private void SceneLoaded(Scene scene, LoadSceneMode lsm)
        {
            try
            {
                if (_uim != null || ModLoader.LoadedMods == null || UIManager.instance == null)
                {
                    return;
                }
            }
            catch (NullReferenceException)
            {
                //Do Nothing.  Something inside of UIManager.instance breaks even if you try to check for null on it.
                return;
            }

            _uim = UIManager.instance;

            //ADD MODS TO OPTIONS MENU
            MenuButton defButton = (MenuButton)_uim.optionsMenuScreen.defaultHighlight;
            MenuButton modButton = Object.Instantiate(defButton.gameObject).GetComponent <MenuButton>();

            _uim.optionsMenuScreen.GetComponent <Patches.MenuButtonList>().AddSelectable(modButton, 5);

            modButton.name = "Mods";

            modButton.transform.SetParent(defButton.FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown()
                                          .FindSelectableOnDown().transform.parent);

            modButton.transform.localPosition = new Vector2(0, -120);
            modButton.transform.localScale    = defButton.FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown()
                                                .FindSelectableOnDown().transform.localScale;

            Object.Destroy(modButton.gameObject.GetComponent <AutoLocalizeTextUI>());
            modButton.gameObject.transform.Find("Text").GetComponent <Text>().text = "Mods";
            //ADD MODS TO OPTIONS MENU

            //SETUP MOD MENU
            GameObject go = Object.Instantiate(_uim.optionsMenuScreen.gameObject);

            ModMenuScreen          = go.GetComponent <MenuScreen>();
            ModMenuScreen.title    = ModMenuScreen.gameObject.transform.Find("Title").GetComponent <CanvasGroup>();
            ModMenuScreen.topFleur = ModMenuScreen.gameObject.transform.Find("TopFleur").GetComponent <Animator>();
            ModMenuScreen.content  = ModMenuScreen.gameObject.transform.Find("Content").GetComponent <CanvasGroup>();

            Patches.MenuButtonList modButtons = go.GetComponent <Patches.MenuButtonList>();
            modButtons.ClearSelectables();

            ModMenuScreen.title.gameObject.GetComponent <Text>().text = "Mods";
            Object.Destroy(ModMenuScreen.title.gameObject.GetComponent <AutoLocalizeTextUI>());

            ModMenuScreen.transform.SetParent(_uim.optionsMenuScreen.gameObject.transform.parent);
            ModMenuScreen.transform.localPosition = _uim.optionsMenuScreen.gameObject.transform.localPosition;
            ModMenuScreen.transform.localScale    = _uim.optionsMenuScreen.gameObject.transform.localScale;

            List <ITogglableMod> managableMods = ModLoader.LoadedMods.Where(x => x is ITogglableMod).Select(x => x)
                                                 .Cast <ITogglableMod>()
                                                 .ToList();

            ModMenuScreen.defaultHighlight = ModMenuScreen.content.gameObject.transform.GetChild(0).GetChild(0)
                                             .GetComponent <MenuButton>();
            Object.Destroy(ModMenuScreen.defaultHighlight.FindSelectableOnDown().FindSelectableOnDown()
                           .FindSelectableOnDown().FindSelectableOnDown().gameObject.transform.parent.gameObject);
            Object.Destroy(ModMenuScreen.defaultHighlight.FindSelectableOnDown().FindSelectableOnDown()
                           .FindSelectableOnDown().gameObject.transform.parent.gameObject);
            Object.Destroy(ModMenuScreen.defaultHighlight.FindSelectableOnDown().FindSelectableOnDown().gameObject
                           .transform.parent.gameObject);
            Object.Destroy(ModMenuScreen.defaultHighlight.FindSelectableOnDown().gameObject.transform.parent
                           .gameObject);

            _back = ModMenuScreen.defaultHighlight.FindSelectableOnUp();
            GameObject item = _uim.videoMenuScreen.defaultHighlight.FindSelectableOnDown().gameObject;

            Object.DestroyImmediate(item.GetComponent <MenuOptionHorizontal>());
            Object.DestroyImmediate(item.GetComponent <MenuSetting>());
            Object.DestroyImmediate(ModMenuScreen.content.GetComponent <VerticalLayoutGroup>());
            Object.Destroy(ModMenuScreen.defaultHighlight.gameObject.transform.parent.gameObject);
            try
            {
                if (managableMods.Count > 0)
                {
                    _modArray = new Selectable[managableMods.Count];

                    for (int i = 0; i < managableMods.Count; i++)
                    {
                        GameObject menuItemParent         = Object.Instantiate(item.gameObject);
                        FauxMenuOptionHorizontal menuItem = menuItemParent.AddComponent <FauxMenuOptionHorizontal>();

                        menuItem.navigation = new Navigation
                        {
                            mode = Navigation.Mode.Explicit
                        };

                        modButtons.AddSelectable(menuItem);

                        int modIndex = i;

                        //Manages what should happen when the menu option changes (the user clicks and the mod is toggled On/Off)
                        menuItem.OnUpdate += optionIndex =>
                        {
                            ITogglableMod mod = managableMods[modIndex];

                            string name = mod.GetName();

                            if (!ModHooks.Instance.GlobalSettings.ModEnabledSettings.ContainsKey(name))
                            {
                                ModHooks.Instance.GlobalSettings.ModEnabledSettings.Add(name, true);
                            }

                            try
                            {
                                if (optionIndex == 1)
                                {
                                    ModLoader.UnloadMod(mod);
                                }
                                else
                                {
                                    ModLoader.LoadMod(mod, true);
                                }
                            }
                            catch (Exception e)
                            {
                                LogError($"Could not load/unload mod \"{name}\":\n{e}");
                            }
                        };

                        menuItem.OptionList          = new[] { "On", "Off" };
                        menuItem.OptionText          = menuItem.gameObject.transform.GetChild(1).GetComponent <Text>();
                        menuItem.SelectedOptionIndex =
                            ModHooks.Instance.GlobalSettings.ModEnabledSettings[managableMods[i].GetName()] ? 0 : 1;
                        menuItem.LocalizeText = false;
                        menuItem.SheetTitle   = managableMods[i].GetName();

                        Object.DestroyImmediate(menuItem.transform.Find("Label")
                                                .GetComponent <AutoLocalizeTextUI>());
                        menuItem.transform.Find("Label").GetComponent <Text>().text = managableMods[i].GetName();

                        menuItem.leftCursor  = menuItem.transform.Find("CursorLeft").GetComponent <Animator>();
                        menuItem.rightCursor = menuItem.transform.Find("CursorRight").GetComponent <Animator>();

                        menuItem.gameObject.name = managableMods[i].GetName();

                        RectTransform rt = menuItemParent.GetComponent <RectTransform>();

                        rt.SetParent(ModMenuScreen.content.transform);
                        rt.localScale = new Vector3(2, 2, 2);

                        rt.sizeDelta        = new Vector2(960, 120);
                        rt.anchoredPosition = new Vector2(0, 766 / 2 - 90 - 150 * i);
                        rt.anchorMin        = new Vector2(0.5f, 1.0f);
                        rt.anchorMax        = new Vector2(0.5f, 1.0f);

                        menuItem.cancelAction = CancelAction.QuitModMenu;

                        _modArray[i] = menuItem;
                    }
                }
            }
            catch (Exception ex)
            {
                LogError(ex);
            }

            _back.navigation = new Navigation
            {
                mode = Navigation.Mode.Explicit
            };

            modButtons.AddSelectable(_back);

            modButtons.RecalculateNavigation();

            ((MenuSelectable)_back).cancelAction = CancelAction.QuitModMenu;
            EventTrigger backEvents = _back.gameObject.GetComponent <EventTrigger>();

            backEvents.triggers = new List <EventTrigger.Entry>();

            EventTrigger.Entry backSubmit = new EventTrigger.Entry {
                eventID = EventTriggerType.Submit
            };
            backSubmit.callback.AddListener(data => { _fauxUim.UIquitModMenu(); });
            backEvents.triggers.Add(backSubmit);

            EventTrigger.Entry backClick = new EventTrigger.Entry {
                eventID = EventTriggerType.PointerClick
            };
            backClick.callback.AddListener(data => { _fauxUim.UIquitModMenu(); });
            backEvents.triggers.Add(backClick);


            //SETUP MOD MENU
            LogDebug("About to add the events to the menu option");
            //SETUP MOD BUTTON TO RESPOND TO SUBMIT AND CANCEL EVENTS CORRECTLY
            EventTrigger events = modButton.gameObject.GetComponent <EventTrigger>();

            events.triggers = new List <EventTrigger.Entry>();

            EventTrigger.Entry submit = new EventTrigger.Entry {
                eventID = EventTriggerType.Submit
            };
            submit.callback.AddListener(data => { _fauxUim.UIloadModMenu(); });
            events.triggers.Add(submit);

            EventTrigger.Entry click = new EventTrigger.Entry {
                eventID = EventTriggerType.PointerClick
            };
            click.callback.AddListener(data => { _fauxUim.UIloadModMenu(); });
            events.triggers.Add(click);

            //SETUP MOD BUTTON TO RESPOND TO SUBMIT AND CANCEL EVENTS CORRECTLY
        }
        private void SetupMods(IList <ITogglableMod> managableMods, GameObject item)
        {
            if (managableMods.Count <= 0)
            {
                return;
            }

            _modArray = new Selectable[managableMods.Count];

            for (int i = 0; i < managableMods.Count; i++)
            {
                ITogglableMod mod = managableMods[i];

                GameObject menuItemParent = UObject.Instantiate(item.gameObject);
                var        menuItem       = menuItemParent.AddComponent <FauxMenuOptionHorizontal>();

                menuItem.navigation = Navigation.defaultNavigation;

                // Manages what should happen when the menu option changes (the user clicks and the mod is toggled On/Off)
                menuItem.OnUpdate += optionIndex =>
                {
                    string name = mod.GetName();

                    if (!ModHooks.Instance.GlobalSettings.ModEnabledSettings.ContainsKey(name))
                    {
                        ModHooks.Instance.GlobalSettings.ModEnabledSettings.Add(name, true);
                    }

                    try
                    {
                        if (optionIndex == 1)
                        {
                            ModLoader.UnloadMod(mod);
                        }
                        else
                        {
                            ModLoader.LoadMod(mod, true);
                        }
                    }
                    catch (Exception e)
                    {
                        LogError($"Could not load/unload mod \"{name}\":\n{e}");
                    }
                };

                menuItem.OptionList          = new[] { "On", "Off" };
                menuItem.OptionText          = menuItem.gameObject.transform.GetChild(1).GetComponent <Text>();
                menuItem.SelectedOptionIndex = ModHooks.Instance.GlobalSettings.ModEnabledSettings[mod.GetName()] ? 0 : 1;
                menuItem.LocalizeText        = false;
                menuItem.SheetTitle          = mod.GetName();

                Transform label = menuItem.transform.Find("Label");

                UObject.DestroyImmediate(label.GetComponent <AutoLocalizeTextUI>());
                label.GetComponent <Text>().text = mod.GetName();

                menuItem.leftCursor  = menuItem.transform.Find("CursorLeft").GetComponent <Animator>();
                menuItem.rightCursor = menuItem.transform.Find("CursorRight").GetComponent <Animator>();

                menuItem.gameObject.name = mod.GetName();

                var rt = menuItemParent.GetComponent <RectTransform>();

                rt.parent     = ModMenuScreen.content.transform;
                rt.localScale = new Vector3(2, 2, 2);

                rt.sizeDelta        = new Vector2(960, 120);
                rt.anchoredPosition = new Vector2(0, 766 / 2 - 90 - 150 * i);
                rt.anchorMin        = rt.anchorMax = new Vector2(0.5f, 1.0f);

                menuItem.cancelAction = CancelAction.QuitModMenu;

                _modArray[i] = menuItem;
            }
        }
Esempio n. 4
0
        private void SceneLoaded(Scene scene, LoadSceneMode lsm)
        {
            try
            {
                if (_uim != null || ModLoader.LoadedMods == null || UIManager.instance == null)
                {
                    return;
                }
            }
            catch (NullReferenceException)
            {
                //Do Nothing.  Something inside of UIManager.instance breaks even if you try to check for null on it.
                return;
            }

            _uim = UIManager.instance;

            //ADD MODS TO OPTIONS MENU
            MenuButton defButton = (MenuButton)_uim.optionsMenuScreen.defaultHighlight;
            MenuButton modButton = Object.Instantiate(defButton.gameObject).GetComponent <MenuButton>();

            Navigation nav = modButton.navigation;

            nav.selectOnUp       = defButton.FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown();
            nav.selectOnDown     = defButton.FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown();
            modButton.navigation = nav;

            nav = modButton.FindSelectableOnUp().navigation;
            nav.selectOnDown = modButton;
            modButton.FindSelectableOnUp().navigation = nav;

            nav            = modButton.FindSelectableOnDown().navigation;
            nav.selectOnUp = modButton;
            modButton.FindSelectableOnDown().navigation = nav;

            modButton.name = "Mods";

            modButton.transform.SetParent(modButton.FindSelectableOnUp().transform.parent);

            modButton.transform.localPosition = new Vector2(0, -120);
            modButton.transform.localScale    = modButton.FindSelectableOnUp().transform.localScale;

            Object.Destroy(modButton.gameObject.GetComponent <AutoLocalizeTextUI>());
            modButton.gameObject.transform.FindChild("Text").GetComponent <Text>().text = "Mods";
            //ADD MODS TO OPTIONS MENU

            //SETUP MOD MENU
            GameObject go = Object.Instantiate(_uim.optionsMenuScreen.gameObject);

            ModMenuScreen          = go.GetComponent <MenuScreen>();
            ModMenuScreen.title    = ModMenuScreen.gameObject.transform.FindChild("Title").GetComponent <CanvasGroup>();
            ModMenuScreen.topFleur = ModMenuScreen.gameObject.transform.FindChild("TopFleur").GetComponent <Animator>();
            ModMenuScreen.content  = ModMenuScreen.gameObject.transform.FindChild("Content").GetComponent <CanvasGroup>();

            ModMenuScreen.title.gameObject.GetComponent <Text>().text = "Mods";
            Object.Destroy(ModMenuScreen.title.gameObject.GetComponent <AutoLocalizeTextUI>());

            ModMenuScreen.transform.SetParent(_uim.optionsMenuScreen.gameObject.transform.parent);
            ModMenuScreen.transform.localPosition = _uim.optionsMenuScreen.gameObject.transform.localPosition;
            ModMenuScreen.transform.localScale    = _uim.optionsMenuScreen.gameObject.transform.localScale;

            // ReSharper disable SuspiciousTypeConversion.Global
            List <ITogglableMod> managableMods = ModLoader.LoadedMods.Where(x => x is ITogglableMod).Select(x => x).Cast <ITogglableMod>().ToList();

            // ReSharper restore SuspiciousTypeConversion.Global

            //modMenuScreen.content = modMenuScreen.gameObject.transform.GetChild()
            ModMenuScreen.defaultHighlight = ModMenuScreen.content.gameObject.transform.GetChild(0).GetChild(0).GetComponent <MenuButton>();
            Object.Destroy(ModMenuScreen.defaultHighlight.FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown().gameObject.transform.parent.gameObject);
            Object.Destroy(ModMenuScreen.defaultHighlight.FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown().gameObject.transform.parent.gameObject);
            Object.Destroy(ModMenuScreen.defaultHighlight.FindSelectableOnDown().FindSelectableOnDown().FindSelectableOnDown().gameObject.transform.parent.gameObject);
            Object.Destroy(ModMenuScreen.defaultHighlight.FindSelectableOnDown().FindSelectableOnDown().gameObject.transform.parent.gameObject);
            Object.Destroy(ModMenuScreen.defaultHighlight.FindSelectableOnDown().gameObject.transform.parent.gameObject);

            Back = ModMenuScreen.defaultHighlight.FindSelectableOnUp();
            GameObject item = _uim.videoMenuScreen.defaultHighlight.FindSelectableOnDown().gameObject;

            Object.DestroyImmediate(item.GetComponent <MenuOptionHorizontal>());
            Object.DestroyImmediate(item.GetComponent <MenuSetting>());
            Object.DestroyImmediate(ModMenuScreen.content.GetComponent <VerticalLayoutGroup>());
            Object.Destroy(ModMenuScreen.defaultHighlight.gameObject.transform.parent.gameObject);

            if (managableMods.Count > 0)
            {
                ModArray = new Selectable[managableMods.Count];

                for (int i = 0; i < managableMods.Count; i++)
                {
                    GameObject menuItemParent         = Object.Instantiate(item.gameObject);
                    FauxMenuOptionHorizontal menuItem = menuItemParent.AddComponent <FauxMenuOptionHorizontal>();

                    menuItem.navigation = Navigation.defaultNavigation;
                    int modIndex = i;

                    //Manages what should happen when the menu option changes (the user clicks and the mod is toggled On/Off)
                    menuItem.OnUpdate += optionIndex =>
                    {
                        ITogglableMod mod = managableMods[modIndex];

                        string name = mod.GetName();

                        if (!ModHooks.Instance.GlobalSettings.ModEnabledSettings.ContainsKey(name))
                        {
                            ModHooks.Instance.GlobalSettings.ModEnabledSettings.Add(name, true);
                        }

                        if (optionIndex == 1)
                        {
                            ModLoader.UnloadMod(mod);
                        }
                        else
                        {
                            ModLoader.LoadMod(mod);
                        }
                    };
                    //dataDump(modArray[i].gameObject, 1);

                    menuItem.OptionList          = new[] { "On", "Off" };
                    menuItem.OptionText          = menuItem.gameObject.transform.GetChild(1).GetComponent <Text>();
                    menuItem.SelectedOptionIndex = ModHooks.Instance.GlobalSettings.ModEnabledSettings[managableMods[i].GetName()] ? 0 : 1;
                    menuItem.LocalizeText        = false;
                    menuItem.SheetTitle          = managableMods[i].GetName();

                    Object.DestroyImmediate(menuItem.transform.FindChild("Label")
                                            .GetComponent <AutoLocalizeTextUI>());
                    menuItem.transform.FindChild("Label").GetComponent <Text>().text = managableMods[i].GetName();

                    menuItem.leftCursor  = menuItem.transform.FindChild("CursorLeft").GetComponent <Animator>();
                    menuItem.rightCursor = menuItem.transform.FindChild("CursorRight").GetComponent <Animator>();

                    menuItem.gameObject.name = managableMods[i].GetName();

                    RectTransform rt = menuItemParent.GetComponent <RectTransform>();

                    rt.SetParent(ModMenuScreen.content.transform);
                    rt.localScale = new Vector3(2, 2, 2);

                    rt.sizeDelta        = new Vector2(960, 120);
                    rt.anchoredPosition = new Vector2(0, (766 / 2) - 90 - (150 * i));
                    rt.anchorMin        = new Vector2(0.5f, 1.0f);
                    rt.anchorMax        = new Vector2(0.5f, 1.0f);

                    //Image img = menuItem.AddComponent<Image>();
                    //img.sprite = nullSprite();

                    menuItem.cancelAction = CancelAction.DoNothing;

                    ModArray[i] = menuItem;

                    //AutoLocalizeTextUI localizeUI = modArray[i].GetComponent<AutoLocalizeTextUI>();
                    //modArray[i].transform.GetChild(0).GetComponent<Text>().text = mods[i];
                    //GameObject.Destroy(localizeUI);
                }

                Navigation[] navs = new Navigation[ModArray.Length];
                for (int i = 0; i < ModArray.Length; i++)
                {
                    navs[i] = new Navigation
                    {
                        mode         = Navigation.Mode.Explicit,
                        selectOnUp   = i == 0 ? Back : ModArray[i - 1],
                        selectOnDown = i == ModArray.Length - 1 ? Back : ModArray[i + 1]
                    };

                    ModArray[i].navigation = navs[i];
                }

                ModMenuScreen.defaultHighlight = ModArray[0];
                Navigation nav2 = Back.navigation;
                nav2.selectOnUp   = ModArray[ModArray.Length - 1];
                nav2.selectOnDown = ModArray[0];
                Back.navigation   = nav2;
            }


            ((MenuButton)Back).cancelAction = CancelAction.DoNothing;
            EventTrigger backEvents = Back.gameObject.GetComponent <EventTrigger>();

            backEvents.triggers = new List <EventTrigger.Entry>();

            EventTrigger.Entry backSubmit = new EventTrigger.Entry {
                eventID = EventTriggerType.Submit
            };
            backSubmit.callback.AddListener(data => { _fauxUim.UIquitModMenu(); });
            backEvents.triggers.Add(backSubmit);

            EventTrigger.Entry backClick = new EventTrigger.Entry {
                eventID = EventTriggerType.PointerClick
            };
            backClick.callback.AddListener(data => { _fauxUim.UIquitModMenu(); });
            backEvents.triggers.Add(backClick);


            //SETUP MOD MENU
            LogDebug("About to add the events to the menu option");
            //SETUP MOD BUTTON TO RESPOND TO SUBMIT AND CANCEL EVENTS CORRECTLY
            EventTrigger events = modButton.gameObject.GetComponent <EventTrigger>();

            events.triggers = new List <EventTrigger.Entry>();

            EventTrigger.Entry submit = new EventTrigger.Entry {
                eventID = EventTriggerType.Submit
            };
            submit.callback.AddListener(data => { _fauxUim.UIloadModMenu(); });
            events.triggers.Add(submit);

            EventTrigger.Entry click = new EventTrigger.Entry {
                eventID = EventTriggerType.PointerClick
            };
            click.callback.AddListener(data => { _fauxUim.UIloadModMenu(); });
            events.triggers.Add(click);

            //SETUP MOD BUTTON TO RESPOND TO SUBMIT AND CANCEL EVENTS CORRECTLY
        }