/// <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())); }
/// <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 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)); }