2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
std::vector<std::string> Bots::BotNames;
|
|
|
|
|
2022-01-23 21:00:30 -05:00
|
|
|
struct BotMovementInfo
|
2020-11-14 03:47:35 -05:00
|
|
|
{
|
2022-01-23 14:32:20 -05:00
|
|
|
int buttons; // Actions
|
2022-01-07 16:00:44 -05:00
|
|
|
int8_t forward;
|
|
|
|
int8_t right;
|
|
|
|
uint16_t weapon;
|
2022-03-21 14:55:35 -04:00
|
|
|
bool active;
|
2022-01-23 14:32:20 -05:00
|
|
|
};
|
2020-11-14 03:47:35 -05:00
|
|
|
|
2022-01-23 21:00:30 -05:00
|
|
|
static BotMovementInfo g_botai[18];
|
2020-11-14 03:47:35 -05:00
|
|
|
|
2022-01-23 14:32:20 -05:00
|
|
|
struct BotAction
|
2020-11-14 03:47:35 -05:00
|
|
|
{
|
|
|
|
const char* action;
|
|
|
|
int key;
|
|
|
|
};
|
|
|
|
|
2022-01-23 14:32:20 -05:00
|
|
|
static const BotAction BotActions[] =
|
2020-11-14 03:47:35 -05:00
|
|
|
{
|
2022-02-01 07:41:38 -05:00
|
|
|
{ "gostand", Game::usercmdButtonBits::CMD_BUTTON_UP },
|
|
|
|
{ "gocrouch", Game::usercmdButtonBits::CMD_BUTTON_CROUCH },
|
|
|
|
{ "goprone", Game::usercmdButtonBits::CMD_BUTTON_PRONE },
|
|
|
|
{ "fire", Game::usercmdButtonBits::CMD_BUTTON_ATTACK },
|
|
|
|
{ "melee", Game::usercmdButtonBits::CMD_BUTTON_MELEE },
|
|
|
|
{ "frag", Game::usercmdButtonBits::CMD_BUTTON_FRAG },
|
|
|
|
{ "smoke", Game::usercmdButtonBits::CMD_BUTTON_OFFHAND_SECONDARY },
|
|
|
|
{ "reload", Game::usercmdButtonBits::CMD_BUTTON_RELOAD },
|
|
|
|
{ "sprint", Game::usercmdButtonBits::CMD_BUTTON_SPRINT },
|
|
|
|
{ "leanleft", Game::usercmdButtonBits::CMD_BUTTON_LEAN_LEFT },
|
|
|
|
{ "leanright", Game::usercmdButtonBits::CMD_BUTTON_LEAN_RIGHT },
|
|
|
|
{ "ads", Game::usercmdButtonBits::CMD_BUTTON_ADS },
|
|
|
|
{ "holdbreath", Game::usercmdButtonBits::CMD_BUTTON_BREATH },
|
2022-03-21 14:55:35 -04:00
|
|
|
{ "usereload", Game::usercmdButtonBits::CMD_BUTTON_USE_RELOAD },
|
|
|
|
{ "activate", Game::usercmdButtonBits::CMD_BUTTON_ACTIVATE },
|
2022-01-23 14:32:20 -05:00
|
|
|
{ "0", Bots::NUM_0 },
|
|
|
|
{ "1", Bots::NUM_1 },
|
|
|
|
{ "2", Bots::NUM_2 },
|
|
|
|
{ "3", Bots::NUM_3 },
|
|
|
|
{ "4", Bots::NUM_4},
|
|
|
|
{ "5", Bots::NUM_5 },
|
|
|
|
{ "6", Bots::NUM_6 },
|
|
|
|
{ "7", Bots::NUM_7 },
|
|
|
|
{ "8", Bots::NUM_8 },
|
2022-02-01 07:41:38 -05:00
|
|
|
{ "9", Bots::NUM_9 }
|
2020-11-14 03:47:35 -05:00
|
|
|
};
|
|
|
|
|
2022-01-28 06:28:52 -05:00
|
|
|
int Bots::BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-03-21 14:55:35 -04:00
|
|
|
static size_t botId = 0;
|
2020-11-14 04:37:58 -05:00
|
|
|
const char* botName;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
if (Bots::BotNames.empty())
|
|
|
|
{
|
|
|
|
FileSystem::File bots("bots.txt");
|
|
|
|
|
|
|
|
if (bots.exists())
|
|
|
|
{
|
2022-02-26 18:30:58 -05:00
|
|
|
auto names = Utils::String::Split(bots.getBuffer(), '\n');
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-01-07 16:00:44 -05:00
|
|
|
for (auto& name : names)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
Utils::String::Replace(name, "\r", "");
|
|
|
|
name = Utils::String::Trim(name);
|
|
|
|
|
|
|
|
if (!name.empty())
|
|
|
|
{
|
|
|
|
Bots::BotNames.push_back(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-14 04:37:58 -05:00
|
|
|
}
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2020-11-14 04:37:58 -05:00
|
|
|
if (!Bots::BotNames.empty())
|
|
|
|
{
|
|
|
|
botId %= Bots::BotNames.size();
|
|
|
|
botName = Bots::BotNames[botId++].data();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
botName = Utils::String::VA("bot%d", ++botId);
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
|
2022-01-28 06:28:52 -05:00
|
|
|
return _snprintf_s(buffer, 0x400, _TRUNCATE, connectString, num, botName, protocol, checksum, statVer, statStuff, port);
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
|
2022-01-23 14:32:20 -05:00
|
|
|
void Bots::Spawn(unsigned int count)
|
2017-04-23 07:31:48 -04:00
|
|
|
{
|
2022-01-23 14:32:20 -05:00
|
|
|
for (auto i = 0u; i < count; ++i)
|
2017-04-23 07:31:48 -04:00
|
|
|
{
|
2017-05-31 09:45:12 -04:00
|
|
|
Scheduler::OnDelay([]()
|
2017-04-23 07:31:48 -04:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
auto* ent = Game::SV_AddTestClient();
|
|
|
|
if (ent == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Scheduler::OnDelay([ent]()
|
2017-04-23 07:31:48 -04:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
Game::Scr_AddString("autoassign");
|
|
|
|
Game::Scr_AddString("team_marinesopfor");
|
|
|
|
Game::Scr_Notify(ent, Game::SL_GetString("menuresponse", 0), 2);
|
|
|
|
|
|
|
|
Scheduler::OnDelay([ent]()
|
2017-04-24 15:14:08 -04:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
Game::Scr_AddString(Utils::String::VA("class%u", Utils::Cryptography::Rand::GenerateInt() % 5u));
|
|
|
|
Game::Scr_AddString("changeclass");
|
|
|
|
Game::Scr_Notify(ent, Game::SL_GetString("menuresponse", 0), 2);
|
|
|
|
}, 1s);
|
|
|
|
}, 1s);
|
2017-04-24 15:14:08 -04:00
|
|
|
}, 500ms * (i + 1));
|
2017-04-23 07:31:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 03:58:05 -05:00
|
|
|
void Bots::AddMethods()
|
|
|
|
{
|
2022-01-16 08:45:18 -05:00
|
|
|
Script::AddFunction("SetPing", [](Game::scr_entref_t entref) // gsc: self SetPing(<int>)
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-03-02 06:46:02 -05:00
|
|
|
auto ping = Game::Scr_GetInt(0);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-03-02 06:46:02 -05:00
|
|
|
ping = std::clamp(ping, 0, 999);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-02-25 07:17:57 -05:00
|
|
|
const auto* ent = Game::GetPlayerEntity(entref);
|
|
|
|
auto* client = Script::GetClient(ent);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-01-23 22:15:05 -05:00
|
|
|
if (!client->bIsTestClient)
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
|
|
|
Game::Scr_Error("^1SetPing: Can only call on a bot!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-07 16:00:44 -05:00
|
|
|
client->ping = static_cast<int16_t>(ping);
|
2020-11-14 04:20:56 -05:00
|
|
|
});
|
|
|
|
|
2022-02-01 07:29:27 -05:00
|
|
|
Script::AddFunction("IsTestClient", [](Game::scr_entref_t entref) // Usage: <bot> IsTestClient();
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-02-25 07:17:57 -05:00
|
|
|
const auto* gentity = Game::GetPlayerEntity(entref);
|
2022-02-01 07:29:27 -05:00
|
|
|
const auto* client = Script::GetClient(gentity);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-01-23 22:15:05 -05:00
|
|
|
Game::Scr_AddBool(client->bIsTestClient == 1);
|
2020-11-14 04:20:56 -05:00
|
|
|
});
|
|
|
|
|
2022-01-16 08:45:18 -05:00
|
|
|
Script::AddFunction("BotStop", [](Game::scr_entref_t entref) // Usage: <bot> BotStop();
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-02-25 07:17:57 -05:00
|
|
|
const auto* ent = Game::GetPlayerEntity(entref);
|
|
|
|
const auto* client = Script::GetClient(ent);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-01-23 22:15:05 -05:00
|
|
|
if (!client->bIsTestClient)
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
Game::Scr_Error("^1BotStop: Can only call on a bot!\n");
|
2020-11-14 04:20:56 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:21:25 -05:00
|
|
|
g_botai[entref.entnum] = {0};
|
|
|
|
g_botai[entref.entnum].weapon = 1;
|
2022-03-21 14:55:35 -04:00
|
|
|
g_botai[entref.entnum].active = false;
|
2020-11-14 04:20:56 -05:00
|
|
|
});
|
|
|
|
|
2022-01-16 08:45:18 -05:00
|
|
|
Script::AddFunction("BotWeapon", [](Game::scr_entref_t entref) // Usage: <bot> BotWeapon(<str>);
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
const auto* weapon = Game::Scr_GetString(0);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-02-25 07:17:57 -05:00
|
|
|
const auto* ent = Game::GetPlayerEntity(entref);
|
|
|
|
const auto* client = Script::GetClient(ent);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-01-23 22:15:05 -05:00
|
|
|
if (!client->bIsTestClient)
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
Game::Scr_Error("^1BotWeapon: Can only call on a bot!\n");
|
2020-11-14 04:20:56 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-23 21:08:28 -05:00
|
|
|
if (weapon == nullptr || weapon[0] == '\0')
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-01-17 19:21:25 -05:00
|
|
|
g_botai[entref.entnum].weapon = 1;
|
2020-11-14 04:20:56 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-07 16:00:44 -05:00
|
|
|
const auto weapId = Game::G_GetWeaponIndexForName(weapon);
|
2022-01-23 21:00:30 -05:00
|
|
|
g_botai[entref.entnum].weapon = static_cast<uint16_t>(weapId);
|
2022-03-21 14:55:35 -04:00
|
|
|
g_botai[entref.entnum].active = true;
|
2020-11-14 04:20:56 -05:00
|
|
|
});
|
|
|
|
|
2022-01-16 08:45:18 -05:00
|
|
|
Script::AddFunction("BotAction", [](Game::scr_entref_t entref) // Usage: <bot> BotAction(<str action>);
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
const auto* action = Game::Scr_GetString(0);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-01-23 14:32:20 -05:00
|
|
|
if (action == nullptr)
|
|
|
|
{
|
|
|
|
Game::Scr_ParamError(0, "^1BotAction: Illegal parameter!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-25 07:17:57 -05:00
|
|
|
const auto* ent = Game::GetPlayerEntity(entref);
|
|
|
|
const auto* client = Script::GetClient(ent);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-01-23 22:15:05 -05:00
|
|
|
if (!client->bIsTestClient)
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
Game::Scr_Error("^1BotAction: Can only call on a bot!\n");
|
2020-11-14 04:20:56 -05:00
|
|
|
return;
|
|
|
|
}
|
2022-01-07 16:00:44 -05:00
|
|
|
|
2020-11-14 04:20:56 -05:00
|
|
|
if (action[0] != '+' && action[0] != '-')
|
|
|
|
{
|
2022-01-16 08:45:18 -05:00
|
|
|
Game::Scr_ParamError(0, "^1BotAction: Sign for action must be '+' or '-'.\n");
|
2020-11-14 04:20:56 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-23 14:32:20 -05:00
|
|
|
for (auto i = 0u; i < std::extent_v<decltype(BotActions)>; ++i)
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-01-23 14:32:20 -05:00
|
|
|
if (strcmp(&action[1], BotActions[i].action) != 0)
|
2020-11-14 04:20:56 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (action[0] == '+')
|
2022-01-17 19:21:25 -05:00
|
|
|
g_botai[entref.entnum].buttons |= BotActions[i].key;
|
2020-11-14 04:20:56 -05:00
|
|
|
else
|
2022-01-17 19:21:25 -05:00
|
|
|
g_botai[entref.entnum].buttons &= ~(BotActions[i].key);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-03-21 14:55:35 -04:00
|
|
|
g_botai[entref.entnum].active = true;
|
2020-11-14 04:20:56 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-16 08:45:18 -05:00
|
|
|
Game::Scr_ParamError(0, "^1BotAction: Unknown action.\n");
|
2020-11-14 04:20:56 -05:00
|
|
|
});
|
|
|
|
|
2022-01-16 08:45:18 -05:00
|
|
|
Script::AddFunction("BotMovement", [](Game::scr_entref_t entref) // Usage: <bot> BotMovement(<int>, <int>);
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
|
|
|
auto forwardInt = Game::Scr_GetInt(0);
|
|
|
|
auto rightInt = Game::Scr_GetInt(1);
|
|
|
|
|
2022-02-25 07:17:57 -05:00
|
|
|
const auto* ent = Game::GetPlayerEntity(entref);
|
|
|
|
const auto* client = Script::GetClient(ent);
|
2020-11-14 04:20:56 -05:00
|
|
|
|
2022-01-23 22:15:05 -05:00
|
|
|
if (!client->bIsTestClient)
|
2020-11-14 04:20:56 -05:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
Game::Scr_Error("^1BotMovement: Can only call on a bot!\n");
|
2020-11-14 04:20:56 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-15 12:41:30 -05:00
|
|
|
forwardInt = std::clamp<int>(forwardInt, std::numeric_limits<char>::min(), std::numeric_limits<char>::max());
|
|
|
|
rightInt = std::clamp<int>(rightInt, std::numeric_limits<char>::min(), std::numeric_limits<char>::max());
|
2020-11-14 03:58:05 -05:00
|
|
|
|
2022-01-17 19:21:25 -05:00
|
|
|
g_botai[entref.entnum].forward = static_cast<int8_t>(forwardInt);
|
|
|
|
g_botai[entref.entnum].right = static_cast<int8_t>(rightInt);
|
2022-03-21 14:55:35 -04:00
|
|
|
g_botai[entref.entnum].active = true;
|
2020-11-14 04:20:56 -05:00
|
|
|
});
|
2020-11-14 03:58:05 -05:00
|
|
|
}
|
|
|
|
|
2022-01-24 07:15:33 -05:00
|
|
|
void Bots::BotAiAction(Game::client_t* cl)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-01-24 07:15:33 -05:00
|
|
|
if (cl->gentity == nullptr)
|
|
|
|
return;
|
2020-11-14 03:44:59 -05:00
|
|
|
|
2022-01-24 07:15:33 -05:00
|
|
|
const auto entnum = cl->gentity->s.number;
|
2022-01-23 21:00:30 -05:00
|
|
|
|
2022-03-21 14:55:35 -04:00
|
|
|
// Keep test client functionality
|
|
|
|
if (!g_botai[entnum].active)
|
|
|
|
{
|
|
|
|
Game::SV_BotUserMove(cl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Game::usercmd_s userCmd = {0};
|
2022-02-14 13:14:07 -05:00
|
|
|
|
2022-03-21 14:55:35 -04:00
|
|
|
userCmd.serverTime = *Game::svs_time;
|
2022-01-23 21:00:30 -05:00
|
|
|
|
2022-03-21 14:55:35 -04:00
|
|
|
userCmd.buttons = g_botai[entnum].buttons;
|
|
|
|
userCmd.forwardmove = g_botai[entnum].forward;
|
|
|
|
userCmd.rightmove = g_botai[entnum].right;
|
|
|
|
userCmd.weapon = g_botai[entnum].weapon;
|
2022-01-23 21:00:30 -05:00
|
|
|
|
2022-03-21 14:55:35 -04:00
|
|
|
Game::SV_ClientThink(cl, &userCmd);
|
2022-01-23 21:00:30 -05:00
|
|
|
}
|
2020-11-14 04:05:00 -05:00
|
|
|
|
2022-01-24 07:15:33 -05:00
|
|
|
constexpr auto SV_BotUserMove = 0x626E50;
|
2022-03-15 18:49:58 -04:00
|
|
|
__declspec(naked) void Bots::SV_BotUserMove_Hk()
|
2022-01-23 21:00:30 -05:00
|
|
|
{
|
|
|
|
__asm
|
2020-11-14 04:05:00 -05:00
|
|
|
{
|
2022-01-24 07:03:35 -05:00
|
|
|
pushad
|
2020-11-14 04:05:00 -05:00
|
|
|
|
2022-01-24 07:15:33 -05:00
|
|
|
push edi
|
2022-01-23 22:20:57 -05:00
|
|
|
call Bots::BotAiAction
|
2022-01-24 07:15:33 -05:00
|
|
|
add esp, 4
|
2022-01-24 07:03:35 -05:00
|
|
|
|
2022-01-23 21:00:30 -05:00
|
|
|
popad
|
2022-02-27 12:36:13 -05:00
|
|
|
ret
|
2022-03-21 14:55:35 -04:00
|
|
|
}
|
|
|
|
}
|
2022-02-27 12:36:13 -05:00
|
|
|
|
2022-03-21 14:55:35 -04:00
|
|
|
void Bots::G_SelectWeaponIndex(int clientNum, int iWeaponIndex)
|
|
|
|
{
|
|
|
|
if (g_botai[clientNum].active)
|
|
|
|
{
|
|
|
|
g_botai[clientNum].weapon = static_cast<uint16_t>(iWeaponIndex);
|
2022-01-23 21:00:30 -05:00
|
|
|
}
|
|
|
|
}
|
2020-11-14 04:05:00 -05:00
|
|
|
|
2022-03-21 14:55:35 -04:00
|
|
|
__declspec(naked) void Bots::G_SelectWeaponIndex_Hk()
|
2022-01-23 21:00:30 -05:00
|
|
|
{
|
2022-03-21 14:55:35 -04:00
|
|
|
__asm
|
|
|
|
{
|
|
|
|
pushad
|
|
|
|
|
|
|
|
push [esp + 0x20 + 0x8]
|
|
|
|
push [esp + 0x20 + 0x8]
|
|
|
|
call Bots::G_SelectWeaponIndex
|
|
|
|
add esp, 0x8
|
|
|
|
|
|
|
|
popad
|
|
|
|
|
|
|
|
// Code skipped by hook
|
|
|
|
mov eax, [esp + 0x8]
|
|
|
|
push eax
|
|
|
|
|
|
|
|
push 0x441B85
|
|
|
|
retn
|
|
|
|
}
|
|
|
|
}
|
2022-02-27 12:36:13 -05:00
|
|
|
|
2022-03-21 14:55:35 -04:00
|
|
|
Bots::Bots()
|
|
|
|
{
|
2022-01-23 21:00:30 -05:00
|
|
|
// 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\"");
|
2020-11-14 04:05:00 -05:00
|
|
|
|
2022-01-23 21:00:30 -05:00
|
|
|
// Intercept sprintf for the connect string
|
|
|
|
Utils::Hook(0x48ADAB, Bots::BuildConnectString, HOOK_CALL).install()->quick();
|
2020-11-14 04:05:00 -05:00
|
|
|
|
2022-03-15 18:49:58 -04:00
|
|
|
Utils::Hook(0x627021, Bots::SV_BotUserMove_Hk, HOOK_CALL).install()->quick();
|
|
|
|
Utils::Hook(0x627241, Bots::SV_BotUserMove_Hk, HOOK_CALL).install()->quick();
|
2022-01-23 21:00:30 -05:00
|
|
|
|
2022-03-21 14:55:35 -04:00
|
|
|
Utils::Hook(0x441B80, Bots::G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick();
|
|
|
|
|
2022-01-23 21:00:30 -05:00
|
|
|
// Zero the bot command array
|
|
|
|
for (auto i = 0u; i < std::extent_v<decltype(g_botai)>; i++)
|
|
|
|
{
|
|
|
|
g_botai[i] = {0};
|
|
|
|
g_botai[i].weapon = 1; // Prevent the bots from defaulting to the 'none' weapon
|
|
|
|
}
|
2020-11-14 04:05:00 -05:00
|
|
|
|
2017-04-23 07:31:48 -04:00
|
|
|
Command::Add("spawnBot", [](Command::Params* params)
|
|
|
|
{
|
2022-01-23 14:32:20 -05:00
|
|
|
auto count = 1u;
|
2017-04-23 07:31:48 -04:00
|
|
|
|
2022-03-17 14:50:20 -04:00
|
|
|
if (params->size() > 1)
|
2017-04-23 07:31:48 -04:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
if (params->get(1) == "all"s)
|
2022-01-23 14:32:20 -05:00
|
|
|
{
|
2022-01-07 16:00:44 -05:00
|
|
|
count = *Game::svs_numclients;
|
2022-01-23 14:32:20 -05:00
|
|
|
}
|
2022-01-07 16:00:44 -05:00
|
|
|
else
|
2022-01-23 14:32:20 -05:00
|
|
|
{
|
|
|
|
char* endptr;
|
|
|
|
const auto* input = params->get(1);
|
|
|
|
count = std::strtoul(input, &endptr, 10);
|
|
|
|
|
|
|
|
if (input == endptr)
|
|
|
|
{
|
|
|
|
Logger::Print("Warning: %s is not a valid input\n"
|
2022-02-09 18:40:27 -05:00
|
|
|
"Usage: %s optional <number of bots> or optional <\"all\">\n",
|
2022-01-23 14:32:20 -05:00
|
|
|
input, params->get(0));
|
|
|
|
}
|
|
|
|
}
|
2017-04-23 07:31:48 -04:00
|
|
|
}
|
|
|
|
|
2022-01-23 14:32:20 -05:00
|
|
|
count = std::min(static_cast<unsigned int>(*Game::svs_numclients), count);
|
2017-04-24 15:14:08 -04:00
|
|
|
|
2017-04-23 07:31:48 -04:00
|
|
|
// Check if ingame and host
|
|
|
|
if (!Game::SV_Loaded())
|
|
|
|
{
|
|
|
|
Toast::Show("cardicon_headshot", "^1Error", "You need to be host to spawn bots!", 3000);
|
|
|
|
Logger::Print("You need to be host to spawn bots!\n");
|
2017-04-24 15:14:08 -04:00
|
|
|
return;
|
2017-04-23 07:31:48 -04:00
|
|
|
}
|
|
|
|
|
2017-04-24 15:14:08 -04:00
|
|
|
Toast::Show("cardicon_headshot", "^2Success", Utils::String::VA("Spawning %d %s...", count, (count == 1 ? "bot" : "bots")), 3000);
|
|
|
|
Logger::Print("Spawning %d %s...\n", count, (count == 1 ? "bot" : "bots"));
|
|
|
|
|
|
|
|
Bots::Spawn(count);
|
2017-04-23 07:31:48 -04:00
|
|
|
});
|
2020-11-14 03:58:05 -05:00
|
|
|
|
|
|
|
Bots::AddMethods();
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|