From 38adae2c75e96bff72a3062a3be8f27df54f836d Mon Sep 17 00:00:00 2001 From: ineedbots Date: Mon, 28 Jun 2021 21:35:05 -0600 Subject: [PATCH] Hook switching weapons --- src/Components/Modules/Bots.cpp | 45 +++++++++++++++++++++++++++++++++ src/Components/Modules/Bots.hpp | 6 +++++ src/Game/Game.cpp | 12 +++++++++ src/Game/Game.hpp | 1 + 4 files changed, 64 insertions(+) diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index 2b46c2e..2f2eb93 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -41,6 +41,44 @@ namespace Components } } + void Bots::G_SelectWeaponIndex_Func(int wpIdx, int clNum) + { + Game::G_SelectWeaponIndex(wpIdx, clNum); + } + + __declspec(naked) void Bots::G_SelectWeaponIndex_Stub() + { + __asm + { + push esi; + push eax; + call G_SelectWeaponIndex_Func; + add esp, 8; + retn; + } + } + + void Bots::PlayerCmd_setSpawnWeapon_Func(Game::gentity_t* ent, int wpIdx) + { + + } + + __declspec(naked) void Bots::PlayerCmd_setSpawnWeapon_Stub() + { + __asm + { + push edx; + push esi; + call PlayerCmd_setSpawnWeapon_Func; + add esp, 8; + + // go back + mov eax, [esi + 0x158]; + push 0x52B16C; + retn; + } + } + Bots::Bots() { // intercept the sprintf when creating the bot connect string @@ -51,6 +89,13 @@ namespace Components // stop the ping spam Utils::Hook::Nop(0x45BF59, 5); + + + // fix bots switching weapons + Utils::Hook(0x52A1C2, G_SelectWeaponIndex_Stub, HOOK_CALL).install()->quick(); + Utils::Hook(0x51E2DC, G_SelectWeaponIndex_Stub, HOOK_CALL).install()->quick(); + Utils::Hook(0x501E0D, G_SelectWeaponIndex_Stub, HOOK_CALL).install()->quick(); + Utils::Hook(0x52B166, PlayerCmd_setSpawnWeapon_Stub, HOOK_JUMP).install()->quick(); } Bots::~Bots() diff --git a/src/Components/Modules/Bots.hpp b/src/Components/Modules/Bots.hpp index 6b80a1f..4a90c10 100644 --- a/src/Components/Modules/Bots.hpp +++ b/src/Components/Modules/Bots.hpp @@ -13,5 +13,11 @@ namespace Components static int BuildConnectString(char*, const char*, int, int); static void SV_BotUserMove_Func(Game::client_t*); static void SV_BotUserMove_Stub(); + + static void G_SelectWeaponIndex_Func(int, int); + static void G_SelectWeaponIndex_Stub(); + + static void PlayerCmd_setSpawnWeapon_Func(Game::gentity_t*, int); + static void PlayerCmd_setSpawnWeapon_Stub(); }; } diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index 423f57b..80f5876 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -65,6 +65,18 @@ namespace Game bgs_ptr = ASSIGN(bgs_s**, 0x19A1C78); } + void G_SelectWeaponIndex(int wpIdx, int clNum) + { + int func_loc = 0x5282E0; + + __asm + { + mov esi, clNum; + mov eax, wpIdx; + call func_loc; + } + } + void SV_ClientThink(Game::usercmd_s* cmd, Game::client_t* client) { int func_loc = 0x456010; diff --git a/src/Game/Game.hpp b/src/Game/Game.hpp index d0c7c8e..92909b3 100644 --- a/src/Game/Game.hpp +++ b/src/Game/Game.hpp @@ -39,6 +39,7 @@ namespace Game typedef Game::xfunction_t* (Scr_GetFunction_t)(const char**, int*); extern Scr_GetFunction_t* Scr_GetFunction; + 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*); }