/// <summary> /// FSM Inject as extension (same as old FsmHook.FsmInject) /// </summary> /// <param name="gameObject">GameObject where to hook</param> /// <param name="stateName">Name of the state</param> /// <param name="hook">Your function to hook</param> /// <example><code lang="C#" title="Fsm Inject as /// Extension">GameObject.Find("Some game object").FsmInject("state name", /// function);</code></example> public static void FsmInject( this GameObject gameObject, string stateName, Action hook) { FsmHook.FsmInject(gameObject, stateName, hook); }
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); }