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:
parent
27d6e530e0
commit
2c3d2410a8
13 changed files with 540 additions and 15 deletions
|
|
@ -136,6 +136,21 @@ internal static class ClientActionHooks
|
|||
return CommandInterpreterHooks.TapJump();
|
||||
}
|
||||
|
||||
public static bool CommenceJump()
|
||||
{
|
||||
return CommandInterpreterHooks.CommenceJump();
|
||||
}
|
||||
|
||||
public static bool DoJump(bool autonomous)
|
||||
{
|
||||
return CommandInterpreterHooks.DoJump(autonomous);
|
||||
}
|
||||
|
||||
public static bool LaunchJumpWithMotion(bool shift, bool holdW, bool holdX, bool holdZ, bool holdC)
|
||||
{
|
||||
return PlayerPhysicsHooks.LaunchJumpWithMotion(shift, holdW, holdX, holdZ, holdC);
|
||||
}
|
||||
|
||||
public static bool SetMotion(uint motion, bool enabled)
|
||||
{
|
||||
return CommandInterpreterHooks.SetMotion(motion, enabled);
|
||||
|
|
|
|||
|
|
@ -244,6 +244,38 @@ internal static class CommandInterpreterHooks
|
|||
}
|
||||
}
|
||||
|
||||
public static bool CommenceJump()
|
||||
{
|
||||
if (!TryBindDelegates())
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
_commenceJump!(_boundCmdInterp);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DoJump(bool autonomous)
|
||||
{
|
||||
if (!TryBindDelegates())
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
_doJump!(_boundCmdInterp, autonomous ? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryBindDelegates()
|
||||
{
|
||||
IntPtr selectedStaticAddr = IntPtr.Zero;
|
||||
|
|
|
|||
|
|
@ -17,15 +17,43 @@ internal static class PlayerPhysicsHooks
|
|||
private const int ReferencePhysicsGetHeading = 0x00512010;
|
||||
private const int ReferencePhysicsSetHeading = 0x00514C60;
|
||||
|
||||
// CPhysicsObj::m_pMovementManager lives at +0xC4 (same offset UB's Jumper uses).
|
||||
// The CMotionInterp pointer is the first field of MovementManager.
|
||||
private const int MovementManagerOffset = 0xC4;
|
||||
|
||||
// CMotionInterp::get_max_speed — Chorizite RVA 0x001278C0, our client is +0x1000
|
||||
// from Chorizite (confirmed via set_heading/get_heading/CommenceJump addresses).
|
||||
private const int ReferenceGetMaxSpeed = 0x005288C0;
|
||||
|
||||
// Fields in CMotionInterp holding the "current motion command" for each
|
||||
// channel. Writing these right before DoJump tells the physics simulation
|
||||
// to launch the jump with that velocity baked in.
|
||||
private const int CMotionForwardIdOffset = 76; // 0x4C
|
||||
private const int CMotionForwardSpeedOffset = 80; // 0x50
|
||||
private const int CMotionStrafeIdOffset = 84; // 0x54
|
||||
private const int CMotionStrafeSpeedOffset = 88; // 0x58
|
||||
private const int CMotionTurnOffset = 92; // 0x5C
|
||||
|
||||
// Raw motion-command IDs the physics simulation reads from CMotionInterp.
|
||||
// Sourced from UB's UBHelper.Jumper — these are *not* the SetMotion IDs.
|
||||
private const int MotionIdForward = 0x44000007;
|
||||
private const int MotionIdBackward = 0x45000005;
|
||||
private const int MotionIdIdle = 0x41000003;
|
||||
private const int MotionIdSidestep = 0x6500000F;
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate float PhysicsGetHeadingDelegate(IntPtr physicsObjPtr);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate void PhysicsSetHeadingDelegate(IntPtr physicsObjPtr, float headingDegrees, int sendEvent);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate double GetMaxSpeedDelegate(IntPtr cmotionInterpPtr);
|
||||
|
||||
private static string _statusMessage = "Not probed yet.";
|
||||
private static PhysicsGetHeadingDelegate? _getHeading;
|
||||
private static PhysicsSetHeadingDelegate? _setHeading;
|
||||
private static GetMaxSpeedDelegate? _getMaxSpeed;
|
||||
|
||||
public static bool IsInitialized { get; private set; }
|
||||
public static bool HasGetHeading => _getHeading != null;
|
||||
|
|
@ -185,6 +213,137 @@ internal static class PlayerPhysicsHooks
|
|||
}
|
||||
}
|
||||
|
||||
public static bool HasLaunchJumpWithMotion => SmartBoxLocator.IsPointerInModule(new(ReferenceGetMaxSpeed));
|
||||
|
||||
/// <summary>
|
||||
/// Writes motion-vector fields directly into CMotionInterp, calls DoJump(1),
|
||||
/// then clears them back out. Mirrors UB's UBHelper.Jumper algorithm, minus
|
||||
/// the power-bar hook (the plugin drives timing with a ms delay).
|
||||
///
|
||||
/// This is the only reliable way to jump *with forward/back/strafe momentum*
|
||||
/// in AC — SetMotion routes through the command interpreter, which doesn't
|
||||
/// bake velocity into the physics simulation in time for DoJump.
|
||||
/// </summary>
|
||||
public static bool LaunchJumpWithMotion(bool shift, bool holdW, bool holdX, bool holdZ, bool holdC)
|
||||
{
|
||||
if (!TryGetCMotionInterp(out IntPtr cmi))
|
||||
{
|
||||
RynthLog.Compat("LaunchJumpWithMotion: CMotionInterp unavailable");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryGetMaxSpeed(cmi, out double maxSpeed))
|
||||
{
|
||||
RynthLog.Compat("LaunchJumpWithMotion: get_max_speed failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
double num = maxSpeed / 4.0;
|
||||
|
||||
IntPtr pForwardId = cmi + CMotionForwardIdOffset;
|
||||
IntPtr pForwardSpeed = cmi + CMotionForwardSpeedOffset;
|
||||
IntPtr pStrafeId = cmi + CMotionStrafeIdOffset;
|
||||
IntPtr pStrafeSpeed = cmi + CMotionStrafeSpeedOffset;
|
||||
IntPtr pTurn = cmi + CMotionTurnOffset;
|
||||
|
||||
try
|
||||
{
|
||||
// Forward/back channel
|
||||
if (holdW || holdX)
|
||||
{
|
||||
if (holdW)
|
||||
{
|
||||
Marshal.WriteInt32(pForwardId, MotionIdForward);
|
||||
WriteFloat(pForwardSpeed, shift ? 1f : (float)num);
|
||||
}
|
||||
else
|
||||
{
|
||||
Marshal.WriteInt32(pForwardId, MotionIdBackward);
|
||||
WriteFloat(pForwardSpeed, shift ? -1f : (float)(-0.65 * num));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Marshal.WriteInt32(pForwardId, MotionIdIdle);
|
||||
}
|
||||
|
||||
// Strafe channel
|
||||
if (holdZ || holdC)
|
||||
{
|
||||
Marshal.WriteInt32(pStrafeId, MotionIdSidestep);
|
||||
double s = num * 1.248;
|
||||
if (shift) s *= 0.5;
|
||||
if (s > 3.0) s = 3.0;
|
||||
WriteFloat(pStrafeSpeed, holdC ? (float)s : (float)(-s));
|
||||
}
|
||||
else
|
||||
{
|
||||
Marshal.WriteInt32(pStrafeId, 0);
|
||||
}
|
||||
|
||||
Marshal.WriteInt32(pTurn, 0);
|
||||
|
||||
bool jumped = CommandInterpreterHooks.DoJump(true);
|
||||
|
||||
// Clear immediately so the character doesn't keep walking on landing.
|
||||
if (holdZ || holdC) Marshal.WriteInt32(pStrafeId, 0);
|
||||
if (holdW || holdX) Marshal.WriteInt32(pForwardId, MotionIdIdle);
|
||||
|
||||
return jumped;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Compat($"LaunchJumpWithMotion: write failed: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetCMotionInterp(out IntPtr cmotionInterp)
|
||||
{
|
||||
cmotionInterp = IntPtr.Zero;
|
||||
|
||||
if (!SmartBoxLocator.TryGetPlayer(out IntPtr player, out _, out string failure))
|
||||
{
|
||||
_statusMessage = failure;
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr movementManager = Marshal.ReadIntPtr(player + MovementManagerOffset);
|
||||
if (movementManager == IntPtr.Zero) return false;
|
||||
cmotionInterp = Marshal.ReadIntPtr(movementManager);
|
||||
return cmotionInterp != IntPtr.Zero;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetMaxSpeed(IntPtr cmotionInterp, out double maxSpeed)
|
||||
{
|
||||
maxSpeed = 0;
|
||||
|
||||
if (_getMaxSpeed == null)
|
||||
{
|
||||
IntPtr ptr = new(ReferenceGetMaxSpeed);
|
||||
if (!SmartBoxLocator.IsPointerInModule(ptr))
|
||||
return false;
|
||||
_getMaxSpeed = Marshal.GetDelegateForFunctionPointer<GetMaxSpeedDelegate>(ptr);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
maxSpeed = _getMaxSpeed(cmotionInterp);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteFloat(IntPtr address, float value)
|
||||
{
|
||||
Marshal.WriteInt32(address, BitConverter.SingleToInt32Bits(value));
|
||||
|
|
|
|||
135
src/RynthCore.Engine/Compatibility/RadarHooks.cs
Normal file
135
src/RynthCore.Engine/Compatibility/RadarHooks.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue