diff --git a/src/Components/Modules/Player.cpp b/src/Components/Modules/Player.cpp index 23124f9..790f715 100644 --- a/src/Components/Modules/Player.cpp +++ b/src/Components/Modules/Player.cpp @@ -1,11 +1,63 @@ #include "STDInclude.hpp" #include "Player.hpp" +#include "Scheduler.hpp" namespace Components { + Game::cvar_t* Player::g_playerEjection; + Game::cvar_t* Player::g_playerCollision; + + int Player::StuckInClient_Func(Game::gentity_t* ent) + { + if (!g_playerEjection->current.boolean) + return 0; + + return Game::StuckInClient(ent); + } + + __declspec(naked) void Player::StuckInClient_Stub() + { + __asm + { + push eax; + call StuckInClient_Func; + add esp, 4; + retn; + } + } + + void Player::CM_Trace_Func(float* a1, float* a2, float* a3, int a4, float* a5, int a6, int a7) + { + if (g_playerCollision->current.boolean) + Game::CM_Trace(a1, a2, a3, a4, a5, a6, a7); + } + + __declspec(naked) void Player::CM_Trace_Stub() + { + __asm + { + push ecx; + push edx; + push eax; + call CM_Trace_Func; + add esp, 0xC; + + push 0x41D93E; + retn; + } + } + Player::Player() { - //MessageBoxA(nullptr, Utils::String::VA("%d", Game::svs), "DEBUG", 0); + Scheduler::OnReady([]() + { + g_playerEjection = Game::Dvar_RegisterBool("g_playerEjection", true, Game::CVAR_FLAG_ARCHIVE); + g_playerCollision = Game::Dvar_RegisterBool("g_playerCollision", true, Game::CVAR_FLAG_ARCHIVE); + }); + + Utils::Hook(0x5011D3, StuckInClient_Stub, HOOK_CALL).install()->quick(); + + Utils::Hook(0x41D939, CM_Trace_Stub, HOOK_JUMP).install()->quick(); } Player::~Player() diff --git a/src/Components/Modules/Player.hpp b/src/Components/Modules/Player.hpp index 42862bb..cf30288 100644 --- a/src/Components/Modules/Player.hpp +++ b/src/Components/Modules/Player.hpp @@ -7,5 +7,13 @@ namespace Components public: Player(); ~Player(); + + static Game::cvar_t* g_playerEjection; + static Game::cvar_t* g_playerCollision; + private: + static int StuckInClient_Func(Game::gentity_t* ent); + static void StuckInClient_Stub(); + static void CM_Trace_Func(float*, float*, float*, int, float*, int, int); + static void CM_Trace_Stub(); }; } diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 25309c3..ff48fdf 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -36,6 +36,8 @@ namespace Game Sys_Milliseconds_t* Sys_Milliseconds; Com_Printf_t* Com_Printf; Com_DedicatedModified_t* Com_DedicatedModified; + Dvar_RegisterBool_t* Dvar_RegisterBool; + char* isDvarSystemActive; @@ -54,6 +56,7 @@ namespace Game Sys_Milliseconds = ASSIGN(Sys_Milliseconds_t*, 0x435200); Com_Printf = ASSIGN(Com_Printf_t*, 0x431EE0); Com_DedicatedModified = ASSIGN(Com_DedicatedModified_t*, 0x434DC0); + Dvar_RegisterBool = ASSIGN(Dvar_RegisterBool_t*, 0x438040); isDvarSystemActive = ASSIGN(char*, 0xC5C5C8); @@ -164,5 +167,38 @@ namespace Game add esp, 4; } } + + void CM_Trace(float* a1, float* a2, float* a3, int a4, float* a5, int a6, int a7) + { + int func_loc = 0x41D120; + + __asm + { + push a7; + push a6; + push a5; + push a4; + mov ecx, a3; + mov edx, a2; + mov eax, a1; + call func_loc; + add esp, 0x10; + } + } + + int StuckInClient(Game::gentity_t* ent) + { + int func_loc = 0x5009F0; + int answer; + + __asm + { + mov eax, ent; + call func_loc; + mov answer, eax; + } + + return answer; + } } diff --git a/src/Game/Game.hpp b/src/Game/Game.hpp index e114b88..cdc6bbf 100644 --- a/src/Game/Game.hpp +++ b/src/Game/Game.hpp @@ -54,7 +54,10 @@ namespace Game typedef void(Com_Printf_t)(const char *, ...); extern Com_Printf_t* Com_Printf; - extern unsigned int Scr_GetFunctionHandle(char*, const char*); + typedef cvar_t*(Dvar_RegisterBool_t)(const char *, int, int); + extern Dvar_RegisterBool_t* Dvar_RegisterBool; + + extern unsigned int Scr_GetFunctionHandle(const char*, const char*); extern __int16 Scr_ExecThread(int); extern void RemoveRefToObject(int); @@ -67,4 +70,7 @@ namespace Game extern void G_SelectWeaponIndex(int, int); extern void SV_ClientThink(Game::usercmd_s*, Game::client_t*); extern void SV_DropClient(Game::client_t*, const char*); + extern void CM_Trace(float*, float*, float*, int, float*, int, int); + + extern int StuckInClient(Game::gentity_t*); }