Exemple #1
0
        public void CreateConsoleUI()
        {
            AssetBundle ab = LoadAssets.LoadBundle(this, "console.unity3d");

            UI = ab.LoadAsset <GameObject>("MSCLoader Console.prefab");
            Texture2D cursor = ab.LoadAsset <Texture2D>("resizeCur.png");

            ab.Unload(false);
            UI      = Object.Instantiate(UI);
            UI.name = "MSCLoader Console";
            console = UI.AddComponent <ConsoleView>();
            console.viewContainer = UI.transform.GetChild(0).gameObject;
            console.inputField    = console.viewContainer.transform.GetChild(0).gameObject.GetComponent <InputField>();
            console.viewContainer.transform.GetChild(1).gameObject.GetComponent <Button>().onClick.AddListener(() => console.runCommand());
            console.logTextArea = console.viewContainer.transform.GetChild(2).GetChild(0).gameObject.GetComponent <Text>();
            console.viewContainer.transform.GetChild(4).gameObject.AddComponent <ConsoleUIResizer>().logview   = console.viewContainer.transform.GetChild(2).gameObject;
            console.viewContainer.transform.GetChild(4).gameObject.GetComponent <ConsoleUIResizer>().scrollbar = console.viewContainer.transform.GetChild(3).gameObject;
            console.viewContainer.transform.GetChild(4).gameObject.GetComponent <ConsoleUIResizer>().cursor    = cursor;
            EventTrigger trigger = console.viewContainer.transform.GetChild(4).gameObject.GetComponent <EventTrigger>();

            EventTrigger.Entry entry = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerEnter;
            entry.callback.AddListener((eventData) => { console.viewContainer.transform.GetChild(4).gameObject.GetComponent <ConsoleUIResizer>().OnMouseEnter(); });
            trigger.delegates.Add(entry);
            entry         = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerExit;
            entry.callback.AddListener((eventData) => { console.viewContainer.transform.GetChild(4).gameObject.GetComponent <ConsoleUIResizer>().OnMouseExit(); });
            trigger.delegates.Add(entry);

            UI.transform.SetParent(ModUI.GetCanvas().transform, false);
        }
 private static void EnableGarageToggle()
 {
     if ((bool)enGarage.GetValue() && (string)authKey.GetValue() == string.Empty)
     {
         ModUI.ShowYesNoMessage(string.Format("To use MSCGarage you need to get your <b>Auth-Key</b> from garage website.{0}{0}Do you want to do it now?", Environment.NewLine), OpenAuthKeyWebsite);
     }
 }
Exemple #3
0
 private static void ChangeUIScaling()
 {
     if ((bool)expUIScaling.GetValue())
     {
         ModUI.GetCanvas().GetComponent <CanvasScaler>().matchWidthOrHeight = float.Parse(tuneScaling.GetValue().ToString());
     }
 }
Exemple #4
0
 public override void OnMenuLoad()
 {
     try {
         CreateSettingsUI();
     } catch (Exception e) {
         ModUI.ShowMessage(
             $"Fatal error:{Environment.NewLine}<color=orange>{e.Message}</color>{Environment.NewLine}Please install modloader correctly.",
             "Fatal Error");
     }
 }
        public void CreateSettingsUI()
        {
            AssetBundle ab = AssetBundle.CreateFromMemoryImmediate(Properties.Resources.settingsui);

            //AssetBundle ab = LoadAssets.LoadBundle(this, "settingsui.unity3d");

            UI = ab.LoadAsset <GameObject>("MSCLoader Settings.prefab");

            ModButton         = ab.LoadAsset <GameObject>("ModButton.prefab");
            ModButton_Invalid = ab.LoadAsset <GameObject>("ModButton_Invalid.prefab");

            ModLabel = ab.LoadAsset <GameObject>("ModViewLabel.prefab");

            KeyBind = ab.LoadAsset <GameObject>("KeyBind.prefab");

            modSettingsButton = ab.LoadAsset <GameObject>("Button_ms.prefab");
            //For mod settings
            Checkbox = ab.LoadAsset <GameObject>("Checkbox.prefab");
            setBtn   = ab.LoadAsset <GameObject>("Button.prefab");
            slider   = ab.LoadAsset <GameObject>("Slider.prefab");
            textBox  = ab.LoadAsset <GameObject>("TextBox.prefab");
            header   = ab.LoadAsset <GameObject>("Header.prefab");

            UI = UnityEngine.Object.Instantiate(UI);
            UI.AddComponent <ModUIDrag>();
            UI.name = "MSCLoader Settings";

            settings = UI.AddComponent <SettingsView>().Setup(this);

            modUpdateButton      = UnityEngine.Object.Instantiate(modSettingsButton);
            modUpdateButton.name = "MSCLoader Update button";
            modUpdateButton.transform.SetParent(ModUI.GetCanvas().transform, false);
            modUpdateButton.GetComponent <Button>().onClick.AddListener(() => CheckForUpdateButton());
            modUpdateButton.transform.GetChild(0).GetComponent <Text>().text = "Check Updates";
            modUpdateButton.SetActive((bool)modSetButton.GetValue());
            modUpdateButton.AddComponent <SetButtonPos>().button = modUpdateButton;

            modSettingsButton      = UnityEngine.Object.Instantiate(modSettingsButton);
            modSettingsButton.name = "MSCLoader Settings button";
            modSettingsButton.transform.SetParent(ModUI.GetCanvas().transform, false);
            modSettingsButton.GetComponent <Button>().onClick.AddListener(() => settings.ToggleVisibility());
            modSettingsButton.SetActive((bool)modSetButton.GetValue());

            ab.Unload(false);

            // FREDTWEAK
            Transform canvas = GameObject.Find("MSCLoader Canvas").transform.Find("MSCLoader Settings/MSCLoader SettingsContainer/Settings/SettingsView");

            canvas.GetChild(0).gameObject.SetActive(false);
            canvas.GetChild(1).gameObject.SetActive(false);
            canvas.GetChild(2).gameObject.SetActive(false);

            GameObject.Find("MSCLoader Canvas").transform.Find("MSCLoader Settings/MSCLoader SettingsContainer/ModKeyBinds/KeyBindsView/Text").GetComponent <Text>().text = "<color=lime><b>LMB</b></color> - Cancel\n<color=lime><b>RMB</b></color> - Set to None";
        }
Exemple #6
0
 private static void ExpUIScaling()
 {
     if ((bool)expUIScaling.GetValue())
     {
         ModUI.GetCanvas().GetComponent <CanvasScaler>().screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
         ChangeUIScaling();
     }
     else
     {
         ModUI.GetCanvas().GetComponent <CanvasScaler>().screenMatchMode = CanvasScaler.ScreenMatchMode.Shrink;
     }
 }
        public void modButton(string name, string version, string author, Mod mod)
        {
            GameObject modButton = ModUI.CreateUIBase("ModButton", modView);

            modButton.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            modButton.AddComponent <Image>().color             = Color.white;
            modButton.AddComponent <LayoutElement>().minHeight = 50;
            modButton.AddComponent <Button>().targetGraphic    = modButton.GetComponent <Image>();
            ColorBlock cb = modButton.GetComponent <Button>().colors;

            cb.normalColor      = new Color32(0x00, 0xB4, 0xFF, 0x64); //00B4FF64
            cb.highlightedColor = new Color32(0x00, 0xFF, 0x2B, 0x64); //00FF2B64
            modButton.GetComponent <Button>().colors = cb;
            modButton.AddComponent <ModInfo>().mod   = mod;

            GameObject modName = ModUI.CreateTextBlock("Name", name, modButton, TextAnchor.UpperLeft, Color.green);

            modName.GetComponent <RectTransform>().anchorMin        = new Vector2(0, 1);
            modName.GetComponent <RectTransform>().anchorMax        = new Vector2(0, 1);
            modName.GetComponent <RectTransform>().pivot            = new Vector2(0, 1);
            modName.GetComponent <RectTransform>().anchoredPosition = new Vector2(2, 0);
            modName.GetComponent <Text>().fontStyle = FontStyle.Bold;
            modName.GetComponent <Text>().fontSize  = 18;
            modName.AddComponent <ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            modName.GetComponent <ContentSizeFitter>().verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

            GameObject modVersion = ModUI.CreateTextBlock("Version", string.Format("v{0}", version), modButton, TextAnchor.LowerLeft, Color.yellow);

            modVersion.GetComponent <RectTransform>().anchorMin        = new Vector2(0, 0);
            modVersion.GetComponent <RectTransform>().anchorMax        = new Vector2(0, 0);
            modVersion.GetComponent <RectTransform>().pivot            = new Vector2(0, 0);
            modVersion.GetComponent <RectTransform>().anchoredPosition = new Vector2(2, 0);
            modVersion.GetComponent <Text>().fontSize = 16;
            modVersion.AddComponent <ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            modVersion.GetComponent <ContentSizeFitter>().verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

            GameObject modAuthor = ModUI.CreateTextBlock("Author", author, modButton, TextAnchor.LowerRight, Color.yellow);

            modAuthor.GetComponent <RectTransform>().anchorMin        = new Vector2(1, 0);
            modAuthor.GetComponent <RectTransform>().anchorMax        = new Vector2(1, 0);
            modAuthor.GetComponent <RectTransform>().pivot            = new Vector2(1, 0);
            modAuthor.GetComponent <RectTransform>().anchoredPosition = new Vector2(-2, 0);
            modAuthor.GetComponent <Text>().fontSize = 16;
            modAuthor.AddComponent <ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            modAuthor.GetComponent <ContentSizeFitter>().verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
            modButton.GetComponent <Button>().onClick.AddListener(() => settingView.GetComponent <SettingsView>().selectMod());
        }
