inital SK upload
This commit is contained in:
parent
27d6e530e0
commit
5edb6915ed
125 changed files with 2659 additions and 107 deletions
|
|
@ -11,6 +11,7 @@ using System.Runtime.InteropServices;
|
|||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using ImGuiNET;
|
||||
using RynthCore;
|
||||
using RynthCore.Engine.Compatibility;
|
||||
using RynthCore.Engine.D3D9;
|
||||
using RynthCore.Engine.Plugins;
|
||||
|
|
@ -21,7 +22,8 @@ namespace RynthCore.Engine;
|
|||
|
||||
public static class EntryPoint
|
||||
{
|
||||
internal const string BuildStamp = "2026-03-30-v54-patternscan";
|
||||
// Human-readable build label for logs; bump when shipping a new RynthBundle or notable engine change.
|
||||
internal const string BuildStamp = "2026-04-23-v61-bundle-0411-runtime-detection-fix";
|
||||
private const int MaxRecentLogLines = 256;
|
||||
private static int _initialized;
|
||||
private static bool _imGuiResolverConfigured;
|
||||
|
|
@ -29,7 +31,19 @@ public static class EntryPoint
|
|||
private static readonly object LogLock = new();
|
||||
private static readonly Queue<string> RecentLogLines = new();
|
||||
|
||||
/// <summary>Set true to enable verbose startup logging (hook ready messages, plugin lifecycle, etc.).</summary>
|
||||
internal enum EngineLogLevel
|
||||
{
|
||||
Error = 0,
|
||||
Warning = 1,
|
||||
Info = 2,
|
||||
Debug = 3,
|
||||
Trace = 4
|
||||
}
|
||||
|
||||
/// <summary>Active engine logging threshold loaded from engine settings.</summary>
|
||||
internal static EngineLogLevel LoggingLevel = EngineLogLevel.Info;
|
||||
|
||||
/// <summary>Legacy convenience flag used by existing verbose call sites.</summary>
|
||||
internal static bool VerboseLogging = false;
|
||||
|
||||
/// <summary>Set by ImGuiController once the game window is confirmed. Read by AvaloniaOverlay.</summary>
|
||||
|
|
@ -43,8 +57,15 @@ public static class EntryPoint
|
|||
|
||||
try
|
||||
{
|
||||
LoggingLevel = ParseLoggingLevel(EngineSettings.LoggingLevel);
|
||||
VerboseLogging = LoggingLevel >= EngineLogLevel.Debug;
|
||||
RynthLog.Info($"RynthCoreInit called (build {BuildStamp}) - spawning init thread...");
|
||||
RynthLog.Info($"Engine logging level: {LoggingLevel}");
|
||||
CrashLogger.Install();
|
||||
// MultiClientHooks installs MinHook-based detours immediately. P/Invoke resolves
|
||||
// minhook.x86.dll before InitWorker runs — preload from the engine directory so
|
||||
// LoadLibrary succeeds (avoids false "multi-client hook failed" when the DLL exists).
|
||||
TryPreloadMinHookForEarlyInit();
|
||||
RunInitStep("early multi-client hooks", MultiClientHooks.Initialize);
|
||||
|
||||
var thread = new Thread(InitWorker)
|
||||
|
|
@ -86,6 +107,33 @@ public static class EntryPoint
|
|||
return Path.GetDirectoryName(new string(buffer, 0, (int)length));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads MinHook on the RynthCoreInit thread so <see cref="MultiClientHooks.Initialize"/> can
|
||||
/// call <see cref="Hooking.MinHook"/> P/Invokes without relying on the default DLL search path
|
||||
/// (which often resolves against the AC client directory, not <c>Runtime\</c>).
|
||||
/// </summary>
|
||||
private static void TryPreloadMinHookForEarlyInit()
|
||||
{
|
||||
try
|
||||
{
|
||||
string? engineDir = GetEngineDirectory();
|
||||
if (string.IsNullOrEmpty(engineDir))
|
||||
{
|
||||
RynthLog.Info("Early MinHook preload skipped: could not resolve engine directory.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (PreloadNativeDll(engineDir, "minhook.x86.dll"))
|
||||
RynthLog.Verbose($"Early MinHook preload OK (engine dir: {engineDir})");
|
||||
else
|
||||
RynthLog.Info($"Early MinHook preload failed: minhook.x86.dll not found beside engine ({engineDir}).");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Info($"Early MinHook preload exception: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static bool PreloadNativeDll(string engineDir, string dllName)
|
||||
{
|
||||
foreach (string path in GetNativeDllCandidates(engineDir, dllName))
|
||||
|
|
@ -347,10 +395,8 @@ public static class EntryPoint
|
|||
while (RecentLogLines.Count > MaxRecentLogLines)
|
||||
RecentLogLines.Dequeue();
|
||||
|
||||
string logPath = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
|
||||
"RynthCore.log");
|
||||
File.AppendAllText(logPath, line + "\n");
|
||||
// 10 MB roll + 10 per local day, archives under Desktop\RynthLogs\ (RynthCore.DesktopLog)
|
||||
DesktopRollingLog.AppendLine(DesktopRollingLog.StemEngine, line);
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
|
@ -360,10 +406,26 @@ public static class EntryPoint
|
|||
|
||||
internal static void LogVerbose(string message)
|
||||
{
|
||||
if (VerboseLogging)
|
||||
if (ShouldLog(EngineLogLevel.Debug))
|
||||
Log(message);
|
||||
}
|
||||
|
||||
internal static bool ShouldLog(EngineLogLevel level) => level <= LoggingLevel;
|
||||
|
||||
private static EngineLogLevel ParseLoggingLevel(string? configuredLevel)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(configuredLevel))
|
||||
return EngineLogLevel.Info;
|
||||
|
||||
string normalized = configuredLevel.Trim();
|
||||
if (string.Equals(normalized, "Verbose", StringComparison.OrdinalIgnoreCase))
|
||||
return EngineLogLevel.Debug;
|
||||
|
||||
return Enum.TryParse(normalized, ignoreCase: true, out EngineLogLevel parsed)
|
||||
? parsed
|
||||
: EngineLogLevel.Info;
|
||||
}
|
||||
|
||||
internal static string[] GetRecentLogLines()
|
||||
{
|
||||
lock (LogLock)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,12 +29,18 @@
|
|||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RynthCore.DesktopLog\RynthCore.DesktopLog.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ImGui.NET" Version="1.91.6.1" />
|
||||
<PackageReference Include="Avalonia" Version="11.2.3" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
|
||||
<PackageReference Include="Avalonia.Skia" Version="11.2.3" />
|
||||
<PackageReference Include="Avalonia.Themes.Simple" Version="11.2.3" />
|
||||
<!-- Overrides Avalonia.FreeDesktop transitive Tmds.DBus.Protocol (NU1903 / GHSA-xrw6-gwf8-vvr9). -->
|
||||
<PackageReference Include="Tmds.DBus.Protocol" Version="0.21.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -44,6 +50,10 @@
|
|||
|
||||
<!-- Prevent trimmer from removing ImGui.NET's DllImport methods -->
|
||||
<!-- Root Avalonia assemblies so the AOT trimmer keeps them intact -->
|
||||
<ItemGroup>
|
||||
<TrimmerRootAssembly Include="RynthCore.DesktopLog" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<TrimmerRootAssembly Include="ImGui.NET" />
|
||||
<TrimmerRootAssembly Include="Avalonia" />
|
||||
|
|
@ -62,38 +72,19 @@
|
|||
<BundledSupportDll Include="Native\minhook.x86.dll" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Single ImGui native beside the engine: EntryPoint tries Runtime\RynthCore.cimgui.dll first (see EntryPoint.GetImGuiNativeCandidates). -->
|
||||
<Target Name="CopyBundledNativeDlls" AfterTargets="Build">
|
||||
<Copy
|
||||
SourceFiles="@(BundledNativeDll)"
|
||||
DestinationFiles="@(BundledNativeDll->'$(OutputPath)Native\%(Filename)%(Extension)')"
|
||||
SkipUnchangedFiles="true" />
|
||||
<Copy
|
||||
SourceFiles="@(BundledNativeDll)"
|
||||
DestinationFiles="@(BundledNativeDll->'$(OutputPath)Native\RynthCore.%(Filename)%(Extension)')"
|
||||
SkipUnchangedFiles="true" />
|
||||
<Copy
|
||||
SourceFiles="@(BundledNativeDll)"
|
||||
DestinationFiles="@(BundledNativeDll->'$(OutputPath)%(Filename)%(Extension)')"
|
||||
SkipUnchangedFiles="true" />
|
||||
<Copy
|
||||
SourceFiles="@(BundledNativeDll)"
|
||||
DestinationFiles="@(BundledNativeDll->'$(OutputPath)RynthCore.%(Filename)%(Extension)')"
|
||||
SkipUnchangedFiles="true" />
|
||||
<!-- ImGui.NET / publish may still emit plain cimgui.dll or Native\ copies; keep one prefixed name next to the engine. -->
|
||||
<Delete Files="$(OutputPath)cimgui.dll" Condition="Exists('$(OutputPath)cimgui.dll')" />
|
||||
<Delete Files="$(OutputPath)Native\cimgui.dll" Condition="Exists('$(OutputPath)Native\cimgui.dll')" />
|
||||
<Delete Files="$(OutputPath)Native\RynthCore.cimgui.dll" Condition="Exists('$(OutputPath)Native\RynthCore.cimgui.dll')" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyBundledNativeDllsToPublish" AfterTargets="Publish" Condition="'$(PublishDir)' != ''">
|
||||
<Copy
|
||||
SourceFiles="@(BundledNativeDll)"
|
||||
DestinationFiles="@(BundledNativeDll->'$(PublishDir)Native\%(Filename)%(Extension)')"
|
||||
SkipUnchangedFiles="true" />
|
||||
<Copy
|
||||
SourceFiles="@(BundledNativeDll)"
|
||||
DestinationFiles="@(BundledNativeDll->'$(PublishDir)Native\RynthCore.%(Filename)%(Extension)')"
|
||||
SkipUnchangedFiles="true" />
|
||||
<Copy
|
||||
SourceFiles="@(BundledNativeDll)"
|
||||
DestinationFiles="@(BundledNativeDll->'$(PublishDir)%(Filename)%(Extension)')"
|
||||
SkipUnchangedFiles="true" />
|
||||
<Copy
|
||||
SourceFiles="@(BundledNativeDll)"
|
||||
DestinationFiles="@(BundledNativeDll->'$(PublishDir)RynthCore.%(Filename)%(Extension)')"
|
||||
|
|
@ -104,6 +95,13 @@
|
|||
SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
|
||||
<!-- Run after the full publish graph so package/ILC drops of cimgui.dll are removed last. -->
|
||||
<Target Name="DedupePublishedCimguiCopies" AfterTargets="Publish" Condition="'$(PublishDir)' != ''">
|
||||
<Delete Files="$(PublishDir)cimgui.dll" Condition="Exists('$(PublishDir)cimgui.dll')" />
|
||||
<Delete Files="$(PublishDir)Native\cimgui.dll" Condition="Exists('$(PublishDir)Native\cimgui.dll')" />
|
||||
<Delete Files="$(PublishDir)Native\RynthCore.cimgui.dll" Condition="Exists('$(PublishDir)Native\RynthCore.cimgui.dll')" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyBundledSupportDlls" AfterTargets="Build">
|
||||
<Copy
|
||||
SourceFiles="@(BundledSupportDll)"
|
||||
|
|
|
|||
|
|
@ -20,43 +20,50 @@ internal static class RynthLog
|
|||
/// <summary>D3D9 subsystem: vtable, EndScene, bootstrapper, matrix capture, nav3D.</summary>
|
||||
internal static void D3D9(string msg)
|
||||
{
|
||||
if (D3D9Enabled) Write(msg);
|
||||
if (D3D9Enabled) WriteAt(EntryPoint.EngineLogLevel.Info, msg);
|
||||
}
|
||||
|
||||
/// <summary>Compatibility hooks: SmartBox, client objects, combat, movement, vitals, chat, etc.</summary>
|
||||
internal static void Compat(string msg)
|
||||
{
|
||||
if (CompatEnabled) Write(msg);
|
||||
if (CompatEnabled) WriteAt(EntryPoint.EngineLogLevel.Info, msg);
|
||||
}
|
||||
|
||||
/// <summary>ImGui rendering: context, DX9 backend, Win32 input, shell.</summary>
|
||||
internal static void Render(string msg)
|
||||
{
|
||||
if (RenderEnabled) Write(msg);
|
||||
if (RenderEnabled) WriteAt(EntryPoint.EngineLogLevel.Info, msg);
|
||||
}
|
||||
|
||||
/// <summary>Plugin system: loader, manager, lifecycle callbacks.</summary>
|
||||
internal static void Plugin(string msg)
|
||||
{
|
||||
if (PluginEnabled) Write(msg);
|
||||
if (PluginEnabled) WriteAt(EntryPoint.EngineLogLevel.Info, msg);
|
||||
}
|
||||
|
||||
/// <summary>UI / Avalonia overlay subsystem.</summary>
|
||||
internal static void UI(string msg)
|
||||
{
|
||||
if (UIEnabled) Write(msg);
|
||||
if (UIEnabled) WriteAt(EntryPoint.EngineLogLevel.Info, msg);
|
||||
}
|
||||
|
||||
/// <summary>Verbose-only log (any category). Only written when VerboseLogging is on.</summary>
|
||||
/// <summary>Debug-level log (any category).</summary>
|
||||
internal static void Verbose(string msg)
|
||||
{
|
||||
if (EntryPoint.VerboseLogging) Write(msg);
|
||||
WriteAt(EntryPoint.EngineLogLevel.Debug, msg);
|
||||
}
|
||||
|
||||
/// <summary>Always-on log for critical / uncategorised messages.</summary>
|
||||
internal static void Info(string msg) => Write(msg);
|
||||
internal static void Trace(string msg) => WriteAt(EntryPoint.EngineLogLevel.Trace, msg);
|
||||
internal static void Debug(string msg) => WriteAt(EntryPoint.EngineLogLevel.Debug, msg);
|
||||
internal static void Info(string msg) => WriteAt(EntryPoint.EngineLogLevel.Info, msg);
|
||||
internal static void Warning(string msg) => WriteAt(EntryPoint.EngineLogLevel.Warning, msg);
|
||||
internal static void Error(string msg) => WriteAt(EntryPoint.EngineLogLevel.Error, msg);
|
||||
|
||||
// ── Sink ─────────────────────────────────────────────────────────────
|
||||
|
||||
private static void Write(string message) => EntryPoint.Log(message);
|
||||
private static void WriteAt(EntryPoint.EngineLogLevel level, string message)
|
||||
{
|
||||
if (EntryPoint.ShouldLog(level))
|
||||
EntryPoint.Log(message);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue