Ejemplo n.º 1
0
 /// <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()));
 }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        public static SRModInfo GetCurrentInfo()
        {
            var assembly = ReflectionUtils.GetRelevantAssembly();

            return(SRModLoader.GetModForAssembly(assembly).ModInfo);
        }
Ejemplo n.º 4
0
        /// <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));
        }