RynthCore as of 2026-10-05 (internal 0d3c210): dashboard slide-outs on the left (Ranges with the selected monster, Files, Patrol), fixed draggable vital bar, click an item to add a loot rule, loot rules by WCID, chat and loot editor typing no longer leaks into the game, title-bar text size, plugin API v76 (close container), plugin exception traces, plates drawn under the game UI (in testing), launcher account passwords encrypted with Windows DPAPI (in testing), release 2026.10.5.1

This commit is contained in:
Tom Bohar 2026-10-05 08:03:08 -04:00
commit c3e15480e5
50 changed files with 3315 additions and 490 deletions

View file

@ -0,0 +1,156 @@
// ============================================================================
// RynthCore.Engine - D3D9/AcUiPassHook.cs
// Hooks AC's RenderUI::RenderObjects, the call that draws AC's 2D UI, so the
// world overlays (Nav3D markers, nameplates, combat text) draw right before
// it: after ALL of AC's 3D (alpha-sorted foliage and effects included) and
// under every AC window.
//
// Why a function hook and not a D3D state signal (2026-10-04, plates drew
// behind foliage): AC's frame is Client::UseTime -> SceneTool::StartFrame ->
// SmartBox::Draw (the whole 3D scene) -> SceneTool::EndFrame, and EndFrame
// sets a full-screen viewport, calls RenderUI::RenderObjects (each UI
// element's surface, in z-order), KeyStone::Update, the debug HUDs, restores
// the viewport and ends the scene. Inside SmartBox::Draw, ZENABLE goes 1->0
// more than once before the UI: the outdoor sky pass after the landblocks
// (LScape -> sky pass 1, depth mode ALWAYS/no-write, DrawObjCellForDummies)
// draws with Z off, and only AFTER it does SmartBox::RenderNormalMode flush
// the deferred alpha list (D3DPolyRender::FlushAlphaList(0)) - where the
// alpha-sorted foliage and effects draw. The old "first ZENABLE 1->0" signal
// fired at that sky pass, so the alpha list covered the plates. The entry of
// RenderUI::RenderObjects is exactly "3D done, 2D UI begins", costs one call
// per frame instead of work on every draw, and needs no prediction.
// Evidence and addresses: ops/overnight/2026-10-04-plates-foliage.md (Aeshnidae).
//
// The function takes no arguments and returns nothing (it loads ecx itself;
// its caller doesn't use eax/ecx/edx after it), so a cdecl void() detour is
// exact. AC's main thread only (the render thread). A frame where AC draws no
// UI never calls it; the overlays then draw at EndScene (the existing
// fallback), which is also "after all 3D".
//
// Teardown: EngineLifecycle calls Uninstall before EndSceneHook.Uninstall, so
// the detour stops entering the overlay code before UnderUiLayer/DX9Backend
// are torn down (EndSceneHook.Uninstall then waits 80 ms for a call in flight).
// The hook is only disabled, like every Compatibility hook at MH_DisableHook(ALL);
// the next generation's HookCreate reclaims the target (reload recovery / the
// loader facade).
// ============================================================================
using System;
using System.Runtime.InteropServices;
using System.Threading;
using RynthCore.Engine.Compatibility;
using RynthCore.Engine.Hooking;
namespace RynthCore.Engine.D3D9;
internal static class AcUiPassHook
{
// RenderUI::RenderObjects on the 4,841,472-byte client. Pattern is the source of truth.
private const int RenderObjectsFallbackVa = 0x004488A0;
// mov eax,[list count]; sub esp,8; push esi; xor esi,esi; test eax,eax;
// mov byte [in-render flag],1; mov dword [..],0; mov ecx,imm; jbe +10;
// mov eax,[list head]; test eax,eax; je +5; lea esi,[eax-8]; jmp +2; xor esi,esi;
// test esi,esi; mov [esp+8],ecx; je +20. Unique in .text (checked 2026-10-04 on
// both C:\Turbine and C:\Games\RynthCore\AcClient copies); absolute addresses wildcarded.
private static readonly byte?[] RenderObjectsPattern =
[
0xA1, null, null, null, null,
0x83, 0xEC, 0x08,
0x56,
0x33, 0xF6,
0x85, 0xC0,
0xC6, 0x05, null, null, null, null, 0x01,
0xC7, 0x05, null, null, null, null, 0x00, 0x00, 0x00, 0x00,
0xB9, null, null, null, null,
0x76, 0x10,
0xA1, null, null, null, null,
0x85, 0xC0,
0x74, 0x05,
0x8D, 0x70, 0xF8,
0xEB, 0x02,
0x33, 0xF6,
0x85, 0xF6,
0x89, 0x4C, 0x24, 0x08,
0x74, 0x20,
];
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void RenderObjectsD();
private static RenderObjectsD? _original;
private static RenderObjectsD? _detour;
private static IntPtr _target;
private static long _calls;
/// <summary>True once the hook is live. Read on AC's render thread every frame.</summary>
public static volatile bool IsInstalled;
public static string Status { get; private set; } = "not installed";
/// <summary>AC UI passes seen since install (diagnostics).</summary>
public static long Calls => Interlocked.Read(ref _calls);
/// <summary>InitWorker step. Resolves and hooks RenderUI::RenderObjects. Idempotent.</summary>
public static void Initialize()
{
if (IsInstalled) return;
if (!AcClientModule.TryReadTextSection(out AcClientTextSection text))
{
Status = "acclient.exe not available";
return;
}
var r = HookResolver.Resolve(text, "AcUiPassHook.RenderUI::RenderObjects",
RenderObjectsPattern, RenderObjectsFallbackVa);
if (!r.Success)
{
Status = $"not resolved ({r.Detail}); overlays use the ZENABLE transition";
RynthLog.Compat($"AcUiPassHook: {Status}");
return;
}
try
{
_target = r.Address;
_detour = Detour;
IntPtr detourPtr = Marshal.GetFunctionPointerForDelegate(_detour);
_original = Marshal.GetDelegateForFunctionPointer<RenderObjectsD>(MinHook.HookCreate(_target, detourPtr));
Thread.MemoryBarrier();
MinHook.Enable(_target);
IsInstalled = true;
Status = $"hooked RenderUI::RenderObjects @ 0x{_target.ToInt32():X8} ({r.Detail})";
RynthLog.Compat($"AcUiPassHook: {Status}");
}
catch (Exception ex)
{
Status = $"install failed: {ex.Message}";
RynthLog.Compat($"AcUiPassHook: install threw {ex.GetType().Name}: {ex.Message}");
}
}
/// <summary>
/// Engine shutdown / hot reload (lifecycle thread), before the render-side teardown:
/// stops the detour drawing at once, then disables the hook. Idempotent.
/// </summary>
public static void Uninstall()
{
if (!IsInstalled) return;
IsInstalled = false; // the detour checks this first: no overlay draw from here on
Thread.MemoryBarrier();
int status = MinHook.MH_DisableHook(_target);
Status = $"uninstalled (disable = {MinHook.StatusString(status)})";
RynthLog.Compat($"AcUiPassHook: {Status}");
}
private static void Detour()
{
Interlocked.Increment(ref _calls);
if (IsInstalled && !EngineLifecycle.IsShuttingDown)
{
try { Nav3DRenderInjector.OnAcUiPass(); }
catch { /* never let an overlay problem take AC's UI pass down */ }
}
_original!();
}
}

