RynthCore as of 2026-10-04 (internal 843c801): RynthNav auto-travel and the navigation map, plugin API v75 (server and titles), launcher with Available plugins, download progress and the update on the front page, opt-in usage statistics, NPC names, radar colours, title-bar text size, FPS limiter, client action unlocks, release 2026.10.4.6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tom Bohar 2026-10-04 18:34:27 -04:00
commit a24ed6df7c
322 changed files with 83009 additions and 7504 deletions

View file

@ -1,36 +1,34 @@
// ============================================================================
// RynthCore.Engine - Compatibility/PropertyUpdateHooks.cs
//
// Hooks CM_Qualities network message dispatchers to cache property updates
// broadcast by the server. This solves the problem where
// CBaseQualities::InqInt/InqBool fail for static world objects (doors, signs,
// etc.) because m_pQualities is null — those objects never get a qualities
// block allocated in client memory, but the server still sends property
// update messages that are processed and discarded.
// Caches the property update messages the server sends (UpdateProperty*,
// public and private, every type) and the player's own properties from
// PlayerDescription. This solves the problem where CBaseQualities::Inq* fail
// for objects whose m_pQualities is null (doors, signs, pack items), and where
// off AC's main thread no Inq* may run at all: plugins, metas and Lua read
// from these caches instead.
//
// Hooked functions (all cdecl, from Chorizite CM.cs):
// CM_Qualities::DispatchUI_UpdateInt @ 0x006B0000
// CM_Qualities::DispatchUI_UpdateBool @ 0x006AFF00
// CM_Qualities::DispatchUI_PrivateUpdateInt @ 0x006AF960
// CM_Qualities::DispatchUI_PrivateUpdateBool@ 0x006AF880
// Sources (all on AC's main thread):
// - SmartBoxHooks.ParseGameEvent (UIQueueManager::ProcessNetBlobData) hands
// every UpdateProperty* message (0x02CD-0x02DA) to OnUpdateWire and the
// PlayerDescription (game event 0x13) to OnPlayerDescriptionWire, parsed by
// PropertyWire in ACE's exact formats. This is the one path for int64,
// float, string, data id and instance id updates (2026-09-30).
// - The older CM_Qualities::DispatchUI_Update{Int,Bool} hooks (from Chorizite
// CM.cs) stay installed: they cache int/bool updates only when the
// game-event hook is missing, so nothing is lost if it fails to install.
// CM_Qualities::DispatchUI_UpdateInt @ 0x006B0000
// CM_Qualities::DispatchUI_UpdateBool @ 0x006AFF00
// CM_Qualities::DispatchUI_PrivateUpdateInt @ 0x006AF960
// CM_Qualities::DispatchUI_PrivateUpdateBool@ 0x006AF880
//
// Eviction via:
// ECM_Physics::SendNotice_BeingDeleted @ 0x00693960
//
// Public message buffer layout:
// [0..3] sequence (uint)
// [4..7] objectGUID (uint)
// [8..11] stype (uint)
// [12..15] value (int / int-as-bool)
//
// Private message buffer layout (player implied):
// [0..3] sequence (uint)
// [4..7] stype (uint)
// [8..11] value (int / int-as-bool)
// Bounds: evicted on ECM_Physics::SendNotice_BeingDeleted @ 0x00693960,
// cleared on logout (PluginManager.DispatchPendingLogout), and pruned to the
// live objects when more than MaxObjects are cached.
// ============================================================================
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using RynthCore.Engine.Hooking;
@ -76,43 +74,226 @@ internal static class PropertyUpdateHooks
private static string _statusMessage = "Not initialized.";
private static int _hookCount; // how many of the 5 hooks succeeded
// --- Property caches ---
// guid → (stype → value)
private static readonly ConcurrentDictionary<uint, ConcurrentDictionary<uint, int>> _intCache = new();
private static readonly ConcurrentDictionary<uint, ConcurrentDictionary<uint, int>> _boolCache = new();
// --- Property caches (all under _lock) ---
// Public updates: guid → every property the server updated for it this session.
private static readonly Dictionary<uint, PropertyBag> _bags = new();
// The player: PlayerDescription's tables, then every private update (they carry no guid).
private static PropertyBag _self = new();
private static bool _selfDescribed;
private static readonly object _lock = new();
private const int MaxObjects = 4096;
private static int _updateLogCount;
public static bool IsInstalled => _hookInstalled;
public static string StatusMessage => _statusMessage;
// --- Public query API ---
// --- Public query API (any thread: dictionary reads under _lock) ---
public static bool TryGetCachedIntProperty(uint objectId, uint stype, out int value)
{
value = 0;
if (_intCache.TryGetValue(objectId, out var props))
return props.TryGetValue(stype, out value);
return false;
lock (_lock)
return _bags.TryGetValue(objectId, out PropertyBag? b) && b.Ints.TryGetValue(stype, out value);
}
public static bool TryGetCachedBoolProperty(uint objectId, uint stype, out bool value)
{
value = false;
if (_boolCache.TryGetValue(objectId, out var props))
lock (_lock)
return _bags.TryGetValue(objectId, out PropertyBag? b) && b.Bools.TryGetValue(stype, out value);
}
public static bool TryGetCachedInt64Property(uint objectId, uint stype, out long value)
{
value = 0;
lock (_lock)
return _bags.TryGetValue(objectId, out PropertyBag? b) && b.Int64s.TryGetValue(stype, out value);
}
public static bool TryGetCachedDoubleProperty(uint objectId, uint stype, out double value)
{
value = 0;
lock (_lock)
return _bags.TryGetValue(objectId, out PropertyBag? b) && b.Floats.TryGetValue(stype, out value);
}
public static bool TryGetCachedStringProperty(uint objectId, uint stype, out string value)
{
value = string.Empty;
lock (_lock)
{
if (props.TryGetValue(stype, out int raw))
if (_bags.TryGetValue(objectId, out PropertyBag? b) && b.Strings.TryGetValue(stype, out string? s))
{
value = raw != 0;
value = s;
return true;
}
return false;
}
return false;
}
public static bool TryGetCachedDataIdProperty(uint objectId, uint stype, out uint value)
{
value = 0;
lock (_lock)
return _bags.TryGetValue(objectId, out PropertyBag? b) && b.DataIds.TryGetValue(stype, out value);
}
public static bool TryGetCachedInstanceIdProperty(uint objectId, uint stype, out uint value)
{
value = 0;
lock (_lock)
return _bags.TryGetValue(objectId, out PropertyBag? b) && b.InstanceIds.TryGetValue(stype, out value);
}
// The player's own record (PlayerDescription + private updates).
public static bool TryGetSelfInt(uint stype, out int value) { lock (_lock) return _self.Ints.TryGetValue(stype, out value); }
public static bool TryGetSelfInt64(uint stype, out long value) { lock (_lock) return _self.Int64s.TryGetValue(stype, out value); }
public static bool TryGetSelfBool(uint stype, out bool value) { lock (_lock) return _self.Bools.TryGetValue(stype, out value); }
public static bool TryGetSelfFloat(uint stype, out double value) { lock (_lock) return _self.Floats.TryGetValue(stype, out value); }
public static bool TryGetSelfDataId(uint stype, out uint value) { lock (_lock) return _self.DataIds.TryGetValue(stype, out value); }
public static bool TryGetSelfInstanceId(uint stype, out uint value) { lock (_lock) return _self.InstanceIds.TryGetValue(stype, out value); }
public static bool TryGetSelfString(uint stype, out string value)
{
value = string.Empty;
lock (_lock)
{
if (!_self.Strings.TryGetValue(stype, out string? s)) return false;
value = s;
return true;
}
}
/// <summary>True once this session's PlayerDescription was read.</summary>
public static bool HasPlayerDescription
{
get { lock (_lock) return _selfDescribed; }
}
public static int CachedObjectCount
{
get { lock (_lock) return _bags.Count; }
}
public static int SelfPropertyCount
{
get { lock (_lock) return _self.Count; }
}
/// <summary>Evict all cached properties for an object (e.g. when it is destroyed).</summary>
public static void EvictObject(uint objectId)
{
_intCache.TryRemove(objectId, out _);
_boolCache.TryRemove(objectId, out _);
lock (_lock)
_bags.Remove(objectId);
}
/// <summary>Logout: nothing here survives the session (guids and the player change).</summary>
public static void ClearSession()
{
lock (_lock)
{
_bags.Clear();
_self = new PropertyBag();
_selfDescribed = false;
}
ClientObjectHooks.ClearPlayerQualitiesSnapshot();
}
// --- Wire entry points (AC's main thread, SmartBoxHooks.ParseGameEvent) ---
/// <summary>One UpdateProperty* message (0x02CD-0x02DA), from its opcode on.</summary>
internal static unsafe void OnUpdateWire(IntPtr data, int size)
{
if (data == IntPtr.Zero || size < 9)
return;
if (PropertyWire.TryParsePropertyUpdate(new ReadOnlySpan<byte>((void*)data, size), out PropertyUpdate u))
Apply(u);
}
/// <summary>The player's PlayerDescription (game event 0x13), from its event type on.</summary>
internal static unsafe void OnPlayerDescriptionWire(IntPtr data, int size)
{
if (data == IntPtr.Zero || size < 12)
return;
if (!PropertyWire.TryParsePlayerDescription(new ReadOnlySpan<byte>((void*)data, size), out PropertyBag bag, out bool truncated))
return;
lock (_lock)
{
// Private updates that raced ahead of the description are newer: keep them on top.
bag.MergeFrom(_self);
_self = bag;
_selfDescribed = true;
}
RynthLog.Compat($"Compat: PlayerDescription properties int={bag.Ints.Count} int64={bag.Int64s.Count} bool={bag.Bools.Count} " +
$"float={bag.Floats.Count} string={bag.Strings.Count} did={bag.DataIds.Count} iid={bag.InstanceIds.Count}{(truncated ? " TRUNCATED" : "")}");
}
/// <summary>
/// Files one update: a private one into the player's record, a public one under its object;
/// either way it is also folded into that object's identify record so the appraisal cache
/// (read first) doesn't serve a stale value.
/// </summary>
internal static void Apply(in PropertyUpdate u)
{
uint target;
if (u.IsPrivate)
{
lock (_lock)
_self.Apply(u);
target = ClientHelperHooks.GetPlayerId();
}
else
{
if (u.ObjectId == 0)
return;
lock (_lock)
{
if (!_bags.TryGetValue(u.ObjectId, out PropertyBag? bag))
{
if (_bags.Count >= MaxObjects)
PruneToLiveLocked();
_bags[u.ObjectId] = bag = new PropertyBag();
}
bag.Apply(u);
}
target = u.ObjectId;
}
if (target != 0)
AppraisalHooks.ApplyUpdate(target, u);
if (_updateLogCount < 8)
{
_updateLogCount++;
RynthLog.Info($"[PropUpd] {(u.IsPrivate ? "private" : "public")} {u.Kind} obj=0x{target:X8} key={u.Key} " +
$"value={(u.Kind == PropertyKind.Float ? u.Real.ToString(System.Globalization.CultureInfo.InvariantCulture) : u.Kind == PropertyKind.String ? u.Text : u.Integer.ToString(System.Globalization.CultureInfo.InvariantCulture))}");
}
}
// Caller holds _lock. Drops objects the client no longer knows (the identity walk's id list),
// or everything if that list is empty; the player's own public updates are kept.
private static void PruneToLiveLocked()
{
uint[] live = ClientObjectHooks.LiveObjectIds;
uint me = ClientHelperHooks.GetPlayerId();
if (live.Length == 0)
{
PropertyBag? mine = me != 0 && _bags.TryGetValue(me, out PropertyBag? m) ? m : null;
_bags.Clear();
if (mine != null) _bags[me] = mine;
return;
}
var keep = new HashSet<uint>(live);
var drop = new List<uint>();
foreach (uint id in _bags.Keys)
if (id != me && !keep.Contains(id))
drop.Add(id);
foreach (uint id in drop)
_bags.Remove(id);
if (_bags.Count >= MaxObjects) // everything is live: make room anyway
{
PropertyBag? mine = me != 0 && _bags.TryGetValue(me, out PropertyBag? m) ? m : null;
_bags.Clear();
if (mine != null) _bags[me] = mine;
}
}
// --- Initialization ---
@ -226,77 +407,39 @@ internal static class PropertyUpdateHooks
// --- Detour implementations ---
// The CM_Qualities dispatchers receive the message from its opcode on (acclient.exe:
// each begins `mov edx,[buf]; add buf,4; cmp edx,<its opcode>`), the same bytes
// ProcessNetBlobData hands SmartBoxHooks.ParseGameEvent - which caches every update type
// when the game-event hook is installed. These detours are the fallback for when it isn't.
private static unsafe void ApplyFromDispatcher(IntPtr buf, uint size)
{
if (SmartBoxHooks.IsGameEventHookInstalled || buf == IntPtr.Zero || size < 9 || size > 0x1000)
return;
if (PropertyWire.TryParsePropertyUpdate(new ReadOnlySpan<byte>((void*)buf, (int)size), out PropertyUpdate u))
Apply(u);
}
private static uint DetourUpdateInt(IntPtr uiPtr, IntPtr bufPtr, uint size)
{
try
{
// Public: seq(4) + guid(4) + stype(4) + value(4) = 16 bytes minimum
if (bufPtr != IntPtr.Zero && size >= 16)
{
uint guid = (uint)Marshal.ReadInt32(bufPtr + 4);
uint stype = (uint)Marshal.ReadInt32(bufPtr + 8);
int val = Marshal.ReadInt32(bufPtr + 12);
CacheInt(guid, stype, val);
}
}
catch { }
try { ApplyFromDispatcher(bufPtr, size); } catch { }
return _origUpdateInt!(uiPtr, bufPtr, size);
}
private static uint DetourUpdateBool(IntPtr uiPtr, IntPtr bufPtr, uint size)
{
try
{
// Public: seq(4) + guid(4) + stype(4) + value(4) = 16 bytes minimum
if (bufPtr != IntPtr.Zero && size >= 16)
{
uint guid = (uint)Marshal.ReadInt32(bufPtr + 4);
uint stype = (uint)Marshal.ReadInt32(bufPtr + 8);
int val = Marshal.ReadInt32(bufPtr + 12);
CacheBool(guid, stype, val);
}
}
catch { }
try { ApplyFromDispatcher(bufPtr, size); } catch { }
return _origUpdateBool!(uiPtr, bufPtr, size);
}
private static uint DetourPrivateUpdateInt(IntPtr uiPtr, IntPtr bufPtr, uint size)
{
try
{
// Private: seq(4) + stype(4) + value(4) = 12 bytes minimum
if (bufPtr != IntPtr.Zero && size >= 12)
{
uint playerId = ClientHelperHooks.GetPlayerId();
if (playerId != 0)
{
uint stype = (uint)Marshal.ReadInt32(bufPtr + 4);
int val = Marshal.ReadInt32(bufPtr + 8);
CacheInt(playerId, stype, val);
}
}
}
catch { }
try { ApplyFromDispatcher(bufPtr, size); } catch { }
return _origPrivateUpdateInt!(uiPtr, bufPtr, size);
}
private static uint DetourPrivateUpdateBool(IntPtr uiPtr, IntPtr bufPtr, uint size)
{
try
{
// Private: seq(4) + stype(4) + value(4) = 12 bytes minimum
if (bufPtr != IntPtr.Zero && size >= 12)
{
uint playerId = ClientHelperHooks.GetPlayerId();
if (playerId != 0)
{
uint stype = (uint)Marshal.ReadInt32(bufPtr + 4);
int val = Marshal.ReadInt32(bufPtr + 8);
CacheBool(playerId, stype, val);
}
}
}
catch { }
try { ApplyFromDispatcher(bufPtr, size); } catch { }
return _origPrivateUpdateBool!(uiPtr, bufPtr, size);
}
@ -311,25 +454,14 @@ internal static class PropertyUpdateHooks
{
uint objectId = (uint)Marshal.ReadInt32(idAddr);
if (objectId != 0)
{
EvictObject(objectId);
AppraisalHooks.EvictObject(objectId);
}
}
}
}
catch { }
return _origBeingDeleted!(weenieObjPtr);
}
// --- Cache helpers ---
private static void CacheInt(uint guid, uint stype, int value)
{
var props = _intCache.GetOrAdd(guid, _ => new ConcurrentDictionary<uint, int>());
props[stype] = value;
}
private static void CacheBool(uint guid, uint stype, int value)
{
var props = _boolCache.GetOrAdd(guid, _ => new ConcurrentDictionary<uint, int>());
props[stype] = value;
}
}