Пример #1
0
        public static void RegisterAllEnums(Module module)
        {
            SRMod.ForceModContext(SRModLoader.GetModForAssembly(module.Assembly));
            foreach (var type in module.GetTypes())
            {
                if (type.GetCustomAttributes(true).Any((x) => x is EnumHolderAttribute))
                {
                    foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public |
                                                         BindingFlags.NonPublic))
                    {
                        if (!field.FieldType.IsEnum)
                        {
                            continue;
                        }

                        if ((int)field.GetValue(null) == 0)
                        {
                            var newVal = EnumPatcher.GetFirstFreeValue(field.FieldType);
                            EnumPatcher.AddEnumValueWithAlternatives(field.FieldType, newVal, field.Name);
                            field.SetValue(null, newVal);
                        }
                        else
                        {
                            EnumPatcher.AddEnumValueWithAlternatives(field.FieldType, field.GetValue(null), field.Name);
                        }
                    }
                }
            }
            SRMod.ClearModContext();
        }
Пример #2
0
 public static SRMod GetModForParticipant(ExtendedData.Participant p)
 {
     return(SRModLoader.GetModForAssembly(p.GetType().Assembly));
 }