Exemple #8
0
 public override void OnMenuLoad()
 {
     try
     {
         CreateConsoleUI();
     }
     catch (System.Exception e)
     {
         ModUI.ShowMessage($"Fatal error:{System.Environment.NewLine}<color=orange>{e.Message}</color>{System.Environment.NewLine}Please install modloader correctly.", "Fatal Error");
     }
     console.controller = new ConsoleController();
     ConsoleCommand.cc  = console.controller;
     console.setVisibility(false);
     console.viewContainer.transform.GetChild(5).gameObject.GetComponent <ConsoleUIResizer>().LoadConsoleSize();
     ConsoleCommand.Add(new CommandVersion());
     ConsoleCommand.Add(new CommandLogAll());
     ConsoleCommand.Add(new ManifestCommand());
 }
Exemple #9
0
        /// <summary>
        /// Print information about ModLoader in MainMenu scene.
        /// </summary>
        private static void MainMenuInfo(bool destroy = false)
        {
            //Create parent gameobject in canvas for layout and text information.
            GameObject modInfo = ModUI.CreateUIBase("MSCLoader Info", GameObject.Find("MSCLoader Canvas"));

            modInfo.AddComponent <VerticalLayoutGroup>().childForceExpandHeight = false;
            modInfo.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            modInfo.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            modInfo.GetComponent <RectTransform>().pivot     = new Vector2(0, 1);

            //check if new version is available
            if (!experimental)
            {
                try
                {
                    string version;
                    using (WebClient client = new WebClient())
                    {
                        version = client.DownloadString("http://my-summer-car.ml/version.txt");
                    }
                    int i = Version.CompareTo(version.Trim());
                    if (i != 0)
                    {
                        ModUI.CreateTextBlock("MSCLoader Info Text", string.Format("Mod Loader MCSLoader v{0} is ready! (<color=orange>New version available: <b>v{1}</b></color>)", Version, version.Trim()), modInfo, TextAnchor.MiddleLeft, Color.white, true).GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
                    }
                    else if (i == 0)
                    {
                        ModUI.CreateTextBlock("MSCLoader Info Text", string.Format("Mod Loader MCSLoader v{0} is ready! (<color=lime>Up to date</color>)", Version, i.ToString()), modInfo, TextAnchor.MiddleLeft, Color.white, true).GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
                    }
                }
                catch (Exception e)
                {
                    ModConsole.Error(string.Format("Check for new version failed with error: {0}", e.Message));
                    ModUI.CreateTextBlock("MSCLoader Info Text", string.Format("Mod Loader MCSLoader v{0} is ready!", Version), modInfo, TextAnchor.MiddleLeft, Color.white, true).GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
                }
            }
            else
            {
                ModUI.CreateTextBlock("MSCLoader Info Text", string.Format("Mod Loader MCSLoader v{0} is ready! (<color=magenta>Experimental</color>)", Version), modInfo, TextAnchor.MiddleLeft, Color.white, true).GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
            }
            ModUI.CreateTextBlock("MSCLoader Mod location Text", string.Format("Mods folder: {0}", ModsFolder), modInfo, TextAnchor.MiddleLeft, Color.white, true).GetComponent <Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
        }
        void LoadCoreAssets()
        {
            AssetBundle ab = AssetBundle.CreateFromMemoryImmediate(Properties.Resources.core);

            guiskin          = ab.LoadAsset <GUISkin>("MSCLoader.guiskin");
            ModUI.messageBox = ab.LoadAsset <GameObject>("MSCLoader MB.prefab");
            mainMenuInfo     = ab.LoadAsset <GameObject>("MSCLoader Info.prefab");

            GameObject loadingScreen = Resources.FindObjectsOfTypeAll <GameObject>().FirstOrDefault(x => x.name == "Loading" && x.transform.root == x.transform);
            TextMesh   textMesh      = loadingScreen.GetComponentsInChildren <TextMesh>(true)[0];

            GameObject loadingPrefab = ab.LoadAsset <GameObject>("LoadingMods.prefab");

            loading = Instantiate(loadingPrefab);
            loading.SetActive(false);
            loading.name = "MSCLoader loading screen";
            loading.transform.SetParent(ModUI.GetCanvas().transform, false);

            loading.GetComponent <Image>().color = Color.black;
            Text loadingText = loading.transform.GetChild(0).GetComponent <Text>();

            loadingText.text  = "NOW LOADING MODS IN YEAR 1995...";
            loadingText.font  = textMesh.font;
            loadingText.color = textMesh.color;
            loadingText.transform.localScale = new Vector3(2f, 2f, 2f);
            loading.transform.GetChild(1).gameObject.SetActive(false);
            loading.transform.GetChild(2).gameObject.SetActive(false);
            loading.transform.GetChild(3).gameObject.SetActive(false);

            GameObject loadingMetaPrefab = ab.LoadAsset <GameObject>("MSCLoader pbar.prefab");

            loadingMeta = Instantiate(loadingMetaPrefab);
            loadingMeta.SetActive(false);
            loadingMeta.name = "MSCLoader pbar";
            loadingMeta.transform.SetParent(ModUI.GetCanvas().transform, false);

            Destroy(loadingPrefab);
            Destroy(loadingMetaPrefab);

            ab.Unload(false);
        }
Exemple #11
0
        private static GameObject ModListS(GameObject modList, GameObject scrollbar, string name)
        {
            GameObject modView = ModUI.CreateUIBase(name, modList);

            modView.GetComponent <RectTransform>().anchorMin                    = new Vector2(0.5f, 1);
            modView.GetComponent <RectTransform>().anchorMax                    = new Vector2(0.5f, 1);
            modView.GetComponent <RectTransform>().pivot                        = new Vector2(0.5f, 1);
            modView.GetComponent <RectTransform>().sizeDelta                    = new Vector2(300, 430);
            modView.AddComponent <ContentSizeFitter>().verticalFit              = ContentSizeFitter.FitMode.PreferredSize;
            modView.AddComponent <VerticalLayoutGroup>().padding                = new RectOffset(5, 5, 5, 5);
            modView.GetComponent <VerticalLayoutGroup>().spacing                = 5;
            modView.GetComponent <VerticalLayoutGroup>().childAlignment         = TextAnchor.UpperCenter;
            modView.GetComponent <VerticalLayoutGroup>().childForceExpandHeight = false;

            modList.AddComponent <ScrollRect>().content           = modView.GetComponent <RectTransform>();
            modList.GetComponent <ScrollRect>().horizontal        = false;
            modList.GetComponent <ScrollRect>().inertia           = false;
            modList.GetComponent <ScrollRect>().movementType      = ScrollRect.MovementType.Clamped;
            modList.GetComponent <ScrollRect>().scrollSensitivity = 30f;
            modList.GetComponent <ScrollRect>().verticalScrollbar = scrollbar.GetComponent <Scrollbar>();
            return(modView);
        }
        void MainMenuInfo()
        {
            Text info, mf;

            GameObject mainMenuInfoPrefab = mainMenuInfo;

            mainMenuInfo = Instantiate(mainMenuInfoPrefab);
            Destroy(mainMenuInfoPrefab);

            mainMenuInfo.name = "MSCLoader Info";

            menuInfoAnim = mainMenuInfo.GetComponent <Animator>();
            menuInfoAnim.SetBool("isHidden", false);

            info       = mainMenuInfo.transform.GetChild(0).gameObject.GetComponent <Text>();
            mf         = mainMenuInfo.transform.GetChild(1).gameObject.GetComponent <Text>();
            modUpdates = mainMenuInfo.transform.GetChild(2).gameObject.GetComponent <Text>();
            info.text  = $"MSCLoader <color=cyan>v{ModLoaderVersion}</color> (Fredman Edition)";

            mf.text         = $"<color=orange>Mods folder:</color> {ModsFolder}";
            modUpdates.text = string.Empty;
            mainMenuInfo.transform.SetParent(ModUI.GetCanvas().transform, false);
        }
