private static void LoadMod(Mod mod, string msver) { // Check if mod already exists if (!LoadedMods.Contains(mod)) { // Create config folder if (!Directory.Exists(ConfigFolder + mod.ID)) { Directory.CreateDirectory(ConfigFolder + mod.ID); } if (mod.UseAssetsFolder) { if (!Directory.Exists(AssetsFolder + mod.ID)) { Directory.CreateDirectory(AssetsFolder + mod.ID); } } if (mod.LoadInMenu) { mod.OnMenuLoad(); ModSettings_menu.LoadBinds(); } mod.compiledVersion = msver; LoadedMods.Add(mod); } else { ModConsole.Print(string.Format("<color=orange><b>Mod already loaded (or duplicated ID):</b></color><color=red><b>{0}</b></color>", mod.ID)); } }
private void LoadMod(Mod mod, string msver) { // Check if mod already exists if (!LoadedMods.Contains(mod)) { // Create config folder if (!Directory.Exists(ConfigFolder + mod.ID)) { Directory.CreateDirectory(ConfigFolder + mod.ID); } if (mod.UseAssetsFolder && !Directory.Exists(AssetsFolder + mod.ID)) { Directory.CreateDirectory(AssetsFolder + mod.ID); } try { if (mod.LoadInMenu) { mod.OnMenuLoad(); ModSettings_menu.LoadBinds(); } } catch (Exception e) { 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)); ModConsole.Error(e.ToString()); UnityEngine.Debug.Log(e); } mod.compiledVersion = msver; LoadedMods.Add(mod); } else { ModConsole.Error(string.Format("<color=orange><b>Mod already loaded (or duplicated ID):</b></color><color=red><b>{0}</b></color>", mod.ID)); } }
IEnumerator LoadMods() { loading.transform.GetChild(2).GetComponent <Text>().text = string.Format("MSCLoader <color=green>v{0}</color>", Version); ModConsole.Print("Loading mods..."); Stopwatch s = new Stopwatch(); s.Start(); ModConsole.Print("<color=#505050ff>"); loading.SetActive(true); loading.transform.GetChild(3).GetComponent <Slider>().minValue = 1; loading.transform.GetChild(3).GetComponent <Slider>().maxValue = LoadedMods.Count - 2; int i = 1; foreach (Mod mod in LoadedMods) { loading.transform.GetChild(0).GetComponent <Text>().text = string.Format("Loading mods: <color=orage><b>{0}</b></color> of <color=orage><b>{1}</b></color>. Please wait...", i, LoadedMods.Count - 2); loading.transform.GetChild(3).GetComponent <Slider>().value = i; loading.transform.GetChild(3).GetChild(1).GetChild(0).GetComponent <Image>().color = new Color32(0, 113, 0, 255); if (mod.ID.StartsWith("MSCLoader_")) { continue; } i++; if (!mod.isDisabled) { loading.transform.GetChild(1).GetComponent <Text>().text = mod.Name; } yield return(new WaitForSeconds(.05f)); try { if (!mod.isDisabled) { mod.OnLoad(); FsmHook.FsmInject(GameObject.Find("ITEMS"), "Save game", mod.OnSave); } } catch (Exception e) { 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); } } loading.SetActive(false); ModConsole.Print("</color>"); allModsLoaded = true; ModSettings_menu.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)); } }
IEnumerator LoadMods() { menuInfoAnim.SetBool("isHidden", true); allModsLoaded = false; loading.SetActive(true); while (GameObject.Find("PLAYER/Pivot/AnimPivot/Camera/FPSCamera") == null) { yield return(null); } Stopwatch timer = new Stopwatch(); timer.Start(); yield return(null); ModConsole.Print("<color=#FFFF00>Loading mods...</color>"); ModConsole.console.controller.AppendLogLine("<color=#505050ff>"); if (newGameStarted && ModMethods[5].Count > 0) { foreach (Mod mod in ModMethods[5]) { try { mod.OnNewGame(); } catch (Exception e) { StackFrame frame = new StackTrace(e, true).GetFrame(0); ModConsole.Error($"<b>{mod.ID}</b>! <b>Details:</b>\n{e.Message} in <b>{frame.GetMethod()}</b>."); ModConsole.Error(e.ToString()); System.Console.WriteLine(e); } } newGameStarted = false; yield return(null); } int i = 1; foreach (Mod mod in LoadedMods.Where(mod => !mod.isDisabled && !mod.ID.StartsWith("MSCLoader_"))) { try { mod.OnLoad(); } catch (Exception e) { StackFrame frame = new StackTrace(e, true).GetFrame(0); ModConsole.Error($"<b>{mod.ID}</b>! <b>Details:</b>\n{e.Message} in <b>{frame.GetMethod()}</b>."); ModConsole.Error(e.ToString()); System.Console.WriteLine(e); } i++; } if (ModMethods[3].Count > 0) { yield return(null); foreach (Mod mod in ModMethods[3].Where(mod => !mod.isDisabled && !mod.ID.StartsWith("MSCLoader_"))) { try { mod.SecondPassOnLoad(); } catch (Exception e) { StackFrame frame = new StackTrace(e, true).GetFrame(0); ModConsole.Error($"<b>{mod.ID}</b>! <b>Details:</b>\n{e.Message} in <b>{frame.GetMethod()}</b>."); ModConsole.Error(e.ToString()); System.Console.WriteLine(e); } } } if (i > 1) { FsmHook.FsmInject(GameObject.Find("ITEMS"), "Save game", SaveMods); } ModSettings_menu.LoadBinds(); timer.Stop(); ModConsole.console.controller.AppendLogLine("</color>"); ModConsole.Print($"<color=#FFFF00>Loading mods finished ({timer.ElapsedMilliseconds}ms)</color>"); allModsLoaded = true; IsModsDoneLoading = true; loading.SetActive(false); }
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; } } }