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:
itsRevela
2026-04-10 02:03:44 -05:00
parent d14e46701c
commit 8f41d34325
3 changed files with 37 additions and 3 deletions

View File

@@ -28,6 +28,22 @@ public abstract class ServerPlugin
/// </summary>
public virtual string author { get; } = "Unknown";
/// <summary>
/// The server's root directory (where the server executable lives).
/// Use this instead of <c>AppContext.BaseDirectory</c> which points
/// to the .NET runtime subfolder. Set automatically before
/// <see cref="onEnable"/> is called.
/// </summary>
public string serverDirectory { get; internal set; } = string.Empty;
/// <summary>
/// A per-plugin data directory (<c>plugins/&lt;PluginName&gt;/</c>).
/// Created automatically if it does not exist. Use this for config
/// files, logs, databases, or any plugin-specific storage.
/// Set automatically before <see cref="onEnable"/> is called.
/// </summary>
public string dataDirectory { get; internal set; } = string.Empty;
/// <summary>
/// Called when this plugin is enabled
/// </summary>