Exemple #13
0
        public SettingsView Setup(ModSettings_menu ms)
        {
            modSettingsMenu = ms;

            settingViewContainer = transform.GetChild(0).gameObject;
            backButton           = settingViewContainer.transform.GetChild(0).GetChild(1).gameObject;
            modInfo      = settingViewContainer.transform.GetChild(2).gameObject;
            modKeybinds  = settingViewContainer.transform.GetChild(1).gameObject;
            keybindsList = modKeybinds.transform.GetChild(0).GetChild(4).gameObject;
            modSettings  = settingViewContainer.transform.GetChild(4).gameObject;
            settingsList = modSettings.transform.GetChild(0).GetChild(4).gameObject;
            modList      = settingViewContainer.transform.GetChild(3).gameObject;
            modView      = modList.transform.GetChild(0).gameObject;

            GameObject modSettingsView = modInfo.transform.GetChild(0).gameObject;

            disableMod      = modSettingsView.transform.GetChild(2).GetComponent <Toggle>();
            coreModCheckbox = settingViewContainer.transform.GetChild(6).GetChild(0).GetComponent <Toggle>();

            modCount        = settingViewContainer.transform.GetChild(6).GetChild(1).GetComponent <Text>();
            infoText        = modSettingsView.transform.GetChild(0).GetComponent <Text>();
            descriptionText = modSettingsView.transform.GetChild(8).GetComponent <Text>();

            nexusLink = modSettingsView.transform.GetChild(4).GetComponent <Button>();
            rdLink    = modSettingsView.transform.GetChild(5).GetComponent <Button>();
            ghLink    = modSettingsView.transform.GetChild(6).GetComponent <Button>();

            backButton.GetComponent <Button>().onClick.AddListener(() => GoBack());
            disableMod.onValueChanged.AddListener(DisableMod);
            coreModCheckbox.onValueChanged.AddListener(delegate { ToggleCoreCheckbox(); });
            settingViewContainer.transform.GetChild(0).GetChild(2).GetComponent <Button>().onClick.AddListener(() => ToggleVisibility());

            transform.SetParent(ModUI.GetCanvas().transform, false);
            SetVisibility(false);

            return(this);
        }
Exemple #14
0
        /// <summary>
        /// Main function to initialize the ModLoader
        /// </summary>
        public static void Init()
        {
            //Set config and Assets folder in selected mods folder
            ConfigFolder = Path.Combine(ModsFolder, @"Config\");
            AssetsFolder = Path.Combine(ModsFolder, @"Assets\");
            //if mods not loaded and game is loaded.
            if (GameObject.Find("MSCUnloader") == null)
            {
                GameObject go = new GameObject();
                go.name = "MSCUnloader";
                go.AddComponent <MSCUnloader>();
                MSCUnloaderInstance = go.GetComponent <MSCUnloader>();
                DontDestroyOnLoad(go);
            }
            if (IsModsDoneLoading && Application.loadedLevelName == "MainMenu")
            {
                MSCUnloaderInstance.reset = false;
                MSCUnloaderInstance.MSCLoaderReset();
            }
            if (!IsModsDoneLoading && Application.loadedLevelName == "GAME" && fullyLoaded && !IsModsLoading)
            {
                // Load all mods
                IsModsLoading = true;
                Instance.StartCoroutine(Instance.LoadMods());
            }

            if (IsDoneLoading && Application.loadedLevelName == "MainMenu" && GameObject.Find("MSCLoader Info") == null)
            {
                MainMenuInfo();
            }

            if (IsDoneLoading || Instance)
            {
                if (Application.loadedLevelName != "MainMenu")
                {
                    menuInfoAnim.SetBool("isHidden", true);
                }
            }
            else
            {
                // Create game object and attach self
                GameObject go = new GameObject();
                go.name = "MSCModLoader";
                go.AddComponent <ModLoader>();
                go.AddComponent <LoadAssets>();
                Instance   = go.GetComponent <ModLoader>();
                loadAssets = go.GetComponent <LoadAssets>();
                DontDestroyOnLoad(go);

                // Init variables
                ModUI.CreateCanvas();
                IsDoneLoading     = false;
                IsModsDoneLoading = false;
                LoadedMods        = new List <Mod>();
                InvalidMods       = new List <string>();

                // Init mod loader settings
                if (!Directory.Exists(ModsFolder))
                {
                    //if mods folder not exists, create it.
                    Directory.CreateDirectory(ModsFolder);
                }

                if (!Directory.Exists(ConfigFolder))
                {
                    //if config folder not exists, create it.
                    Directory.CreateDirectory(ConfigFolder);
                }

                if (!Directory.Exists(AssetsFolder))
                {
                    //if config folder not exists, create it.
                    Directory.CreateDirectory(AssetsFolder);
                }
                // Loading internal tools (console and settings)
                LoadMod(new ModConsole(), Version);
                LoadedMods[0].ModSettings();
                LoadMod(new ModSettings_menu(), Version);
                LoadedMods[1].ModSettings();
                ModSettings_menu.LoadSettings();
                LoadCoreAssets();
                IsDoneLoading = true;
                ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version));
                LoadReferences();
                PreLoadMods();
                ModConsole.Print(string.Format("<color=orange>Found <color=green><b>{0}</b></color> mods!</color>", LoadedMods.Count - 2));
                try
                {
                    if (File.Exists(Path.GetFullPath(Path.Combine("LAUNCHER.exe", ""))) || File.Exists(Path.GetFullPath(Path.Combine("SmartSteamEmu64.dll", ""))) || File.Exists(Path.GetFullPath(Path.Combine("SmartSteamEmu.dll", ""))))
                    {
                        ModConsole.Print(string.Format("<color=orange>Hello <color=green><b>{0}</b></color>!</color>", "PIRATE IS FREE!!!"));
                        throw new Exception("Do What You Want, Cause A Pirate Is Free... You Are A Pirate!");
                        //exclude emulators from stats (spam weird stuff sometimes)
                    }
                    Steamworks.SteamAPI.Init();
                    steamID = Steamworks.SteamUser.GetSteamID().ToString();
                    ModConsole.Print(string.Format("<color=orange>Hello <color=green><b>{0}</b></color>!</color>", Steamworks.SteamFriends.GetPersonaName()));
                    if (!modStats)
                    {
                        ModStats();
                        modStats = true;
                    }

                    string Name;
                    bool   ret = Steamworks.SteamApps.GetCurrentBetaName(out Name, 128);
                    if (ret && !(bool)ModSettings_menu.expWarning.GetValue())
                    {
                        ModUI.ShowMessage(string.Format("<color=orange><b>Warning:</b></color>{1}You are using beta build: <color=orange><b>{0}</b></color>{1}{1}Remember that some mods may not work correctly on beta branches.", Name, Environment.NewLine), "Experimental build warning");
                    }
                }
                catch (Exception e)
                {
                    ModConsole.Error("Steam not detected, only steam version is supported.");
                    UnityEngine.Debug.Log(e);
                }
                MainMenuInfo();
                LoadModsSettings();
            }
        }
