Snapshot for release 2026.10.13.1 (internal 90a2f4a)
This commit is contained in:
parent
b0f9d74b21
commit
1d86acdf27
218 changed files with 24019 additions and 1517 deletions
|
|
@ -241,6 +241,24 @@ internal static class ClientObjectHooks
|
|||
private static DateTime _lastObjectIdentityPrefetchUtc = DateTime.MinValue;
|
||||
private static bool _loggedObjectIdentityServe;
|
||||
private const int ObjectIdentityPrefetchThrottleMs = 500;
|
||||
|
||||
// Create-time identity seeds. ACCObjectMaint::CreateObject receives the server's
|
||||
// PublicWeenieDesc, which already carries the object's name and ITEM_TYPE before
|
||||
// qualities/appraisal exist. The main-thread snapshot above can't resolve names for
|
||||
// ~10 s after login (qualities not populated yet), so off-thread readers fall back to
|
||||
// these seeds when the snapshot has no entry (or reports type 0). Entries live from
|
||||
// create until delete; the cap only guards against a missed delete hook.
|
||||
private static readonly object _createSeedLock = new();
|
||||
private static readonly Dictionary<uint, string> _createSeedNames = new(1024);
|
||||
private static readonly Dictionary<uint, uint> _createSeedTypes = new(1024);
|
||||
private const int CreateSeedCap = 16384;
|
||||
// PublicWeenieDesc field offsets (Chorizite Weenie.cs; same layout the PWD-direct
|
||||
// fallbacks in TryGetObjectName / TryGetItemType read from the embedded copy).
|
||||
// PwdTypeOffset is declared with the other PublicWeenieDesc offsets further down.
|
||||
private const int PwdNameOffset = 4;
|
||||
private static int _createSeedCount;
|
||||
private static bool _loggedCreateSeedServe;
|
||||
|
||||
// Every id the same walk visited, swapped whole (readers never see a half-built array).
|
||||
private static volatile uint[] _liveObjectIds = Array.Empty<uint>();
|
||||
|
||||
|
|
@ -393,6 +411,7 @@ internal static class ClientObjectHooks
|
|||
private static readonly object _weeniePtrSwapLock = new();
|
||||
private static Dictionary<uint, IntPtr> _weeniePtrFront = new(512);
|
||||
private static Dictionary<uint, IntPtr> _weeniePtrBack = new(512);
|
||||
|
||||
// Diagnostic (temporary): periodic snapshot-size log + live-read probe of
|
||||
// objects with a position but no cached name. Remove once the missing-
|
||||
// monsters cause is pinned. _diagSampleBuf preallocated to stay low-alloc.
|
||||
|
|
@ -2019,8 +2038,9 @@ internal static class ClientObjectHooks
|
|||
value = 0;
|
||||
if (pwdFieldOffset < 0 || pwdFieldOffset > 172 || (pwdFieldOffset & 3) != 0)
|
||||
return false;
|
||||
// Off-thread: served from the main-thread PWD byte snapshot, never from AC memory.
|
||||
if (!MainThreadGuard.IsOnMainThread())
|
||||
return false;
|
||||
return TryGetPwdSnapshotRawInt32(objectId, pwdFieldOffset, out value);
|
||||
if (_getWeenieObject == null)
|
||||
{
|
||||
if (!Probe() || _getWeenieObject == null)
|
||||
|
|
@ -2393,6 +2413,19 @@ internal static class ClientObjectHooks
|
|||
// Off-thread: serve from the main-thread snapshot populated by PrefetchObjectIdentity().
|
||||
if (!MainThreadGuard.IsOnMainThread())
|
||||
{
|
||||
lock (_objectIdentityCacheLock)
|
||||
{
|
||||
// A zero snapshot value means qualities weren't populated when the walk
|
||||
// ran; prefer the create-time descriptor type in that case.
|
||||
if (_objectTypeCache.TryGetValue(objectId, out typeFlags) && typeFlags != 0)
|
||||
return true;
|
||||
}
|
||||
if (TryGetCreateSeedType(objectId, out uint seeded))
|
||||
{
|
||||
typeFlags = seeded;
|
||||
return true;
|
||||
}
|
||||
// Snapshot hit with flags=0 is still an answer (static scenery often has no type).
|
||||
lock (_objectIdentityCacheLock)
|
||||
{
|
||||
if (_objectTypeCache.TryGetValue(objectId, out typeFlags))
|
||||
|
|
@ -2592,36 +2625,7 @@ internal static class ClientObjectHooks
|
|||
return TryGetPwdSnapshotInt(objectId, stype, out value);
|
||||
}
|
||||
|
||||
if (pwdFieldOffset >= 0 && _weeniePhysicsObjOffset >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr weeniePtr = _getWeenieObject(objectId);
|
||||
if (weeniePtr == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
int pwdBase = _weeniePhysicsObjOffset + 4;
|
||||
IntPtr fieldAddr = weeniePtr + pwdBase + pwdFieldOffset;
|
||||
// Page-probe BOTH ends of the 4-byte read span (mirrors
|
||||
// TryGetObjectOwnershipInfo's dual-end probe): a freed-but-decommitted
|
||||
// weenie whose field straddles a committed/decommitted page boundary is
|
||||
// an uncatchable AV under NativeAOT; the catch below only covers
|
||||
// null-page faults. All stypes served here are Marshal.ReadInt32
|
||||
// (4 bytes), so the span is [fieldAddr, fieldAddr+3].
|
||||
if (!IsReadablePointer(fieldAddr) || !IsReadablePointer(fieldAddr + 3))
|
||||
return false;
|
||||
|
||||
value = Marshal.ReadInt32(fieldAddr);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Fall through to CBaseQualities::InqInt for stypes not in PWD.
|
||||
// (IsOnMainThread already checked above, before the PWD fast path.)
|
||||
// CBaseQualities::InqInt for stypes not in PWD.
|
||||
if (_inqInt == null)
|
||||
{
|
||||
if (!Probe() || _inqInt == null)
|
||||
|
|
@ -3341,6 +3345,101 @@ internal static class ClientObjectHooks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records an object's name and ITEM_TYPE straight from the PublicWeenieDesc passed
|
||||
/// to ACCObjectMaint::CreateObject. Called from the create hook on AC's main thread,
|
||||
/// after the original returns. The descriptor is server data that exists before the
|
||||
/// object's qualities do, so this makes names/types readable off-thread immediately
|
||||
/// instead of after the first successful identity snapshot (~10 s at login).
|
||||
/// Every read is pointer-validated; a bad descriptor simply records nothing.
|
||||
/// </summary>
|
||||
internal static void SeedIdentityFromCreate(uint objectId, IntPtr weenieDesc)
|
||||
{
|
||||
if (objectId == 0 || weenieDesc == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
// PublicWeenieDesc derives from PackObj, so a real descriptor starts with an
|
||||
// acclient.exe vtable; reject anything else before reading fields.
|
||||
if (!LooksLikeAcHeapObject(weenieDesc))
|
||||
return;
|
||||
|
||||
bool gotName = TryReadPwdString(weenieDesc, PwdNameOffset, out string name);
|
||||
|
||||
uint typeFlags = 0;
|
||||
IntPtr typeAddr = weenieDesc + PwdTypeOffset;
|
||||
bool gotType = IsReadablePointer(typeAddr);
|
||||
if (gotType)
|
||||
typeFlags = unchecked((uint)Marshal.ReadInt32(typeAddr));
|
||||
|
||||
if (!gotName && (!gotType || typeFlags == 0))
|
||||
return;
|
||||
|
||||
lock (_createSeedLock)
|
||||
{
|
||||
// Safety valve for a missed delete: drop everything rather than grow forever.
|
||||
// The live snapshot covers anything still in the world.
|
||||
if (_createSeedNames.Count >= CreateSeedCap || _createSeedTypes.Count >= CreateSeedCap)
|
||||
{
|
||||
_createSeedNames.Clear();
|
||||
_createSeedTypes.Clear();
|
||||
}
|
||||
if (gotName)
|
||||
_createSeedNames[objectId] = name;
|
||||
if (gotType && typeFlags != 0)
|
||||
_createSeedTypes[objectId] = typeFlags;
|
||||
}
|
||||
|
||||
int seedNo = System.Threading.Interlocked.Increment(ref _createSeedCount);
|
||||
// First few samples let a log reader confirm the descriptor offsets resolve
|
||||
// to sensible names/types on this client build.
|
||||
if (seedNo <= 5)
|
||||
RynthLog.Compat($"[CreateSeed] #{seedNo} 0x{objectId:X8} name='{(gotName ? name : "")}' type=0x{typeFlags:X8}");
|
||||
if (!_loggedCreateSeedServe && seedNo >= 50)
|
||||
{
|
||||
_loggedCreateSeedServe = true;
|
||||
int names, types;
|
||||
lock (_createSeedLock) { names = _createSeedNames.Count; types = _createSeedTypes.Count; }
|
||||
RynthLog.Compat($"ClientObjectHooks: create-descriptor identity seeds active — {names} names, {types} types captured at CreateObject.");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Descriptor read failures are non-fatal; the periodic snapshot still runs.
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Drops create-time seeds for a deleted object (called from the delete hook).</summary>
|
||||
internal static void ForgetCreateSeed(uint objectId)
|
||||
{
|
||||
lock (_createSeedLock)
|
||||
{
|
||||
_createSeedNames.Remove(objectId);
|
||||
_createSeedTypes.Remove(objectId);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetCreateSeedName(uint objectId, out string name)
|
||||
{
|
||||
lock (_createSeedLock)
|
||||
{
|
||||
if (_createSeedNames.TryGetValue(objectId, out string? seeded) && seeded.Length > 0)
|
||||
{
|
||||
name = seeded;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
name = string.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool TryGetCreateSeedType(uint objectId, out uint typeFlags)
|
||||
{
|
||||
lock (_createSeedLock)
|
||||
return _createSeedTypes.TryGetValue(objectId, out typeFlags);
|
||||
}
|
||||
|
||||
public static bool TryGetObjectName(uint objectId, out string name)
|
||||
{
|
||||
name = string.Empty;
|
||||
|
|
@ -3356,6 +3455,10 @@ internal static class ClientObjectHooks
|
|||
return true;
|
||||
}
|
||||
}
|
||||
// Snapshot miss (login burst / object newer than the last walk): serve the
|
||||
// name captured from the create descriptor.
|
||||
if (TryGetCreateSeedName(objectId, out name))
|
||||
return true;
|
||||
name = string.Empty;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -3809,6 +3912,21 @@ internal static class ClientObjectHooks
|
|||
&& PwdLayout.TryGetInt(e.Bytes, stype, out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Off-thread read of one 4-byte PWD field by raw offset (the <see cref="TryReadPwdInt32"/>
|
||||
/// contract) from the main-thread snapshot. False for objects the last walk didn't see.
|
||||
/// </summary>
|
||||
private static bool TryGetPwdSnapshotRawInt32(uint objectId, int pwdFieldOffset, out int value)
|
||||
{
|
||||
value = 0;
|
||||
if (pwdFieldOffset < 0 || pwdFieldOffset + 4 > PwdLayout.Size)
|
||||
return false;
|
||||
if (!TryGetPwdSnapshot(objectId, out PwdEntry e))
|
||||
return false;
|
||||
value = System.Buffers.Binary.BinaryPrimitives.ReadInt32LittleEndian(((ReadOnlySpan<byte>)e.Bytes).Slice(pwdFieldOffset));
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryGetPwdSnapshotFloat(uint objectId, uint stype, out double value)
|
||||
{
|
||||
value = 0;
|
||||
|
|
@ -3830,6 +3948,16 @@ internal static class ClientObjectHooks
|
|||
&& PwdLayout.TryGetInstanceId(e.Bytes, stype, out value);
|
||||
}
|
||||
|
||||
/// <summary>The PWD snapshot has been filled at least once (AutoId: an object missing from it may still come).</summary>
|
||||
internal static bool HasPwdSnapshot
|
||||
{
|
||||
get { lock (_weeniePtrSwapLock) return _pwdFront.Count > 0; }
|
||||
}
|
||||
|
||||
/// <summary>The object holds items (ItemsCapacity, stype 6, > 0 in the PWD snapshot: a pack, a chest).</summary>
|
||||
internal static bool IsContainerInSnapshot(uint objectId) =>
|
||||
TryGetPwdSnapshotInt(objectId, 6, out int capacity) && capacity > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Off-thread helper for UpdateObjectInventoryHooks: writes the ids whose PWD
|
||||
/// container or wielder is <paramref name="containerId"/> from the main-thread
|
||||
|
|
|
|||
Loading…
Reference in a new issue