diff --git a/src/RynthCore.Engine/Compatibility/AppraisalHooks.cs b/src/RynthCore.Engine/Compatibility/AppraisalHooks.cs index 65cab62..bcd36d6 100644 --- a/src/RynthCore.Engine/Compatibility/AppraisalHooks.cs +++ b/src/RynthCore.Engine/Compatibility/AppraisalHooks.cs @@ -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 _appraisedGuids = new(); + // Unix timestamp (seconds) of last appraisal receipt per guid + private static readonly Dictionary _lastIdTime = new(); // Bool property cache: guid → (stype → value) private static readonly Dictionary> _boolCache = new(); + // String property cache: guid → (stype → value) + private static readonly Dictionary> _stringCache = new(); + // Spell book cache: guid → spell ID array (from AppraisalProfile._spellBook PSmartArray at +0x30) + private static readonly Dictionary _spellIdCache = new(); private static readonly object _cacheLock = new(); public static bool IsInstalled => _hookInstalled; public static string StatusMessage => _statusMessage; + /// + /// Returns true if a SendNotice_SetAppraiseInfo has been received for this guid this session. + /// + public static bool HasAppraisalData(uint guid) + { + lock (_cacheLock) + return _appraisedGuids.Contains(guid); + } + + /// + /// Returns the Unix timestamp (seconds) of when appraisal data was last received for this guid, or 0 if never. + /// + public static long GetLastIdTime(uint guid) + { + lock (_cacheLock) + return _lastIdTime.TryGetValue(guid, out long t) ? t : 0L; + } + /// /// 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 } } + /// + /// Returns a string property from the last server appraisal for this object. + /// Only populated after the player has identified the item (RequestId). + /// + public static bool TryGetCachedStringProperty(uint guid, uint stype, out string value) + { + value = string.Empty; + lock (_cacheLock) + { + if (!_stringCache.TryGetValue(guid, out Dictionary? 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>: 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(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.m_buffer (PSRefBuffer*) + // PSRefBuffer 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*) 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}"); + } + + /// + /// Fills with spell IDs from the last appraisal spell book. + /// Returns the total number of spell IDs (may exceed ), or -1 if no data. + /// + 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; + } + } } diff --git a/src/RynthCore.Engine/Compatibility/BusyCountHooks.cs b/src/RynthCore.Engine/Compatibility/BusyCountHooks.cs index 12129dc..2389bf1 100644 --- a/src/RynthCore.Engine/Compatibility/BusyCountHooks.cs +++ b/src/RynthCore.Engine/Compatibility/BusyCountHooks.cs @@ -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; + /// Returns 0 if the character is idle, positive if a UI action is in progress. + 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(); } diff --git a/src/RynthCore.Engine/Compatibility/ClientObjectHooks.cs b/src/RynthCore.Engine/Compatibility/ClientObjectHooks.cs index 99760e1..880e528 100644 --- a/src/RynthCore.Engine/Compatibility/ClientObjectHooks.cs +++ b/src/RynthCore.Engine/Compatibility/ClientObjectHooks.cs @@ -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(getNameInstancePtr); _inqType = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceInqType)); _inqInt = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceInqInt)); + _inqInt64 = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceInqInt64)); + _inqAttribute2ndBaseLevel = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceInqAttribute2ndBaseLevel)); _inqFloat = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceInqFloat)); _inqBool = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceInqBool)); _inqString = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceInqString)); @@ -317,6 +353,7 @@ internal static class ClientObjectHooks _objectIsAttackable = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceObjectIsAttackable)); _inqSkillLevel = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceInqSkillLevel)); _inqSkillAdvancementClass = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceInqSkillAdvancementClass)); + _inqAttribute = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceInqAttribute)); _isSpellKnown = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceIsSpellKnown)); _getVitaeValue = Marshal.GetDelegateForFunctionPointer(new IntPtr(ReferenceGetVitaeValue)); RynthLog.Compat( @@ -535,6 +572,57 @@ internal static class ClientObjectHooks } } + /// + /// Returns a skill level via CACQualities::InqSkill(stype, retval, raw). + /// raw=0 → buffed (with enchantments), raw=1 → base (no enchantments, includes attribute contribution). + /// + 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; } + } + + /// + /// 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. + /// + 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; } + } + /// /// 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 } } + /// + /// Calls CBaseQualities::InqInt64 on the object's weenie to read a STypeInt64 (quad) property. + /// Example: stype=1 = TOTAL_EXPERIENCE. + /// + 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; + } + } + + /// + /// 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. + /// + 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; + } + } + /// /// 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 } } + /// + /// Reads an object's facing heading (0–360°, clockwise, 0=North) from its CPhysicsObj quaternion. + /// Same qw/qz offsets as the player position struct. + /// + 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); diff --git a/src/RynthCore.Engine/Compatibility/PlayerVitalsHooks.cs b/src/RynthCore.Engine/Compatibility/PlayerVitalsHooks.cs index 8d60e2a..d01c17f 100644 --- a/src/RynthCore.Engine/Compatibility/PlayerVitalsHooks.cs +++ b/src/RynthCore.Engine/Compatibility/PlayerVitalsHooks.cs @@ -149,6 +149,40 @@ internal static class PlayerVitalsHooks return false; } + /// + /// 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). + /// + 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) diff --git a/src/RynthCore.Engine/D3D9/Nav3DRenderer.cs b/src/RynthCore.Engine/D3D9/Nav3DRenderer.cs index 64be315..b3de565 100644 --- a/src/RynthCore.Engine/D3D9/Nav3DRenderer.cs +++ b/src/RynthCore.Engine/D3D9/Nav3DRenderer.cs @@ -8,8 +8,8 @@ namespace RynthCore.Engine.D3D9; internal static class Nav3DRenderer { - private const int MaxRings = 128; - private const int MaxLines = 128; + private const int MaxRings = 256; + private const int MaxLines = 512; // Ring: center(x,y,z) + radius + thickness + color private static readonly float[] _ringX = new float[MaxRings]; diff --git a/src/RynthCore.Engine/Plugins/PluginContract.cs b/src/RynthCore.Engine/Plugins/PluginContract.cs index 0697fca..0448c20 100644 --- a/src/RynthCore.Engine/Plugins/PluginContract.cs +++ b/src/RynthCore.Engine/Plugins/PluginContract.cs @@ -170,7 +170,8 @@ internal struct RynthCoreAPI /// Function pointer: int ObjectIsAttackable(uint objectId) — calls ClientCombatSystem::ObjectIsAttackable, returns 1 if attackable public IntPtr ObjectIsAttackableFn; - /// Function pointer: int GetObjectSkill(uint objectId, uint skillStype, int* buffed, int* training) + /// Function pointer: int GetObjectSkill(uint objectId, uint skillStype, int* base, int* training) + /// base = InitialLevel + LevelFromPracticePoints (no enchantments). training: 0=Unusable,1=Untrained,2=Trained,3=Specialized. public IntPtr GetObjectSkillFn; /// Function pointer: int IsSpellKnown(uint objectId, uint spellId) — returns 1 if in spell book @@ -244,6 +245,29 @@ internal struct RynthCoreAPI /// public IntPtr GetObjectDoublePropertyFn; + /// + /// Function pointer: int GetObjectQuadProperty(uint objectId, uint stype, __int64* value) + /// Reads an STypeInt64 (quad) property from any game object. + /// Returns 1 on success, 0 if undefined. + /// + public IntPtr GetObjectQuadPropertyFn; + + /// + /// Function pointer: int GetObjectAttribute2ndBaseLevel(uint objectId, uint stype2nd, ulong* value) + /// Reads the unbuffed base maximum vital via CACQualities::InqAttribute2ndBaseLevel. + /// stype2nd: 1=MAX_HEALTH, 3=MAX_STAMINA, 5=MAX_MANA. + /// Returns 1 on success, 0 if unavailable. + /// + public IntPtr GetObjectAttribute2ndBaseLevelFn; + + /// + /// Function pointer: int GetPlayerBaseVitals(uint* baseMaxHp, uint* baseMaxStam, uint* baseMaxMana) + /// Returns unbuffed base maximum vitals via InqAttribute2ndStruct(_initLevel + _levelFromCp). + /// Excludes spell enchantments; includes base training, gear, and augmentations. + /// Returns 1 on success, 0 if player qualities not yet available. + /// + public IntPtr GetPlayerBaseVitalsFn; + /// /// Function pointer: IntPtr GetObjectStringProperty(uint objectId, uint stype) /// Returns pointer to ANSI string data, or IntPtr.Zero if undefined. @@ -363,12 +387,55 @@ internal struct RynthCoreAPI /// Returns 0 if the object is not found or the phys_obj offset is not yet probed. /// public IntPtr GetObjectWcidFn; + + /// + /// Function pointer: int HasAppraisalData(uint objectId) + /// Returns 1 if a SendNotice_SetAppraiseInfo has been received for this guid this session, 0 otherwise. + /// + public IntPtr HasAppraisalDataFn; + + /// + /// Function pointer: long GetLastIdTime(uint objectId) + /// Returns the Unix timestamp (seconds) of the last appraisal receipt for this guid, or 0 if never. + /// + public IntPtr GetLastIdTimeFn; + + /// + /// Function pointer: int GetObjectHeading(uint objectId, float* headingDegrees) + /// Returns the object's facing direction (0–360°, clockwise, 0=North). Returns 1 on success, 0 on failure. + /// + public IntPtr GetObjectHeadingFn; + + /// + /// Function pointer: int GetBusyState() + /// Returns 0 if the character is idle, positive if a UI action is in progress. + /// + public IntPtr GetBusyStateFn; + + /// + /// Function pointer: int GetObjectSpellIds(uint objectId, uint* spellIds, int maxCount) + /// Fills spellIds with the spell book IDs from the last server appraisal for this object. + /// Returns total count (may exceed maxCount), or -1 if no appraisal data is cached. + /// Requires the player to have identified (RequestId) the object this session. + /// + public IntPtr GetObjectSpellIdsFn; + + /// Function pointer: int GetObjectSkillBuffed(uint objectId, uint skillStype, int* buffed) + /// Returns the live buffed skill level (with spell enchantments) via InqSkill(raw=0). + public IntPtr GetObjectSkillBuffedFn; + + /// Function pointer: int GetObjectAttribute(uint objectId, uint stype, int raw, uint* value) + /// Reads a primary attribute via InqAttribute. raw=0→buffed, raw=1→base. + /// stype: 1=Strength, 2=Endurance, 3=Quickness, 4=Coordination, 5=Focus, 6=Self. + public IntPtr GetObjectAttributeFn; } + + /// Current API version. Bump when adding fields to RynthCoreAPI. internal static class PluginContractVersion { - public const uint Current = 40; + public const uint Current = 46; } internal static class ClientActionHookFlags @@ -671,6 +738,15 @@ internal delegate int InvokeChatParserCallbackDelegate(IntPtr textUtf16); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal unsafe delegate int GetObjectDoublePropertyCallbackDelegate(uint objectId, uint stype, double* value); +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal unsafe delegate int GetObjectQuadPropertyCallbackDelegate(uint objectId, uint stype, long* value); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal unsafe delegate int GetObjectAttribute2ndBaseLevelCallbackDelegate(uint objectId, uint stype2nd, uint* value); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal unsafe delegate int GetPlayerBaseVitalsCallbackDelegate(uint* baseMaxHp, uint* baseMaxStam, uint* baseMaxMana); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate IntPtr GetObjectStringPropertyCallbackDelegate(uint objectId, uint stype); @@ -704,3 +780,24 @@ internal delegate IntPtr GetWorldNameCallbackDelegate(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate uint GetObjectWcidCallbackDelegate(uint objectId); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal delegate int HasAppraisalDataCallbackDelegate(uint objectId); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal delegate long GetLastIdTimeCallbackDelegate(uint objectId); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal unsafe delegate int GetObjectHeadingCallbackDelegate(uint objectId, float* headingDegrees); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal delegate int GetBusyStateCallbackDelegate(); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal unsafe delegate int GetObjectSpellIdsCallbackDelegate(uint guid, uint* spellIds, int maxCount); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal unsafe delegate int GetObjectSkillLevelCallbackDelegate(uint objectId, uint skillStype, int raw, int* level); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal unsafe delegate int GetObjectAttributeCallbackDelegate(uint objectId, uint stype, int raw, uint* value); diff --git a/src/RynthCore.Engine/Plugins/PluginManager.cs b/src/RynthCore.Engine/Plugins/PluginManager.cs index e2808f7..cea3d83 100644 --- a/src/RynthCore.Engine/Plugins/PluginManager.cs +++ b/src/RynthCore.Engine/Plugins/PluginManager.cs @@ -149,6 +149,9 @@ internal static class PluginManager private static Nav3DAddLineCallbackDelegate? _nav3DAddLineCallback; private static InvokeChatParserCallbackDelegate? _invokeChatParserCallback; private static GetObjectDoublePropertyCallbackDelegate? _getObjectDoublePropertyCallback; + private static GetObjectQuadPropertyCallbackDelegate? _getObjectQuadPropertyCallback; + private static GetObjectAttribute2ndBaseLevelCallbackDelegate? _getObjectAttribute2ndBaseLevelCallback; + private static GetPlayerBaseVitalsCallbackDelegate? _getPlayerBaseVitalsCallback; private static GetObjectStringPropertyCallbackDelegate? _getObjectStringPropertyCallback; private static GetObjectWielderInfoCallbackDelegate? _getObjectWielderInfoCallback; private static NativeAttackCallbackDelegate? _nativeAttackCallback; @@ -164,6 +167,13 @@ internal static class PluginManager private static GetAccountNameCallbackDelegate? _getAccountNameCallback; private static GetWorldNameCallbackDelegate? _getWorldNameCallback; private static GetObjectWcidCallbackDelegate? _getObjectWcidCallback; + private static HasAppraisalDataCallbackDelegate? _hasAppraisalDataCallback; + private static GetLastIdTimeCallbackDelegate? _getLastIdTimeCallback; + private static GetObjectHeadingCallbackDelegate? _getObjectHeadingCallback; + private static GetBusyStateCallbackDelegate? _getBusyStateCallback; + private static GetObjectSpellIdsCallbackDelegate? _getObjectSpellIdsCallback; + private static GetObjectSkillLevelCallbackDelegate? _getObjectSkillBuffedCallback; + private static GetObjectAttributeCallbackDelegate? _getObjectAttributeCallback; private static IntPtr _accountNameScratchPtr; private static IntPtr _worldNameScratchPtr; [ThreadStatic] private static IntPtr _objectNameScratchPtr; @@ -1569,6 +1579,9 @@ internal static class PluginManager _nav3DAddLineCallback ??= D3D9.Nav3DRenderer.Nav3DAddLineCallback; _invokeChatParserCallback ??= InvokeChatParser; _getObjectDoublePropertyCallback ??= GetObjectDoublePropertyAction; + _getObjectQuadPropertyCallback ??= GetObjectQuadPropertyAction; + _getObjectAttribute2ndBaseLevelCallback ??= GetObjectAttribute2ndBaseLevelAction; + _getPlayerBaseVitalsCallback ??= GetPlayerBaseVitalsAction; _getObjectStringPropertyCallback ??= GetObjectStringPropertyAction; _getObjectWielderInfoCallback ??= GetObjectWielderInfoAction; _nativeAttackCallback ??= NativeAttackAction; @@ -1584,6 +1597,13 @@ internal static class PluginManager _getAccountNameCallback ??= GetAccountNameAction; _getWorldNameCallback ??= GetWorldNameAction; _getObjectWcidCallback ??= GetObjectWcidAction; + _hasAppraisalDataCallback ??= HasAppraisalDataAction; + _getLastIdTimeCallback ??= GetLastIdTimeAction; + _getObjectHeadingCallback ??= GetObjectHeadingAction; + _getBusyStateCallback ??= GetBusyStateAction; + _getObjectSpellIdsCallback ??= GetObjectSpellIdsAction; + _getObjectSkillBuffedCallback ??= GetObjectSkillLevelAction; + _getObjectAttributeCallback ??= GetObjectAttributeAction; _api.Version = PluginContractVersion.Current; _api.LogFn = Marshal.GetFunctionPointerForDelegate(_logCallback); @@ -1642,6 +1662,9 @@ internal static class PluginManager _api.Nav3DAddLineFn = Marshal.GetFunctionPointerForDelegate(_nav3DAddLineCallback); _api.InvokeChatParserFn = Marshal.GetFunctionPointerForDelegate(_invokeChatParserCallback); _api.GetObjectDoublePropertyFn = Marshal.GetFunctionPointerForDelegate(_getObjectDoublePropertyCallback); + _api.GetObjectQuadPropertyFn = Marshal.GetFunctionPointerForDelegate(_getObjectQuadPropertyCallback); + _api.GetObjectAttribute2ndBaseLevelFn = Marshal.GetFunctionPointerForDelegate(_getObjectAttribute2ndBaseLevelCallback); + _api.GetPlayerBaseVitalsFn = Marshal.GetFunctionPointerForDelegate(_getPlayerBaseVitalsCallback); _api.GetObjectStringPropertyFn = Marshal.GetFunctionPointerForDelegate(_getObjectStringPropertyCallback); _api.GetObjectWielderInfoFn = Marshal.GetFunctionPointerForDelegate(_getObjectWielderInfoCallback); _api.NativeAttackFn = Marshal.GetFunctionPointerForDelegate(_nativeAttackCallback); @@ -1659,6 +1682,13 @@ internal static class PluginManager _api.GetAccountNameFn = Marshal.GetFunctionPointerForDelegate(_getAccountNameCallback); _api.GetWorldNameFn = Marshal.GetFunctionPointerForDelegate(_getWorldNameCallback); _api.GetObjectWcidFn = Marshal.GetFunctionPointerForDelegate(_getObjectWcidCallback); + _api.HasAppraisalDataFn = Marshal.GetFunctionPointerForDelegate(_hasAppraisalDataCallback); + _api.GetLastIdTimeFn = Marshal.GetFunctionPointerForDelegate(_getLastIdTimeCallback); + _api.GetObjectHeadingFn = Marshal.GetFunctionPointerForDelegate(_getObjectHeadingCallback); + _api.GetBusyStateFn = Marshal.GetFunctionPointerForDelegate(_getBusyStateCallback); + _api.GetObjectSpellIdsFn = Marshal.GetFunctionPointerForDelegate(_getObjectSpellIdsCallback); + _api.GetObjectSkillBuffedFn = Marshal.GetFunctionPointerForDelegate(_getObjectSkillBuffedCallback); + _api.GetObjectAttributeFn = Marshal.GetFunctionPointerForDelegate(_getObjectAttributeCallback); } private static void ProbeClientHooks() @@ -1779,6 +1809,35 @@ internal static class PluginManager return 1; } + private static unsafe int GetObjectQuadPropertyAction(uint objectId, uint stype, long* value) + { + if (!ClientObjectHooks.TryGetObjectQuadProperty(objectId, stype, out long v)) + return 0; + + *value = v; + return 1; + } + + private static unsafe int GetObjectAttribute2ndBaseLevelAction(uint objectId, uint stype2nd, uint* value) + { + if (!ClientObjectHooks.TryGetObjectAttribute2ndBaseLevel(objectId, stype2nd, out uint v)) + return 0; + + *value = v; + return 1; + } + + private static unsafe int GetPlayerBaseVitalsAction(uint* baseMaxHp, uint* baseMaxStam, uint* baseMaxMana) + { + if (!PlayerVitalsHooks.TryGetPlayerBaseVitals(out uint hp, out uint stam, out uint mana)) + return 0; + + *baseMaxHp = hp; + *baseMaxStam = stam; + *baseMaxMana = mana; + return 1; + } + private static unsafe int GetObjectBoolPropertyAction(uint objectId, uint stype, int* value) { if (!ClientObjectHooks.TryGetObjectBoolProperty(objectId, stype, out bool v)) @@ -1863,6 +1922,22 @@ internal static class PluginManager return 1; } + private static unsafe int GetObjectSkillLevelAction(uint objectId, uint skillStype, int raw, int* level) + { + if (!ClientObjectHooks.TryGetObjectSkillLevel(objectId, skillStype, raw, out int v)) + return 0; + *level = v; + return 1; + } + + private static unsafe int GetObjectAttributeAction(uint objectId, uint stype, int raw, uint* value) + { + if (!ClientObjectHooks.TryGetObjectAttribute(objectId, stype, raw, out uint v)) + return 0; + *value = v; + return 1; + } + private static unsafe int ReadPlayerEnchantmentsAction(uint* spellIds, double* expiryTimes, int maxCount) { return EnchantmentHooks.ReadPlayerEnchantments(spellIds, expiryTimes, maxCount); @@ -2109,6 +2184,41 @@ internal static class PluginManager return ClientObjectHooks.TryGetObjectWcid(objectId, out uint wcid) ? wcid : 0u; } + private static int HasAppraisalDataAction(uint objectId) + { + return AppraisalHooks.HasAppraisalData(objectId) ? 1 : 0; + } + + private static long GetLastIdTimeAction(uint objectId) + { + return AppraisalHooks.GetLastIdTime(objectId); + } + + private static unsafe int GetObjectHeadingAction(uint objectId, float* headingDegrees) + { + if (!ClientObjectHooks.TryGetObjectHeading(objectId, out float h)) + return 0; + *headingDegrees = h; + return 1; + } + + private static int GetBusyStateAction() => BusyCountHooks.GetBusyState(); + + private static unsafe int GetObjectSpellIdsAction(uint guid, uint* spellIds, int maxCount) + { + if (spellIds == null || maxCount <= 0) + return -1; + var output = new uint[maxCount]; + int result = AppraisalHooks.GetObjectSpellIds(guid, output, maxCount); + if (result > 0) + { + int count = Math.Min(result, maxCount); + for (int i = 0; i < count; i++) + spellIds[i] = output[i]; + } + return result; + } + private static unsafe int GetPlayerPose( uint* objCellId, float* x, diff --git a/src/RynthCore.PluginSdk/RynthCoreApiNative.cs b/src/RynthCore.PluginSdk/RynthCoreApiNative.cs index a81cb11..60712b8 100644 --- a/src/RynthCore.PluginSdk/RynthCoreApiNative.cs +++ b/src/RynthCore.PluginSdk/RynthCoreApiNative.cs @@ -66,6 +66,9 @@ public struct RynthCoreApiNative public IntPtr Nav3DAddLineFn; public IntPtr InvokeChatParserFn; public IntPtr GetObjectDoublePropertyFn; + public IntPtr GetObjectQuadPropertyFn; + public IntPtr GetObjectAttribute2ndBaseLevelFn; + public IntPtr GetPlayerBaseVitalsFn; public IntPtr GetObjectStringPropertyFn; public IntPtr GetObjectWielderInfoFn; public IntPtr NativeAttackFn; @@ -83,4 +86,11 @@ public struct RynthCoreApiNative public IntPtr GetAccountNameFn; public IntPtr GetWorldNameFn; public IntPtr GetObjectWcidFn; + public IntPtr HasAppraisalDataFn; + public IntPtr GetLastIdTimeFn; + public IntPtr GetObjectHeadingFn; + public IntPtr GetBusyStateFn; + public IntPtr GetObjectSpellIdsFn; + public IntPtr GetObjectSkillBuffedFn; + public IntPtr GetObjectAttributeFn; } diff --git a/src/RynthCore.PluginSdk/RynthCoreHost.cs b/src/RynthCore.PluginSdk/RynthCoreHost.cs index 9761954..842a20a 100644 --- a/src/RynthCore.PluginSdk/RynthCoreHost.cs +++ b/src/RynthCore.PluginSdk/RynthCoreHost.cs @@ -54,7 +54,12 @@ public readonly unsafe struct RynthCoreHost public bool HasGetVitae => _api.GetVitaeFn != IntPtr.Zero; public bool HasGetAccountName => _api.GetAccountNameFn != IntPtr.Zero; public bool HasGetWorldName => _api.GetWorldNameFn != IntPtr.Zero; - public bool HasGetObjectWcid => _api.GetObjectWcidFn != IntPtr.Zero; + public bool HasGetObjectWcid => _api.GetObjectWcidFn != IntPtr.Zero; + public bool HasHasAppraisalData => _api.HasAppraisalDataFn != IntPtr.Zero; + public bool HasGetLastIdTime => _api.GetLastIdTimeFn != IntPtr.Zero; + public bool HasGetObjectHeading => _api.GetObjectHeadingFn != IntPtr.Zero; + public bool HasGetBusyState => _api.GetBusyStateFn != IntPtr.Zero; + public bool HasGetObjectSpellIds => _api.GetObjectSpellIdsFn != IntPtr.Zero; public bool HasSetMotion => _api.SetMotionFn != IntPtr.Zero; public bool HasStopCompletely => _api.StopCompletelyFn != IntPtr.Zero; public bool HasTurnToHeading => _api.TurnToHeadingFn != IntPtr.Zero; @@ -79,6 +84,9 @@ public readonly unsafe struct RynthCoreHost public bool HasNav3D => _api.Nav3DClearFn != IntPtr.Zero && _api.Nav3DAddRingFn != IntPtr.Zero && _api.Nav3DAddLineFn != IntPtr.Zero; public bool HasInvokeChatParser => _api.InvokeChatParserFn != IntPtr.Zero; public bool HasGetObjectDoubleProperty => _api.GetObjectDoublePropertyFn != IntPtr.Zero; + public bool HasGetObjectQuadProperty => _api.GetObjectQuadPropertyFn != IntPtr.Zero; + public bool HasGetObjectAttribute2ndBaseLevel => _api.GetObjectAttribute2ndBaseLevelFn != IntPtr.Zero; + public bool HasGetPlayerBaseVitals => _api.GetPlayerBaseVitalsFn != IntPtr.Zero; public bool HasGetObjectStringProperty => _api.GetObjectStringPropertyFn != IntPtr.Zero; public bool HasGetObjectWielderInfo => _api.GetObjectWielderInfoFn != IntPtr.Zero; public bool HasNativeAttack => _api.NativeAttackFn != IntPtr.Zero; @@ -455,6 +463,32 @@ public readonly unsafe struct RynthCoreHost return wcid != 0; } + public bool HasAppraisalData(uint objectId) + { + if (_api.HasAppraisalDataFn == IntPtr.Zero) return false; + return ((delegate* unmanaged[Cdecl])_api.HasAppraisalDataFn)(objectId) != 0; + } + + public long GetLastIdTime(uint objectId) + { + if (_api.GetLastIdTimeFn == IntPtr.Zero) return 0L; + return ((delegate* unmanaged[Cdecl])_api.GetLastIdTimeFn)(objectId); + } + + public bool TryGetObjectHeading(uint objectId, out float headingDegrees) + { + headingDegrees = 0; + if (_api.GetObjectHeadingFn == IntPtr.Zero) return false; + fixed (float* hPtr = &headingDegrees) + return ((delegate* unmanaged[Cdecl])_api.GetObjectHeadingFn)(objectId, hPtr) != 0; + } + + public int GetBusyState() + { + if (_api.GetBusyStateFn == IntPtr.Zero) return 0; + return ((delegate* unmanaged[Cdecl])_api.GetBusyStateFn)(); + } + public bool TryGetObjectName(uint objectId, out string name) { name = string.Empty; @@ -612,6 +646,27 @@ public readonly unsafe struct RynthCoreHost } } + public bool HasGetObjectSkillBuffed => _api.GetObjectSkillBuffedFn != IntPtr.Zero; + + /// raw=0 → buffed (with enchantments), raw=1 → base (no enchantments, includes attribute contribution). + public bool TryGetObjectSkillLevel(uint objectId, uint skillStype, int raw, out int level) + { + level = 0; + if (_api.GetObjectSkillBuffedFn == IntPtr.Zero) return false; + fixed (int* p = &level) + return ((delegate* unmanaged[Cdecl])_api.GetObjectSkillBuffedFn)(objectId, skillStype, raw, p) != 0; + } + + public bool HasGetObjectAttribute => _api.GetObjectAttributeFn != IntPtr.Zero; + + public bool TryGetObjectAttribute(uint objectId, uint stype, int raw, out uint value) + { + value = 0; + if (_api.GetObjectAttributeFn == IntPtr.Zero) return false; + fixed (uint* p = &value) + return ((delegate* unmanaged[Cdecl])_api.GetObjectAttributeFn)(objectId, stype, raw, p) != 0; + } + public bool IsSpellKnown(uint objectId, uint spellId, out bool known) { known = true; @@ -719,6 +774,29 @@ public readonly unsafe struct RynthCoreHost } } + public int GetObjectSpellIds(uint objectId, uint[] spellIds, int maxCount) + { + if (_api.GetObjectSpellIdsFn == IntPtr.Zero || spellIds == null || maxCount <= 0) + return -1; + + IntPtr spellBuf = Marshal.AllocHGlobal(maxCount * sizeof(uint)); + try + { + int result = ((delegate* unmanaged[Cdecl])_api.GetObjectSpellIdsFn)( + objectId, (uint*)spellBuf, maxCount); + + int count = result > 0 ? Math.Min(result, Math.Min(maxCount, spellIds.Length)) : 0; + uint* sp = (uint*)spellBuf; + for (int i = 0; i < count; i++) + spellIds[i] = sp[i]; + return result; + } + finally + { + Marshal.FreeHGlobal(spellBuf); + } + } + // ─── World projection & viewport ──────────────────────────────────────── public bool WorldToScreen(float worldX, float worldY, float worldZ, out float screenX, out float screenY) @@ -793,6 +871,44 @@ public readonly unsafe struct RynthCoreHost // ─── Extended object properties ───────────────────────────────────────── + public bool TryGetObjectAttribute2ndBaseLevel(uint objectId, uint stype2nd, out uint value) + { + value = 0; + if (_api.GetObjectAttribute2ndBaseLevelFn == IntPtr.Zero) + return false; + + fixed (uint* valuePtr = &value) + { + return ((delegate* unmanaged[Cdecl])_api.GetObjectAttribute2ndBaseLevelFn)(objectId, stype2nd, valuePtr) != 0; + } + } + + public bool TryGetPlayerBaseVitals(out uint baseMaxHp, out uint baseMaxStam, out uint baseMaxMana) + { + baseMaxHp = baseMaxStam = baseMaxMana = 0; + if (_api.GetPlayerBaseVitalsFn == IntPtr.Zero) + return false; + + fixed (uint* hpPtr = &baseMaxHp) + fixed (uint* stamPtr = &baseMaxStam) + fixed (uint* manaPtr = &baseMaxMana) + { + return ((delegate* unmanaged[Cdecl])_api.GetPlayerBaseVitalsFn)(hpPtr, stamPtr, manaPtr) != 0; + } + } + + public bool TryGetObjectQuadProperty(uint objectId, uint stype, out long value) + { + value = 0; + if (_api.GetObjectQuadPropertyFn == IntPtr.Zero) + return false; + + fixed (long* valuePtr = &value) + { + return ((delegate* unmanaged[Cdecl])_api.GetObjectQuadPropertyFn)(objectId, stype, valuePtr) != 0; + } + } + public bool TryGetObjectDoubleProperty(uint objectId, uint stype, out double value) { value = 0;