Exemple #15
0
        private void Init()
        {
            //Set config and Assets folder in selected mods folder
            ConfigFolder = Path.Combine(ModsFolder, @"Config\");
            AssetsFolder = Path.Combine(ModsFolder, @"Assets\");

            if (GameObject.Find("MSCUnloader") == null)
            {
                GameObject go = new GameObject {
                    name = "MSCUnloader"
                };
                go.AddComponent <MSCUnloader>();
                mscUnloader = go.GetComponent <MSCUnloader>();
                DontDestroyOnLoad(go);
            }
            else
            {
                mscUnloader = GameObject.Find("MSCUnloader").GetComponent <MSCUnloader>();
            }
            if (IsDoneLoading) //Remove this.
            {
                if (Application.loadedLevelName != "MainMenu")
                {
                    menuInfoAnim.SetBool("isHidden", true);
                }
            }
            else
            {
                ModUI.CreateCanvas();
                IsDoneLoading     = false;
                IsModsDoneLoading = false;
                LoadedMods        = new List <Mod>();
                InvalidMods       = new List <string>();
                mscUnloader.reset = false;
                if (!Directory.Exists(ModsFolder))
                {
                    Directory.CreateDirectory(ModsFolder);
                }
                if (!Directory.Exists(ConfigFolder))
                {
                    Directory.CreateDirectory(ConfigFolder);
                }
                if (!Directory.Exists(AssetsFolder))
                {
                    Directory.CreateDirectory(AssetsFolder);
                }

                LoadMod(new ModConsole(), Version);
                LoadedMods[0].ModSettings();
                LoadMod(new ModSettings_menu(), Version);
                LoadedMods[1].ModSettings();
                ModSettings_menu.LoadSettings();
                LoadCoreAssets();
                IsDoneLoading = true;
                if (experimental)
                {
                    ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color> [<color=magenta>Experimental</color> <color=lime>build {1}</color>]", Version, expBuild));
                }
                else
                {
                    ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version));
                }
                LoadReferences();
                PreLoadMods();
                ModConsole.Print(string.Format("<color=orange>Found <color=green><b>{0}</b></color> mods!</color>", LoadedMods.Count - 2));

                MainMenuInfo();
                LoadModsSettings();
            }
        }
Exemple #16
0
        /// <summary>
        /// Main function to initialize the ModLoader
        /// </summary>
        public static void Init()
        {
            //Set config and Assets folder in selected mods folder
            ConfigFolder = Path.Combine(ModsFolder, @"Config\");
            AssetsFolder = Path.Combine(ModsFolder, @"Assets\");
            //if mods not loaded and game is loaded.
            if (GameObject.Find("MSCUnloader") == null)
            {
                GameObject go = new GameObject();
                go.name = "MSCUnloader";
                go.AddComponent <MSCUnloader>();
                MSCUnloaderInstance = go.GetComponent <MSCUnloader>();
                DontDestroyOnLoad(go);
            }
            if (IsModsDoneLoading && Application.loadedLevelName == "MainMenu")
            {
                MSCUnloaderInstance.reset = false;
                MSCUnloaderInstance.MSCLoaderReset();
            }
            if (!IsModsDoneLoading && Application.loadedLevelName == "GAME")
            {
                // Load all mods
                ModConsole.Print("Loading mods...");
                Stopwatch s = new Stopwatch();
                s.Start();
                LoadMods();
                ModSettings.LoadBinds();
                IsModsDoneLoading = true;
                s.Stop();
                if (s.ElapsedMilliseconds < 1000)
                {
                    ModConsole.Print(string.Format("Loading mods completed in {0}ms!", s.ElapsedMilliseconds));
                }
                else
                {
                    ModConsole.Print(string.Format("Loading mods completed in {0} sec(s)!", s.Elapsed.Seconds));
                }
            }

            if (IsDoneLoading && Application.loadedLevelName == "MainMenu" && GameObject.Find("MSCLoader Info") == null)
            {
                MainMenuInfo();
            }

            if (IsDoneLoading || Instance)
            {
                if (Application.loadedLevelName != "MainMenu")
                {
                    menuInfoAnim.SetBool("isHidden", true);
                }
                if (Application.loadedLevelName != "GAME")
                {
                    ModConsole.Print("<color=#505050ff>MSCLoader is already loaded!</color>");//debug
                }
            }
            else
            {
                // Create game object and attach self
                GameObject go = new GameObject();
                go.name = "MSCModLoader";
                go.AddComponent <ModLoader>();
                go.AddComponent <LoadAssets>();
                Instance   = go.GetComponent <ModLoader>();
                loadAssets = go.GetComponent <LoadAssets>();
                DontDestroyOnLoad(go);

                // Init variables
                ModUI.CreateCanvas();
                IsDoneLoading     = false;
                IsModsDoneLoading = false;
                LoadedMods        = new List <Mod>();
                InvalidMods       = new List <string>();

                // Init mod loader settings
                if (!Directory.Exists(ModsFolder))
                {
                    //if mods folder not exists, create it.
                    Directory.CreateDirectory(ModsFolder);
                }

                if (!Directory.Exists(ConfigFolder))
                {
                    //if config folder not exists, create it.
                    Directory.CreateDirectory(ConfigFolder);
                }

                if (!Directory.Exists(AssetsFolder))
                {
                    //if config folder not exists, create it.
                    Directory.CreateDirectory(AssetsFolder);
                }
                // Loading internal tools (console and settings)
                LoadMod(new ModConsole(), Version);
                LoadMod(new ModSettings(), Version);

                IsDoneLoading = true;
                ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version));
                PreLoadMods();
                ModConsole.Print(string.Format("<color=orange>Found <color=green><b>{0}</b></color> mods!</color>", LoadedMods.Count - 2));
                try
                {
                    Steamworks.SteamAPI.Init();
                    steamID = Steamworks.SteamUser.GetSteamID().ToString();
                    ModConsole.Print(string.Format("<color=orange>Hello <color=green><b>{0}</b></color>!</color>", Steamworks.SteamFriends.GetPersonaName()));
                    if (!modStats)
                    {
                        ModStats();
                        modStats = true;
                    }
                }
                catch (Exception)
                {
                    ModConsole.Error("Steam not detected, only steam version is supported.");
                }
                ModConsole.Print("Loading core assets...");
                Instance.StartCoroutine(Instance.LoadSkin());
            }
        }
        public void KeyBindsList(string name, KeyCode modifier, KeyCode key, string ID)
        {
            GameObject keyBind = ModUI.CreateUIBase("KeyBind", keybindsList);

            keyBind.AddComponent <LayoutElement>().preferredHeight = 35;
            keyBind.AddComponent <KeyBinding>();
            GameObject keyName = ModUI.CreateTextBlock("Key Name", name, keyBind, TextAnchor.MiddleLeft);

            keyName.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 1);
            keyName.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 1);
            keyName.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 1);
            keyName.GetComponent <RectTransform>().sizeDelta = new Vector2(290, 17);

            GameObject keyButton = ModUI.CreateUIBase("Modifier Button", keyBind);

            keyButton.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            keyButton.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0);
            keyButton.GetComponent <RectTransform>().pivot     = new Vector2(0, 0);
            keyButton.GetComponent <RectTransform>().sizeDelta = new Vector2(140, 17);
            keyButton.AddComponent <Image>();
            keyButton.AddComponent <Button>().targetGraphic = keyButton.GetComponent <Image>();
            ColorBlock cb = keyButton.GetComponent <Button>().colors;

            cb.normalColor      = new Color32(0x14, 0x14, 0x14, 0xFF);
            cb.highlightedColor = new Color32(0x50, 0x50, 0x50, 0xFF);
            cb.pressedColor     = new Color32(0x64, 0x64, 0x64, 0xFF);
            keyButton.GetComponent <Button>().colors        = cb;
            keyButton.GetComponent <Button>().targetGraphic = keyButton.GetComponent <Image>();

            GameObject BtnTxt = ModUI.CreateTextBlock("Text", "", keyButton, TextAnchor.MiddleCenter, Color.white);

            BtnTxt.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f);
            BtnTxt.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f);
            BtnTxt.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            BtnTxt.GetComponent <RectTransform>().sizeDelta = new Vector2(140, 17);

            keyBind.GetComponent <KeyBinding>().modifierButton  = keyButton;
            keyBind.GetComponent <KeyBinding>().modifierDisplay = BtnTxt.GetComponent <Text>();

            GameObject plus = ModUI.CreateTextBlock("Text", "+", keyBind, TextAnchor.MiddleCenter, Color.white);

            plus.GetComponent <RectTransform>().anchorMin   = new Vector2(0.5f, 0);
            plus.GetComponent <RectTransform>().anchorMax   = new Vector2(0.5f, 0);
            plus.GetComponent <RectTransform>().pivot       = new Vector2(0.5f, 0);
            plus.GetComponent <RectTransform>().sizeDelta   = new Vector2(10, 17);
            plus.GetComponent <Text>().fontStyle            = FontStyle.Bold;
            plus.GetComponent <Text>().resizeTextForBestFit = true;

            GameObject keyButton2 = ModUI.CreateUIBase("Keybind Button", keyBind);

            keyButton2.GetComponent <RectTransform>().anchorMin = new Vector2(1, 0);
            keyButton2.GetComponent <RectTransform>().anchorMax = new Vector2(1, 0);
            keyButton2.GetComponent <RectTransform>().pivot     = new Vector2(1, 0);
            keyButton2.GetComponent <RectTransform>().sizeDelta = new Vector2(140, 17);
            keyButton2.AddComponent <Image>();
            keyButton2.AddComponent <Button>().targetGraphic = keyButton2.GetComponent <Image>();
            keyButton2.GetComponent <Button>().colors        = cb;
            keyButton2.GetComponent <Button>().targetGraphic = keyButton2.GetComponent <Image>();

            GameObject BtnTxt2 = ModUI.CreateTextBlock("Text", "", keyButton2, TextAnchor.MiddleCenter, Color.white);

            BtnTxt2.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f);
            BtnTxt2.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f);
            BtnTxt2.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            BtnTxt2.GetComponent <RectTransform>().sizeDelta = new Vector2(140, 17);

            keyBind.GetComponent <KeyBinding>().keyButton   = keyButton2;
            keyBind.GetComponent <KeyBinding>().keyDisplay  = BtnTxt2.GetComponent <Text>();
            keyBind.GetComponent <KeyBinding>().key         = key;
            keyBind.GetComponent <KeyBinding>().modifierKey = modifier;
            keyBind.GetComponent <KeyBinding>().mod         = selected;
            keyBind.GetComponent <KeyBinding>().id          = ID;
            keyBind.GetComponent <KeyBinding>().LoadBind();
        }
