diff --git a/EXILED/Exiled.Loader/Loader.cs b/EXILED/Exiled.Loader/Loader.cs index 77894ba66..3ac49effc 100644 --- a/EXILED/Exiled.Loader/Loader.cs +++ b/EXILED/Exiled.Loader/Loader.cs @@ -26,7 +26,6 @@ namespace Exiled.Loader using Features; using Features.Configs; using Features.Configs.CustomConverters; - using MEC; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NodeDeserializers; @@ -116,39 +115,15 @@ public Loader() .Build(); /// - /// Loads all plugins. + /// Loads all plugins, both globals and locals. /// public static void LoadPlugins() { File.Delete(Path.Combine(Paths.Plugins, "Exiled.Updater.dll")); - foreach (string assemblyPath in Directory.GetFiles(Paths.Plugins, "*.dll")) - { - Assembly assembly = LoadAssembly(assemblyPath); - - if (assembly is null) - continue; - - Locations[assembly] = assemblyPath; - } - - foreach (Assembly assembly in Locations.Keys) - { - if (Locations[assembly].Contains("dependencies")) - continue; - - IPlugin plugin = CreatePlugin(assembly); - - if (plugin is null) - continue; - - AssemblyInformationalVersionAttribute attribute = plugin.Assembly.GetCustomAttribute(); - - Log.Info($"Loaded plugin {plugin.Name}@{(plugin.Version is not null ? $"{plugin.Version.Major}.{plugin.Version.Minor}.{plugin.Version.Build}" : attribute is not null ? attribute.InformationalVersion : string.Empty)}"); - - Server.PluginAssemblies.Add(assembly, plugin); - Plugins.Add(plugin); - } + LoadPluginsFromDirectory(); + LoadPluginsFromDirectory("global"); + LoadPluginsFromDirectory(Server.Port.ToString()); } /// @@ -486,6 +461,51 @@ private static bool CheckPluginRequiredExiledVersion(IPlugin plugin) return false; } + /// + /// Load every plugin inside the given directory, if null it's default EXILED one (global). + /// + /// The sub-directory of the plugin - if null the default EXILED one will be used. + private static void LoadPluginsFromDirectory(string dir = null) + { + string path = Paths.Plugins; + if (dir != null) + path = Path.Combine(path, dir); + + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + + foreach (string assemblyPath in Directory.GetFiles(path, "*.dll")) + { + Assembly assembly = LoadAssembly(assemblyPath); + + if (assembly == null) + continue; + + Locations[assembly] = assemblyPath; + } + + foreach (Assembly assembly in Locations.Keys) + { + if (Locations[assembly].Contains("dependencies")) + continue; + + IPlugin plugin = CreatePlugin(assembly); + + if (plugin == null) + continue; + + if (Plugins.Any(p => p.Name == plugin.Name)) + continue; + + AssemblyInformationalVersionAttribute attribute = plugin.Assembly.GetCustomAttribute(); + + Log.Info($"Loaded plugin {plugin.Name}@{(plugin.Version != null ? $"{plugin.Version}" : attribute != null ? attribute.InformationalVersion : string.Empty)}"); + + Server.PluginAssemblies.Add(assembly, plugin); + Plugins.Add(plugin); + } + } + /// /// Attempts to load Embedded (compressed) assemblies from specified Assembly. ///