Add radar rect API, jump primitives, account profile tweaks

- Hook gmRadarUI::DrawObjects to capture the UI singleton; expose
  host.TryGetRadarRect via UIElement::GetSurfaceBox (API v53).
- Plumb CommenceJump/DoJump/LaunchJumpWithMotion through
  ClientActionHooks and PlayerPhysicsHooks.
- Account profile dialog + LaunchAccountProfile adjustments.
- Viewport platform backend tweak.
This commit is contained in:
tombohar 2026-04-22 21:28:29 -04:00
commit 2c3d2410a8
13 changed files with 540 additions and 15 deletions

View file

@ -0,0 +1,135 @@
// ============================================================================
// RynthCore.Engine - Compatibility/RadarHooks.cs
//
// Hooks gmRadarUI::DrawObjects to capture the singleton 'this' pointer.
// Exposes TryGetRadarRect, which asks UIElement::GetSurfaceBox for the
// radar element's current screen rect (used to overlay dungeon walls on
// the retail radar).
//
// VA derivation (map offset + 0x00401000 = live VA):
// 000D8FE0 gmRadarUI::DrawObjects(UISurface*) → 0x004D9FE0
// 00061220 UIElement::GetSurfaceBox(Box2D*) → 0x00462220
// ============================================================================
using System;
using System.Runtime.InteropServices;
using System.Threading;
using RynthCore.Engine.Hooking;
namespace RynthCore.Engine.Compatibility;
internal static class RadarHooks
{
private const int GmRadarUIDrawObjectsVa = 0x004D9FE0;
private const int UIElementGetSurfaceBoxVa = 0x00462220;
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private delegate void GmRadarUIDrawObjectsDelegate(IntPtr thisPtr, IntPtr uiSurface);
private static GmRadarUIDrawObjectsDelegate? _originalDrawObjects;
private static GmRadarUIDrawObjectsDelegate? _drawObjectsDetour; // held alive to prevent GC
private static IntPtr _gmRadarUIInstance;
private static bool _hookInstalled;
private static string _statusMessage = "Not initialized.";
public static bool IsInstalled => _hookInstalled;
public static string StatusMessage => _statusMessage;
/// <summary>
/// The captured gmRadarUI singleton. Zero until the radar has rendered at
/// least once this session (usually within the first frame after login).
/// </summary>
public static IntPtr GmRadarUIInstance => _gmRadarUIInstance;
public static void Initialize()
{
if (_hookInstalled)
return;
if (!AcClientModule.TryReadTextSection(out AcClientTextSection textSection))
{
_statusMessage = "acclient.exe not available.";
return;
}
int funcOff = GmRadarUIDrawObjectsVa - textSection.TextBaseVa;
if (funcOff < 0 || funcOff >= textSection.Bytes.Length)
{
_statusMessage = $"gmRadarUI::DrawObjects VA out of range @ 0x{GmRadarUIDrawObjectsVa:X8}.";
RynthLog.Compat($"Compat: radar hook failed - {_statusMessage}");
return;
}
byte firstByte = textSection.Bytes[funcOff];
if (firstByte is 0x00 or 0xCC or 0xC3)
{
_statusMessage = $"gmRadarUI::DrawObjects looks invalid @ 0x{GmRadarUIDrawObjectsVa:X8} (opcode 0x{firstByte:X2}).";
RynthLog.Compat($"Compat: radar hook failed - {_statusMessage}");
return;
}
try
{
IntPtr targetAddress = new IntPtr(textSection.TextBaseVa + funcOff);
_drawObjectsDetour = DrawObjectsDetour;
IntPtr detourPtr = Marshal.GetFunctionPointerForDelegate(_drawObjectsDetour);
_originalDrawObjects = Marshal.GetDelegateForFunctionPointer<GmRadarUIDrawObjectsDelegate>(
MinHook.HookCreate(targetAddress, detourPtr));
Thread.MemoryBarrier();
MinHook.Enable(targetAddress);
_hookInstalled = true;
_statusMessage = $"Hooked gmRadarUI::DrawObjects @ 0x{targetAddress.ToInt32():X8}.";
RynthLog.Verbose($"Compat: radar hook ready @ 0x{targetAddress.ToInt32():X8}, firstByte=0x{firstByte:X2}");
}
catch (Exception ex)
{
_statusMessage = ex.Message;
RynthLog.Compat($"Compat: radar hook failed - {ex.Message}");
}
}
private static void DrawObjectsDetour(IntPtr thisPtr, IntPtr uiSurface)
{
if (thisPtr != IntPtr.Zero)
_gmRadarUIInstance = thisPtr;
_originalDrawObjects!(thisPtr, uiSurface);
}
/// <summary>
/// Returns the retail radar element's current screen rect (x0,y0,x1,y1 in
/// pixels, exclusive on x1/y1). Calls UIElement::GetSurfaceBox on the
/// captured singleton. Returns false until the radar has rendered at least
/// once, or if the rect looks invalid.
/// </summary>
public static unsafe bool TryGetRadarRect(out int x0, out int y0, out int x1, out int y1)
{
x0 = y0 = x1 = y1 = 0;
IntPtr inst = _gmRadarUIInstance;
if (inst == IntPtr.Zero)
return false;
// Box2D is four int32s laid out (x0, y0, x1, y1). GetSurfaceBox follows
// MSVC's "return struct by value" ABI: caller passes the output slot as
// the first stack argument; the callee fills it and returns the same ptr.
int* box = stackalloc int[4];
box[0] = box[1] = box[2] = box[3] = 0;
try
{
((delegate* unmanaged[Thiscall]<IntPtr, int*, int*>)UIElementGetSurfaceBoxVa)(inst, box);
}
catch
{
return false;
}
int bx0 = box[0], by0 = box[1], bx1 = box[2], by1 = box[3];
if (bx1 <= bx0 || by1 <= by0 || bx1 > 10000 || by1 > 10000 || bx0 < -1000 || by0 < -1000)
return false;
x0 = bx0; y0 = by0; x1 = bx1; y1 = by1;
return true;
}
}