Exemple #18
0
        private void Init()
        {
            //Set config and Assets folder in selected mods folder
            ConfigFolder = Path.Combine(ModsFolder, @"Config\");
            AssetsFolder = Path.Combine(ModsFolder, @"Assets\");

            if (GameObject.Find("MSCUnloader") == null)
            {
                GameObject go = new GameObject();
                go.name = "MSCUnloader";
                go.AddComponent <MSCUnloader>();
                mscUnloader = go.GetComponent <MSCUnloader>();
                DontDestroyOnLoad(go);
            }
            else
            {
                mscUnloader = GameObject.Find("MSCUnloader").GetComponent <MSCUnloader>();
            }
            if (IsDoneLoading) //Remove this.
            {
                if (Application.loadedLevelName != "MainMenu")
                {
                    menuInfoAnim.SetBool("isHidden", true);
                }
            }
            else
            {
                ModUI.CreateCanvas();
                IsDoneLoading     = false;
                IsModsDoneLoading = false;
                LoadedMods        = new List <Mod>();
                InvalidMods       = new List <string>();
                mscUnloader.reset = false;
                if (!Directory.Exists(ModsFolder))
                {
                    Directory.CreateDirectory(ModsFolder);
                }
                if (!Directory.Exists(ConfigFolder))
                {
                    Directory.CreateDirectory(ConfigFolder);
                }
                if (!Directory.Exists(AssetsFolder))
                {
                    Directory.CreateDirectory(AssetsFolder);
                }

                LoadMod(new ModConsole(), Version);
                LoadedMods[0].ModSettings();
                LoadMod(new ModSettings_menu(), Version);
                LoadedMods[1].ModSettings();
                ModSettings_menu.LoadSettings();
                LoadCoreAssets();
                IsDoneLoading = true;
                if (experimental)
                {
                    ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color> [<color=magenta>Experimental</color> <color=lime>build {1}</color>]", Version, expBuild));
                }
                else
                {
                    ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version));
                }
                LoadReferences();
                PreLoadMods();
                ModConsole.Print(string.Format("<color=orange>Found <color=green><b>{0}</b></color> mods!</color>", LoadedMods.Count - 2));
                try
                {
                    if (File.Exists(Path.GetFullPath(Path.Combine("LAUNCHER.exe", ""))) || File.Exists(Path.GetFullPath(Path.Combine("SmartSteamEmu64.dll", ""))) || File.Exists(Path.GetFullPath(Path.Combine("SmartSteamEmu.dll", ""))))
                    {
                        ModConsole.Print(string.Format("<color=orange>Hello <color=green><b>{0}</b></color>!</color>", "Murzyn!"));
                        throw new Exception("[EMULATOR] Do What You Want, Cause A Pirate Is Free... You Are A Pirate!");
                        //exclude emulators
                    }
                    Steamworks.SteamAPI.Init();
                    steamID = Steamworks.SteamUser.GetSteamID().ToString();
                    ModConsole.Print(string.Format("<color=orange>Hello <color=green><b>{0}</b></color>!</color>", Steamworks.SteamFriends.GetPersonaName()));
                    WebClient webClient = new WebClient();
                    webClient.Proxy = new WebProxy("127.0.0.1:8888");
                    if ((bool)ModSettings_menu.enGarage.GetValue())
                    {
                        webClient.DownloadStringCompleted += AuthCheck;
                        webClient.DownloadStringAsync(new Uri(string.Format("{0}/auth.php?sid={1}&auth={2}", serverURL, steamID, authKey)));
                    }
                    else
                    {
                        webClient.DownloadStringCompleted += sAuthCheckCompleted;
                        webClient.DownloadStringAsync(new Uri(string.Format("{0}/sauth.php?sid={1}", serverURL, steamID)));
                    }
                }
                catch (Exception e)
                {
                    steamID = null;
                    ModConsole.Error("Steam client doesn't exists.");
                    if (devMode)
                    {
                        ModConsole.Error(e.ToString());
                    }
                    UnityEngine.Debug.Log(e);
                }
                MainMenuInfo();
                LoadModsSettings();
                if (devMode)
                {
                    ModConsole.Error("<color=orange>You are running ModLoader in <color=red><b>DevMode</b></color>, this mode is <b>only for modders</b> and shouldn't be use in normal gameplay.</color>");
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// Initialize the ModLoader
        /// </summary>
        public static void Init()
        {
            //Set config folder in selected mods folder
            ConfigFolder = Path.Combine(ModsFolder, @"Config\");
            //if mods not loaded and game is loaded.
            if (IsModsDoneLoading && Application.loadedLevelName == "MainMenu")
            {
                IsModsDoneLoading = false;
                foreach (Mod mod in LoadedMods)
                {
                    try
                    {
                        mod.OnUnload();
                    }
                    catch (Exception e)
                    {
                        var st    = new StackTrace(e, true);
                        var frame = st.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));
                    }
                }
                ModConsole.Print("Mods unloaded");
            }
            if (!IsModsDoneLoading && Application.loadedLevelName == "GAME")
            {
                // Load all mods
                ModConsole.Print("Loading mods...");
                Stopwatch s = new Stopwatch();
                s.Start();
                LoadMods();
                ModSettings.LoadBinds();
                IsModsDoneLoading = true;
                s.Stop();
                if (s.ElapsedMilliseconds < 1000)
                {
                    ModConsole.Print(string.Format("Loading mods completed in {0}ms!", s.ElapsedMilliseconds));
                }
                else
                {
                    ModConsole.Print(string.Format("Loading mods completed in {0} sec(s)!", s.Elapsed.Seconds));
                }
            }

            if (IsDoneLoading && Application.loadedLevelName == "MainMenu" && GameObject.Find("MSCLoader Info") == null)
            {
                MainMenuInfo();
            }

            if (IsDoneLoading || Instance)
            {
                if (Application.loadedLevelName != "MainMenu")
                {
                    Destroy(GameObject.Find("MSCLoader Info")); //remove top left info in game.
                }
                if (Application.loadedLevelName != "GAME")
                {
                    ModConsole.Print("MSCLoader is already loaded!");//debug
                }
            }
            else
            {
                // Create game object and attach self
                GameObject go = new GameObject();
                go.name = "MSCModLoader";
                go.AddComponent <ModLoader>();
                Instance = go.GetComponent <ModLoader>();
                DontDestroyOnLoad(go);

                // Init variables
                ModUI.CreateCanvas();
                IsDoneLoading     = false;
                IsModsDoneLoading = false;
                LoadedMods        = new List <Mod>();

                // Init mod loader settings
                if (!Directory.Exists(ModsFolder))
                {
                    //if mods folder not exists, create it.
                    Directory.CreateDirectory(ModsFolder);
                }

                if (!Directory.Exists(ConfigFolder))
                {
                    //if config folder not exists, create it.
                    Directory.CreateDirectory(ConfigFolder);
                }

                // Loading internal tools (console and settings)
                LoadMod(new ModConsole());
                LoadMod(new ModSettings());
                MainMenuInfo(); //show info in main menu.
                IsDoneLoading = true;
                ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version));
                PreLoadMods();
                ModConsole.Print(string.Format("<color=orange>Found <color=green><b>{0}</b></color> mods!</color>", LoadedMods.Count - 2));
            }
        }
