Example #1
0
        public static void PreLoad()
        {
            if (isPreInitialized)
            {
                return;
            }
            isPreInitialized = true;
            Debug.Log("SRML has successfully invaded the game!");
            HarmonyPatcher.PatchAll();



            try
            {
                SRModLoader.LoadMods();
            }
            catch (Exception e)
            {
                ErrorGUI.CreateError($"{e.GetType().Name}: {e.Message}");
                return;
            }

            try
            {
                SRModLoader.PreLoadMods();
            }
            catch (Exception e)
            {
                ErrorGUI.CreateError($"{e.Message}");
            }
            ReplacerCache.ClearCache();

            HarmonyPatcher.Instance.Patch(typeof(GameContext).GetMethod("Start"),
                                          new HarmonyMethod(typeof(Main).GetMethod("PostLoad", BindingFlags.NonPublic | BindingFlags.Static)));
        }
Example #2
0
        /// <summary>
        /// Called before GameContext.Start()
        /// </summary>
        static void Load()
        {
            if (isInitialized)
            {
                return;
            }
            isInitialized = true;

            BaseObjects.Populate();
            SRCallbacks.OnLoad();
            PrefabUtils.ProcessReplacements();
            KeyBindManager.ReadBinds();
            GameContext.Instance.gameObject.AddComponent <ModManager>();
            GameContext.Instance.gameObject.AddComponent <KeyBindManager.ProcessAllBindings>();
            try
            {
                SRModLoader.LoadMods();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                ErrorGUI.CreateError($"{e.GetType().Name}: {e.Message}");
                return;
            }
            PostLoad();
        }
Example #3
0
        /// <summary>
        /// Called before GameContext.Awake()
        /// </summary>
        internal static void PreLoad()
        {
            if (isPreInitialized)
            {
                return;
            }
            isPreInitialized = true;
            Debug.Log("SRML has successfully invaded the game!");

            prefabParent = new GameObject("PrefabParent").transform;
            prefabParent.gameObject.SetActive(false);
            GameObject.DontDestroyOnLoad(prefabParent.gameObject);
            foreach (var v in Assembly.GetExecutingAssembly().GetTypes())
            {
                System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(v.TypeHandle);
            }

            HarmonyPatcher.PatchAll();

            try
            {
                SRModLoader.InitializeMods();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                ErrorGUI.CreateError($"{e.GetType().Name}: {e.Message}");
                return;
            }
            FileLogger.Init();
            Console.Console.Init();
            HarmonyOverrideHandler.PatchAll();
            try
            {
                SRModLoader.PreLoadMods();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                ErrorGUI.CreateError($"{e.Message}");
                return;
            }
            IdentifiableRegistry.CategorizeAllIds();
            GadgetRegistry.CategorizeAllIds();
            ReplacerCache.ClearCache();

            HarmonyPatcher.Instance.Patch(typeof(GameContext).GetMethod("Start"),
                                          prefix: new HarmonyMethod(typeof(Main).GetMethod("Load", BindingFlags.NonPublic | BindingFlags.Static)));
        }
Example #4
0
 static void PostLoad()
 {
     if (isPostInitialized)
     {
         return;
     }
     isPostInitialized = true;
     PrefabUtils.ProcessReplacements();
     try
     {
         SRModLoader.PostLoadMods();
     }
     catch (Exception e)
     {
         ErrorGUI.CreateError($"{e.GetType().Name}: {e.Message}");
         return;
     }
 }
Example #5
0
 /// <summary>
 /// Called after Load
 /// </summary>
 static void PostLoad()
 {
     if (isPostInitialized)
     {
         return;
     }
     isPostInitialized = true;
     try
     {
         SRModLoader.PostLoadMods();
     }
     catch (Exception e)
     {
         Debug.LogError(e);
         ErrorGUI.CreateError($"{e.GetType().Name}: {e.Message}");
         return;
     }
 }