コード例 #1
0
        //Called for every mod loaded
        public static void RegisterEventHandlers(string name, PulsarMod mod)
        {
            Assembly asm = mod.GetType().Assembly;

            foreach (Type classType in asm.GetTypes())
            {
                foreach (MethodInfo method in classType.GetMethods())
                {
                    ParameterInfo[] param = method.GetParameters();
                    if (method.GetCustomAttributes(typeof(EventHandler), false).Any() && method.ReturnType == typeof(void) &&
                        param.Count() == 1 && (param[0].ParameterType.IsSubclassOf(typeof(Event)) || param[0].ParameterType == typeof(Event)))
                    {
                        if (EventHandlers.TryGetValue(param[0].ParameterType, out List <MethodInfo> methods))
                        {
                            methods.Add(method);
                        }
                        else
                        {
                            methods = new List <MethodInfo> {
                                method
                            };
                            EventHandlers.Add(param[0].ParameterType, methods);
                        }
                    }
                }
            }
        }
コード例 #2
0
        void UpdateOnModLoaded(string modName, PulsarMod mod)
        {
            mods.Add(mod);
            var modsettingstype = typeof(ModSettingsMenu);

            mod.GetType().Assembly.GetTypes().AsParallel().ForAll((type) =>
            {
                if (modsettingstype.IsAssignableFrom(type))
                {
                    #if DEBUG
                    Utilities.Logger.Info($"Loaded new settings! {type.FullName}");
                    #endif
                    settings.Add(Activator.CreateInstance(type) as ModSettingsMenu);
                }
            });
        }
コード例 #3
0
        void UpdateOnModRemoved(PulsarMod mod)
        {
            selectedMod = ushort.MaxValue;
            mods.Remove(mod);
            List <ModSettingsMenu> settingsToRemove = new List <ModSettingsMenu>();
            Assembly asm = mod.GetType().Assembly;

            settings.AsParallel().ForAll((arg) => { if (arg.GetType().Assembly == asm)
                                                    {
                                                        settingsToRemove.Add(arg);
                                                    }
                                         });
            for (byte s = 0; s < settingsToRemove.Count; s++)
            {
                settings.Remove(settingsToRemove[s]);
            }
            settingsToRemove = null;
        }
コード例 #4
0
        public void OnModLoaded(string name, PulsarMod mod)
        {
            Assembly asm = mod.GetType().Assembly;

            LoadCommandsFromAssembly(asm, mod);
        }