Add salvage, appraisal, account, teleport hooks and expand engine API

New hooks:
- AppraisalHooks: hook CM_Examine::SendNotice_SetAppraiseInfo (0x006B05B0) to
  cache bool properties from server appraisal data; fixes wobjectgetboolprop
  returning 0 for inventory items whose m_pQualities is null in client memory
- SalvageHooks: hook gmSalvageUI::OpenSalvagePanel to capture singleton instance
  for use by SalvagePanelAddItem and SalvagePanelExecute
- AccountHooks: capture account name and world/server name from login flow
- TeleportStateHooks: track teleport/portal state via SmartBox

ClientObjectHooks: check AppraisalHooks cache before CBaseQualities::InqBool in
TryGetObjectBoolProperty so identified inventory items return correct values

API v40 additions (PluginContract / PluginManager / PluginSdk):
- GetCurrentCombatMode: direct read from ClientCombatSystem without hook
- SalvagePanelOpen / SalvagePanelAddItem / SalvagePanelExecute
- GetVitae: reads vitae multiplier via CACQualities::GetVitaeValue
- GetAccountName / GetWorldName
- GetObjectWcid: reads PublicWeenieDesc._wcid fast path

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
tombohar 2026-04-12 00:27:17 -04:00
commit c2ca425f87
12 changed files with 1161 additions and 12 deletions

View file