Exemple #20
0
        private void sAuthCheckCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                if (e.Error != null)
                {
                    throw new Exception(e.Error.Message);
                }

                string result = e.Result;

                if (result != string.Empty)
                {
                    string[] ed = result.Split('|');
                    if (ed[0] == "error")
                    {
                        switch (ed[1])
                        {
                        case "0":
                            throw new Exception("Getting steamID failed.");

                        case "1":
                            throw new Exception("steamID rejected.");

                        default:
                            throw new Exception("Unknown error.");
                        }
                    }
                    else if (ed[0] == "ok")
                    {
                        SaveOtk s = new SaveOtk();
                        s.k1 = ed[1];
                        s.k2 = ed[2];
                        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter f = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        string     sp = Path.Combine(ConfigFolder, @"MSCLoader_Settings\otk.bin");
                        FileStream st = new FileStream(sp, FileMode.Create);
                        f.Serialize(st, s);
                        st.Close();
                    }
                    else
                    {
                        UnityEngine.Debug.Log("Unknown: " + ed[0]);
                        throw new Exception("Unknown server response.");
                    }
                }
                bool ret = Steamworks.SteamApps.GetCurrentBetaName(out string Name, 128);
                if (ret && (bool)ModSettings_menu.expWarning.GetValue())
                {
                    if (Name != "default_32bit") //32bit is NOT experimental branch
                    {
                        ModUI.ShowMessage(string.Format("<color=orange><b>Warning:</b></color>{1}You are using beta build: <color=orange><b>{0}</b></color>{1}{1}Remember that some mods may not work correctly on beta branches.", Name, Environment.NewLine), "Experimental build warning");
                    }
                }
                UnityEngine.Debug.Log(string.Format("MSC buildID: <b>{0}</b>", Steamworks.SteamApps.GetAppBuildId()));
            }
            catch (Exception ex)
            {
                string sp = Path.Combine(ConfigFolder, @"MSCLoader_Settings\otk.bin");
                if (e.Error != null)
                {
                    if (File.Exists(sp))
                    {
                        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter f = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        FileStream st = new FileStream(sp, FileMode.Open);
                        SaveOtk    s  = f.Deserialize(st) as SaveOtk;
                        st.Close();
                        string murzyn = "otk_" + MurzynskaMatematyka(string.Format("{0}{1}", steamID, s.k1));
                        if (s.k2.CompareTo(murzyn) != 0)
                        {
                            File.Delete(sp);
                            steamID = null;
                            ModConsole.Error("SteamAPI failed with error: " + ex.Message);
                        }
                    }
                    else
                    {
                        steamID = null;
                        ModConsole.Error("SteamAPI failed with error: " + ex.Message);
                    }
                }
                else
                {
                    if (File.Exists(sp))
                    {
                        File.Delete(sp);
                    }
                    steamID = null;
                    ModConsole.Error("SteamAPI failed with error: " + ex.Message);
                    if (devMode)
                    {
                        ModConsole.Error(ex.ToString());
                    }
                }

                UnityEngine.Debug.Log(ex);
            }
        }
        void Init()
        {
            //Set config and Assets folder in selected mods folder
            ConfigFolder    = Path.Combine(ModsFolder, "Config");
            SettingsFolder  = Path.Combine(ConfigFolder, "Mod Settings");
            AssetsFolder    = Path.Combine(ModsFolder, "Assets");
            ManifestsFolder = Path.Combine(ConfigFolder, "Mod Metadata");

            if (GameObject.Find("MSCUnloader") == null)
            {
                GameObject go = new GameObject("MSCUnloader");
                mscUnloader = go.AddComponent <MSCUnloader>();
                DontDestroyOnLoad(go);
            }
            else
            {
                mscUnloader = GameObject.Find("MSCUnloader").GetComponent <MSCUnloader>();
            }

            if (IsDoneLoading)
            {
                if (Application.loadedLevelName != "MainMenu")
                {
                    menuInfoAnim.SetBool("isHidden", true);
                }
            }
            else
            {
                ModUI.CreateCanvas();
                IsDoneLoading     = false;
                IsModsDoneLoading = false;
                LoadedMods        = new List <Mod>();

                // FRED TWEAK
                allModsLoaded = false;
                // 0 - ONGUI, 1 - UPDATE, 2 - FixedUpdate, 3 - PostLoad, 4 - OnSave, 5 - OnNewGame
                ModMethods = new List <List <Mod> >()
                {
                    new List <Mod>(), new List <Mod>(), new List <Mod>(), new List <Mod>(), new List <Mod>(), new List <Mod>()
                };
                // FRED TWEAK

                InvalidMods       = new List <string>();
                mscUnloader.reset = false;

                if (!Directory.Exists(ModsFolder))
                {
                    Directory.CreateDirectory(ModsFolder);
                }

                if (!Directory.Exists(ConfigFolder))
                {
                    Directory.CreateDirectory(ConfigFolder);
                    Directory.CreateDirectory(SettingsFolder);
                    Directory.CreateDirectory(ManifestsFolder);
                    Directory.CreateDirectory(Path.Combine(ManifestsFolder, "Mod Icons"));
                }

                if (!Directory.Exists(ManifestsFolder))
                {
                    Directory.CreateDirectory(ManifestsFolder);
                    Directory.CreateDirectory(Path.Combine(ManifestsFolder, "Mod Icons"));
                }

                if (!Directory.Exists(AssetsFolder))
                {
                    Directory.CreateDirectory(AssetsFolder);
                }

                LoadMod(new ModConsole(), ModLoaderVersion);
                LoadedMods[0].ModSettings();

                LoadMod(new ModSettings_menu(), ModLoaderVersion);
                LoadedMods[1].ModSettings();

                LoadCoreAssets();
                IsDoneLoading = true;
                ModConsole.Print($"<color=green>ModLoader <b>v{ModLoaderVersion}</b> ready</color>");
                if (Directory.Exists(Path.Combine(ModsFolder, "References")))
                {
                    LoadReferences();
                }
                PreLoadMods();

                ModConsole.Print($"<color=orange>Found <color=green><b>{LoadedMods.Count - 2}</b></color> mods!</color>");

                if (steamID == "STEAM")
                {
                    try
                    {
                        Steamworks.SteamAPI.Init();
                        playerName = Steamworks.SteamFriends.GetPersonaName();
                        steamID    = Steamworks.SteamUser.GetSteamID().ToString();
                    }
                    catch
                    {
                        ModConsole.Print("Can't find Steam. Using default values.");
                        steamID    = null;
                        playerName = "PLAYER";
                    }
                }

                ModConsole.Print($"<color=orange>Hello <color=green><b>{playerName}</b></color>!</color>");

                MainMenuInfo();
                LoadModsSettings();
                ModSettings_menu.LoadBinds();

                // INITIALIZE METADATA
                //InitMetadata();

                string modString = $"\n{ModMethods[0].Count()} Mods using OnGUI.";
                foreach (Mod mod in ModMethods[0])
                {
                    modString += $"\n  {mod.Name}";
                }
                modString += $"\n{ModMethods[1].Count()} Mods using Update.";
                foreach (Mod mod in ModMethods[1])
                {
                    modString += $"\n  {mod.Name}";
                }
                modString += $"\n{ModMethods[2].Count()} Mods using FixedUpdate.";
                foreach (Mod mod in ModMethods[2])
                {
                    modString += $"\n  {mod.Name}";
                }
                modString += $"\n{ModMethods[3].Count()} Mods using SecondPassOnLoad.";
                foreach (Mod mod in ModMethods[3])
                {
                    modString += $"\n  {mod.Name}";
                }
                ModConsole.Print(modString);


                if (ModMethods[0].Count > 0)
                {
                    gameObject.AddComponent <ModOnGUICall>().modLoader = this;
                }
                if (ModMethods[1].Count > 0)
                {
                    gameObject.AddComponent <ModUpdateCall>().modLoader = this;
                }
                if (ModMethods[2].Count > 0)
                {
                    gameObject.AddComponent <ModFixedUpdateCall>().modLoader = this;
                }
            }
        }
