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))); }
/// <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(); }
/// <summary> /// Gets the current executing mod as an SRMod instance /// </summary> /// <returns>The current executing mod</returns> public static SRMod GetCurrentMod() { if (forcedContext != null) { return(forcedContext); } return(SRModLoader.GetModForAssembly(ReflectionUtils.GetRelevantAssembly())); }
internal static void LateUpdate() { try { SRModLoader.UpdateModsLate(); } catch (Exception e) { Debug.LogError(e); } }
internal static void UnLoad() { try { SRModLoader.UnLoadMods(); } catch (Exception e) { Debug.LogError(e); } }
/// <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))); }
static void PostLoad() { if (isPostInitialized) { return; } isPostInitialized = true; PrefabUtils.ProcessReplacements(); try { SRModLoader.PostLoadMods(); } catch (Exception e) { ErrorGUI.CreateError($"{e.GetType().Name}: {e.Message}"); return; } }
/// <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; } }
/// <summary> /// Add a new value to the given <paramref name="enumType"/> /// </summary> /// <param name="enumType">Enum to add the new value to</param> /// <param name="value">Value to add to the enum</param> /// <param name="name">The name of the new value</param> public static void AddEnumValue(Type enumType, object value, string name) { if (SRModLoader.GetModForAssembly(Assembly.GetCallingAssembly()) != null && BANNED_ENUMS.ContainsKey(enumType)) { throw new Exception($"Patching {enumType} through EnumPatcher is not supported!"); } if (!enumType.IsEnum) { throw new Exception($"{enumType} is not a valid Enum!"); } value = (ulong)Convert.ToInt64(value, CultureInfo.InvariantCulture); if (!patches.TryGetValue(enumType, out var patch)) { patch = new EnumPatch(); patches.Add(enumType, patch); } ClearEnumCache(enumType); patch.AddValue((ulong)value, name); }
public static object CallIMCMethod(string modid, string methodName, params object[] args) { try { var currentMod = SRMod.GetCurrentMod(); var mod = SRModLoader.GetMod(modid); if (mod == null) { throw new Exception($"Non-Existent modid: '{modid}'"); } if (!TryGetIMCInfo(mod, methodName, out var info)) { throw new Exception($"Non-Existent IMC method '{methodName}' for mod '{modid}'"); } CallingMod = currentMod?.ModInfo.Id ?? "srml"; return(info.Invoke(args)); } finally { CallingMod = null; } }
public static SRModInfo GetCurrentInfo() { var assembly = ReflectionUtils.GetRelevantAssembly(); return(SRModLoader.GetModForAssembly(assembly).ModInfo); }
/// <summary> /// When called from a mod, gets the base path of that mod /// </summary> /// <returns>The base path of the current executing mod</returns> public static String GetMyPath() { var assembly = ReflectionUtils.GetRelevantAssembly(); return(SRModLoader.GetModForAssembly(assembly)?.Path ?? Path.GetDirectoryName(assembly.Location)); }