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

@ -57,6 +57,8 @@ internal static class AppraisalHooks
private static readonly HashSet<uint> _appraisedGuids = new();
// Unix timestamp (seconds) of last appraisal receipt per guid
private static readonly Dictionary<uint, long> _lastIdTime = new();
// Int property cache: guid → (stype → value)
private static readonly Dictionary<uint, Dictionary<uint, int>> _intCache = new();
// Bool property cache: guid → (stype → value)
private static readonly Dictionary<uint, Dictionary<uint, bool>> _boolCache = new();
// String property cache: guid → (stype → value)
@ -86,6 +88,21 @@ internal static class AppraisalHooks
return _lastIdTime.TryGetValue(guid, out long t) ? t : 0L;
}
/// <summary>
/// Returns an int property from the last server appraisal for this object.
/// Only populated after the player has identified the item (RequestId).
/// </summary>
public static bool TryGetCachedIntProperty(uint guid, uint stype, out int value)
{
value = 0;
lock (_cacheLock)
{
if (!_intCache.TryGetValue(guid, out Dictionary<uint, int>? props))
return false;
return props.TryGetValue(stype, out value);
}
}
/// <summary>
/// Returns a bool property from the last server appraisal for this object.
/// Only populated after the player has identified the item (RequestId).
@ -175,6 +192,15 @@ internal static class AppraisalHooks
_lastIdTime[guid] = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
}
try
{
CacheIntProps(guid, profilePtr);
}
catch (Exception ex)
{
try { RynthLog.Compat($"Compat: appraisal int cache error guid=0x{guid:X8} - {ex.GetType().Name}: {ex.Message}"); } catch { }
}
try
{
CacheBoolProps(guid, profilePtr);
@ -205,6 +231,48 @@ internal static class AppraisalHooks
return result;
}
private static void CacheIntProps(uint guid, IntPtr profilePtr)
{
if (profilePtr == IntPtr.Zero)
return;
// AppraisalProfile._intStatsTable* is at offset +0x18
IntPtr intTablePtr = Marshal.ReadIntPtr(profilePtr + 0x18);
if (intTablePtr == IntPtr.Zero)
return;
// PackableHashTable<uint,int>: bucket_array at +0x8, bucket_count at +0xC
IntPtr bucketArray = Marshal.ReadIntPtr(intTablePtr + 0x08);
int bucketCount = Marshal.ReadInt32(intTablePtr + 0x0C);
if (bucketArray == IntPtr.Zero || bucketCount <= 0 || bucketCount > 65536)
return;
var props = new Dictionary<uint, int>(8);
for (int i = 0; i < bucketCount; i++)
{
IntPtr node = Marshal.ReadIntPtr(bucketArray + i * 4);
while (node != IntPtr.Zero)
{
uint key = (uint)Marshal.ReadInt32(node);
int val = Marshal.ReadInt32(node + 4);
props[key] = val;
node = Marshal.ReadIntPtr(node + 8);
}
}
if (props.Count == 0)
return;
lock (_cacheLock)
{
_intCache[guid] = props;
}
RynthLog.Compat($"Compat: cached {props.Count} int prop(s) for guid=0x{guid:X8}");
}
private static void CacheBoolProps(uint guid, IntPtr profilePtr)
{
if (profilePtr == IntPtr.Zero)