Skip to content

Commit 0ede5ca

Browse files
committed
feat: Implemented EntityToEdict
1 parent 9b749e3 commit 0ede5ca

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/utils.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,17 @@ void Utils::SetOrigin(CBaseEntity* entity, const Vector& vecOrigin, const bool f
286286
setOrigin(entity, vecOrigin, fireTriggers);
287287
}
288288

289+
/**
290+
* @brief CBaseEntity to entity index.
291+
* @param pEntity Pointer to entity.
292+
* @return Entity index of entity.
293+
*/
294+
int Utils::EntityIndex(CBaseEntity* pEntity)
295+
{
296+
static auto entIndex = reinterpret_cast<int (__cdecl*)(CBaseEntity*)>(Memory::Scan<void*>(MODULE_SERVER, "55 8B EC 8B 45 ? 85 C0 74 ? 8B 40 ? 85 C0 74 ? 8B 0D"));
297+
return entIndex(pEntity);
298+
}
299+
289300
/**
290301
* @brief Entity edict to entity index.
291302
* @param pEdict Pointer to edict.
@@ -318,6 +329,16 @@ edict_t* Utils::IndexToEdict(const int entityIndex)
318329
return nullptr;
319330
}
320331

332+
/**
333+
* @brief Convert CBaseEntity to entity edict.
334+
* @param pEntity Pointer to entity.
335+
* @return Edict of CBaseEntity.
336+
*/
337+
edict_t* Utils::EntityToEdict(CBaseEntity* pEntity)
338+
{
339+
return IndexToEdict(EntityIndex(pEntity));
340+
}
341+
321342
/**
322343
* @brief Returns the current game directory. Ex. "portal2"
323344
* @return The current game directory.
@@ -365,13 +386,3 @@ bool Utils::IsGameShutdown()
365386
return bIsGameShuttingDown;
366387
}
367388

368-
/**
369-
* @brief CBaseEntity to entity index.
370-
* @param pEntity Pointer to entity.
371-
* @return Entity index of entity.
372-
*/
373-
int Utils::EntityIndex(CBaseEntity* pEntity)
374-
{
375-
static auto entIndex = reinterpret_cast<int (__cdecl*)(CBaseEntity*)>(Memory::Scan<void*>(MODULE_SERVER, "55 8B EC 8B 45 ? 85 C0 74 ? 8B 40 ? 85 C0 74 ? 8B 0D"));
376-
return entIndex(pEntity);
377-
}

src/utils.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ namespace Utils
8282
CBasePlayer* GetCommandClient();
8383
int GetCommandClientIndex();
8484
void SetOrigin(CBaseEntity* entity, const Vector& vecOrigin, bool fireTriggers);
85+
int EntityIndex(CBaseEntity* pEntity);
8586
int EdictIndex(const edict_t* pEdict);
8687
edict_t* IndexToEdict(const int entityIndex);
88+
edict_t* EntityToEdict(CBaseEntity* pEntity);
8789
const char* GetGameMainDir();
8890
const char* GetGameRootDir();
8991
bool IsGameActive();
9092
bool IsGameShutdown();
91-
int EntityIndex(CBaseEntity* pEntity);
9293
}
9394

9495
/**

0 commit comments

Comments
 (0)