コード例 #1
0
 /// <summary>
 /// Mod config folder, use this if you want save something.
 /// </summary>
 /// <returns>Path to your mod config folder</returns>
 /// <param name="mod">Your mod Class.</param>
 /// <example>Example Code in Mod subclass.
 /// <code source="Examples.cs" region="GetModConfigFolder" lang="C#" />
 /// Example from other than Mod subclass.
 /// <code source="Examples.cs" region="GetModConfigFolder2" lang="C#" />
 /// </example>
 public static string GetModConfigFolder(Mod mod)
 {
     return(Path.Combine(ConfigFolder, mod.ID));
 }
コード例 #2
0
        private void Update()
        {
            if (!fullyLoaded)
            {
                //check if camera is active.
                if (GameObject.Find("PLAYER/Pivot/Camera/FPSCamera") != null)
                {
                    //load mods
                    allModsLoaded = false;
                    fullyLoaded   = true;
                    StartLoadingMods();
                }
            }

            for (int i = 0; i < LoadedMods.Count; i++)
            {
                Mod mod = LoadedMods[i];
                try
                {
                    if (mod.LoadInMenu && !mod.isDisabled)
                    {
                        mod.Update();
                    }
                    else if (Application.loadedLevelName == "GAME" && !mod.isDisabled && allModsLoaded)
                    {
                        mod.Update();
                    }
                }
                catch (Exception e)
                {
                    if (LogAllErrors)
                    {
                        StackFrame frame = new StackTrace(e, true).GetFrame(0);

                        string errorDetails = string.Format("{2}<b>Details: </b>{0} in <b>{1}</b>", e.Message, frame.GetMethod(), Environment.NewLine);
                        ModConsole.Error(string.Format("Mod <b>{0}</b> throw an error!{1}", mod.ID, errorDetails));
                    }
                    UnityEngine.Debug.Log(e);
                    if (allModsLoaded && fullyLoaded)
                    {
                        mod.modErrors++;
                    }
                    if (devMode)
                    {
                        if (mod.modErrors == 30)
                        {
                            ModConsole.Error(string.Format("Mod <b>{0}</b> thrown <b>too many errors</b>!", mod.ID));
                            ModConsole.Error(e.ToString());
                        }
                    }
                    else
                    {
                        if (mod.modErrors > 30)
                        {
                            mod.isDisabled = true;
                            ModConsole.Error(string.Format("Mod <b>{0}</b> has been <b>disabled!</b> Because it thrown too many errors!{1}Report this problem to mod author.", mod.ID, Environment.NewLine));
                        }
                    }
                }
            }
        }
