Follow advice from a friendly guy

This commit is contained in:
FutureRave 2022-02-27 17:36:13 +00:00
parent 30f47bf2b8
commit 41ff80759d
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
4 changed files with 22 additions and 12 deletions

View File

@ -2,6 +2,7 @@
namespace Components namespace Components
{ {
Game::dvar_t* Bots::TestClientsActivate;
std::vector<std::string> Bots::BotNames; std::vector<std::string> Bots::BotNames;
struct BotMovementInfo struct BotMovementInfo
@ -10,7 +11,6 @@ namespace Components
int8_t forward; int8_t forward;
int8_t right; int8_t right;
uint16_t weapon; uint16_t weapon;
bool active;
}; };
static BotMovementInfo g_botai[18]; static BotMovementInfo g_botai[18];
@ -160,7 +160,6 @@ namespace Components
g_botai[entref.entnum] = {0}; g_botai[entref.entnum] = {0};
g_botai[entref.entnum].weapon = 1; g_botai[entref.entnum].weapon = 1;
g_botai[entref.entnum].active = false;
}); });
Script::AddFunction("BotWeapon", [](Game::scr_entref_t entref) // Usage: <bot> BotWeapon(<str>); Script::AddFunction("BotWeapon", [](Game::scr_entref_t entref) // Usage: <bot> BotWeapon(<str>);
@ -184,7 +183,6 @@ namespace Components
const auto weapId = Game::G_GetWeaponIndexForName(weapon); const auto weapId = Game::G_GetWeaponIndexForName(weapon);
g_botai[entref.entnum].weapon = static_cast<uint16_t>(weapId); g_botai[entref.entnum].weapon = static_cast<uint16_t>(weapId);
g_botai[entref.entnum].active = true;
}); });
Script::AddFunction("BotAction", [](Game::scr_entref_t entref) // Usage: <bot> BotAction(<str action>); Script::AddFunction("BotAction", [](Game::scr_entref_t entref) // Usage: <bot> BotAction(<str action>);
@ -222,7 +220,6 @@ namespace Components
else else
g_botai[entref.entnum].buttons &= ~(BotActions[i].key); g_botai[entref.entnum].buttons &= ~(BotActions[i].key);
g_botai[entref.entnum].active = true;
return; return;
} }
@ -248,7 +245,6 @@ namespace Components
g_botai[entref.entnum].forward = static_cast<int8_t>(forwardInt); g_botai[entref.entnum].forward = static_cast<int8_t>(forwardInt);
g_botai[entref.entnum].right = static_cast<int8_t>(rightInt); g_botai[entref.entnum].right = static_cast<int8_t>(rightInt);
g_botai[entref.entnum].active = true;
}); });
} }
@ -259,10 +255,6 @@ namespace Components
const auto entnum = cl->gentity->s.number; const auto entnum = cl->gentity->s.number;
// Keep test client functionality
if (!g_botai[entnum].active)
return;
Game::usercmd_s ucmd = {0}; Game::usercmd_s ucmd = {0};
ucmd.serverTime = *Game::svs_time; ucmd.serverTime = *Game::svs_time;
@ -280,7 +272,12 @@ namespace Components
{ {
__asm __asm
{ {
call SV_BotUserMove push eax
mov eax, Bots::TestClientsActivate
cmp byte ptr [eax + 0x10], 0x1
pop eax
jz enableBots
pushad pushad
@ -289,20 +286,28 @@ namespace Components
add esp, 4 add esp, 4
popad popad
ret
enableBots:
call SV_BotUserMove
ret ret
} }
} }
Bots::Bots() Bots::Bots()
{ {
Bots::TestClientsActivate = Game::Dvar_RegisterBool("testClients_activate", true,
Game::dvar_flag::DVAR_FLAG_NONE, "Testclients will retain their native functionality.");
// Replace connect string // Replace connect string
Utils::Hook::Set<const char*>(0x48ADA6, "connect bot%d \"\\cg_predictItems\\1\\cl_anonymous\\0\\color\\4\\head\\default\\model\\multi\\snaps\\20\\rate\\5000\\name\\%s\\protocol\\%d\\checksum\\%d\\statver\\%d %u\\qport\\%d\""); Utils::Hook::Set<const char*>(0x48ADA6, "connect bot%d \"\\cg_predictItems\\1\\cl_anonymous\\0\\color\\4\\head\\default\\model\\multi\\snaps\\20\\rate\\5000\\name\\%s\\protocol\\%d\\checksum\\%d\\statver\\%d %u\\qport\\%d\"");
// Intercept sprintf for the connect string // Intercept sprintf for the connect string
Utils::Hook(0x48ADAB, Bots::BuildConnectString, HOOK_CALL).install()->quick(); Utils::Hook(0x48ADAB, Bots::BuildConnectString, HOOK_CALL).install()->quick();
Utils::Hook(0x627021, SV_UpdateBots_Hk, HOOK_CALL).install()->quick(); Utils::Hook(0x627021, Bots::SV_UpdateBots_Hk, HOOK_CALL).install()->quick();
Utils::Hook(0x627241, SV_UpdateBots_Hk, HOOK_CALL).install()->quick(); Utils::Hook(0x627241, Bots::SV_UpdateBots_Hk, HOOK_CALL).install()->quick();
// Zero the bot command array // Zero the bot command array
for (auto i = 0u; i < std::extent_v<decltype(g_botai)>; i++) for (auto i = 0u; i < std::extent_v<decltype(g_botai)>; i++)

View File

@ -22,6 +22,7 @@ namespace Components
}; };
private: private:
static Game::dvar_t* TestClientsActivate;
static std::vector<std::string> BotNames; static std::vector<std::string> BotNames;
static int BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port); static int BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port);