@ -125,6 +125,9 @@ internal struct RynthCoreAPI
/// <summary>Function pointer: int GetPlayerPose(uint* objCellId, float* x, float* y, float* z, float* qw, float* qx, float* qy, float* qz)</summary>
public IntPtr GetPlayerPoseFn;
/// <summary>Function pointer: int IsPortaling() — returns 1 if SmartBox::teleport_in_progress, 0 otherwise</summary>
public IntPtr IsPortalingFn;
/// <summary>Function pointer: int SetMotion(uint motion, int enabled)</summary>
public IntPtr SetMotionFn;
@ -301,12 +304,71 @@ internal struct RynthCoreAPI
/// creates new stacks instead of merging, so AutoStack must use this entry point.
/// </summary>
public IntPtr MergeStackInternalFn;
/// <summary>
/// Function pointer: int GetCurrentCombatMode()
/// Reads the current combat mode directly from ClientCombatSystem in AC memory.
/// Returns 1=NonCombat, 2=Melee, 4=Missile, 8=Magic.
/// </summary>
public IntPtr GetCurrentCombatModeFn;
/// <summary>
/// Function pointer: int SalvagePanelOpen(uint toolId)
/// Calls CM_Inventory::SendNotice_OpenSalvagePanel to open the salvage panel
/// for the given salvage tool. Returns 1 on success. The panel opens
/// asynchronously — wait ~400 ms before calling SalvagePanelAddItem.
/// </summary>
public IntPtr SalvagePanelOpenFn;
/// <summary>
/// Function pointer: int SalvagePanelAddItem(uint itemId)
/// Calls gmSalvageUI::AddNewItem to add an item to the open salvage panel.
/// Requires the panel to have been opened at least once.
/// Returns 1 on success, 0 if the gmSalvageUI instance is not yet captured.
/// </summary>
public IntPtr SalvagePanelAddItemFn;
/// <summary>
/// Function pointer: int SalvagePanelExecute()
/// Calls gmSalvageUI::Salvage to execute the salvage operation.
/// Requires the panel to have been opened at least once.
/// Returns 1 on success, 0 if the gmSalvageUI instance is not yet captured.
/// </summary>
public IntPtr SalvagePanelExecuteFn;
/// <summary>
/// Function pointer: float GetVitae(uint playerId)
/// Returns the player's vitae multiplier via CACQualities::GetVitaeValue.
/// 1.0 = no vitae, 0.95 = 5% penalty. Returns 1.0 if unavailable.
/// </summary>
public IntPtr GetVitaeFn;
/// <summary>
/// Function pointer: const char* GetAccountName()
/// Returns a pointer to the cached ANSI account name string, or IntPtr.Zero if not available.
/// The pointer is valid until the next call.
/// </summary>
public IntPtr GetAccountNameFn;
/// <summary>
/// Function pointer: const char* GetWorldName()
/// Returns a pointer to the cached UTF-8 world/server name string, or IntPtr.Zero if not available.
/// The pointer is valid until the next call.
/// </summary>
public IntPtr GetWorldNameFn;
/// <summary>
/// Function pointer: uint GetObjectWcid(uint objectId)
/// Returns the Weenie Class ID (WCID) from PublicWeenieDesc._wcid for the given object.
/// Returns 0 if the object is not found or the phys_obj offset is not yet probed.
/// </summary>
public IntPtr GetObjectWcidFn;
}
/// <summary>Current API version. Bump when adding fields to RynthCoreAPI.</summary>
internal static class PluginContractVersion
{
public const uint Current = 34;
public const uint Current = 40;
}
internal static class ClientActionHookFlags
@ -433,6 +495,9 @@ internal delegate int NativeAttackCallbackDelegate(int attackHeight, float power
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int IsPlayerReadyCallbackDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int IsPortalingCallbackDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void SetFpsLimitCallbackDelegate(int enabled, int focusedFps, int backgroundFps);
@ -615,3 +680,27 @@ internal unsafe delegate int GetContainerContentsCallbackDelegate(uint container
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate int GetObjectOwnershipInfoCallbackDelegate(uint objectId, uint* containerID, uint* wielderID, uint* location);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int GetCurrentCombatModeCallbackDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int SalvagePanelOpenCallbackDelegate(uint toolId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int SalvagePanelAddItemCallbackDelegate(uint itemId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int SalvagePanelExecuteCallbackDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate float GetVitaeCallbackDelegate(uint playerId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate IntPtr GetAccountNameCallbackDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate IntPtr GetWorldNameCallbackDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate uint GetObjectWcidCallbackDelegate(uint objectId);

View file

@ -46,6 +46,9 @@ internal static class PluginManager
private const int MaxPendingStopViewingObjectContents = 128;
private const int MaxPendingUpdateHealth = 512;
private const int MaxPendingEnchantmentEvents = 256;
private const int MaxPrePluginCreateObjects = 4096;
private static readonly Queue<uint> _prePluginCreateObjects = new();
private static readonly object PrePluginCreateObjectsLock = new();
private static readonly List<LoadedPlugin> _plugins = new();
private static readonly Queue<PendingIncomingChat> _pendingIncomingChats = new();
private static readonly Queue<PendingBusyCountIncremented> _pendingBusyCountIncremented = new();
@ -123,6 +126,7 @@ internal static class PluginManager
private static MergeStackInternalCallbackDelegate? _mergeStackInternalCallback;
private static WriteToChatCallbackDelegate? _writeToChatCallback;
private static GetPlayerPoseCallbackDelegate? _getPlayerPoseCallback;
private static IsPortalingCallbackDelegate? _isPortalingCallback;
private static GetObjectNameCallbackDelegate? _getObjectNameCallback;
private static GetPlayerVitalsCallbackDelegate? _getPlayerVitalsCallback;
private static GetObjectPositionCallbackDelegate? _getObjectPositionCallback;
@ -152,6 +156,16 @@ internal static class PluginManager
private static SetFpsLimitCallbackDelegate? _setFpsLimitCallback;
private static GetContainerContentsCallbackDelegate? _getContainerContentsCallback;
private static GetObjectOwnershipInfoCallbackDelegate? _getObjectOwnershipInfoCallback;
private static GetCurrentCombatModeCallbackDelegate? _getCurrentCombatModeCallback;
private static SalvagePanelOpenCallbackDelegate? _salvagePanelOpenCallback;
private static SalvagePanelAddItemCallbackDelegate? _salvagePanelAddItemCallback;
private static SalvagePanelExecuteCallbackDelegate? _salvagePanelExecuteCallback;
private static GetVitaeCallbackDelegate? _getVitaeCallback;
private static GetAccountNameCallbackDelegate? _getAccountNameCallback;
private static GetWorldNameCallbackDelegate? _getWorldNameCallback;
private static GetObjectWcidCallbackDelegate? _getObjectWcidCallback;
private static IntPtr _accountNameScratchPtr;
private static IntPtr _worldNameScratchPtr;
[ThreadStatic] private static IntPtr _objectNameScratchPtr;
private static string _pluginsDir = "";
private static string _shadowRootDir = "";
@ -208,6 +222,29 @@ internal static class PluginManager
InitializeLoadedPlugins();
DispatchUIInitializedToLoadedPlugins();
DispatchLoginCompleteToLoadedPlugins();
ReplayPrePluginCreateObjects();
}
private static void ReplayPrePluginCreateObjects()
{
uint[] prePending;
lock (PrePluginCreateObjectsLock)
{
if (_prePluginCreateObjects.Count == 0) return;
prePending = _prePluginCreateObjects.ToArray();
// Do NOT clear — keep accumulating so hot-reloads can replay the full snapshot.
}
RynthLog.Plugin($"PluginManager: Replaying {prePending.Length} pre-plugin CreateObject event(s).");
lock (PendingCreateObjectsLock)
{
foreach (uint objectId in prePending)
{
if (_pendingCreateObjects.Count >= MaxPendingCreateObjects)
_pendingCreateObjects.Dequeue();
_pendingCreateObjects.Enqueue(new PendingCreateObject(objectId));
}
}
}
public static void RequestRescan()
@ -416,6 +453,14 @@ internal static class PluginManager
public static void QueueCreateObject(uint objectId)
{
// Always buffer for replay — covers the race between hook install and plugin load
lock (PrePluginCreateObjectsLock)
{
if (_prePluginCreateObjects.Count >= MaxPrePluginCreateObjects)
_prePluginCreateObjects.Dequeue();
_prePluginCreateObjects.Enqueue(objectId);
}
if (_plugins.Count == 0)
return;
@ -704,6 +749,7 @@ internal static class PluginManager
InitializeLoadedPlugins();
DispatchUIInitializedToLoadedPlugins();
DispatchLoginCompleteToLoadedPlugins();
ReplayPrePluginCreateObjects();
}
private static void DispatchQueuedChatWindowText()
@ -1455,6 +1501,12 @@ internal static class PluginManager
CombatActionHooks.RequestId(playerId);
RynthLog.Plugin($"PluginManager: sent self-identify for player 0x{playerId:X8} to seed max vitals.");
}
// Sync the actual current combat mode to newly initialized plugins.
// Reads directly from ClientCombatSystem so this is accurate even at first inject.
int actualCombatMode = CombatModeHooks.ReadCurrentCombatMode();
QueueCombatModeChange(actualCombatMode, CombatActionHooks.CombatModeNonCombat);
RynthLog.Plugin($"PluginManager: synced combat mode {actualCombatMode} to plugins.");
}
private static unsafe void EnsureHostCallbacks()
@ -1494,6 +1546,7 @@ internal static class PluginManager
_mergeStackInternalCallback ??= MergeStackInternal;
_writeToChatCallback ??= WriteToChat;
_getPlayerPoseCallback ??= GetPlayerPose;
_isPortalingCallback ??= IsPortalingCallback;
_getObjectNameCallback ??= GetObjectName;
_getPlayerVitalsCallback ??= GetPlayerVitals;
_getObjectPositionCallback ??= GetObjectPosition;
@ -1523,6 +1576,14 @@ internal static class PluginManager
_setFpsLimitCallback ??= SetFpsLimitAction;
_getContainerContentsCallback ??= GetContainerContentsAction;
_getObjectOwnershipInfoCallback ??= GetObjectOwnershipInfoAction;
_getCurrentCombatModeCallback ??= GetCurrentCombatModeAction;
_salvagePanelOpenCallback ??= SalvagePanelOpenAction;
_salvagePanelAddItemCallback ??= SalvagePanelAddItemAction;
_salvagePanelExecuteCallback ??= SalvagePanelExecuteAction;
_getVitaeCallback ??= GetVitaeAction;
_getAccountNameCallback ??= GetAccountNameAction;
_getWorldNameCallback ??= GetWorldNameAction;
_getObjectWcidCallback ??= GetObjectWcidAction;
_api.Version = PluginContractVersion.Current;
_api.LogFn = Marshal.GetFunctionPointerForDelegate(_logCallback);
@ -1558,6 +1619,7 @@ internal static class PluginManager
_api.MoveItemInternalFn = Marshal.GetFunctionPointerForDelegate(_moveItemInternalCallback);
_api.WriteToChatFn = Marshal.GetFunctionPointerForDelegate(_writeToChatCallback);
_api.GetPlayerPoseFn = Marshal.GetFunctionPointerForDelegate(_getPlayerPoseCallback);
_api.IsPortalingFn = Marshal.GetFunctionPointerForDelegate(_isPortalingCallback);
_api.GetObjectNameFn = Marshal.GetFunctionPointerForDelegate(_getObjectNameCallback);
_api.GetPlayerVitalsFn = Marshal.GetFunctionPointerForDelegate(_getPlayerVitalsCallback);
_api.GetObjectPositionFn = Marshal.GetFunctionPointerForDelegate(_getObjectPositionCallback);
@ -1589,6 +1651,14 @@ internal static class PluginManager
_api.GetObjectOwnershipInfoFn = Marshal.GetFunctionPointerForDelegate(_getObjectOwnershipInfoCallback);
_api.SplitStackInternalFn = Marshal.GetFunctionPointerForDelegate(_splitStackInternalCallback);
_api.MergeStackInternalFn = Marshal.GetFunctionPointerForDelegate(_mergeStackInternalCallback);
_api.GetCurrentCombatModeFn = Marshal.GetFunctionPointerForDelegate(_getCurrentCombatModeCallback);
_api.SalvagePanelOpenFn = Marshal.GetFunctionPointerForDelegate(_salvagePanelOpenCallback);
_api.SalvagePanelAddItemFn = Marshal.GetFunctionPointerForDelegate(_salvagePanelAddItemCallback);
_api.SalvagePanelExecuteFn = Marshal.GetFunctionPointerForDelegate(_salvagePanelExecuteCallback);
_api.GetVitaeFn = Marshal.GetFunctionPointerForDelegate(_getVitaeCallback);
_api.GetAccountNameFn = Marshal.GetFunctionPointerForDelegate(_getAccountNameCallback);
_api.GetWorldNameFn = Marshal.GetFunctionPointerForDelegate(_getWorldNameCallback);
_api.GetObjectWcidFn = Marshal.GetFunctionPointerForDelegate(_getObjectWcidCallback);
}
private static void ProbeClientHooks()
@ -1763,6 +1833,17 @@ internal static class PluginManager
return 1;
}
private static int GetCurrentCombatModeAction() => CombatModeHooks.ReadCurrentCombatMode();
private static int SalvagePanelOpenAction(uint toolId)
=> ToAbiBool(ClientHelperHooks.SalvagePanelOpen(toolId));
private static int SalvagePanelAddItemAction(uint itemId)
=> ToAbiBool(ClientHelperHooks.SalvagePanelAddItem(itemId));
private static int SalvagePanelExecuteAction()
=> ToAbiBool(ClientHelperHooks.SalvagePanelExecute());
private static unsafe int GetContainerContentsAction(uint containerId, uint* itemIds, int maxCount)
{
RynthLog.Compat($"Compat: GetContainerContentsAction ENTRY id=0x{containerId:X8} itemIds=0x{(int)itemIds:X8} maxCount={maxCount}");
@ -1983,6 +2064,51 @@ internal static class PluginManager
return ToAbiBool(ClientHelperHooks.InvokeParser(text));
}
private static int IsPortalingCallback()
{
return TeleportStateHooks.IsPortaling ? 1 : 0;
}
private static float GetVitaeAction(uint playerId)
{
return ClientObjectHooks.TryGetVitae(playerId, out float v) ? v : 1.0f;
}
private static IntPtr GetAccountNameAction()
{
if (!AccountHooks.TryGetAccountName(out string name) || string.IsNullOrEmpty(name))
return IntPtr.Zero;
if (_accountNameScratchPtr != IntPtr.Zero)
{
Marshal.FreeHGlobal(_accountNameScratchPtr);
_accountNameScratchPtr = IntPtr.Zero;
}
_accountNameScratchPtr = Marshal.StringToHGlobalAnsi(name);
return _accountNameScratchPtr;
}
private static IntPtr GetWorldNameAction()
{
if (!AccountHooks.TryGetWorldName(out string name) || string.IsNullOrEmpty(name))
return IntPtr.Zero;
if (_worldNameScratchPtr != IntPtr.Zero)
{
Marshal.FreeHGlobal(_worldNameScratchPtr);
_worldNameScratchPtr = IntPtr.Zero;
}
_worldNameScratchPtr = Marshal.StringToHGlobalAnsi(name);
return _worldNameScratchPtr;
}
private static uint GetObjectWcidAction(uint objectId)
{
return ClientObjectHooks.TryGetObjectWcid(objectId, out uint wcid) ? wcid : 0u;
}
private static unsafe int GetPlayerPose(
uint* objCellId,
float* x,