コード例 #3
0
        public void ModButton(string name, string version, string author, Mod mod)
        {
            GameObject modButton = Instantiate(ms.ModButton);

            if (mod.ID.StartsWith("MSCLoader_"))
            {
                modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.cyan;
                modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text  = "<color=cyan>Core Module!</color>";
                modButton.transform.GetChild(1).GetChild(4).GetChild(0).GetComponent <Button>().interactable = false;
            }
            else if (mod.isDisabled)
            {
                modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.red;
                modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text  = "<color=red>Mod is disabled!</color>";
                modButton.transform.GetChild(2).GetChild(1).gameObject.SetActive(true); //Add plugin Disabled icon
                modButton.transform.GetChild(2).GetChild(1).GetComponent <Image>().color = Color.red;
            }
            else if (!mod.LoadInMenu && ModLoader.GetCurrentScene() == CurrentScene.MainMenu)
            {
                modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.yellow;
                modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text  = "<color=yellow>Ready to load</color>";
            }
            else
            {
                modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().color = Color.green;
            }

            modButton.transform.GetChild(1).GetChild(4).GetChild(0).GetComponent <Button>().onClick.AddListener(() => ms.settings.ModDetailsShow(mod));

            if (Settings.Get(mod).Count > 0)
            {
                modButton.transform.GetChild(1).GetChild(4).GetChild(1).GetComponent <Button>().interactable = true;
                modButton.transform.GetChild(1).GetChild(4).GetChild(1).GetComponent <Button>().onClick.AddListener(() => ms.settings.ModSettingsShow(mod));
            }

            if (Keybind.Get(mod).Count > 0)
            {
                modButton.transform.GetChild(1).GetChild(4).GetChild(2).GetComponent <Button>().interactable = true;
                modButton.transform.GetChild(1).GetChild(4).GetChild(2).GetComponent <Button>().onClick.AddListener(() => ms.settings.ModKeybindsShow(mod));
            }

            if (name.Length > 24)
            {
                modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().text = string.Format("{0}...", name.Substring(0, 22));
            }
            else
            {
                modButton.transform.GetChild(1).GetChild(0).GetComponent <Text>().text = name;
            }

            modButton.transform.GetChild(1).GetChild(1).GetComponent <Text>().text = string.Format("by <color=orange>{0}</color>", author);
            modButton.transform.GetChild(1).GetChild(2).GetComponent <Text>().text = version;
            modButton.transform.SetParent(modView.transform, false);

            if (mod.metadata != null && mod.metadata.icon.iconFileName != null && mod.metadata.icon.iconFileName != string.Empty)
            {
                if (mod.metadata.icon.isIconRemote)
                {
                    if (File.Exists(Path.Combine(ModLoader.ManifestsFolder, @"Mod Icons\" + mod.metadata.icon.iconFileName)))
                    {
                        try
                        {
                            Texture2D t2d = new Texture2D(1, 1);
                            t2d.LoadImage(File.ReadAllBytes(Path.Combine(ModLoader.ManifestsFolder, @"Mod Icons\" + mod.metadata.icon.iconFileName)));
                            modButton.transform.GetChild(0).GetChild(0).GetComponent <RawImage>().texture = t2d;
                        }
                        catch (Exception e)
                        {
                            ModConsole.Error(e.Message);
                            System.Console.WriteLine(e);
                        }
                    }
                }
                else if (mod.metadata.icon.isIconUrl)
                {
                    try
                    {
                        WWW www = new WWW(mod.metadata.icon.iconFileName);
                        modButton.transform.GetChild(0).GetChild(0).GetComponent <RawImage>().texture = www.texture;
                    }
                    catch (Exception e)
                    {
                        ModConsole.Error(e.Message);
                        System.Console.WriteLine(e);
                    }
                }
                else
                {
                    if (File.Exists(Path.Combine(ModLoader.GetModAssetsFolder(mod), mod.metadata.icon.iconFileName)))
                    {
                        try
                        {
                            Texture2D t2d = new Texture2D(1, 1);
                            t2d.LoadImage(File.ReadAllBytes(Path.Combine(ModLoader.GetModAssetsFolder(mod), mod.metadata.icon.iconFileName)));
                            modButton.transform.GetChild(0).GetChild(0).GetComponent <RawImage>().texture = t2d;
                        }
                        catch (Exception e)
                        {
                            ModConsole.Error(e.Message);
                            System.Console.WriteLine(e);
                        }
                    }
                }
            }
            if (mod.hasUpdate)
            {
                modButton.transform.GetChild(1).GetChild(3).GetComponent <Text>().text = "<color=lime>UPDATE AVAILABLE!</color>";
            }
            if (mod.UseAssetsFolder)
            {
                modButton.transform.GetChild(2).GetChild(2).gameObject.SetActive(true); //Add assets icon
            }
            if (!mod.isDisabled)
            {
                modButton.transform.GetChild(2).GetChild(1).gameObject.SetActive(true); //Add plugin OK icon
            }
            if (mod.LoadInMenu)
            {
                modButton.transform.GetChild(2).GetChild(0).gameObject.SetActive(true);//Add Menu Icon
            }
        }
コード例 #4
0
        // Manage windows
        private void windowManager(int id)
        {
            if (id == 0)
            {
                if (menuState == 0)
                {
                    // Main menu

                    scrollPos = GUILayout.BeginScrollView(scrollPos);

                    GUILayout.Label("Loaded mods");

                    GUILayout.Space(20);

                    foreach (Mod mod in ModLoader.LoadedMods)
                    {
                        if (GUILayout.Button(mod.Name, GUILayout.Height(30)))
                        {
                            menuState   = 1;
                            selectedMod = mod;
                        }
                    }

                    GUILayout.EndScrollView();

                    GUILayout.Space(20);

                    if (GUILayout.Button("Close", GUILayout.Height(30)))
                    {
                        menuOpen = false;
                    }
                }
                else if (menuState == 1)
                {
                    // Mod info

                    scrollPos = GUILayout.BeginScrollView(scrollPos);

                    GUILayout.Space(20);

                    if (selectedMod != null)
                    {
                        GUILayout.Label("ID: " + selectedMod.ID);
                        GUILayout.Label("Name: " + selectedMod.Name);
                        GUILayout.Label("Version: " + selectedMod.Version);
                        GUILayout.Label("Author: " + selectedMod.Author);

                        GUILayout.Space(20);

                        if (GUILayout.Button("Keybinds", GUILayout.Height(30)))
                        {
                            menuState = 2;
                            scrollPos = Vector2.zero;
                        }
                    }
                    else
                    {
                        GUILayout.Label("Invalid mod");
                    }

                    GUILayout.EndScrollView();

                    GUILayout.Space(20);

                    if (GUILayout.Button("Back", GUILayout.Height(30)))
                    {
                        menuState   = 0;
                        selectedMod = null;
                        scrollPos   = Vector2.zero;
                    }
                }
                else if (menuState == 2)
                {
                    // Edit keybinds

                    GUILayout.Label("Keybinds");
                    GUILayout.Space(20);

                    scrollPos = GUILayout.BeginScrollView(scrollPos);

                    if (selectedMod != null)
                    {
                        bool none = true;

                        foreach (Keybind key in Keybind.Keybinds)
                        {
                            if (key.Mod == selectedMod)
                            {
                                GUILayout.Label(key.Name);

                                string modStr = key.Modifier.ToString();
                                string keyStr = key.Key.ToString();

                                if (awaitingInput)
                                {
                                    if (awaitingKeyID == 0)
                                    {
                                        modStr = "Press any key";
                                    }
                                    else if (awaitingKeyID == 1)
                                    {
                                        keyStr = "Press any key";
                                    }
                                }

                                if (GUILayout.Button("Modifier - " + modStr, GUILayout.Height(30)))
                                {
                                    if (!awaitingInput)
                                    {
                                        awaitingInput = true;
                                        awaitingKeyID = 0;
                                        awaitingKey   = key;
                                    }
                                }

                                if (GUILayout.Button("Key - " + keyStr, GUILayout.Height(30)))
                                {
                                    if (!awaitingInput)
                                    {
                                        awaitingInput = true;
                                        awaitingKeyID = 1;
                                        awaitingKey   = key;
                                    }
                                }

                                GUILayout.Space(10);

                                none = false;
                            }
                        }

                        if (none)
                        {
                            GUILayout.Label("This mod has no keybinds");
                        }
                    }
                    else
                    {
                        GUILayout.Label("Invalid mod");
                    }

                    GUILayout.EndScrollView();

                    GUILayout.Space(20);

                    if (GUILayout.Button("Reset", GUILayout.Height(30)))
                    {
                        resetBinds();
                    }

                    if (GUILayout.Button("Back", GUILayout.Height(30)))
                    {
                        menuState = 1;
                        scrollPos = Vector2.zero;
                    }
                }
            }
        }
コード例 #5
0
        public void ModDetailsShow(Mod mod)
        {
            //  bool core = false;
            selected_mod = mod;
            // if (selected.ID.StartsWith("MSCLoader_"))
            //      core = true; //can't disable core components
            goBackBtn.SetActive(true);
            InfoTxt.text  = string.Format("<color=yellow>ID:</color> <b><color=lime>{0}</color></b>{1}", mod.ID, Environment.NewLine);
            InfoTxt.text += string.Format("<color=yellow>Name:</color> <b><color=lime>{0}</color></b>{1}", mod.Name, Environment.NewLine);
            //if (core)
            //     InfoTxt.text += string.Format("<color=yellow>Version:</color> <b><color=lime>{0}</color></b>{1}", selected.Version, Environment.NewLine);
            // else
            //{
            if (mod.hasUpdate)
            {
                InfoTxt.text += string.Format("<color=yellow>Version:</color> <b><color=orange>{0}</color></b> (<color=lime>{3} available</color>){2}(designed for <b><color=lime>v{1}</color></b>){2}", mod.Version, mod.compiledVersion, Environment.NewLine, mod.RemMetadata.version);
            }
            else
            {
                InfoTxt.text += string.Format("<color=yellow>Version:</color> <b><color=lime>{0}</color></b>{2}(designed for <b><color=lime>v{1}</color></b>){2}", mod.Version, mod.compiledVersion, Environment.NewLine);
            }

            //}
            InfoTxt.text += string.Format("<color=yellow>Author:</color> <b><color=lime>{0}</color></b>", mod.Author);
            if (Application.loadedLevelName == "MainMenu")
            {
                DisableMod.interactable = true;
            }
            else
            {
                DisableMod.interactable = false;
            }
            DisableMod.isOn = mod.isDisabled;
            nexusLink.gameObject.SetActive(false);
            rdLink.gameObject.SetActive(false);
            ghLink.gameObject.SetActive(false);
            descriptionTxt.text = "<i>No description provided...</i>";
            if (mod.metadata != null)
            {
                if (!string.IsNullOrEmpty(mod.metadata.links.nexusLink))
                {
                    nexusLink.gameObject.SetActive(true);
                    nexusLink.onClick.RemoveAllListeners();
                    nexusLink.onClick.AddListener(() => OpenModLink(mod.metadata.links.nexusLink));
                }
                if (!string.IsNullOrEmpty(mod.metadata.links.rdLink))
                {
                    rdLink.gameObject.SetActive(true);
                    rdLink.onClick.RemoveAllListeners();
                    rdLink.onClick.AddListener(() => OpenModLink(mod.metadata.links.rdLink));
                }
                if (!string.IsNullOrEmpty(mod.metadata.links.githubLink))
                {
                    ghLink.gameObject.SetActive(true);
                    ghLink.onClick.RemoveAllListeners();
                    ghLink.onClick.AddListener(() => OpenModLink(mod.metadata.links.githubLink));
                }
                descriptionTxt.text = mod.metadata.description;
            }
            settingViewContainer.GetComponent <Animator>().SetBool("goDetails", true);

            page = 1;
            SetScrollRect();
        }