File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed
Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -223,6 +223,23 @@ inline edict_t* INDEXENT(const int iEdictNum)
223223 return nullptr ;
224224}
225225
226+ // ---------------------------------------------------------------------------------
227+ // Purpose: VScript instance to void*. void* because we can not assume that the returned instance is a CBaseEntity* because VScript instances can be
228+ // ---------------------------------------------------------------------------------
229+ inline void * HSCRIPTENT (const HSCRIPT ent)
230+ {
231+ if (!ent)
232+ return nullptr ;
233+
234+ static uintptr_t func = reinterpret_cast <uintptr_t >(Memory::Scanner::Scan<void *>(SERVERDLL, " E8 ?? ?? ?? ?? 8B 4D 18 8B 57 5C" , 1 ));
235+ static auto GetCBaseEntityScriptDesc = reinterpret_cast <ScriptClassDesc_t* (__cdecl*)()>(*reinterpret_cast <uintptr_t *>(func) + func + sizeof (func));
236+ void * pEntity = g_pScriptVM->GetInstanceValue (ent, GetCBaseEntityScriptDesc ());
237+ if (!pEntity)
238+ return nullptr ;
239+
240+ return pEntity;
241+ }
242+
226243// ---------------------------------------------------------------------------------
227244// Purpose: Returns the current game directory. Ex. portal2
228245// ---------------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -75,15 +75,16 @@ static bool IsDedicatedServer()
7575// ---------------------------------------------------------------------------------
7676static void InitializeEntity (const HSCRIPT ent)
7777{
78- static uintptr_t func = (uintptr_t )Memory::Scanner::Scan<void *>(SERVERDLL, " E8 ?? ?? ?? ?? 8B 4D 18 8B 57 5C" , 1 );
79- static auto GetCBaseEntityScriptDesc = reinterpret_cast <ScriptClassDesc_t* (__cdecl*)()>(*reinterpret_cast <uintptr_t *>(func) + func + sizeof (func));
80- if (void * pEntity = reinterpret_cast <void *>(g_pScriptVM->GetInstanceValue (ent, GetCBaseEntityScriptDesc ())))
81- {
82- g_pServerTools->DispatchSpawn (pEntity);
78+ // Get the entity of the instance.
79+ const auto pEntity = static_cast <CBaseEntity*>(HSCRIPTENT (ent));
80+ if (!pEntity)
81+ return ;
8382
84- static auto Activate = *reinterpret_cast <void (__thiscall**)(void *)>(*reinterpret_cast <uintptr_t *>(pEntity) + 148 );
85- Activate (pEntity);
86- }
83+ // Spawn the new entity into the world.
84+ g_pServerTools->DispatchSpawn (pEntity);
85+ // Call the entities Activate class function to make it fully work.
86+ static auto Activate = *reinterpret_cast <void (__thiscall**)(void *)>(*reinterpret_cast <uintptr_t *>(pEntity) + 148 );
87+ Activate (pEntity);
8788}
8889
8990// ---------------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments