fix(engine): keep off-thread int reads current with server property updates

Patch the appraisal cache from PublicUpdateProperty messages and fall back to the update cache off-thread, so a refilled pet essence no longer reads 0 charges from a stale ID snapshot.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
BlankenshipG 2026-10-04 23:46:20 -04:00
commit ccfa22af09
4 changed files with 83 additions and 2 deletions

View file

@ -129,6 +129,30 @@ internal static class AppraisalHooks
}
}
/// <summary>
/// Applies a later server property update to an already-appraised object so the cache
/// doesn't keep serving the value from the last ID. Objects never appraised are left
/// alone (the update cache covers them).
/// </summary>
public static void PatchCachedInt(uint guid, uint stype, int value)
{
lock (_cacheLock)
{
if (_intCache.TryGetValue(guid, out Dictionary<uint, int>? props))
props[stype] = value;
}
}
/// <summary>Bool counterpart of <see cref="PatchCachedInt"/>.</summary>
public static void PatchCachedBool(uint guid, uint stype, bool value)
{
lock (_cacheLock)
{
if (_boolCache.TryGetValue(guid, out Dictionary<uint, bool>? props))
props[stype] = value;
}
}
/// <summary>
/// Returns a bool property from the last server appraisal for this object.
/// Only populated after the player has identified the item (RequestId).

View file

@ -1991,9 +1991,10 @@ internal static class ClientObjectHooks
// Deep-audit finding #24 (2026-06-18): never touch AC memory off-thread here. PWD-backed
// stypes were handled above (live on the main thread, snapshot off-thread); InqInt
// walks qualities and stays main-thread-only.
// walks qualities and stays main-thread-only. Off-thread, the network update cache
// (a managed ConcurrentDictionary) still answers for never-appraised objects.
if (!MainThreadGuard.IsOnMainThread())
return false;
return PropertyUpdateHooks.TryGetCachedIntProperty(objectId, stype, out value);
// CBaseQualities::InqInt for stypes not in PWD.
if (_inqInt == null)

View file

@ -325,11 +325,15 @@ internal static class PropertyUpdateHooks
{
var props = _intCache.GetOrAdd(guid, _ => new ConcurrentDictionary<uint, int>());
props[stype] = value;
// The appraisal snapshot is read first off-thread; keep it current (e.g. an essence's
// Structure after a refill or summon) instead of serving the value from the last ID.
AppraisalHooks.PatchCachedInt(guid, stype, value);
}
private static void CacheBool(uint guid, uint stype, int value)
{
var props = _boolCache.GetOrAdd(guid, _ => new ConcurrentDictionary<uint, int>());
props[stype] = value;
AppraisalHooks.PatchCachedBool(guid, stype, value != 0);
}
}