Пример #1
0
 public static CommandManager GetInstance(RedoxPlugin plugin)
 {
     if (instance == null)
     {
         instance = new CommandManager(plugin);
     }
     Commands.Add(instance);
     return(instance);
 }
Пример #2
0
        public static void LoadPlugin(string dir)
        {
            FileInfo info = null;

            try
            {
                foreach (var file in Directory.GetFiles(dir, Expression))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    info = new FileInfo(file);
                    string   name = info.Name.Replace(".dll", string.Empty);
                    Assembly assembly;

                    if (!Plugins.TryGetValue(name, out assembly))
                    {
                        assembly = Assembly.Load(File.ReadAllBytes(file));
                        Plugins.Add(name, assembly);
                    }
                    foreach (Type type in assembly.GetExportedTypes())
                    {
                        if (type.IsSubclassOf(typeof(RedoxPlugin)) && type.IsPublic && !type.IsAbstract)
                        {
                            object          instance  = Activator.CreateInstance(type);
                            RedoxPlugin     plugin    = (RedoxPlugin)instance;
                            PluginContainer container = new PluginContainer(plugin, instance);
                            PluginCollector.GetCollector().AddPlugin(container);

                            container.Plugin.Path = Path.GetDirectoryName(info.Directory.FullName);

                            logger.LogInfo(string.Format("[Redox] Succesfully loaded plugin {0}, {1}, Author {2} ({3}", plugin.Title, plugin.Version, plugin.Author, plugin.Description));
                        }
                    }
                    sw.Stop();
                    int time = sw.Elapsed.Milliseconds;

                    if (time > 500)
                    {
                        logger.LogSpeed(string.Format("[Redox] Plugin {0} took {1} milliseconds to load", name, time));
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(string.Format("An exception has thrown while trying to load plugin {0}, Error: {1}", info.FullName, ex));
            }
        }
Пример #3
0
        public static void LoadPlugin(string dir)
        {
            foreach (var file in Directory.GetFiles(dir, Expression))
            {
                FileInfo info = new FileInfo(file);
                string   name = info.Name.Replace(".dll", string.Empty);
                Assembly assembly;

                if (!Plugins.TryGetValue(name, out assembly))
                {
                    assembly = Assembly.Load(File.ReadAllBytes(file));
                    Plugins.Add(name, assembly);
                }

                if (ValidPlugin(assembly))
                {
                    foreach (Type type in assembly.GetExportedTypes())
                    {
                        if (type.IsSubclassOf(typeof(RedoxPlugin)) && type.IsPublic && !type.IsAbstract)
                        {
                            RedoxPlugin     plugin    = (RedoxPlugin)Activator.CreateInstance(type);
                            PluginContainer container = new PluginContainer(plugin);

                            PluginCollector.GetCollector().AddPlugin(container);

                            foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                            {
                                container.Methods.Add(method.Name, method);
                            }

                            Debug.Log(string.Format("[Redox] Succesfully loaded plugin {0}, {1}, {2} ({3})", plugin.Title, plugin.Author, plugin.Version, plugin.Description));
                        }
                    }
                }
                else
                {
                    Debug.LogWarning(string.Format("[Redox] Denied plugin {0} because of forbidden references", assembly.FullName));
                }
            }
        }
Пример #4
0
 public Config(string name, RedoxPlugin plugin)
 {
     this.name   = name + ".json";
     Settings    = new Dictionary <string, object>();
     this.plugin = plugin;
 }
Пример #5
0
 public PluginContainer(RedoxPlugin plugin, object instance)
 {
     this.Running  = true;
     this.Plugin   = plugin;
     this.instance = instance;
 }
Пример #6
0
 public Datafile(string name, RedoxPlugin plugin)
 {
     this.name   = name + ".data";
     Settings    = new Dictionary <string, object>();
     this.plugin = plugin;
 }
Пример #7
0
 public CommandManager(RedoxPlugin plugin)
 {
     _commands   = new List <Command>();
     this.plugin = plugin;
 }