View file

@ -1,8 +1,22 @@
// ═══════════════════════════════════════════════════════════════════════════
// RynthCore.Engine — D3D9/Nav3DRenderInjector.cs
// Hooks DrawIndexedPrimitive to inject nav marker rendering at the
// 3D→UI boundary. When ZENABLE transitions from 1→0, renders markers
// so they appear after the 3D world but before the game's UI pass.
// Where the world overlays (Nav3D markers, then UnderUiLayer's nameplates and
// combat text) draw in AC's frame: after AC's 3D world, before AC's 2D UI.
// At most once per frame (one flag for every path).
//
// Paths, in order of preference (WorldLayerMode.Auto):
// UI pass AcUiPassHook: the entry of AC's RenderUI::RenderObjects, after
// all 3D including the alpha-sorted foliage/effects list. One
// call per frame; the DrawIndexedPrimitive hook below is then
// switched OFF (no per-draw cost).
// Transition only when the UI-pass hook isn't installed: the DIP hook spots
// ZENABLE going 1->0 after 3D draws. Known to fire too early
// outdoors (AC's sky pass after the landblocks draws with Z off,
// before the alpha list), so foliage can cover the overlays.
// EndScene the fallback (EngineFrameController): a frame where neither
// fired (no AC UI this frame, portal space, a loading screen).
// "/rc worldlayer" reports the path and counters, and "/rc worldlayer
// auto|uipass|transition|endscene" forces a path for the session (A/B checks).
// ═══════════════════════════════════════════════════════════════════════════
using System;
@ -12,6 +26,19 @@ using RynthCore.Engine.Hooking;
namespace RynthCore.Engine.D3D9;
/// <summary>Where the world overlays draw. Session only (/rc worldlayer); Auto at every start.</summary>
internal enum WorldLayerMode
{
/// <summary>UI pass when the hook is installed, else the ZENABLE transition.</summary>
Auto,
/// <summary>Only at AC's UI pass (EndScene fallback otherwise).</summary>
UiPass,
/// <summary>Only at the first ZENABLE 1->0 transition (the pre-2026-10-04 behaviour).</summary>
Transition,
/// <summary>Always at EndScene (over AC's UI): for comparison only.</summary>
EndScene,
}
internal static class Nav3DRenderInjector
{
private const uint D3DRS_ZENABLE = 7;
@ -23,7 +50,9 @@ internal static class Nav3DRenderInjector
private static DrawIndexedPrimitiveD? _originalDIP;
private static DrawIndexedPrimitiveD? _hookDelegate;
private static IntPtr _dipTarget;
private static bool _hookInstalled;
private static bool _dipEnabled;
private static bool _inRender;
// Per-frame transition detection
@ -31,8 +60,24 @@ internal static class Nav3DRenderInjector
private static bool _markersRenderedThisFrame;
private static bool _seen3D;
// Frames whose overlays drew at each place (diagnostics; AC's render thread).
private static long _atUiPass, _atTransition, _atEndScene;
/// <summary>Session override, set by /rc worldlayer (any thread; read on AC's render thread).</summary>
public static volatile WorldLayerMode Mode = WorldLayerMode.Auto;
/// <summary>The world overlays already drew this frame (any path).</summary>
public static bool RenderedThisFrame => _markersRenderedThisFrame;
/// <summary>True while the overlays themselves are drawing (the draw hooks ignore those draws).</summary>
internal static bool InOverlayRender => _inRender;
private static bool UseUiPass =>
Mode == WorldLayerMode.UiPass || (Mode == WorldLayerMode.Auto && AcUiPassHook.IsInstalled);
private static bool UseTransition =>
Mode == WorldLayerMode.Transition || (Mode == WorldLayerMode.Auto && !AcUiPassHook.IsInstalled);
public static void ResetFrame()
{
_markersRenderedThisFrame = false;
@ -55,6 +100,8 @@ internal static class Nav3DRenderInjector
MinHook.HookCreate(addr, hookPtr));
Thread.MemoryBarrier();
MinHook.Enable(addr);
_dipTarget = addr;
_dipEnabled = true;
_hookInstalled = true;
RynthLog.D3D9("Nav3DRenderInjector: DrawIndexedPrimitive hook installed.");
@ -65,6 +112,97 @@ internal static class Nav3DRenderInjector
}
}
/// <summary>
/// Frame boundary (end of EndScene, AC's render thread): the DIP hook runs only
/// when the transition path needs it. With the UI-pass hook live it is switched
/// off, so AC's draws pay nothing.
/// </summary>
public static void SyncHookState()
{
// Teardown: AcUiPassHook.Uninstall flips Auto to "transition"; don't re-patch then.
if (!_hookInstalled || EngineLifecycle.IsShuttingDown) return;
bool want = UseTransition;
if (want == _dipEnabled) return;
int status = want ? MinHook.MH_EnableHook(_dipTarget) : MinHook.MH_DisableHook(_dipTarget);
if (status == MinHook.MH_OK || status == MinHook.MH_ERROR_ENABLED || status == MinHook.MH_ERROR_DISABLED)
{
_dipEnabled = want;
RynthLog.D3D9($"Nav3DRenderInjector: DrawIndexedPrimitive hook {(want ? "enabled" : "disabled")} " +
$"(world overlays: {DescribePath()}).");
}
else if (want)
{
RynthLog.D3D9($"Nav3DRenderInjector: re-enabling the DrawIndexedPrimitive hook failed ({MinHook.StatusString(status)}).");
}
else
{
// Couldn't switch it off: harmless, the detour returns early when not needed.
_dipEnabled = true;
}
}
/// <summary>AcUiPassHook: AC's RenderUI::RenderObjects is about to draw AC's 2D UI.</summary>
public static void OnAcUiPass()
{
if (!UseUiPass) return;
IntPtr dev = ImGuiBackend.EngineFrameController.CachedDevice;
if (dev == IntPtr.Zero) return;
if (PresentWorldOverlays(dev, sceneViewport: true))
_atUiPass++;
}
/// <summary>
/// EngineFrameController, EndScene, before the ImGui panels: draws the overlays
/// when no earlier path did this frame, then closes the frame for them (the ImGui
/// panels' own draws can't trigger the transition path afterwards).
/// </summary>
public static void PresentAtEndScene(IntPtr dev)
{
if (_markersRenderedThisFrame || dev == IntPtr.Zero) return;
_markersRenderedThisFrame = true;
_inRender = true;
try { ImGuiBackend.DX9Backend.RenderNav3D(dev); }
catch { }
try { ImGuiBackend.UnderUiLayer.PresentFallback(dev); }
catch { }
_inRender = false;
_atEndScene++;
}
/// <summary>Draws the Nav3D markers, then the world overlays, once per frame. False: not drawn here.</summary>
private static bool PresentWorldOverlays(IntPtr dev, bool sceneViewport)
{
if (_markersRenderedThisFrame) return false;
// Decal clients: VVS/Decal/UB draw 3D into their own render targets too; only AC's
// back buffer gets the markers and nameplates (measured 2026-09-30: without this they
// showed up inside a Virindi window). Checked once per frame, only with Decal.
if (DecalD3D9.Enabled && !ImGuiBackend.DX9Backend.IsRenderingToBackBuffer(dev)) return false;
_markersRenderedThisFrame = true;
_inRender = true;
try
{
// At the UI pass AC has set a full-screen viewport; the markers project
// with the 3D view's (captured at the last EndScene).
ImGuiBackend.DX9Backend.RenderNav3D(dev, sceneViewport);
}
catch
{
}
// The world overlays (nameplates, combat text) go here too, over the
// markers and under AC's UI. UnderUiLayer presents a list at most once.
try
{
if (sceneViewport) ImGuiBackend.UnderUiLayer.PresentAtUiPass(dev);
else ImGuiBackend.UnderUiLayer.PresentAtTransition(dev);
}
catch
{
}
_inRender = false;
return true;
}
private static int Detour(IntPtr dev, uint primitiveType,
int baseVertexIndex, uint minVertexIndex, uint numVertices,
uint startIndex, uint primCount)
@ -73,37 +211,20 @@ internal static class Nav3DRenderInjector
return _originalDIP!(dev, primitiveType, baseVertexIndex,
minVertexIndex, numVertices, startIndex, primCount);
if (!UseTransition)
return _originalDIP!(dev, primitiveType, baseVertexIndex,
minVertexIndex, numVertices, startIndex, primCount);
ImGuiBackend.DX9Backend.DeviceGetRenderState(dev, D3DRS_ZENABLE, out uint zEnable);
if (zEnable != 0)
_seen3D = true;
// Detect 3D→UI transition: ZENABLE goes from 1→0 after 3D draws
// Decal clients: VVS/Decal/UB draw 3D into their own render targets too; only AC's
// back buffer gets the markers and nameplates (measured 2026-09-30: without this they
// showed up inside a Virindi window). Evaluated only at a transition, and only with Decal.
if (!_markersRenderedThisFrame && _seen3D && _lastZEnable != 0 && zEnable == 0 &&
(!DecalD3D9.Enabled || ImGuiBackend.DX9Backend.IsRenderingToBackBuffer(dev)))
if (!_markersRenderedThisFrame && _seen3D && _lastZEnable != 0 && zEnable == 0)
{
_markersRenderedThisFrame = true;
_inRender = true;
try
{
ImGuiBackend.DX9Backend.RenderNav3D(dev);
}
catch
{
}
// The world overlays (nameplates, combat text) go here too, over the
// markers and under AC's UI. Its own frame flag: drawn at most once.
try
{
ImGuiBackend.UnderUiLayer.PresentAtTransition(dev);
}
catch
{
}
_inRender = false;
if (PresentWorldOverlays(dev, sceneViewport: false))
_atTransition++;
}
_lastZEnable = zEnable;
@ -111,4 +232,19 @@ internal static class Nav3DRenderInjector
return _originalDIP!(dev, primitiveType, baseVertexIndex,
minVertexIndex, numVertices, startIndex, primCount);
}
/// <summary>The path the overlays use now, for status lines.</summary>
public static string DescribePath() => Mode switch
{
WorldLayerMode.UiPass => AcUiPassHook.IsInstalled ? "AC UI pass (forced)" : "AC UI pass (forced, hook missing: EndScene)",
WorldLayerMode.Transition => _hookInstalled ? "ZENABLE 1->0 transition (forced)" : "ZENABLE transition (forced, DIP hook missing: EndScene)",
WorldLayerMode.EndScene => "EndScene (forced, over AC's UI)",
_ => AcUiPassHook.IsInstalled ? "AC UI pass (auto)" : "ZENABLE 1->0 transition (auto: UI-pass hook not installed)",
};
/// <summary>One line for /rc worldlayer status and /rc imgui diag.</summary>
public static string Describe() =>
$"world overlays: {DescribePath()}; frames drawn at UI pass {_atUiPass}, at transition {_atTransition}, " +
$"at EndScene {_atEndScene}; DIP hook {(_hookInstalled ? (_dipEnabled ? "on" : "off") : "not installed")}; " +
$"UI-pass hook: {AcUiPassHook.Status}, {AcUiPassHook.Calls} calls";
}