Пример #1
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);
        }
Пример #2
0
 internal static bool TryGetRawPatch(Type enumType, out EnumPatch patch)
 {
     return(patches.TryGetValue(enumType, out patch));
 }