1- #include " cbaseentity.h"
1+ /* ******************************************************************
2+ * @file cbaseentity.cpp
3+ * @brief CBaseEntity class recreation.
4+ * @author Orsell/Valve
5+ * @date 06 2025
6+ *********************************************************************/
7+
8+ #include " stdafx.hpp"
9+ #include " modules/cbaseentity.h"
10+
11+ #include " modules/cbaseplayer.h"
12+
13+ #include " utils/memory.hpp"
14+ #include " utils/loggingsystem.hpp"
15+
16+ #include " globals.hpp"
17+
18+ #include " vscript/ivscript.h"
19+ #include " irecipientfilter.h"
20+
21+ /* *
22+ * @brief Remove a entity from the world.
23+ * @param pEntity Pointer to entity.
24+ */
25+ void CBaseEntity::RemoveEntity (CBaseEntity* pEntity)
26+ {
27+ if (!pEntity)
28+ return ;
29+
30+ static auto removeEntity = reinterpret_cast <void (__cdecl*)(void *)>(Memory::Scan<void *>(SERVER, " 55 8B EC 57 8B 7D 08 85 FF 74 72" ));
31+ removeEntity ((reinterpret_cast <IServerEntity*>(pEntity)->GetNetworkable ()));
32+ }
33+
34+ /* *
35+ * @brief Get team number of a player.
36+ * @param pPlayer Pointer to player.
37+ * @return Team number or -1 if invalid player pointer or team.
38+ */
39+ int CBaseEntity::GetTeamNumber (CBasePlayer* pPlayer)
40+ {
41+ if (!pPlayer)
42+ return -1 ;
43+
44+ static auto getTeamNumber = reinterpret_cast <int (__thiscall*)(CBaseEntity*)>(Memory::Scan<void *>(SERVER, " 8B 81 F4 02 00 00 C3" ));
45+ return getTeamNumber (reinterpret_cast <CBaseEntity*>(pPlayer));
46+ }
47+
48+ /* *
49+ * @brief Get the script scope of a entity.
50+ * @param pEntity Pointer to entity.
51+ * @return VScript handle to entity's script scope.
52+ */
53+ HSCRIPT CBaseEntity::GetScriptScope (CBaseEntity* pEntity)
54+ {
55+ if (!pEntity)
56+ return nullptr ;
57+
58+ return *reinterpret_cast <HSCRIPT*>(reinterpret_cast <uintptr_t >(pEntity) + 0x33c );
59+ }
60+
61+ /* *
62+ * @brief Get the script instance of a entity.
63+ * @param entity Pointer to entity.
64+ * @return VScript instance handle of the entity.
65+ */
66+ HSCRIPT CBaseEntity::GetScriptInstance (CBaseEntity* entity)
67+ {
68+ static auto getScriptInstance = reinterpret_cast <HSCRIPT (__thiscall*)(CBaseEntity*)>(Memory::Scan<void *>(SERVER, " 55 8B EC 51 56 8B F1 83 BE 50" ));
69+ if (!getScriptInstance)
70+ {
71+ Log (WARNING, false , " Could not get script instance for entity!" );
72+ return nullptr ;
73+ }
74+
75+ return getScriptInstance (entity);
76+ }
77+
78+ /* *
79+ * @brief Make a entity emit a sound.
80+ * @param pEntity Entity that will call to emit a sound.
81+ * @param entityIndex Entity that will emit the sound. Use -1 if you want to set a position in the world for it to play.
82+ * @param filter Filter of recipient entities that can hear this noise.
83+ * @param soundName Sound file path, or script name to play.
84+ * @param pOrigin Position in the world the sound will play.
85+ * @param soundTime Time in seconds till sound is played. NOT HOW LONG SOUND WILL PLAY!
86+ * @return Return code for sound.
87+ */
88+ int CBaseEntity::EmitSound (CBaseEntity* pEntity, int entityIndex, IRecipientFilter* filter, const char * soundName, const Vector* pOrigin, const float soundTime)
89+ {
90+ static auto emitSound = reinterpret_cast <int (__thiscall*)(CBaseEntity*, IRecipientFilter*, int , const char *, const Vector*, float )>(Memory::Scan<void *>(SERVER, " 55 8B EC 83 EC 4C 8B 0D" ));
91+ return emitSound (pEntity, filter, entityIndex, soundName, pOrigin, soundTime);
92+ }
0 commit comments