From 177cf2ca558c5a5894fa334e30e52d21b7e05000 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 31 May 2023 23:55:18 +0200 Subject: [PATCH] Add 'UTIL_GetEntityScriptInfo' to SDK Retrieves information for an entity, formats it as [] or []. --- r5dev/game/shared/util_shared.cpp | 19 +++++++++++++++++-- r5dev/game/shared/util_shared.h | 11 ++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/r5dev/game/shared/util_shared.cpp b/r5dev/game/shared/util_shared.cpp index ae31ffb7..5f2a0b66 100644 --- a/r5dev/game/shared/util_shared.cpp +++ b/r5dev/game/shared/util_shared.cpp @@ -10,12 +10,17 @@ #include "game/server/gameinterface.h" #endif // !CLIENT_DLL - #ifndef CLIENT_DLL +//----------------------------------------------------------------------------- +// Purpose: returns the player instance by edict +//----------------------------------------------------------------------------- CPlayer* UTIL_PlayerByIndex(int nIndex) { - if (nIndex < 1 || nIndex > (*g_pGlobals)->m_nMaxClients || nIndex == FL_EDICT_INVALID) + if (nIndex < 1 || nIndex >(*g_pGlobals)->m_nMaxClients || nIndex == FL_EDICT_INVALID) + { + assert(0); return nullptr; + } // !TODO: Improve this!!! CPlayer* pPlayer = reinterpret_cast((*g_pGlobals)->m_pEdicts[nIndex + 0x7808]); @@ -23,6 +28,16 @@ CPlayer* UTIL_PlayerByIndex(int nIndex) } #endif // CLIENT_DLL +//----------------------------------------------------------------------------- +// Purpose: returns the class name, script name, and edict of the entity +// returns "<>" on NULL entity +//----------------------------------------------------------------------------- +const char* UTIL_GetEntityScriptInfo(CBaseEntity* pEnt) +{ + assert(pEnt != nullptr); + return v_UTIL_GetEntityScriptInfo(pEnt); +} + CTraceFilterSimple::CTraceFilterSimple(const IHandleEntity* pPassEntity, int collisionGroup, ShouldHitFunc_t pExtraShouldHitCheckFn) { void** pVTable = reinterpret_cast(&*this); // Assign vftable pointer to the implementation supplied by the engine. diff --git a/r5dev/game/shared/util_shared.h b/r5dev/game/shared/util_shared.h index 9583a74f..589a8c26 100644 --- a/r5dev/game/shared/util_shared.h +++ b/r5dev/game/shared/util_shared.h @@ -15,6 +15,10 @@ class CTraceFilterSimple; #ifndef CLIENT_DLL CPlayer* UTIL_PlayerByIndex(int nIndex); #endif // CLIENT_DLL +const char* UTIL_GetEntityScriptInfo(CBaseEntity* pEnt); + +inline CMemory p_UTIL_GetEntityScriptInfo; +inline auto v_UTIL_GetEntityScriptInfo = p_UTIL_GetEntityScriptInfo.RCast(); inline CTraceFilterSimple* g_pTraceFilterSimpleVFTable = nullptr; typedef bool (*ShouldHitFunc_t)(IHandleEntity* pHandleEntity, int contentsMask); @@ -49,9 +53,14 @@ class VUtil_Shared : public IDetour virtual void GetAdr(void) const { LogConAdr("CTraceFilterSimple::`vftable'", reinterpret_cast(g_pTraceFilterSimpleVFTable)); + LogFunAdr("UTIL_GetEntityScriptInfo", p_UTIL_GetEntityScriptInfo.GetPtr()); } virtual void GetFun(void) const { } - virtual void GetVar(void) const { } + virtual void GetVar(void) const + { + p_UTIL_GetEntityScriptInfo = g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 4C 8B 5E ??").FollowNearCallSelf(); + v_UTIL_GetEntityScriptInfo = p_UTIL_GetEntityScriptInfo.RCast(); + } virtual void GetCon(void) const { g_pTraceFilterSimpleVFTable = g_GameDll.GetVirtualMethodTable(".?AVCTraceFilterSimple@@").RCast();