Ejemplo n.º 1
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)));
        }
Ejemplo n.º 2
0
 internal static void PreLoadMods()
 {
     CurrentLoadingStep      = LoadingStep.PRELOAD;
     Console.Console.Reload += Main.Reload;
     foreach (var modid in loadOrder)
     {
         var mod = Mods[modid];
         try
         {
             EnumHolderResolver.RegisterAllEnums(mod.EntryType.Module);
             ConfigManager.PopulateConfigs(mod);
             mod.PreLoad();
         }
         catch (Exception e)
         {
             throw new Exception($"Error pre-loading mod '{modid}'!\n{e.GetType().Name}: {e}");
         }
     }
     IdentifiableRegistry.CategorizeAllIds();
     GadgetRegistry.CategorizeAllIds();
 }