inital SK upload
This commit is contained in:
parent
27d6e530e0
commit
5edb6915ed
125 changed files with 2659 additions and 107 deletions
|
|
@ -13,6 +13,7 @@ internal static class EngineSettings
|
|||
"engine.json");
|
||||
|
||||
private static List<string> _pluginPaths = new();
|
||||
private static string _loggingLevel = "Info";
|
||||
private static bool _loaded;
|
||||
|
||||
public static IReadOnlyList<string> PluginPaths
|
||||
|
|
@ -24,6 +25,15 @@ internal static class EngineSettings
|
|||
}
|
||||
}
|
||||
|
||||
public static string LoggingLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureLoaded();
|
||||
return _loggingLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddPluginPath(string path)
|
||||
{
|
||||
EnsureLoaded();
|
||||
|
|
@ -66,6 +76,14 @@ internal static class EngineSettings
|
|||
_pluginPaths.Add(val);
|
||||
}
|
||||
}
|
||||
|
||||
if (doc.RootElement.TryGetProperty("LoggingLevel", out var loggingLevelElement) &&
|
||||
loggingLevelElement.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
string? configuredLevel = loggingLevelElement.GetString();
|
||||
if (!string.IsNullOrWhiteSpace(configuredLevel))
|
||||
_loggingLevel = configuredLevel;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -88,6 +106,7 @@ internal static class EngineSettings
|
|||
foreach (string p in _pluginPaths)
|
||||
w.WriteStringValue(p);
|
||||
w.WriteEndArray();
|
||||
w.WriteString("LoggingLevel", _loggingLevel);
|
||||
w.WriteEndObject();
|
||||
}
|
||||
File.WriteAllBytes(SettingsPath, ms.ToArray());
|
||||
|
|
|
|||
|
|
@ -57,4 +57,43 @@ internal sealed class LoadedPlugin
|
|||
public bool Failed { get; set; }
|
||||
public string DisplayName { get; set; } = "";
|
||||
public string VersionString { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Drops managed delegates wrapping exports so the native module can fully unload after
|
||||
/// the host calls FreeLibrary (hot-reload / rescan).
|
||||
/// </summary>
|
||||
internal void ClearResolvedDelegates()
|
||||
{
|
||||
Init = null;
|
||||
Shutdown = null;
|
||||
GetName = null;
|
||||
GetVersion = null;
|
||||
OnLoginComplete = null;
|
||||
OnUIInitialized = null;
|
||||
OnBusyCountIncremented = null;
|
||||
OnBusyCountDecremented = null;
|
||||
OnSelectedTargetChange = null;
|
||||
OnCombatModeChange = null;
|
||||
OnSmartBoxEventPtr = IntPtr.Zero;
|
||||
OnSmartBoxEvent = null;
|
||||
OnDeleteObject = null;
|
||||
OnCreateObject = null;
|
||||
OnUpdateObjectPtr = IntPtr.Zero;
|
||||
OnUpdateObject = null;
|
||||
OnUpdateObjectInventory = null;
|
||||
OnViewObjectContents = null;
|
||||
OnStopViewingObjectContents = null;
|
||||
OnVendorOpen = null;
|
||||
OnVendorClose = null;
|
||||
OnUpdateHealthPtr = IntPtr.Zero;
|
||||
OnUpdateHealth = null;
|
||||
OnChatWindowTextPtr = IntPtr.Zero;
|
||||
OnChatWindowText = null;
|
||||
OnChatBarEnter = null;
|
||||
OnBarAction = null;
|
||||
OnEnchantmentAdded = null;
|
||||
OnEnchantmentRemoved = null;
|
||||
Tick = null;
|
||||
Render = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,9 @@ internal static class PluginLoader
|
|||
/// </summary>
|
||||
public static void Unload(LoadedPlugin plugin)
|
||||
{
|
||||
// Release managed thunks first so the module ref-count can drop to zero on FreeLibrary.
|
||||
plugin.ClearResolvedDelegates();
|
||||
|
||||
if (plugin.ModuleHandle != IntPtr.Zero)
|
||||
{
|
||||
FreeLibrary(plugin.ModuleHandle);
|
||||
|
|
|
|||
|
|
@ -1501,6 +1501,18 @@ internal static class PluginManager
|
|||
var loaded = PluginLoader.LoadAll(_pluginsDir, _shadowRootDir, _loadGeneration);
|
||||
_plugins.AddRange(loaded);
|
||||
|
||||
// Track DLL file names and canonical paths already staged this generation. Extra paths
|
||||
// often repeat the same plugin as under Runtime\Plugins (e.g. RynthCore.Plugin.RynthAi.dll
|
||||
// in both); a second File.Copy to the same shadow file name fails while the first copy
|
||||
// is still mapped ("used by another process") and breaks hot-reload ordering for later DLLs.
|
||||
var loadedBasenames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
var loadedCanonicalPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var p in loaded)
|
||||
{
|
||||
loadedBasenames.Add(p.FileName);
|
||||
TryAddCanonicalPath(loadedCanonicalPaths, p.SourceFilePath);
|
||||
}
|
||||
|
||||
// Extra DLL paths from engine settings
|
||||
var extraPaths = EngineSettings.PluginPaths;
|
||||
for (int i = 0; i < extraPaths.Count; i++)
|
||||
|
|
@ -1511,10 +1523,48 @@ internal static class PluginManager
|
|||
RynthLog.Plugin($"PluginManager: Extra plugin not found: {dllPath}");
|
||||
continue;
|
||||
}
|
||||
|
||||
string baseName = Path.GetFileName(dllPath);
|
||||
if (loadedBasenames.Contains(baseName))
|
||||
{
|
||||
RynthLog.Plugin($"PluginManager: Skipping extra plugin (same file name already loaded from plugins directory or earlier extra path): {dllPath}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TryGetCanonicalPath(dllPath, out string extraCanon) && loadedCanonicalPaths.Contains(extraCanon))
|
||||
{
|
||||
RynthLog.Plugin($"PluginManager: Skipping extra plugin (same resolved path already loaded): {dllPath}");
|
||||
continue;
|
||||
}
|
||||
|
||||
RynthLog.Plugin($"PluginManager: Loading extra plugin: {dllPath}");
|
||||
var plugin = PluginLoader.LoadSingle(dllPath, _shadowRootDir, _loadGeneration);
|
||||
if (plugin != null)
|
||||
{
|
||||
_plugins.Add(plugin);
|
||||
loadedBasenames.Add(plugin.FileName);
|
||||
TryAddCanonicalPath(loadedCanonicalPaths, plugin.SourceFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void TryAddCanonicalPath(HashSet<string> set, string path)
|
||||
{
|
||||
if (TryGetCanonicalPath(path, out string canon))
|
||||
set.Add(canon);
|
||||
}
|
||||
|
||||
private static bool TryGetCanonicalPath(string path, out string canonical)
|
||||
{
|
||||
try
|
||||
{
|
||||
canonical = Path.GetFullPath(path);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
canonical = string.Empty;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue