Add door/vendor/motion hooks, auto-ID service, and int property caching

Adds engine-side support for door interaction (DoMotion, SmartBoxSetState,
physics state, bitfield reading), vendor open/close events, automatic
object identification service, int property appraisal caching, container
item counts, and property update hooks. Cleans up verbose inventory logging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
tombohar 2026-04-14 20:24:46 -04:00
commit ccb08ecb4a
19 changed files with 1292 additions and 7 deletions

View file

@ -37,6 +37,8 @@ internal sealed class LoadedPlugin
public PluginOnUpdateObjectInventoryDelegate? OnUpdateObjectInventory { get; set; }
public PluginOnViewObjectContentsDelegate? OnViewObjectContents { get; set; }
public PluginOnStopViewingObjectContentsDelegate? OnStopViewingObjectContents { get; set; }
public PluginOnVendorOpenDelegate? OnVendorOpen { get; set; }
public PluginOnVendorCloseDelegate? OnVendorClose { get; set; }
public IntPtr OnUpdateHealthPtr { get; set; }
public PluginOnUpdateHealthDelegate? OnUpdateHealth { get; set; }
public IntPtr OnChatWindowTextPtr { get; set; }

View file

@ -101,6 +101,12 @@ internal struct RynthCoreAPI
/// <summary>Function pointer: uint GetGroundContainerId()</summary>
public IntPtr GetGroundContainerIdFn;
/// <summary>Function pointer: int GetNumContainedItems(uint objectId)</summary>
public IntPtr GetNumContainedItemsFn;
/// <summary>Function pointer: int GetNumContainedContainers(uint objectId)</summary>
public IntPtr GetNumContainedContainersFn;
/// <summary>Function pointer: int GetCurCoords(double* northSouth, double* eastWest)</summary>
public IntPtr GetCurCoordsFn;
@ -428,6 +434,22 @@ internal struct RynthCoreAPI
/// Reads a primary attribute via InqAttribute. raw=0→buffed, raw=1→base.
/// stype: 1=Strength, 2=Endurance, 3=Quickness, 4=Coordination, 5=Focus, 6=Self.</summary>
public IntPtr GetObjectAttributeFn;
/// <summary>Function pointer: int GetObjectMotionOn(uint objectId, int* isOn)
/// Returns 1 if a DoMotion On/Off state is known for the object; isOn is 1 if On (open), 0 if Off (closed).
/// Returns 0 if no motion state has been observed for this object since injection.</summary>
public IntPtr GetObjectMotionOnFn;
/// <summary>Function pointer: int GetObjectState(uint objectId, uint* state)
/// Returns 1 if a PhysicsState has been received from the server for this object; state is the raw bitfield.
/// Returns 0 if no SetState message has been observed for this object since injection.</summary>
public IntPtr GetObjectStateFn;
/// <summary>Function pointer: uint GetObjectBitfield(uint objectId)
/// Returns the PublicWeenieDesc._bitfield (ObjectDescriptionFlags) for the given object.
/// BF_DOOR = 0x1000, BF_VENDOR = 0x200, BF_CORPSE = 0x2000, etc.
/// Returns 0 if the object is not found.</summary>
public IntPtr GetObjectBitfieldFn;
}
@ -435,7 +457,7 @@ internal struct RynthCoreAPI
/// <summary>Current API version. Bump when adding fields to RynthCoreAPI.</summary>
internal static class PluginContractVersion
{
public const uint Current = 46;
public const uint Current = 49;
}
internal static class ClientActionHookFlags
@ -512,6 +534,12 @@ internal delegate void PluginOnViewObjectContentsDelegate(uint objectId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void PluginOnStopViewingObjectContentsDelegate(uint objectId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void PluginOnVendorOpenDelegate(uint vendorId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void PluginOnVendorCloseDelegate(uint vendorId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void PluginOnUpdateHealthDelegate(uint targetId, float healthRatio, uint currentHealth, uint maxHealth);
@ -801,3 +829,12 @@ internal unsafe delegate int GetObjectSkillLevelCallbackDelegate(uint objectId,
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate int GetObjectAttributeCallbackDelegate(uint objectId, uint stype, int raw, uint* value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate int GetObjectMotionOnCallbackDelegate(uint objectId, int* isOn);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate int GetObjectStateCallbackDelegate(uint objectId, uint* state);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate uint GetObjectBitfieldCallbackDelegate(uint objectId);

View file

@ -219,6 +219,14 @@ internal static class PluginLoader
if (onStopViewingObjectContentsPtr != IntPtr.Zero)
plugin.OnStopViewingObjectContents = Marshal.GetDelegateForFunctionPointer<PluginOnStopViewingObjectContentsDelegate>(onStopViewingObjectContentsPtr);
IntPtr onVendorOpenPtr = GetProcAddress(handle, "RynthPluginOnVendorOpen");
if (onVendorOpenPtr != IntPtr.Zero)
plugin.OnVendorOpen = Marshal.GetDelegateForFunctionPointer<PluginOnVendorOpenDelegate>(onVendorOpenPtr);
IntPtr onVendorClosePtr = GetProcAddress(handle, "RynthPluginOnVendorClose");
if (onVendorClosePtr != IntPtr.Zero)
plugin.OnVendorClose = Marshal.GetDelegateForFunctionPointer<PluginOnVendorCloseDelegate>(onVendorClosePtr);
IntPtr onUpdateHealthPtr = GetProcAddress(handle, "RynthPluginOnUpdateHealth");
if (onUpdateHealthPtr != IntPtr.Zero)
{
@ -356,6 +364,8 @@ internal static class PluginLoader
if (p.OnUpdateObjectInventory != null) parts.Add("inventory");
if (p.OnViewObjectContents != null) parts.Add("contents-open");
if (p.OnStopViewingObjectContents != null) parts.Add("contents-close");
if (p.OnVendorOpen != null) parts.Add("vendor-open");
if (p.OnVendorClose != null) parts.Add("vendor-close");
if (p.OnUpdateHealth != null || p.OnUpdateHealthPtr != IntPtr.Zero) parts.Add("health");
if (p.OnChatWindowText != null) parts.Add("chat-in");
if (p.OnChatBarEnter != null) parts.Add("chat-out");

View file

@ -27,6 +27,8 @@ internal static class PluginManager
private readonly record struct PendingUpdateObjectInventory(uint ObjectId);
private readonly record struct PendingViewObjectContents(uint ObjectId);
private readonly record struct PendingStopViewingObjectContents(uint ObjectId);
private readonly record struct PendingVendorOpen(uint VendorId);
private readonly record struct PendingVendorClose(uint VendorId);
private readonly record struct PendingUpdateHealth(uint TargetId, float HealthRatio, uint CurrentHealth, uint MaxHealth);
private readonly record struct PendingEnchantmentAdded(uint SpellId, double DurationSeconds);
private readonly record struct PendingEnchantmentRemoved(uint EnchantmentId);
@ -44,6 +46,8 @@ internal static class PluginManager
private const int MaxPendingUpdateObjectInventory = 128;
private const int MaxPendingViewObjectContents = 128;
private const int MaxPendingStopViewingObjectContents = 128;
private const int MaxPendingVendorOpen = 32;
private const int MaxPendingVendorClose = 32;
private const int MaxPendingUpdateHealth = 512;
private const int MaxPendingEnchantmentEvents = 256;
private const int MaxPrePluginCreateObjects = 4096;
@ -63,6 +67,8 @@ internal static class PluginManager
private static readonly Queue<PendingUpdateObjectInventory> _pendingUpdateObjectInventory = new();
private static readonly Queue<PendingViewObjectContents> _pendingViewObjectContents = new();
private static readonly Queue<PendingStopViewingObjectContents> _pendingStopViewingObjectContents = new();
private static readonly Queue<PendingVendorOpen> _pendingVendorOpen = new();
private static readonly Queue<PendingVendorClose> _pendingVendorClose = new();
private static readonly Queue<PendingUpdateHealth> _pendingUpdateHealth = new();
private static readonly Queue<PendingEnchantmentAdded> _pendingEnchantmentAdded = new();
private static readonly Queue<PendingEnchantmentRemoved> _pendingEnchantmentRemoved = new();
@ -78,6 +84,8 @@ internal static class PluginManager
private static readonly object PendingUpdateObjectInventoryLock = new();
private static readonly object PendingViewObjectContentsLock = new();
private static readonly object PendingStopViewingObjectContentsLock = new();
private static readonly object PendingVendorOpenLock = new();
private static readonly object PendingVendorCloseLock = new();
private static readonly object PendingUpdateHealthLock = new();
private static readonly object PendingEnchantmentAddedLock = new();
private static readonly object PendingEnchantmentRemovedLock = new();
@ -116,6 +124,8 @@ internal static class PluginManager
private static GetItemIdCallbackDelegate? _getPreviousSelectedItemIdCallback;
private static GetItemIdCallbackDelegate? _getPlayerIdCallback;
private static GetItemIdCallbackDelegate? _getGroundContainerIdCallback;
private static QueryHealthCallbackDelegate? _getNumContainedItemsCallback;
private static QueryHealthCallbackDelegate? _getNumContainedContainersCallback;
private static GetCurCoordsCallbackDelegate? _getCurCoordsCallback;
private static UseObjectCallbackDelegate? _useObjectCallback;
private static UseObjectOnCallbackDelegate? _useObjectOnCallback;
@ -174,6 +184,9 @@ internal static class PluginManager
private static GetObjectSpellIdsCallbackDelegate? _getObjectSpellIdsCallback;
private static GetObjectSkillLevelCallbackDelegate? _getObjectSkillBuffedCallback;
private static GetObjectAttributeCallbackDelegate? _getObjectAttributeCallback;
private static GetObjectMotionOnCallbackDelegate? _getObjectMotionOnCallback;
private static GetObjectStateCallbackDelegate? _getObjectStateCallback;
private static GetObjectBitfieldCallbackDelegate? _getObjectBitfieldCallback;
private static IntPtr _accountNameScratchPtr;
private static IntPtr _worldNameScratchPtr;
[ThreadStatic] private static IntPtr _objectNameScratchPtr;
@ -276,6 +289,8 @@ internal static class PluginManager
DispatchQueuedSmartBoxEvent();
DispatchQueuedStopViewingObjectContents();
DispatchQueuedViewObjectContents();
DispatchQueuedVendorOpen();
DispatchQueuedVendorClose();
DispatchQueuedUpdateObjectInventory();
DispatchQueuedCreateObject();
DispatchQueuedUpdateObject();
@ -525,6 +540,34 @@ internal static class PluginManager
}
}
public static void QueueVendorOpen(uint vendorId)
{
if (_plugins.Count == 0)
return;
lock (PendingVendorOpenLock)
{
if (_pendingVendorOpen.Count >= MaxPendingVendorOpen)
_pendingVendorOpen.Dequeue();
_pendingVendorOpen.Enqueue(new PendingVendorOpen(vendorId));
}
}
public static void QueueVendorClose(uint vendorId)
{
if (_plugins.Count == 0)
return;
lock (PendingVendorCloseLock)
{
if (_pendingVendorClose.Count >= MaxPendingVendorClose)
_pendingVendorClose.Dequeue();
_pendingVendorClose.Enqueue(new PendingVendorClose(vendorId));
}
}
public static void QueueUpdateHealth(uint targetId, float healthRatio, uint currentHealth, uint maxHealth)
{
if (_plugins.Count == 0)
@ -1257,6 +1300,78 @@ internal static class PluginManager
}
}
private static void DispatchQueuedVendorOpen()
{
if (!_initialized || _plugins.Count == 0)
return;
PendingVendorOpen[] pending;
lock (PendingVendorOpenLock)
{
if (_pendingVendorOpen.Count == 0)
return;
pending = _pendingVendorOpen.ToArray();
_pendingVendorOpen.Clear();
}
foreach (PendingVendorOpen evt in pending)
{
for (int i = 0; i < _plugins.Count; i++)
{
var plugin = _plugins[i];
if (!plugin.Initialized || plugin.Failed || plugin.OnVendorOpen == null)
continue;
try
{
plugin.OnVendorOpen(evt.VendorId);
}
catch (Exception ex)
{
plugin.Failed = true;
RynthLog.Plugin($"PluginManager: {plugin.DisplayName} OnVendorOpen threw {ex.GetType().Name}: {ex.Message}");
}
}
}
}
private static void DispatchQueuedVendorClose()
{
if (!_initialized || _plugins.Count == 0)
return;
PendingVendorClose[] pending;
lock (PendingVendorCloseLock)
{
if (_pendingVendorClose.Count == 0)
return;
pending = _pendingVendorClose.ToArray();
_pendingVendorClose.Clear();
}
foreach (PendingVendorClose evt in pending)
{
for (int i = 0; i < _plugins.Count; i++)
{
var plugin = _plugins[i];
if (!plugin.Initialized || plugin.Failed || plugin.OnVendorClose == null)
continue;
try
{
plugin.OnVendorClose(evt.VendorId);
}
catch (Exception ex)
{
plugin.Failed = true;
RynthLog.Plugin($"PluginManager: {plugin.DisplayName} OnVendorClose threw {ex.GetType().Name}: {ex.Message}");
}
}
}
}
private static void DispatchQueuedUpdateHealth()
{
if (!_initialized || _plugins.Count == 0)
@ -1546,6 +1661,8 @@ internal static class PluginManager
_getPreviousSelectedItemIdCallback ??= GetPreviousSelectedItemId;
_getPlayerIdCallback ??= GetPlayerId;
_getGroundContainerIdCallback ??= GetGroundContainerId;
_getNumContainedItemsCallback ??= GetNumContainedItemsAction;
_getNumContainedContainersCallback ??= GetNumContainedContainersAction;
_getCurCoordsCallback ??= GetCurCoords;
_useObjectCallback ??= UseObject;
_useObjectOnCallback ??= UseObjectOn;
@ -1604,6 +1721,9 @@ internal static class PluginManager
_getObjectSpellIdsCallback ??= GetObjectSpellIdsAction;
_getObjectSkillBuffedCallback ??= GetObjectSkillLevelAction;
_getObjectAttributeCallback ??= GetObjectAttributeAction;
_getObjectMotionOnCallback ??= GetObjectMotionOnAction;
_getObjectStateCallback ??= GetObjectStateAction;
_getObjectBitfieldCallback ??= GetObjectBitfieldAction;
_api.Version = PluginContractVersion.Current;
_api.LogFn = Marshal.GetFunctionPointerForDelegate(_logCallback);
@ -1631,6 +1751,8 @@ internal static class PluginManager
_api.GetPreviousSelectedItemIdFn = Marshal.GetFunctionPointerForDelegate(_getPreviousSelectedItemIdCallback);
_api.GetPlayerIdFn = Marshal.GetFunctionPointerForDelegate(_getPlayerIdCallback);
_api.GetGroundContainerIdFn = Marshal.GetFunctionPointerForDelegate(_getGroundContainerIdCallback);
_api.GetNumContainedItemsFn = Marshal.GetFunctionPointerForDelegate(_getNumContainedItemsCallback);
_api.GetNumContainedContainersFn = Marshal.GetFunctionPointerForDelegate(_getNumContainedContainersCallback);
_api.GetCurCoordsFn = Marshal.GetFunctionPointerForDelegate(_getCurCoordsCallback);
_api.UseObjectFn = Marshal.GetFunctionPointerForDelegate(_useObjectCallback);
_api.UseObjectOnFn = Marshal.GetFunctionPointerForDelegate(_useObjectOnCallback);
@ -1689,6 +1811,9 @@ internal static class PluginManager
_api.GetObjectSpellIdsFn = Marshal.GetFunctionPointerForDelegate(_getObjectSpellIdsCallback);
_api.GetObjectSkillBuffedFn = Marshal.GetFunctionPointerForDelegate(_getObjectSkillBuffedCallback);
_api.GetObjectAttributeFn = Marshal.GetFunctionPointerForDelegate(_getObjectAttributeCallback);
_api.GetObjectMotionOnFn = Marshal.GetFunctionPointerForDelegate(_getObjectMotionOnCallback);
_api.GetObjectStateFn = Marshal.GetFunctionPointerForDelegate(_getObjectStateCallback);
_api.GetObjectBitfieldFn = Marshal.GetFunctionPointerForDelegate(_getObjectBitfieldCallback);
}
private static void ProbeClientHooks()
@ -1938,6 +2063,22 @@ internal static class PluginManager
return 1;
}
private static unsafe int GetObjectMotionOnAction(uint objectId, int* isOn)
{
if (!DoMotionHooks.TryGetObjectMotionOn(objectId, out bool v))
return 0;
*isOn = v ? 1 : 0;
return 1;
}
private static unsafe int GetObjectStateAction(uint objectId, uint* state)
{
if (!ClientObjectHooks.TryGetObjectPhysicsState(objectId, out uint s))
return 0;
*state = s;
return 1;
}
private static unsafe int ReadPlayerEnchantmentsAction(uint* spellIds, double* expiryTimes, int maxCount)
{
return EnchantmentHooks.ReadPlayerEnchantments(spellIds, expiryTimes, maxCount);
@ -2079,6 +2220,16 @@ internal static class PluginManager
return ClientHelperHooks.GetGroundContainerId();
}
private static int GetNumContainedItemsAction(uint objectId)
{
return ClientObjectHooks.GetNumContainedItems(objectId);
}
private static int GetNumContainedContainersAction(uint objectId)
{
return ClientObjectHooks.GetNumContainedContainers(objectId);
}
private static unsafe int GetCurCoords(double* northSouth, double* eastWest)
{
if (northSouth == null || eastWest == null)
@ -2184,6 +2335,11 @@ internal static class PluginManager
return ClientObjectHooks.TryGetObjectWcid(objectId, out uint wcid) ? wcid : 0u;
}
private static uint GetObjectBitfieldAction(uint objectId)
{
return ClientObjectHooks.TryGetObjectBitfield(objectId, out uint bitfield) ? bitfield : 0u;
}
private static int HasAppraisalDataAction(uint objectId)
{
return AppraisalHooks.HasAppraisalData(objectId) ? 1 : 0;