diff --git a/src/RynthCore.App.Avalonia/AccountProfileDialog.axaml.cs b/src/RynthCore.App.Avalonia/AccountProfileDialog.axaml.cs index b6538cf..44ed1e8 100644 --- a/src/RynthCore.App.Avalonia/AccountProfileDialog.axaml.cs +++ b/src/RynthCore.App.Avalonia/AccountProfileDialog.axaml.cs @@ -55,16 +55,23 @@ internal partial class AccountProfileDialog : Window private void PopulateCharacterDropdown(string accountName, string serverName, string selectedCharacter) { List chars = LoadDetectedCharacters(accountName, serverName); - if (string.IsNullOrWhiteSpace(selectedCharacter) && chars.Count == 1) - selectedCharacter = chars[0]; // Ensure the existing saved name appears even if the scan file is empty - if (!string.IsNullOrEmpty(selectedCharacter) && !chars.Contains(selectedCharacter)) + if (!string.IsNullOrEmpty(selectedCharacter) + && selectedCharacter != LaunchAccountProfile.NoneOption + && !chars.Contains(selectedCharacter)) + { chars.Insert(0, selectedCharacter); + } + + // "(None)" sentinel at the top so users can opt out of auto-login per account + chars.Insert(0, LaunchAccountProfile.NoneOption); CharacterBox.ItemsSource = chars; - if (!string.IsNullOrEmpty(selectedCharacter) && chars.Contains(selectedCharacter)) + if (string.IsNullOrEmpty(selectedCharacter) || selectedCharacter == LaunchAccountProfile.NoneOption) + CharacterBox.SelectedItem = LaunchAccountProfile.NoneOption; + else if (chars.Contains(selectedCharacter)) CharacterBox.SelectedItem = selectedCharacter; } diff --git a/src/RynthCore.App.Avalonia/MainWindow.axaml.cs b/src/RynthCore.App.Avalonia/MainWindow.axaml.cs index 5ba19a2..8cdbaca 100644 --- a/src/RynthCore.App.Avalonia/MainWindow.axaml.cs +++ b/src/RynthCore.App.Avalonia/MainWindow.axaml.cs @@ -607,11 +607,20 @@ internal partial class MainWindow : Window } // Preserve any already-saved character name even if scan hasn't seen it yet - if (!string.IsNullOrEmpty(account.CharacterName) && !dropdownItems.Contains(account.CharacterName)) + if (!string.IsNullOrEmpty(account.CharacterName) + && account.CharacterName != LaunchAccountProfile.NoneOption + && !dropdownItems.Contains(account.CharacterName)) + { dropdownItems.Insert(0, account.CharacterName); + } + + // "(None)" at the top — selecting it opts out of auto-login for this account + dropdownItems.Insert(0, LaunchAccountProfile.NoneOption); charDropdown.ItemsSource = dropdownItems; - if (!string.IsNullOrEmpty(account.CharacterName) && dropdownItems.Contains(account.CharacterName)) + if (account.CharacterName == LaunchAccountProfile.NoneOption) + charDropdown.SelectedItem = LaunchAccountProfile.NoneOption; + else if (!string.IsNullOrEmpty(account.CharacterName) && dropdownItems.Contains(account.CharacterName)) charDropdown.SelectedItem = account.CharacterName; charDropdown.SelectionChanged += (_, _) => @@ -1595,16 +1604,26 @@ internal partial class MainWindow : Window if (!_launchTargetCharacterDropdowns.TryGetValue(account.Id, out ComboBox? dropdown)) continue; - if (!string.IsNullOrWhiteSpace(account.CharacterName) && !detectedCharacters.Contains(account.CharacterName)) + if (!string.IsNullOrWhiteSpace(account.CharacterName) + && account.CharacterName != LaunchAccountProfile.NoneOption + && !detectedCharacters.Contains(account.CharacterName)) + { detectedCharacters.Insert(0, account.CharacterName); + } + + // "(None)" at the top — selecting it opts out of auto-login for this account + detectedCharacters.Insert(0, LaunchAccountProfile.NoneOption); _suppressLaunchTargetCharacterSelectionChanged = true; try { dropdown.ItemsSource = detectedCharacters; - dropdown.SelectedItem = !string.IsNullOrWhiteSpace(account.CharacterName) && detectedCharacters.Contains(account.CharacterName) - ? account.CharacterName - : null; + if (account.CharacterName == LaunchAccountProfile.NoneOption) + dropdown.SelectedItem = LaunchAccountProfile.NoneOption; + else + dropdown.SelectedItem = !string.IsNullOrWhiteSpace(account.CharacterName) && detectedCharacters.Contains(account.CharacterName) + ? account.CharacterName + : null; } finally { @@ -1621,6 +1640,10 @@ internal partial class MainWindow : Window private string ResolveTargetCharacterForLaunch(LaunchAccountProfile account, LaunchServerProfile? server) { + // User explicitly opted out of auto-login → blank target so engine skips it. + if (account.CharacterName == LaunchAccountProfile.NoneOption) + return string.Empty; + List detectedCharacters = GetDetectedCharacters(account.AccountName, server?.Name ?? string.Empty); string bestKnownCharacter = GetPreferredCharacterName(account, server, null, null, detectedCharacters); if (!string.IsNullOrWhiteSpace(bestKnownCharacter) && diff --git a/src/RynthCore.App/LaunchAccountProfile.cs b/src/RynthCore.App/LaunchAccountProfile.cs index d89f267..ed6c24a 100644 --- a/src/RynthCore.App/LaunchAccountProfile.cs +++ b/src/RynthCore.App/LaunchAccountProfile.cs @@ -4,6 +4,11 @@ namespace RynthCore.App; internal sealed class LaunchAccountProfile { + /// Sentinel stored in CharacterName when the user has explicitly opted out of auto-login. + /// At launch time, ResolveTargetCharacterForLaunch translates this to an empty string so + /// the engine's CharacterCapture sees a blank TargetCharacter and skips auto-login entirely. + public const string NoneOption = "(None — no auto-login)"; + public string Id { get; set; } = Guid.NewGuid().ToString("N"); public string AccountName { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; @@ -15,7 +20,7 @@ internal sealed class LaunchAccountProfile { get { - string launchLabel = !string.IsNullOrWhiteSpace(CharacterName) + string launchLabel = !string.IsNullOrWhiteSpace(CharacterName) && CharacterName != NoneOption ? CharacterName : Alias; diff --git a/src/RynthCore.Engine/Compatibility/ClientActionHooks.cs b/src/RynthCore.Engine/Compatibility/ClientActionHooks.cs index ecedb46..e79042d 100644 --- a/src/RynthCore.Engine/Compatibility/ClientActionHooks.cs +++ b/src/RynthCore.Engine/Compatibility/ClientActionHooks.cs @@ -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); diff --git a/src/RynthCore.Engine/Compatibility/CommandInterpreterHooks.cs b/src/RynthCore.Engine/Compatibility/CommandInterpreterHooks.cs index 956a644..832717e 100644 --- a/src/RynthCore.Engine/Compatibility/CommandInterpreterHooks.cs +++ b/src/RynthCore.Engine/Compatibility/CommandInterpreterHooks.cs @@ -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; diff --git a/src/RynthCore.Engine/Compatibility/PlayerPhysicsHooks.cs b/src/RynthCore.Engine/Compatibility/PlayerPhysicsHooks.cs index 3d73436..3bd166f 100644 --- a/src/RynthCore.Engine/Compatibility/PlayerPhysicsHooks.cs +++ b/src/RynthCore.Engine/Compatibility/PlayerPhysicsHooks.cs @@ -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)); + + /// + /// 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. + /// + 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(ptr); + } + + try + { + maxSpeed = _getMaxSpeed(cmotionInterp); + return true; + } + catch + { + return false; + } + } + private static void WriteFloat(IntPtr address, float value) { Marshal.WriteInt32(address, BitConverter.SingleToInt32Bits(value)); diff --git a/src/RynthCore.Engine/Compatibility/RadarHooks.cs b/src/RynthCore.Engine/Compatibility/RadarHooks.cs new file mode 100644 index 0000000..df49db8 --- /dev/null +++ b/src/RynthCore.Engine/Compatibility/RadarHooks.cs @@ -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; + + /// + /// The captured gmRadarUI singleton. Zero until the radar has rendered at + /// least once this session (usually within the first frame after login). + /// + 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( + 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); + } + + /// + /// 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. + /// + 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])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; + } +} diff --git a/src/RynthCore.Engine/EntryPoint.cs b/src/RynthCore.Engine/EntryPoint.cs index c98ebdb..65c6050 100644 --- a/src/RynthCore.Engine/EntryPoint.cs +++ b/src/RynthCore.Engine/EntryPoint.cs @@ -273,6 +273,7 @@ public static class EntryPoint RunInitStep("combat-mode hooks", CombatModeHooks.Initialize); RunInitStep("teleport-state hooks", TeleportStateHooks.Initialize); RunInitStep("salvage hooks", SalvageHooks.Initialize); + RunInitStep("radar hooks", RadarHooks.Initialize); RunInitStep("do-motion hooks", DoMotionHooks.Initialize); RunInitStep("smartbox-setstate hooks", SmartBoxSetStateHooks.Initialize); RunInitStep("appraisal hooks", AppraisalHooks.Initialize); diff --git a/src/RynthCore.Engine/ImGui/ViewportPlatformBackend.cs b/src/RynthCore.Engine/ImGui/ViewportPlatformBackend.cs index 8b5db54..24993fb 100644 --- a/src/RynthCore.Engine/ImGui/ViewportPlatformBackend.cs +++ b/src/RynthCore.Engine/ImGui/ViewportPlatformBackend.cs @@ -470,14 +470,15 @@ internal static unsafe class ViewportPlatformBackend { uint flags = unchecked((uint)vp->Flags); bool noDecoration = (flags & (uint)ImGuiViewportFlags.NoDecoration) != 0; - bool noTaskbarIcon = (flags & (uint)ImGuiViewportFlags.NoTaskBarIcon) != 0; bool topMost = (flags & (uint)ImGuiViewportFlags.TopMost) != 0; uint dwStyle = noDecoration ? WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS : WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; - uint dwExStyle = noTaskbarIcon ? WS_EX_TOOLWINDOW : WS_EX_APPWINDOW; + // Always use WS_EX_TOOLWINDOW so tear-off viewports don't clutter the taskbar / Alt-Tab + // list when users run many clients. Owned by _mainHwnd so it still closes with the game. + uint dwExStyle = WS_EX_TOOLWINDOW; if (topMost) dwExStyle |= WS_EX_TOPMOST; dwExStyle |= WS_EX_NOACTIVATE; @@ -746,7 +747,16 @@ internal static unsafe class ViewportPlatformBackend break; case WM_MOUSEACTIVATE: - return new IntPtr(MA_NOACTIVATE); + { + // If AC is the foreground app, don't steal its focus — just process the click. + // If the user is tabbed out (some other app is foreground), allow Windows to + // activate this viewport so the click actually brings it to the front. + IntPtr fg = GetForegroundWindow(); + IntPtr game = Win32Backend.GameHwnd; + if (game != IntPtr.Zero && fg == game) + return new IntPtr(MA_NOACTIVATE); + break; + } case WM_NCHITTEST: { diff --git a/src/RynthCore.Engine/Plugins/PluginContract.cs b/src/RynthCore.Engine/Plugins/PluginContract.cs index 1faf08e..febc423 100644 --- a/src/RynthCore.Engine/Plugins/PluginContract.cs +++ b/src/RynthCore.Engine/Plugins/PluginContract.cs @@ -461,6 +461,30 @@ internal struct RynthCoreAPI /// Returns total subpalette count, or -1 if no data was captured for this object. /// subIds[i] is the palette DID; offsets[i] is the range-start offset (used as slot index). public IntPtr GetObjectPalettesFn; + + /// Function pointer: int CommenceJump() + /// Calls ClientCombatSystem::CommenceJump (spacebar key-down). Starts the + /// power-bar charge cycle. Pair with DoJump(autonomous) to release. + public IntPtr CommenceJumpFn; + + /// Function pointer: int DoJump(int autonomous) + /// Calls ClientCombatSystem::DoJump (spacebar key-up). Releases a jump + /// at the current power-bar level. Pass autonomous=1 for the normal + /// player-driven jump (matches keyboard behavior). + public IntPtr DoJumpFn; + + /// Function pointer: int LaunchJumpWithMotion(int shift, int w, int x, int z, int c) + /// Writes motion vector directly into CMotionInterp, calls DoJump(1), then + /// clears the motion. This is the only way to jump with forward/back/strafe + /// momentum — SetMotion does not bake velocity into the physics sim in time + /// for DoJump. Mirrors UB's UBHelper.Jumper algorithm. + public IntPtr LaunchJumpWithMotionFn; + + /// Function pointer: int GetRadarRect(int* x0, int* y0, int* x1, int* y1) + /// Returns the retail gmRadarUI element's current screen rect in pixels + /// (x0,y0 top-left, x1,y1 bottom-right exclusive). Returns 1 on success, 0 + /// if the radar has not rendered yet this session. Requires API v53+. + public IntPtr GetRadarRectFn; } @@ -468,7 +492,7 @@ internal struct RynthCoreAPI /// Current API version. Bump when adding fields to RynthCoreAPI. internal static class PluginContractVersion { - public const uint Current = 50; + public const uint Current = 53; } internal static class ClientActionHookFlags @@ -625,6 +649,15 @@ internal delegate int SetAutoRunCallbackDelegate(int enabled); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int TapJumpCallbackDelegate(); +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal delegate int CommenceJumpCallbackDelegate(); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal delegate int DoJumpCallbackDelegate(int autonomous); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal delegate int LaunchJumpWithMotionCallbackDelegate(int shift, int w, int x, int z, int c); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate int SetMotionCallbackDelegate(uint motion, int enabled); @@ -855,3 +888,6 @@ internal delegate void ForceResetBusyCountCallbackDelegate(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal unsafe delegate int GetObjectPalettesCallbackDelegate(uint objectId, uint* subIds, uint* offsets, int maxCount); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal unsafe delegate int GetRadarRectCallbackDelegate(int* x0, int* y0, int* x1, int* y1); diff --git a/src/RynthCore.Engine/Plugins/PluginManager.cs b/src/RynthCore.Engine/Plugins/PluginManager.cs index b68379f..310116d 100644 --- a/src/RynthCore.Engine/Plugins/PluginManager.cs +++ b/src/RynthCore.Engine/Plugins/PluginManager.cs @@ -113,6 +113,10 @@ internal static class PluginManager private static SetAutonomyLevelCallbackDelegate? _setAutonomyLevelCallback; private static SetAutoRunCallbackDelegate? _setAutoRunCallback; private static TapJumpCallbackDelegate? _tapJumpCallback; + private static CommenceJumpCallbackDelegate? _commenceJumpCallback; + private static DoJumpCallbackDelegate? _doJumpCallback; + private static LaunchJumpWithMotionCallbackDelegate? _launchJumpWithMotionCallback; + private static GetRadarRectCallbackDelegate? _getRadarRectCallback; private static SetMotionCallbackDelegate? _setMotionCallback; private static StopCompletelyCallbackDelegate? _stopCompletelyCallback; private static TurnToHeadingCallbackDelegate? _turnToHeadingCallback; @@ -1671,6 +1675,10 @@ internal static class PluginManager _setAutonomyLevelCallback ??= SetAutonomyLevel; _setAutoRunCallback ??= SetAutoRun; _tapJumpCallback ??= TapJump; + _commenceJumpCallback ??= CommenceJump; + _doJumpCallback ??= DoJump; + _launchJumpWithMotionCallback ??= LaunchJumpWithMotion; + _getRadarRectCallback ??= GetRadarRect; _setMotionCallback ??= SetMotion; _stopCompletelyCallback ??= StopCompletely; _turnToHeadingCallback ??= TurnToHeading; @@ -1839,6 +1847,10 @@ internal static class PluginManager _api.ForceResetBusyCountFn = Marshal.GetFunctionPointerForDelegate(_forceResetBusyCountCallback); _getObjectPalettesCallback ??= GetObjectPalettesAction; _api.GetObjectPalettesFn = Marshal.GetFunctionPointerForDelegate(_getObjectPalettesCallback); + _api.CommenceJumpFn = Marshal.GetFunctionPointerForDelegate(_commenceJumpCallback); + _api.DoJumpFn = Marshal.GetFunctionPointerForDelegate(_doJumpCallback); + _api.LaunchJumpWithMotionFn = Marshal.GetFunctionPointerForDelegate(_launchJumpWithMotionCallback); + _api.GetRadarRectFn = Marshal.GetFunctionPointerForDelegate(_getRadarRectCallback); } private static void ProbeClientHooks() @@ -2183,6 +2195,33 @@ internal static class PluginManager return ToAbiBool(ClientActionHooks.TapJump()); } + private static int CommenceJump() + { + return ToAbiBool(ClientActionHooks.CommenceJump()); + } + + private static int DoJump(int autonomous) + { + return ToAbiBool(ClientActionHooks.DoJump(autonomous != 0)); + } + + private static int LaunchJumpWithMotion(int shift, int w, int x, int z, int c) + { + return ToAbiBool(ClientActionHooks.LaunchJumpWithMotion(shift != 0, w != 0, x != 0, z != 0, c != 0)); + } + + private static unsafe int GetRadarRect(int* x0, int* y0, int* x1, int* y1) + { + if (x0 == null || y0 == null || x1 == null || y1 == null) + return 0; + + if (!RadarHooks.TryGetRadarRect(out int rx0, out int ry0, out int rx1, out int ry1)) + return 0; + + *x0 = rx0; *y0 = ry0; *x1 = rx1; *y1 = ry1; + return 1; + } + private static int SetMotion(uint motion, int enabled) { return ToAbiBool(ClientActionHooks.SetMotion(motion, enabled != 0)); diff --git a/src/RynthCore.PluginSdk/RynthCoreApiNative.cs b/src/RynthCore.PluginSdk/RynthCoreApiNative.cs index 11d83c8..9331c38 100644 --- a/src/RynthCore.PluginSdk/RynthCoreApiNative.cs +++ b/src/RynthCore.PluginSdk/RynthCoreApiNative.cs @@ -100,4 +100,8 @@ public struct RynthCoreApiNative public IntPtr GetObjectBitfieldFn; public IntPtr ForceResetBusyCountFn; public IntPtr GetObjectPalettesFn; + public IntPtr CommenceJumpFn; + public IntPtr DoJumpFn; + public IntPtr LaunchJumpWithMotionFn; + public IntPtr GetRadarRectFn; } diff --git a/src/RynthCore.PluginSdk/RynthCoreHost.cs b/src/RynthCore.PluginSdk/RynthCoreHost.cs index e41bb40..ea5c07a 100644 --- a/src/RynthCore.PluginSdk/RynthCoreHost.cs +++ b/src/RynthCore.PluginSdk/RynthCoreHost.cs @@ -100,6 +100,10 @@ public readonly unsafe struct RynthCoreHost public bool HasGetCurrentCombatMode => _api.GetCurrentCombatModeFn != IntPtr.Zero; public bool HasSalvagePanel => _api.SalvagePanelOpenFn != IntPtr.Zero && _api.SalvagePanelAddItemFn != IntPtr.Zero && _api.SalvagePanelExecuteFn != IntPtr.Zero; public bool HasGetObjectPalettes => _api.Version >= 50 && _api.GetObjectPalettesFn != IntPtr.Zero; + public bool HasCommenceJump => _api.Version >= 51 && _api.CommenceJumpFn != IntPtr.Zero; + public bool HasDoJump => _api.Version >= 51 && _api.DoJumpFn != IntPtr.Zero; + public bool HasLaunchJumpWithMotion => _api.Version >= 52 && _api.LaunchJumpWithMotionFn != IntPtr.Zero; + public bool HasGetRadarRect => _api.Version >= 53 && _api.GetRadarRectFn != IntPtr.Zero; // ─── Methods ──────────────────────────────────────────────────────────── @@ -223,6 +227,61 @@ public readonly unsafe struct RynthCoreHost ((delegate* unmanaged[Cdecl])_api.TapJumpFn)() != 0; } + /// + /// Starts a charged jump (mirrors the keyboard spacebar-down path). + /// Follow with once the desired charge time has elapsed. + /// + public bool CommenceJump() + { + return _api.CommenceJumpFn != IntPtr.Zero && + ((delegate* unmanaged[Cdecl])_api.CommenceJumpFn)() != 0; + } + + /// + /// Releases a jump begun with (mirrors the keyboard spacebar-up path). + /// Pass autonomous=true to match UB's Jumper (player-authoritative extent). + /// + public bool DoJump(bool autonomous) + { + return _api.DoJumpFn != IntPtr.Zero && + ((delegate* unmanaged[Cdecl])_api.DoJumpFn)(autonomous ? 1 : 0) != 0; + } + + /// + /// Writes forward/back/strafe motion directly into CMotionInterp, calls + /// DoJump(autonomous=1), then clears the motion — mirrors UB's UBHelper.Jumper + /// algorithm. This is the only reliable way to jump *with momentum*; SetMotion + /// does not bake velocity into the physics simulation in time for DoJump. + /// Call this *in place of* when you want a directional jump. + /// + public bool LaunchJumpWithMotion(bool shift, bool holdW, bool holdX, bool holdZ, bool holdC) + { + return _api.LaunchJumpWithMotionFn != IntPtr.Zero && + ((delegate* unmanaged[Cdecl])_api.LaunchJumpWithMotionFn)( + shift ? 1 : 0, holdW ? 1 : 0, holdX ? 1 : 0, holdZ ? 1 : 0, holdC ? 1 : 0) != 0; + } + + /// + /// Returns the retail gmRadarUI element's current screen rect in pixels + /// (x0,y0 top-left, x1,y1 bottom-right exclusive). Returns false until the + /// radar has rendered at least once this session. + /// + public bool TryGetRadarRect(out int x0, out int y0, out int x1, out int y1) + { + x0 = y0 = x1 = y1 = 0; + if (_api.GetRadarRectFn == IntPtr.Zero) + return false; + + fixed (int* x0Ptr = &x0) + fixed (int* y0Ptr = &y0) + fixed (int* x1Ptr = &x1) + fixed (int* y1Ptr = &y1) + { + return ((delegate* unmanaged[Cdecl])_api.GetRadarRectFn)( + x0Ptr, y0Ptr, x1Ptr, y1Ptr) != 0; + } + } + public bool SetMotion(uint motion, bool enabled) { return _api.SetMotionFn != IntPtr.Zero &&