RynthCore as of 2026-10-04 (internal 843c801): RynthNav auto-travel and the navigation map, plugin API v75 (server and titles), launcher with Available plugins, download progress and the update on the front page, opt-in usage statistics, NPC names, radar colours, title-bar text size, FPS limiter, client action unlocks, release 2026.10.4.6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9b5e2765b7
commit
a24ed6df7c
322 changed files with 83009 additions and 7504 deletions
58
src/RynthCore.Engine/Hooking/LoaderServices.cs
Normal file
58
src/RynthCore.Engine/Hooking/LoaderServices.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - Hooking/LoaderServices.cs
|
||||
//
|
||||
// The native loader (native/Loader/Services.c, loader 2.0+) owns the permanent native
|
||||
// entry points the engine used to hand out itself: the game window's subclass proc and
|
||||
// the plugin API table's function pointers. With them, nothing native ever points into
|
||||
// an engine generation after its shutdown, so the CoreCLR host can unload it
|
||||
// (docs/UNLOADABLE_ENGINE_PLAN.md). Under an older loader (or none) Available is false
|
||||
// and callers keep their old behaviour.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RynthCore.Engine.Hooking;
|
||||
|
||||
internal static unsafe class LoaderServices
|
||||
{
|
||||
private static readonly delegate* unmanaged[Stdcall]<IntPtr, IntPtr, IntPtr*, int> s_subclassInstall;
|
||||
private static readonly delegate* unmanaged[Stdcall]<IntPtr, int> s_subclassRelease;
|
||||
private static readonly delegate* unmanaged[Stdcall]<int, IntPtr, IntPtr> s_apiStub;
|
||||
|
||||
static LoaderServices()
|
||||
{
|
||||
IntPtr loader = GetModuleHandleW("RynthCore.Loader.dll");
|
||||
if (loader == IntPtr.Zero || GetProcAddress(loader, "RcServices_Version") == IntPtr.Zero)
|
||||
return;
|
||||
s_subclassInstall = (delegate* unmanaged[Stdcall]<IntPtr, IntPtr, IntPtr*, int>)GetProcAddress(loader, "RcSubclass_Install");
|
||||
s_subclassRelease = (delegate* unmanaged[Stdcall]<IntPtr, int>)GetProcAddress(loader, "RcSubclass_Release");
|
||||
s_apiStub = (delegate* unmanaged[Stdcall]<int, IntPtr, IntPtr>)GetProcAddress(loader, "RcApiStub");
|
||||
}
|
||||
|
||||
public static bool Available => s_subclassInstall != null && s_subclassRelease != null && s_apiStub != null;
|
||||
|
||||
/// <summary>
|
||||
/// Routes <paramref name="hwnd"/>'s messages to <paramref name="handler"/> through the
|
||||
/// loader's permanent subclass. <paramref name="previous"/> is the proc to forward to.
|
||||
/// </summary>
|
||||
public static bool SubclassInstall(IntPtr hwnd, IntPtr handler, out IntPtr previous)
|
||||
{
|
||||
IntPtr prev = IntPtr.Zero;
|
||||
bool ok = s_subclassInstall(hwnd, handler, &prev) != 0;
|
||||
previous = prev;
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// <summary>The loader's subclass passes everything straight to the previous proc again.</summary>
|
||||
public static void SubclassRelease(IntPtr hwnd) => s_subclassRelease(hwnd);
|
||||
|
||||
/// <summary>A permanent stub for plugin API slot <paramref name="index"/> that calls <paramref name="fn"/>.</summary>
|
||||
public static IntPtr ApiStub(int index, IntPtr fn) => s_apiStub(index, fn);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern IntPtr GetModuleHandleW(string lpModuleName);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
|
||||
private static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
|
||||
}
|
||||
|
|
@ -13,9 +13,10 @@ using System.Threading;
|
|||
|
||||
namespace RynthCore.Engine.Hooking;
|
||||
|
||||
internal static class MinHook
|
||||
internal static unsafe class MinHook
|
||||
{
|
||||
private const string DLL = "minhook.x86.dll";
|
||||
private const string LoaderDll = "RynthCore.Loader.dll";
|
||||
|
||||
// ─── Status codes (must match MinHook's MH_STATUS enum) ────────────
|
||||
public const int MH_OK = 0;
|
||||
|
|
@ -25,35 +26,86 @@ internal static class MinHook
|
|||
public const int MH_ERROR_NOT_CREATED = 4;
|
||||
|
||||
// ─── Core API ─────────────────────────────────────────────────────
|
||||
//
|
||||
// The native loader (native/Loader, 2.0+) exports MinHook's API itself: every
|
||||
// target gets a permanent stub and a reload only re-points it, so no hook ever
|
||||
// points into an unloaded engine (docs/UNLOADABLE_ENGINE_PLAN.md). The engine uses
|
||||
// that facade when the loader has it (RcHooks_Version), else minhook.x86.dll as
|
||||
// before (the NativeAOT loader, or the engine loaded directly).
|
||||
|
||||
[DllImport(DLL, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern int MH_Initialize();
|
||||
private static readonly Api s_api = ResolveApi();
|
||||
|
||||
[DllImport(DLL, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern int MH_Uninitialize();
|
||||
/// <summary>True when hooks go through the native loader's facade.</summary>
|
||||
public static bool UsesLoaderFacade => s_api.IsFacade;
|
||||
|
||||
[DllImport(DLL, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern int MH_CreateHook(
|
||||
IntPtr pTarget,
|
||||
IntPtr pDetour,
|
||||
out IntPtr ppOriginal);
|
||||
public static int MH_Initialize() => s_api.Initialize();
|
||||
|
||||
[DllImport(DLL, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern int MH_RemoveHook(IntPtr pTarget);
|
||||
public static int MH_Uninitialize() => s_api.Uninitialize();
|
||||
|
||||
[DllImport(DLL, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern int MH_EnableHook(IntPtr pTarget);
|
||||
public static int MH_CreateHook(IntPtr pTarget, IntPtr pDetour, out IntPtr ppOriginal)
|
||||
{
|
||||
IntPtr original = IntPtr.Zero;
|
||||
int status = s_api.Create(pTarget, pDetour, &original);
|
||||
ppOriginal = original;
|
||||
return status;
|
||||
}
|
||||
|
||||
[DllImport(DLL, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern int MH_DisableHook(IntPtr pTarget);
|
||||
public static int MH_RemoveHook(IntPtr pTarget) => s_api.Remove(pTarget);
|
||||
|
||||
public static int MH_EnableHook(IntPtr pTarget) => s_api.Enable(pTarget);
|
||||
|
||||
public static int MH_DisableHook(IntPtr pTarget) => s_api.Disable(pTarget);
|
||||
|
||||
/// <summary>Enable/disable all hooks at once.</summary>
|
||||
public static readonly IntPtr MH_ALL_HOOKS = IntPtr.Zero;
|
||||
|
||||
// ─── Status to string ─────────────────────────────────────────────
|
||||
private static IntPtr MH_StatusToString(int status) => s_api.StatusToString(status);
|
||||
|
||||
[DllImport(DLL, CallingConvention = CallingConvention.StdCall)]
|
||||
private static extern IntPtr MH_StatusToString(int status);
|
||||
private sealed class Api
|
||||
{
|
||||
public bool IsFacade;
|
||||
public delegate* unmanaged[Stdcall]<int> Initialize;
|
||||
public delegate* unmanaged[Stdcall]<int> Uninitialize;
|
||||
public delegate* unmanaged[Stdcall]<IntPtr, IntPtr, IntPtr*, int> Create;
|
||||
public delegate* unmanaged[Stdcall]<IntPtr, int> Remove;
|
||||
public delegate* unmanaged[Stdcall]<IntPtr, int> Enable;
|
||||
public delegate* unmanaged[Stdcall]<IntPtr, int> Disable;
|
||||
public delegate* unmanaged[Stdcall]<int, IntPtr> StatusToString;
|
||||
}
|
||||
|
||||
private static Api ResolveApi()
|
||||
{
|
||||
IntPtr module = GetModuleHandleW(LoaderDll);
|
||||
bool facade = module != IntPtr.Zero && GetProcAddress(module, "RcHooks_Version") != IntPtr.Zero;
|
||||
if (!facade)
|
||||
module = NativeLibrary.Load(DLL, typeof(MinHook).Assembly, null);
|
||||
|
||||
IntPtr Get(string name)
|
||||
{
|
||||
IntPtr fn = GetProcAddress(module, name);
|
||||
if (fn == IntPtr.Zero)
|
||||
throw new EntryPointNotFoundException($"{(facade ? LoaderDll : DLL)} has no export {name}");
|
||||
return fn;
|
||||
}
|
||||
|
||||
return new Api
|
||||
{
|
||||
IsFacade = facade,
|
||||
Initialize = (delegate* unmanaged[Stdcall]<int>)Get("MH_Initialize"),
|
||||
Uninitialize = (delegate* unmanaged[Stdcall]<int>)Get("MH_Uninitialize"),
|
||||
Create = (delegate* unmanaged[Stdcall]<IntPtr, IntPtr, IntPtr*, int>)Get("MH_CreateHook"),
|
||||
Remove = (delegate* unmanaged[Stdcall]<IntPtr, int>)Get("MH_RemoveHook"),
|
||||
Enable = (delegate* unmanaged[Stdcall]<IntPtr, int>)Get("MH_EnableHook"),
|
||||
Disable = (delegate* unmanaged[Stdcall]<IntPtr, int>)Get("MH_DisableHook"),
|
||||
StatusToString = (delegate* unmanaged[Stdcall]<int, IntPtr>)Get("MH_StatusToString"),
|
||||
};
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern IntPtr GetModuleHandleW(string lpModuleName);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
|
||||
private static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
|
||||
|
||||
public static string StatusString(int status)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue