Add skill level, attribute, vitals, and appraisal engine API
- InqSkill with raw param (0=buffed, 1=base incl. attribute contribution) - InqAttribute for primary attributes (Str/End/Qui/Coo/Foc/Self, buffed + base) - InqAttribute2nd for max vitals base level (health/stamina/mana) - InqInt64 delegate for quad properties - AppraisalHooks: full item appraisal support via AC client appraisal path - PlayerVitalsHooks and BusyCountHooks additions - Expose all new hooks through PluginContract/PluginManager/RynthCoreApiNative/RynthCoreHost (contract version 46) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c2ca425f87
commit
610c9feaec
9 changed files with 764 additions and 7 deletions
|
|
@ -53,13 +53,39 @@ internal static class AppraisalHooks
|
|||
private static bool _hookInstalled;
|
||||
private static string _statusMessage = "Not initialized.";
|
||||
|
||||
// Tracks every guid for which we've received a SendNotice_SetAppraiseInfo (has assess data)
|
||||
private static readonly HashSet<uint> _appraisedGuids = new();
|
||||
// Unix timestamp (seconds) of last appraisal receipt per guid
|
||||
private static readonly Dictionary<uint, long> _lastIdTime = new();
|
||||
// Bool property cache: guid → (stype → value)
|
||||
private static readonly Dictionary<uint, Dictionary<uint, bool>> _boolCache = new();
|
||||
// String property cache: guid → (stype → value)
|
||||
private static readonly Dictionary<uint, Dictionary<uint, string>> _stringCache = new();
|
||||
// Spell book cache: guid → spell ID array (from AppraisalProfile._spellBook PSmartArray<UInt32> at +0x30)
|
||||
private static readonly Dictionary<uint, uint[]> _spellIdCache = new();
|
||||
private static readonly object _cacheLock = new();
|
||||
|
||||
public static bool IsInstalled => _hookInstalled;
|
||||
public static string StatusMessage => _statusMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if a SendNotice_SetAppraiseInfo has been received for this guid this session.
|
||||
/// </summary>
|
||||
public static bool HasAppraisalData(uint guid)
|
||||
{
|
||||
lock (_cacheLock)
|
||||
return _appraisedGuids.Contains(guid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Unix timestamp (seconds) of when appraisal data was last received for this guid, or 0 if never.
|
||||
/// </summary>
|
||||
public static long GetLastIdTime(uint guid)
|
||||
{
|
||||
lock (_cacheLock)
|
||||
return _lastIdTime.TryGetValue(guid, out long t) ? t : 0L;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a bool property from the last server appraisal for this object.
|
||||
/// Only populated after the player has identified the item (RequestId).
|
||||
|
|
@ -75,6 +101,21 @@ internal static class AppraisalHooks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string property from the last server appraisal for this object.
|
||||
/// Only populated after the player has identified the item (RequestId).
|
||||
/// </summary>
|
||||
public static bool TryGetCachedStringProperty(uint guid, uint stype, out string value)
|
||||
{
|
||||
value = string.Empty;
|
||||
lock (_cacheLock)
|
||||
{
|
||||
if (!_stringCache.TryGetValue(guid, out Dictionary<uint, string>? props))
|
||||
return false;
|
||||
return props.TryGetValue(stype, out value!);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (_hookInstalled)
|
||||
|
|
@ -128,6 +169,12 @@ internal static class AppraisalHooks
|
|||
// Call original first — notification fires, profile is still live in our frame
|
||||
int result = _originalSendNotice!(guid, profilePtr);
|
||||
|
||||
lock (_cacheLock)
|
||||
{
|
||||
_appraisedGuids.Add(guid);
|
||||
_lastIdTime[guid] = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CacheBoolProps(guid, profilePtr);
|
||||
|
|
@ -137,6 +184,24 @@ internal static class AppraisalHooks
|
|||
try { RynthLog.Compat($"Compat: appraisal bool cache error guid=0x{guid:X8} - {ex.GetType().Name}: {ex.Message}"); } catch { }
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CacheStringProps(guid, profilePtr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try { RynthLog.Compat($"Compat: appraisal string cache error guid=0x{guid:X8} - {ex.GetType().Name}: {ex.Message}"); } catch { }
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CacheSpellIds(guid, profilePtr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try { RynthLog.Compat($"Compat: appraisal spell cache error guid=0x{guid:X8} - {ex.GetType().Name}: {ex.Message}"); } catch { }
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -181,4 +246,110 @@ internal static class AppraisalHooks
|
|||
|
||||
RynthLog.Compat($"Compat: cached {props.Count} bool prop(s) for guid=0x{guid:X8}");
|
||||
}
|
||||
|
||||
private static void CacheStringProps(uint guid, IntPtr profilePtr)
|
||||
{
|
||||
if (profilePtr == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
// AppraisalProfile._strStatsTable* is at offset +0x28
|
||||
IntPtr strTablePtr = Marshal.ReadIntPtr(profilePtr + 0x28);
|
||||
if (strTablePtr == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
// PackableHashTable<uint, PStringBase<char>>: bucket_array at +0x8, bucket_count at +0xC
|
||||
IntPtr bucketArray = Marshal.ReadIntPtr(strTablePtr + 0x08);
|
||||
int bucketCount = Marshal.ReadInt32(strTablePtr + 0x0C);
|
||||
|
||||
if (bucketArray == IntPtr.Zero || bucketCount <= 0 || bucketCount > 65536)
|
||||
return;
|
||||
|
||||
var props = new Dictionary<uint, string>(4);
|
||||
|
||||
for (int i = 0; i < bucketCount; i++)
|
||||
{
|
||||
IntPtr node = Marshal.ReadIntPtr(bucketArray + i * 4);
|
||||
while (node != IntPtr.Zero)
|
||||
{
|
||||
uint key = (uint)Marshal.ReadInt32(node);
|
||||
|
||||
// Node value at +4: PStringBase<char>.m_buffer (PSRefBuffer<char>*)
|
||||
// PSRefBuffer<char> layout: vtable(4) + m_cRef(4) + m_len(4) + m_size(4) + m_hash(4) + m_data[]
|
||||
IntPtr bufferPtr = Marshal.ReadIntPtr(node + 4);
|
||||
if (bufferPtr != IntPtr.Zero)
|
||||
{
|
||||
int len = Marshal.ReadInt32(bufferPtr + 8);
|
||||
if (len > 1)
|
||||
{
|
||||
string? str = Marshal.PtrToStringAnsi(bufferPtr + 20, len - 1);
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
props[key] = str;
|
||||
}
|
||||
}
|
||||
|
||||
node = Marshal.ReadIntPtr(node + 8);
|
||||
}
|
||||
}
|
||||
|
||||
if (props.Count == 0)
|
||||
return;
|
||||
|
||||
lock (_cacheLock)
|
||||
{
|
||||
_stringCache[guid] = props;
|
||||
}
|
||||
|
||||
RynthLog.Compat($"Compat: cached {props.Count} string prop(s) for guid=0x{guid:X8}");
|
||||
}
|
||||
|
||||
private static void CacheSpellIds(uint guid, IntPtr profilePtr)
|
||||
{
|
||||
if (profilePtr == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
// AppraisalProfile._spellBook (PSmartArray<UInt32>*) is at offset +0x30
|
||||
// PSmartArray layout: +0x00 vtable, +0x04 m_data*, +0x08 m_sizeAndDeallocate, +0x0C m_num
|
||||
IntPtr spellBookPtr = Marshal.ReadIntPtr(profilePtr + 0x30);
|
||||
if (spellBookPtr == IntPtr.Zero)
|
||||
return;
|
||||
|
||||
IntPtr mData = Marshal.ReadIntPtr(spellBookPtr + 0x04);
|
||||
int mNum = Marshal.ReadInt32(spellBookPtr + 0x0C);
|
||||
|
||||
if (mNum == 0)
|
||||
{
|
||||
RynthLog.Compat($"Compat: guid=0x{guid:X8} spell book present but empty (mNum=0)");
|
||||
return;
|
||||
}
|
||||
if (mData == IntPtr.Zero || mNum < 0 || mNum > 512)
|
||||
{
|
||||
RynthLog.Compat($"Compat: guid=0x{guid:X8} spell book invalid (mData=0x{mData.ToInt32():X8} mNum={mNum})");
|
||||
return;
|
||||
}
|
||||
|
||||
var ids = new uint[mNum];
|
||||
for (int i = 0; i < mNum; i++)
|
||||
ids[i] = (uint)Marshal.ReadInt32(mData + i * 4);
|
||||
|
||||
lock (_cacheLock)
|
||||
_spellIdCache[guid] = ids;
|
||||
|
||||
RynthLog.Compat($"Compat: cached {mNum} spell ID(s) for guid=0x{guid:X8}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills <paramref name="output"/> with spell IDs from the last appraisal spell book.
|
||||
/// Returns the total number of spell IDs (may exceed <paramref name="maxCount"/>), or -1 if no data.
|
||||
/// </summary>
|
||||
public static int GetObjectSpellIds(uint guid, uint[] output, int maxCount)
|
||||
{
|
||||
lock (_cacheLock)
|
||||
{
|
||||
if (!_spellIdCache.TryGetValue(guid, out uint[]? cached))
|
||||
return -1;
|
||||
int count = Math.Min(cached.Length, Math.Min(maxCount, output.Length));
|
||||
Array.Copy(cached, output, count);
|
||||
return cached.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,14 @@ internal static class BusyCountHooks
|
|||
private static string _statusMessage = "Not probed yet.";
|
||||
private static int _incrementDispatchCount;
|
||||
private static int _decrementDispatchCount;
|
||||
private static int _netBusyCount;
|
||||
|
||||
public static bool IsInstalled { get; private set; }
|
||||
public static string StatusMessage => _statusMessage;
|
||||
|
||||
/// <summary>Returns 0 if the character is idle, positive if a UI action is in progress.</summary>
|
||||
public static int GetBusyState() => Math.Max(0, _netBusyCount);
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (IsInstalled)
|
||||
|
|
@ -90,6 +94,7 @@ internal static class BusyCountHooks
|
|||
if (count <= 0)
|
||||
RynthLog.Compat($"Compat: busy count incremented #{count}");
|
||||
|
||||
Interlocked.Increment(ref _netBusyCount);
|
||||
PluginManager.QueueBusyCountIncremented();
|
||||
}
|
||||
|
||||
|
|
@ -101,6 +106,7 @@ internal static class BusyCountHooks
|
|||
if (count <= 0)
|
||||
RynthLog.Compat($"Compat: busy count decremented #{count}");
|
||||
|
||||
Interlocked.Decrement(ref _netBusyCount);
|
||||
PluginManager.QueueBusyCountDecremented();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,15 @@ internal static class ClientObjectHooks
|
|||
// CBaseQualities::InqFloat(UInt32 stype, double* retval, int raw) — ThisCall
|
||||
private const int ReferenceInqFloat = 0x00590CD0;
|
||||
|
||||
// CBaseQualities::InqInt64(UInt32 stype, __int64* retval) — ThisCall
|
||||
private const int ReferenceInqInt64 = 0x00590C70;
|
||||
|
||||
// CACQualities::InqAttribute2nd(ulong stype, uint* retval, int raw) — ThisCall on CACQualities* (no CBaseQualitiesOffset)
|
||||
// stype: 1=MAX_HEALTH, 3=MAX_STAMINA, 5=MAX_MANA. raw=0 returns base+gear+aug (no spell enchants).
|
||||
// Map: 00191D20 → live VA: 0x00592D20 (offset +0x401000)
|
||||
private const int ReferenceInqAttribute2ndBaseLevel = 0x00592D20;
|
||||
|
||||
|
||||
// CBaseQualities::InqBool(UInt32 stype, int* retval) — ThisCall
|
||||
private const int ReferenceInqBool = 0x00590CA0;
|
||||
|
||||
|
|
@ -50,6 +59,10 @@ internal static class ClientObjectHooks
|
|||
// SKILL_ADVANCEMENT_CLASS: UNDEF=0, UNTRAINED=1, TRAINED=2, SPECIALIZED=3
|
||||
private const int ReferenceInqSkillAdvancementClass = 0x00592B70;
|
||||
|
||||
// CACQualities::InqAttribute(uint stype, uint* retval, int raw) — raw=0→buffed, raw=1→base
|
||||
// stype: 1=Strength, 2=Endurance, 3=Quickness, 4=Coordination, 5=Focus, 6=Self
|
||||
private const int ReferenceInqAttribute = 0x00592700;
|
||||
|
||||
// CACQualities::GetVitaeValue() — ThisCall, no args, returns float (1.0=no vitae, 0.95=5% penalty)
|
||||
// Map: 0018EE80 → live VA: 0x0058FE80
|
||||
private const int ReferenceGetVitaeValue = 0x0058FE80;
|
||||
|
|
@ -98,6 +111,8 @@ internal static class ClientObjectHooks
|
|||
// CPhysicsObj.m_position offset (same as PlayerPhysicsHooks.PhysicsPositionOffset)
|
||||
private const int PhysicsPositionOffset = 0x48;
|
||||
private const int PositionObjCellIdOffset = 0x04;
|
||||
private const int PositionQwOffset = 0x08;
|
||||
private const int PositionQzOffset = 0x14;
|
||||
private const int PositionOriginXOffset = 0x3C;
|
||||
private const int PositionOriginYOffset = 0x40;
|
||||
private const int PositionOriginZOffset = 0x44;
|
||||
|
|
@ -155,6 +170,15 @@ internal static class ClientObjectHooks
|
|||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private unsafe delegate int InqIntDelegate(IntPtr qualitiesPtr, uint stype, int* retval, int raw, int allowNegative);
|
||||
|
||||
// int __thiscall CBaseQualities::InqInt64(unsigned int stype, __int64* retval)
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private unsafe delegate int InqInt64Delegate(IntPtr qualitiesPtr, uint stype, long* retval);
|
||||
|
||||
// int __thiscall CACQualities::InqAttribute2nd(ulong stype, uint* retval, int raw)
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private unsafe delegate int InqAttribute2ndBaseLevelDelegate(IntPtr cacQualitiesPtr, uint stype, uint* retval, int raw);
|
||||
|
||||
|
||||
// int __thiscall CBaseQualities::InqFloat(unsigned int stype, double* retval, int raw)
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private unsafe delegate int InqFloatDelegate(IntPtr qualitiesPtr, uint stype, double* retval, int raw);
|
||||
|
|
@ -175,6 +199,10 @@ internal static class ClientObjectHooks
|
|||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private unsafe delegate int InqSkillAdvancementClassDelegate(IntPtr qualitiesPtr, uint stype, int* retval);
|
||||
|
||||
// int __thiscall CACQualities::InqAttribute(unsigned int stype, unsigned int* retval, int raw) raw=0→buffed, raw=1→base
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private unsafe delegate int InqAttributeDelegate(IntPtr qualitiesPtr, uint stype, uint* retval, int raw);
|
||||
|
||||
// int __thiscall CACQualities::IsSpellKnown(uint spellId)
|
||||
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
|
||||
private delegate int IsSpellKnownDelegate(IntPtr qualitiesPtr, uint spellId);
|
||||
|
|
@ -233,6 +261,8 @@ internal static class ClientObjectHooks
|
|||
private static GetObjectNameInstanceDelegate? _getObjectNameInstance;
|
||||
private static InqTypeDelegate? _inqType;
|
||||
private static InqIntDelegate? _inqInt;
|
||||
private static InqInt64Delegate? _inqInt64;
|
||||
private static InqAttribute2ndBaseLevelDelegate? _inqAttribute2ndBaseLevel;
|
||||
private static InqFloatDelegate? _inqFloat;
|
||||
private static InqBoolDelegate? _inqBool;
|
||||
private static InqStringDelegate? _inqString;
|
||||
|
|
@ -240,6 +270,7 @@ internal static class ClientObjectHooks
|
|||
private static ObjectIsAttackableDelegate? _objectIsAttackable;
|
||||
private static InqSkillLevelDelegate? _inqSkillLevel;
|
||||
private static InqSkillAdvancementClassDelegate? _inqSkillAdvancementClass;
|
||||
private static InqAttributeDelegate? _inqAttribute;
|
||||
private static IsSpellKnownDelegate? _isSpellKnown;
|
||||
private static GetVitaeValueDelegate? _getVitaeValue;
|
||||
private static int _lookupLogCount;
|
||||
|
|
@ -269,13 +300,16 @@ internal static class ClientObjectHooks
|
|||
_getObjectNameStatic = null;
|
||||
_getObjectNameInstance = null;
|
||||
_inqType = null;
|
||||
_inqInt = null;
|
||||
_inqBool = null;
|
||||
_inqInt = null;
|
||||
_inqInt64 = null;
|
||||
_inqAttribute2ndBaseLevel = null;
|
||||
_inqBool = null;
|
||||
_inqString = null;
|
||||
_getCombatSystem = null;
|
||||
_objectIsAttackable = null;
|
||||
_inqSkillLevel = null;
|
||||
_inqSkillAdvancementClass = null;
|
||||
_inqAttribute = null;
|
||||
_isSpellKnown = null;
|
||||
}
|
||||
|
||||
|
|
@ -310,6 +344,8 @@ internal static class ClientObjectHooks
|
|||
_getObjectNameInstance = Marshal.GetDelegateForFunctionPointer<GetObjectNameInstanceDelegate>(getNameInstancePtr);
|
||||
_inqType = Marshal.GetDelegateForFunctionPointer<InqTypeDelegate>(new IntPtr(ReferenceInqType));
|
||||
_inqInt = Marshal.GetDelegateForFunctionPointer<InqIntDelegate>(new IntPtr(ReferenceInqInt));
|
||||
_inqInt64 = Marshal.GetDelegateForFunctionPointer<InqInt64Delegate>(new IntPtr(ReferenceInqInt64));
|
||||
_inqAttribute2ndBaseLevel = Marshal.GetDelegateForFunctionPointer<InqAttribute2ndBaseLevelDelegate>(new IntPtr(ReferenceInqAttribute2ndBaseLevel));
|
||||
_inqFloat = Marshal.GetDelegateForFunctionPointer<InqFloatDelegate>(new IntPtr(ReferenceInqFloat));
|
||||
_inqBool = Marshal.GetDelegateForFunctionPointer<InqBoolDelegate>(new IntPtr(ReferenceInqBool));
|
||||
_inqString = Marshal.GetDelegateForFunctionPointer<InqStringDelegate>(new IntPtr(ReferenceInqString));
|
||||
|
|
@ -317,6 +353,7 @@ internal static class ClientObjectHooks
|
|||
_objectIsAttackable = Marshal.GetDelegateForFunctionPointer<ObjectIsAttackableDelegate>(new IntPtr(ReferenceObjectIsAttackable));
|
||||
_inqSkillLevel = Marshal.GetDelegateForFunctionPointer<InqSkillLevelDelegate>(new IntPtr(ReferenceInqSkillLevel));
|
||||
_inqSkillAdvancementClass = Marshal.GetDelegateForFunctionPointer<InqSkillAdvancementClassDelegate>(new IntPtr(ReferenceInqSkillAdvancementClass));
|
||||
_inqAttribute = Marshal.GetDelegateForFunctionPointer<InqAttributeDelegate>(new IntPtr(ReferenceInqAttribute));
|
||||
_isSpellKnown = Marshal.GetDelegateForFunctionPointer<IsSpellKnownDelegate>(new IntPtr(ReferenceIsSpellKnown));
|
||||
_getVitaeValue = Marshal.GetDelegateForFunctionPointer<GetVitaeValueDelegate>(new IntPtr(ReferenceGetVitaeValue));
|
||||
RynthLog.Compat(
|
||||
|
|
@ -535,6 +572,57 @@ internal static class ClientObjectHooks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a skill level via CACQualities::InqSkill(stype, retval, raw).
|
||||
/// raw=0 → buffed (with enchantments), raw=1 → base (no enchantments, includes attribute contribution).
|
||||
/// </summary>
|
||||
public static unsafe bool TryGetObjectSkillLevel(uint objectId, uint skillStype, int raw, out int level)
|
||||
{
|
||||
level = 0;
|
||||
if (_inqSkillLevel == null || _getWeenieObject == null)
|
||||
{
|
||||
if (!Probe() || _inqSkillLevel == null || _getWeenieObject == null)
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!TryGetObjectQualitiesPtr(objectId, out IntPtr qualitiesPtr))
|
||||
return false;
|
||||
int retval = 0;
|
||||
if (_inqSkillLevel(qualitiesPtr, skillStype, &retval, raw) == 0)
|
||||
return false;
|
||||
level = retval;
|
||||
return true;
|
||||
}
|
||||
catch { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a primary attribute via CACQualities::InqAttribute(stype, retval, raw).
|
||||
/// raw=0 → buffed (with enchantments), raw=1 → base (no enchantments).
|
||||
/// stype: 1=Strength, 2=Endurance, 3=Quickness, 4=Coordination, 5=Focus, 6=Self.
|
||||
/// </summary>
|
||||
public static unsafe bool TryGetObjectAttribute(uint objectId, uint stype, int raw, out uint value)
|
||||
{
|
||||
value = 0;
|
||||
if (_inqAttribute == null || _getWeenieObject == null)
|
||||
{
|
||||
if (!Probe() || _inqAttribute == null || _getWeenieObject == null)
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!TryGetObjectQualitiesPtr(objectId, out IntPtr qualitiesPtr))
|
||||
return false;
|
||||
uint retval = 0;
|
||||
if (_inqAttribute(qualitiesPtr, stype, &retval, raw) == 0)
|
||||
return false;
|
||||
value = retval;
|
||||
return true;
|
||||
}
|
||||
catch { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Derives the player's CACQualities* on demand from the current player object.
|
||||
/// Works even when injected mid-session (before SendNoticePlayerDescReceived fires).
|
||||
|
|
@ -927,6 +1015,82 @@ internal static class ClientObjectHooks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls CBaseQualities::InqInt64 on the object's weenie to read a STypeInt64 (quad) property.
|
||||
/// Example: stype=1 = TOTAL_EXPERIENCE.
|
||||
/// </summary>
|
||||
public static unsafe bool TryGetObjectQuadProperty(uint objectId, uint stype, out long value)
|
||||
{
|
||||
value = 0;
|
||||
if (_inqInt64 == null)
|
||||
{
|
||||
if (!Probe() || _inqInt64 == null)
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
IntPtr weeniePtr = _getWeenieObject!(objectId);
|
||||
if (weeniePtr == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
if (!TryGetQualitiesPtr(weeniePtr, out IntPtr qualitiesPtr))
|
||||
return false;
|
||||
|
||||
IntPtr baseQualitiesPtr = qualitiesPtr + CBaseQualitiesOffset;
|
||||
if (!IsReadablePointer(baseQualitiesPtr))
|
||||
return false;
|
||||
|
||||
long retval = 0;
|
||||
int result = _inqInt64(baseQualitiesPtr, stype, &retval);
|
||||
if (result == 0)
|
||||
return false;
|
||||
|
||||
value = retval;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls CACQualities::InqAttribute2nd(stype, &result, raw=0) to read the base maximum vital.
|
||||
/// Returns base training + gear bonuses + augmentations, but NOT spell enchantments.
|
||||
/// stype: 1=MAX_HEALTH, 3=MAX_STAMINA, 5=MAX_MANA (STypeAttribute2nd enum).
|
||||
/// Calls on CACQualities* directly — no CBaseQualitiesOffset applied.
|
||||
/// </summary>
|
||||
public static unsafe bool TryGetObjectAttribute2ndBaseLevel(uint objectId, uint stype, out uint value)
|
||||
{
|
||||
value = 0;
|
||||
if (_inqAttribute2ndBaseLevel == null)
|
||||
{
|
||||
if (!Probe() || _inqAttribute2ndBaseLevel == null)
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
IntPtr weeniePtr = _getWeenieObject!(objectId);
|
||||
if (weeniePtr == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
if (!TryGetQualitiesPtr(weeniePtr, out IntPtr qualitiesPtr))
|
||||
return false;
|
||||
|
||||
uint retval = 0;
|
||||
int result = _inqAttribute2ndBaseLevel(qualitiesPtr, stype, &retval, 0);
|
||||
if (result == 0)
|
||||
return false;
|
||||
|
||||
value = retval;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls CBaseQualities::InqBool on the object's weenie to read a STypeBool property.
|
||||
/// Common stypes: ATTACKABLE=19, PLAYER_KILLER=7.
|
||||
|
|
@ -980,6 +1144,12 @@ internal static class ClientObjectHooks
|
|||
public static unsafe bool TryGetObjectStringProperty(uint objectId, uint stype, out string value)
|
||||
{
|
||||
value = string.Empty;
|
||||
|
||||
// Appraisal cache covers inventory items where m_pQualities is null
|
||||
// (CBaseQualities::InqString always returns 0 for such objects).
|
||||
if (AppraisalHooks.TryGetCachedStringProperty(objectId, stype, out value))
|
||||
return true;
|
||||
|
||||
if (_inqString == null || _getWeenieObject == null)
|
||||
{
|
||||
if (!Probe() || _inqString == null || _getWeenieObject == null)
|
||||
|
|
@ -1177,6 +1347,49 @@ internal static class ClientObjectHooks
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an object's facing heading (0–360°, clockwise, 0=North) from its CPhysicsObj quaternion.
|
||||
/// Same qw/qz offsets as the player position struct.
|
||||
/// </summary>
|
||||
public static bool TryGetObjectHeading(uint objectId, out float headingDegrees)
|
||||
{
|
||||
headingDegrees = 0;
|
||||
|
||||
if (_weeniePhysicsObjOffset < 0)
|
||||
{
|
||||
ProbePhysObjOffset();
|
||||
if (_weeniePhysicsObjOffset < 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryGetWeenieObjectPtr(objectId, out IntPtr weeniePtr))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr physicsObj = Marshal.ReadIntPtr(weeniePtr + _weeniePhysicsObjOffset);
|
||||
if (physicsObj == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
IntPtr vtable = Marshal.ReadIntPtr(physicsObj);
|
||||
if (!SmartBoxLocator.IsPointerInModule(vtable))
|
||||
return false;
|
||||
|
||||
IntPtr pos = physicsObj + PhysicsPositionOffset;
|
||||
float qw = ReadFloat(pos + PositionQwOffset);
|
||||
float qz = ReadFloat(pos + PositionQzOffset);
|
||||
|
||||
// Same formula as NavigationEngine / CorpseOpenController
|
||||
double physYawDeg = 2.0 * Math.Atan2(qz, qw) * (180.0 / Math.PI);
|
||||
headingDegrees = (float)(((-physYawDeg) % 360.0 + 720.0) % 360.0);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static float ReadFloat(IntPtr address)
|
||||
{
|
||||
int bits = Marshal.ReadInt32(address);
|
||||
|
|
|
|||
|
|
@ -149,6 +149,40 @@ internal static class PlayerVitalsHooks
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the unbuffed base maximum vitals (base training + gear + augmentations, no spell enchantments).
|
||||
/// Uses _initLevel + _levelFromCp from InqAttribute2ndStruct on the current-vital stypes (2/4/6).
|
||||
/// This formula is confirmed "unbuffed base max" by the TryReadSecondary fallback path.
|
||||
/// Must be called after SendNoticePlayerDescReceived has fired (KnownPlayerQualitiesPtr set).
|
||||
/// </summary>
|
||||
public static unsafe bool TryGetPlayerBaseVitals(out uint baseMaxHp, out uint baseMaxStam, out uint baseMaxMana)
|
||||
{
|
||||
baseMaxHp = baseMaxStam = baseMaxMana = 0;
|
||||
if (_inqAttribute2ndStruct == null)
|
||||
return false;
|
||||
|
||||
IntPtr ptr = KnownPlayerQualitiesPtr;
|
||||
if (ptr == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
SecondaryAttributeNative v = default;
|
||||
if (_inqAttribute2ndStruct(ptr, HealthType, &v) != 0)
|
||||
baseMaxHp = v._initLevel + v._levelFromCp;
|
||||
if (_inqAttribute2ndStruct(ptr, StaminaType, &v) != 0)
|
||||
baseMaxStam = v._initLevel + v._levelFromCp;
|
||||
if (_inqAttribute2ndStruct(ptr, ManaType, &v) != 0)
|
||||
baseMaxMana = v._initLevel + v._levelFromCp;
|
||||
|
||||
return baseMaxHp > 0 || baseMaxStam > 0 || baseMaxMana > 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetSnapshot(out PlayerVitalsSnapshot snapshot)
|
||||
{
|
||||
lock (CacheLock)
|
||||
|
|
|
|||
Loading…
Reference in a new issue