Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXILED::Loader] Allow port-binded plugin loading #89

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
74 changes: 45 additions & 29 deletions EXILED/Exiled.Loader/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -116,39 +115,14 @@ public Loader()
.Build();

/// <summary>
/// Loads all plugins.
/// Loads all plugins, both globals and locals.
/// </summary>
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<IConfig> plugin = CreatePlugin(assembly);

if (plugin is null)
continue;

AssemblyInformationalVersionAttribute attribute = plugin.Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();

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(Server.Port.ToString());
}

/// <summary>
Expand Down Expand Up @@ -486,6 +460,48 @@ private static bool CheckPluginRequiredExiledVersion(IPlugin<IConfig> plugin)
return false;
}

/// <summary>
/// Load every plugin inside the given directory, if null it's default EXILED one (global).
/// </summary>
/// <param name="dir">The sub-directory of the plugin - if null the default EXILED one will be used.</param>
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<IConfig> plugin = CreatePlugin(assembly);

if (plugin == null)
continue;

AssemblyInformationalVersionAttribute attribute = plugin.Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();

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);
}
}

/// <summary>
/// Attempts to load Embedded (compressed) assemblies from specified Assembly.
/// </summary>
Expand Down