View File

@ -323,6 +323,7 @@ namespace Game
StringTable_HashString_t StringTable_HashString = StringTable_HashString_t(0x475EB0); StringTable_HashString_t StringTable_HashString = StringTable_HashString_t(0x475EB0);
SV_AddTestClient_t SV_AddTestClient = SV_AddTestClient_t(0x48AD30); SV_AddTestClient_t SV_AddTestClient = SV_AddTestClient_t(0x48AD30);
SV_IsTestClient_t SV_IsTestClient = SV_IsTestClient_t(0x4D6E40);
SV_GameClientNum_Score_t SV_GameClientNum_Score = SV_GameClientNum_Score_t(0x469AC0); SV_GameClientNum_Score_t SV_GameClientNum_Score = SV_GameClientNum_Score_t(0x469AC0);
SV_GameSendServerCommand_t SV_GameSendServerCommand = SV_GameSendServerCommand_t(0x4BC3A0); SV_GameSendServerCommand_t SV_GameSendServerCommand = SV_GameSendServerCommand_t(0x4BC3A0);
SV_Cmd_TokenizeString_t SV_Cmd_TokenizeString = SV_Cmd_TokenizeString_t(0x4B5780); SV_Cmd_TokenizeString_t SV_Cmd_TokenizeString = SV_Cmd_TokenizeString_t(0x4B5780);

View File

@ -768,6 +768,9 @@ namespace Game
typedef gentity_t*(__cdecl* SV_AddTestClient_t)(); typedef gentity_t*(__cdecl* SV_AddTestClient_t)();
extern SV_AddTestClient_t SV_AddTestClient; extern SV_AddTestClient_t SV_AddTestClient;
typedef int(__cdecl * SV_IsTestClient_t)(int clientNum);
extern SV_IsTestClient_t SV_IsTestClient;
typedef int(__cdecl* SV_GameClientNum_Score_t)(int clientID); typedef int(__cdecl* SV_GameClientNum_Score_t)(int clientID);
extern SV_GameClientNum_Score_t SV_GameClientNum_Score; extern SV_GameClientNum_Score_t SV_GameClientNum_Score;