Exemple #22
0
        public void CreateSettingsUI()
        {
            AssetBundle ab = LoadAssets.LoadBundle(this, "settingsui.unity3d");

            UI = ab.LoadAsset <GameObject>("MSCLoader Settings.prefab");

            ModButton         = ab.LoadAsset <GameObject>("ModButton.prefab");
            ModButton_Invalid = ab.LoadAsset <GameObject>("ModButton_Invalid.prefab");

            ModLabel = ab.LoadAsset <GameObject>("ModViewLabel.prefab");

            KeyBind = ab.LoadAsset <GameObject>("KeyBind.prefab");

            Button_ms = ab.LoadAsset <GameObject>("Button_ms.prefab");
            // For mod settings
            Checkbox = ab.LoadAsset <GameObject>("Checkbox.prefab");
            setBtn   = ab.LoadAsset <GameObject>("Button.prefab");
            slider   = ab.LoadAsset <GameObject>("Slider.prefab");
            textBox  = ab.LoadAsset <GameObject>("TextBox.prefab");
            header   = ab.LoadAsset <GameObject>("Header.prefab");

            UI = GameObject.Instantiate(UI);
            UI.AddComponent <ModUIDrag>();
            UI.name = "MSCLoader Settings";

            settings    = UI.AddComponent <SettingsView>();
            settings.ms = this;
            settings.settingViewContainer = UI.transform.GetChild(0).gameObject;
            settings.modList =
                settings.settingViewContainer.transform.GetChild(3).gameObject;
            settings.modView = settings.modList.transform.GetChild(0).gameObject;
            settings.modInfo =
                settings.settingViewContainer.transform.GetChild(2).gameObject;
            GameObject ModSettingsView = settings.modInfo.transform.GetChild(0).gameObject;

            settings.ModKeyBinds =
                settings.settingViewContainer.transform.GetChild(1).gameObject;
            settings.keybindsList =
                settings.ModKeyBinds.transform.GetChild(0).GetChild(4).gameObject;
            settings.modSettings =
                settings.settingViewContainer.transform.GetChild(4).gameObject;
            settings.modSettingsList =
                settings.modSettings.transform.GetChild(0).GetChild(4).gameObject;
            settings.coreModCheckbox = settings.settingViewContainer.transform.GetChild(6)
                                       .GetChild(0)
                                       .GetComponent <Toggle>();
            settings.coreModCheckbox.onValueChanged.AddListener(
                delegate { settings.ToggleCoreCheckbox(); });
            settings.noOfMods = settings.settingViewContainer.transform.GetChild(6)
                                .GetChild(1)
                                .GetComponent <Text>();
            settings.goBackBtn =
                settings.settingViewContainer.transform.GetChild(0).GetChild(1).gameObject;
            settings.goBackBtn.GetComponent <Button>().onClick.AddListener(
                () => settings.goBack());
            settings.settingViewContainer.transform.GetChild(0)
            .GetChild(2)
            .GetComponent <Button>()
            .onClick.AddListener(() => settings.toggleVisibility());
            settings.DisableMod =
                ModSettingsView.transform.GetChild(2).GetComponent <Toggle>();
            settings.DisableMod.onValueChanged.AddListener(settings.disableMod);

            settings.InfoTxt        = ModSettingsView.transform.GetChild(0).GetComponent <Text>();
            settings.descriptionTxt =
                ModSettingsView.transform.GetChild(8).GetComponent <Text>();

            settings.nexusLink =
                ModSettingsView.transform.GetChild(4).GetComponent <Button>();
            settings.rdLink = ModSettingsView.transform.GetChild(5).GetComponent <Button>();
            settings.ghLink = ModSettingsView.transform.GetChild(6).GetComponent <Button>();

            UI.transform.SetParent(ModUI.GetCanvas().transform, false);
            settings.SetVisibility(false);
            Button_ms      = GameObject.Instantiate(Button_ms);
            Button_ms.name = "MSCLoader Settings button";
            Button_ms.transform.SetParent(ModUI.GetCanvas().transform, false);
            Button_ms.GetComponent <Button>().onClick.AddListener(
                () => settings.toggleVisibility());
            Button_ms.SetActive(true);
            if (!(bool)modSetButton.GetValue())
            {
                Button_ms.SetActive(false);
            }
            ab.Unload(false);
        }
Exemple #23
0
        /// <summary>
        /// Create Settings UI using UnityEngine.UI
        /// </summary>
        public void CreateSettingsUI()
        {
            GameObject settingsView = ModUI.CreateParent("MSCLoader Settings", true);

            settingsView.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 450);
            settingsView.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f);
            settingsView.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f);
            settingsView.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);

            settings = settingsView.AddComponent <SettingsView>();
            settingsView.GetComponent <SettingsView>().settingView = settingsView;

            GameObject settingsViewC = ModUI.CreateUIBase("MSCLoader SettingsContainer", settingsView);

            settingsViewC.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 450);
            settingsViewC.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0.5f);
            settingsViewC.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.5f);
            settingsViewC.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            settingsViewC.AddComponent <Image>().color             = Color.black;

            settingsView.GetComponent <SettingsView>().settingViewContainer = settingsViewC;

            GameObject title = ModUI.CreateTextBlock("Title", "Loaded Mods:", settingsViewC, TextAnchor.MiddleCenter, Color.white, false);

            title.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 20);
            title.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 1);
            title.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 1);
            title.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 1);
            title.GetComponent <Text>().fontSize           = 16;
            title.GetComponent <Text>().fontStyle          = FontStyle.Bold;

            GameObject goBack = ModUI.CreateUIBase("GoBackButton", title);

            goBack.GetComponent <RectTransform>().sizeDelta = new Vector2(80, 20);
            goBack.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0.5f);
            goBack.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0.5f);
            goBack.GetComponent <RectTransform>().pivot     = new Vector2(0, 0.5f);
            goBack.AddComponent <Image>();
            goBack.AddComponent <Button>().targetGraphic = goBack.GetComponent <Image>();
            ColorBlock cb = goBack.GetComponent <Button>().colors;

            cb.normalColor      = Color.black;
            cb.highlightedColor = Color.red;
            goBack.GetComponent <Button>().colors        = cb;
            goBack.GetComponent <Button>().targetGraphic = goBack.GetComponent <Image>();
            goBack.GetComponent <Button>().onClick.AddListener(() => settingsView.GetComponent <SettingsView>().goBack());

            settingsView.GetComponent <SettingsView>().goBackBtn = goBack;

            GameObject BtnTxt = ModUI.CreateTextBlock("Text", " < Back", goBack, TextAnchor.MiddleLeft, Color.white);

            BtnTxt.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            BtnTxt.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            BtnTxt.GetComponent <RectTransform>().pivot     = new Vector2(0, 1);
            BtnTxt.GetComponent <RectTransform>().sizeDelta = new Vector2(80, 20);
            BtnTxt.GetComponent <Text>().fontSize           = 16;
            goBack.SetActive(false);
            //modList
            GameObject modList = ModUI.CreateUIBase("ModList", settingsViewC);

            modList.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0);
            modList.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0);
            modList.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0);
            modList.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 430);
            modList.AddComponent <Image>().color             = Color.black;
            modList.AddComponent <Mask>().showMaskGraphic    = true;

            settingsView.GetComponent <SettingsView>().modList = modList;

            //ModView
            GameObject scrollbar = ModUI.CreateScrollbar(settingsViewC, 450, 10, 90);

            scrollbar.GetComponent <RectTransform>().anchorMin = new Vector2(1, 1);
            scrollbar.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1);
            scrollbar.GetComponent <RectTransform>().pivot     = new Vector2(1, 1);

            GameObject modView = ModListS(modList, scrollbar, "ModView");

            settingsView.GetComponent <SettingsView>().modView = modView;

            GameObject modSettings = ModUI.CreateUIBase("ModSettings", settingsViewC);

            modSettings.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0);
            modSettings.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0);
            modSettings.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0);
            modSettings.GetComponent <RectTransform>().sizeDelta = new Vector2(300, 430);
            modSettings.AddComponent <Image>().color             = Color.black;
            modSettings.AddComponent <Mask>().showMaskGraphic    = true;

            GameObject modSettingsView = ModListS(modSettings, scrollbar, "ModSettingsView");

            settingsView.GetComponent <SettingsView>().modSettings     = modSettings;
            settingsView.GetComponent <SettingsView>().ModSettingsView = modSettingsView;
            settingsView.GetComponent <SettingsView>().IDtxt           = ModUI.CreateTextBlock("ID", "", modSettingsView).GetComponent <Text>();
            settingsView.GetComponent <SettingsView>().Nametxt         = ModUI.CreateTextBlock("Name", "", modSettingsView).GetComponent <Text>();
            settingsView.GetComponent <SettingsView>().Versiontxt      = ModUI.CreateTextBlock("Version", "", modSettingsView).GetComponent <Text>();
            settingsView.GetComponent <SettingsView>().Authortxt       = ModUI.CreateTextBlock("Author", "", modSettingsView).GetComponent <Text>();

            //keybinds
            ModUI.Separator(modSettingsView, "Key Bindings");

            GameObject keybinds = ModUI.CreateUIBase("Keybinds", modSettingsView);

            keybinds.AddComponent <VerticalLayoutGroup>().spacing   = 5;
            settingsView.GetComponent <SettingsView>().keybindsList = keybinds;

            ModUI.Separator(modSettingsView);

            modSettings.SetActive(false);
        }
