fix: redirect AppContext.BaseDirectory to server root for FourKit plugins
AppContext.BaseDirectory pointed to the runtime/ subfolder where the self-contained .NET payload lives, causing plugins that use it for file paths to write to the wrong directory. Now set to the server exe directory at startup via AppContext.SetData. Also adds serverDirectory and dataDirectory properties to ServerPlugin so plugin authors have convenient access to the server root and a per-plugin data folder (plugins/<PluginName>/) without needing to resolve paths manually.
This commit is contained in:
@@ -10,11 +10,16 @@ internal sealed class PluginLoader
|
||||
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
||||
|
||||
private readonly List<ServerPlugin> _plugins = new();
|
||||
private string _serverRoot = string.Empty;
|
||||
private string _pluginsDirectory = string.Empty;
|
||||
|
||||
public IReadOnlyList<ServerPlugin> Plugins => _plugins.AsReadOnly();
|
||||
|
||||
public void LoadPlugins(string pluginsDirectory)
|
||||
public void LoadPlugins(string pluginsDirectory, string serverRoot)
|
||||
{
|
||||
_serverRoot = serverRoot;
|
||||
_pluginsDirectory = pluginsDirectory;
|
||||
|
||||
if (!Directory.Exists(pluginsDirectory))
|
||||
{
|
||||
ServerLog.Info("fourkit", $"Creating plugins directory: {pluginsDirectory}");
|
||||
@@ -136,8 +141,15 @@ internal sealed class PluginLoader
|
||||
{
|
||||
try
|
||||
{
|
||||
InvokePluginMethod(plugin, "onEnable", "OnEnable");
|
||||
string pName = GetPluginString(plugin, "name", "getName", "GetName", plugin.GetType().Name);
|
||||
|
||||
plugin.serverDirectory = _serverRoot;
|
||||
string dataDir = Path.Combine(_pluginsDirectory, pName);
|
||||
if (!Directory.Exists(dataDir))
|
||||
Directory.CreateDirectory(dataDir);
|
||||
plugin.dataDirectory = dataDir;
|
||||
|
||||
InvokePluginMethod(plugin, "onEnable", "OnEnable");
|
||||
ServerLog.Info("fourkit", $"Enabled: {pName}");
|
||||
|
||||
FourKit.FireEvent(new PluginEnableEvent(plugin));
|
||||
|
||||
Reference in New Issue
Block a user