static void AddMod(ProtoMod modInfo, Type entryType) { ModEntryPoint entryPoint = (ModEntryPoint)Activator.CreateInstance(entryType); var newmod = new SRMod(modInfo.ToModInfo(), entryPoint, modInfo.path); Mods.Add(modInfo.id, newmod); }
public static Harmony SetInstance(string name) { var currentMod = SRMod.GetCurrentMod(); currentMod.CreateHarmonyInstance(name); return(currentMod.HarmonyInstance); }
internal static void PreLoadMods() { foreach (var modid in loadOrder) { var mod = Mods[modid]; try { EnumHolderResolver.RegisterAllEnums(mod.EntryType.Module); ConfigManager.PopulateConfigs(mod); mod.PreLoad(); Console.Console.Reload += () => { SRMod.ForceModContext(mod); foreach (var v in mod.Configs) { v.TryLoadFromFile(); } SRMod.ClearModContext(); }; } catch (Exception e) { throw new Exception($"Error pre-loading mod '{modid}'!\n{e.GetType().Name}: {e}"); } } }
static void RegisterIntermodMethod(SRMod mod, string imcmethodName, IntermodCommunicationInfo info) { if (!IMCMethods.TryGetValue(mod, out var dict)) { dict = new Dictionary <string, IntermodCommunicationInfo>(); IMCMethods[mod] = dict; } dict.Add(imcmethodName, info); }
internal static void UnLoadMods() { CurrentLoadingStep = LoadingStep.UNLOAD; foreach (string key in loadOrder.ToList().Reverse <string>()) { SRMod mod = Mods[key]; try { mod.UnLoad(); } catch (Exception ex) { Debug.LogError(new Exception(string.Format("Error unloading mod '{0}'!\n{1}: {2}", (object)key, (object)ex.GetType().Name, (object)ex))); } } }
static bool TryGetIMCInfo(SRMod mod, string imcMethod, out IntermodCommunicationInfo info) { info = default(IntermodCommunicationInfo); if (mod == null) { return(false); } if (!IMCMethods.TryGetValue(mod, out var imc)) { return(false); } if (!imc.TryGetValue(imcMethod, out info)) { return(false); } return(true); }
internal static void UpdateModsLate() { if (CurrentLoadingStep != LoadingStep.FINISHED) { return; } foreach (string key in loadOrder) { SRMod mod = Mods[key]; try { mod.LateUpdate(); } catch (Exception ex) { Debug.LogError(new Exception(string.Format("Error late updating mod '{0}'!\n{1}: {2}", (object)key, (object)ex.GetType().Name, (object)ex))); } } }
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; } }
internal static void ReloadMods() { CurrentLoadingStep = LoadingStep.RELOAD; foreach (var modid in loadOrder) { var mod = Mods[modid]; try { SRMod.ForceModContext(mod); foreach (var v in mod.Configs) { v.TryLoadFromFile(); } SRMod.ClearModContext(); mod.Reload(); } catch (Exception e) { throw new Exception($"Error reloading mod '{modid}'!\n{e.GetType().Name}: {e}"); } } CurrentLoadingStep = LoadingStep.FINISHED; }
internal static void ReLoadMods() { CurrentLoadingStep = LoadingStep.RELOAD; foreach (string key in loadOrder) { SRMod mod = Mods[key]; try { SRMod.ForceModContext(mod); foreach (var v in mod.Configs) { v.TryLoadFromFile(); } SRMod.ClearModContext(); mod.ReLoad(); } catch (Exception ex) { Debug.LogError(new Exception(string.Format("Error reloading mod '{0}'!\n{1}: {2}", (object)key, (object)ex.GetType().Name, (object)ex))); } } CurrentLoadingStep = LoadingStep.FINISHED; }
public static Harmony GetInstance() { return(SRMod.GetCurrentMod().HarmonyInstance); }
/// <summary> /// Clears the current mod context /// </summary> internal static void ClearModContext() { forcedContext = null; }
/// <summary> /// Forces a certain mod to be returned from <see cref="SRMod.GetCurrentMod"/> /// </summary> /// <param name="mod">The mod to be forced</param> internal static void ForceModContext(SRMod mod) { forcedContext = mod; }
/// <summary> /// Gets the current mods config path /// </summary> /// <returns>The config path</returns> public static String GetMyConfigPath() { return(GetConfigPath(SRMod.GetCurrentMod())); }
/// <summary> /// Gets a mods config path /// </summary> /// <param name="mod">The mod whose config path is needed</param> /// <returns>The config path</returns> internal static String GetConfigPath(SRMod mod) { return(CheckDirectory(Path.Combine(Path.Combine(Application.persistentDataPath, "SRML/Config"), mod?.ModInfo.Id ?? "SRML"))); }
static void RegisterIntermodMethod(string imcmethodName, IntermodCommunicationInfo info) { RegisterIntermodMethod(SRMod.GetCurrentMod(), imcmethodName, info); }