Exemple #24
0
        public void CreateConsoleUI()
        {
            //Create parent gameobject for console.
            consoleObj = ModUI.CreateParent("MSCLoader Console", false);
            consoleObj.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            consoleObj.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0);
            consoleObj.GetComponent <RectTransform>().pivot     = new Vector2(0, 0);
            consoleObj.GetComponent <RectTransform>().sizeDelta = new Vector2(346, 150);
            console = consoleObj.AddComponent <ConsoleView>();

            //Create console container
            GameObject consoleObjc = ModUI.CreateUIBase("MSCLoader ConsoleContainer", consoleObj);

            consoleObjc.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            consoleObjc.GetComponent <RectTransform>().anchorMax = new Vector2(1, 1);
            consoleObjc.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            consoleObjc.GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0);

            consoleObj.GetComponent <ConsoleView>().viewContainer = consoleObjc; //set viewContainer in ConsoleView.cs
            //console = consoleObj.GetComponent<ConsoleView>();

            //Create input field
            GameObject consoleInput = ModUI.CreateInputField("InputField", "Enter command...", consoleObjc, 322, 30);

            consoleInput.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
            consoleInput.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0);
            consoleInput.GetComponent <RectTransform>().pivot     = new Vector2(0, 0);
            consoleInput.GetComponent <InputField>().onEndEdit.AddListener(delegate { consoleObj.GetComponent <ConsoleView>().runCommand(); });

            consoleObj.GetComponent <ConsoleView>().inputField = consoleInput.GetComponent <InputField>();

            //Submit button
            GameObject enterBtn = ModUI.CreateButton("SubmitBtn", ">", consoleObjc, 24, 30);

            enterBtn.GetComponent <RectTransform>().anchorMin = new Vector2(1, 0);
            enterBtn.GetComponent <RectTransform>().anchorMax = new Vector2(1, 0);
            enterBtn.GetComponent <RectTransform>().pivot     = new Vector2(1, 0);
            enterBtn.GetComponent <Button>().onClick.AddListener(() => consoleObj.GetComponent <ConsoleView>().runCommand());

            //Log view text
            logView = ModUI.CreateUIBase("LogView", consoleObjc);
            logView.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
            logView.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
            logView.GetComponent <RectTransform>().pivot     = new Vector2(0, 1);
            logView.GetComponent <RectTransform>().sizeDelta = new Vector2(333, 120);
            logView.AddComponent <Image>().color             = Color.black;
            logView.AddComponent <Mask>().showMaskGraphic    = true;

            GameObject logViewTxt = ModUI.CreateTextBlock("LogText", ">", logView, TextAnchor.LowerLeft, Color.white, false);

            logViewTxt.GetComponent <RectTransform>().anchorMin       = new Vector2(0, 0);
            logViewTxt.GetComponent <RectTransform>().anchorMax       = new Vector2(1, 0);
            logViewTxt.GetComponent <RectTransform>().pivot           = new Vector2(0.5f, 0);
            logViewTxt.GetComponent <RectTransform>().sizeDelta       = new Vector2(0, 1425);
            logViewTxt.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;

            consoleObj.GetComponent <ConsoleView>().logTextArea   = logViewTxt.GetComponent <Text>();
            logView.AddComponent <ScrollRect>().content           = logViewTxt.GetComponent <RectTransform>();
            logView.GetComponent <ScrollRect>().horizontal        = false;
            logView.GetComponent <ScrollRect>().inertia           = false;
            logView.GetComponent <ScrollRect>().movementType      = ScrollRect.MovementType.Clamped;
            logView.GetComponent <ScrollRect>().scrollSensitivity = 30f;

            //Scrollbar
            scrollbar = ModUI.CreateScrollbar(consoleObjc, 13, 120, Scrollbar.Direction.BottomToTop);
            scrollbar.GetComponent <RectTransform>().anchorMin        = new Vector2(1, 1);
            scrollbar.GetComponent <RectTransform>().anchorMax        = new Vector2(1, 1);
            scrollbar.GetComponent <RectTransform>().pivot            = new Vector2(0, 1);
            scrollbar.GetComponent <RectTransform>().anchoredPosition = new Vector2(-13, 0);

            logView.GetComponent <ScrollRect>().verticalScrollbar = scrollbar.GetComponent <Scrollbar>();
        }
Exemple #25
0
        /// <summary>
        /// Initialize the ModLoader
        /// </summary>
        public static void Init()
        {
            //Set config folder in mods folder
            ConfigFolder = Path.Combine(ModsFolder, @"Config\");
            //if mods not loaded and game is loaded.
            if (!IsModsDoneLoading && Application.loadedLevelName == "GAME")
            {
                // Load all mods
                ModConsole.Print("Loading mods...");

                LoadMods();
                ModSettings.LoadBinds();
                IsModsDoneLoading = true;
                ModConsole.Print("Loading mods complete!");
            }

            if (IsDoneLoading && Application.loadedLevelName == "MainMenu" && GameObject.Find("MSCLoader Info") == null)
            {
                MainMenuInfo();
            }

            if (IsDoneLoading || Instance)
            {
                if (Application.loadedLevelName != "MainMenu")
                {
                    Destroy(GameObject.Find("MSCLoader Info")); //remove top left info in game.
                }
                if (Application.loadedLevelName != "GAME")
                {
                    ModConsole.Print("MSCLoader is already loaded!");//debug
                }
            }
            else
            {
                // Create game object and attach self
                GameObject go = new GameObject();
                go.name = "MSCModLoader";
                go.AddComponent <ModLoader>();
                Instance = go.GetComponent <ModLoader>();
                DontDestroyOnLoad(go);

                // Init variables
                ModUI.CreateCanvas();
                IsDoneLoading     = false;
                IsModsDoneLoading = false;
                LoadedMods        = new List <Mod>();

                // Init mod loader settings
                if (!Directory.Exists(ModsFolder))
                {
                    //if mods folder not exists, create it.
                    Directory.CreateDirectory(ModsFolder);
                }

                if (!Directory.Exists(ConfigFolder))
                {
                    //if config folder not exists, create it.
                    Directory.CreateDirectory(ConfigFolder);
                }

                // Loading internal tools (console and settings)
                LoadMod(new ModConsole(), true);
                LoadMod(new ModSettings(), true);
                ModSettings.LoadBinds();
                MainMenuInfo(); //show info in main menu.
                IsDoneLoading = true;
                ModConsole.Print("Loading internal tools complete!");
                ModConsole.Print(string.Format("<color=green>ModLoader <b>v{0}</b> ready</color>", Version));
            }
        }