Custom.cfg (#213)
Added custom configs. These are used for replacing some hardcoded strings inside bot code, currently custom cvar for parachute detection is available, as well as custom c4 model names. Added editorconfig, and fixed CRLF for files (was a mix between LF & CRLF). Fixed use-after-free sanitizer error with chatlib. Fixed configs files loaded with memory-loader does not process last line in config files.
This commit is contained in:
parent
ed46e3238d
commit
075bff2988
21 changed files with 533 additions and 404 deletions
|
|
@ -572,7 +572,7 @@ void Bot::updatePickups () {
|
|||
allowPickup = true;
|
||||
pickupType = Pickup::DefusalKit;
|
||||
}
|
||||
else if (strncmp ("grenade", classname, 7) == 0 && strcmp (model, "c4.mdl") == 0) {
|
||||
else if (strncmp ("grenade", classname, 7) == 0 && conf.getBombModelName () == model) {
|
||||
allowPickup = true;
|
||||
pickupType = Pickup::PlantedC4;
|
||||
}
|
||||
|
|
@ -2888,7 +2888,7 @@ void Bot::checkDarkness () {
|
|||
}
|
||||
|
||||
void Bot::checkParachute () {
|
||||
static auto parachute = engfuncs.pfnCVarGetPointer ("sv_parachute");
|
||||
static auto parachute = engfuncs.pfnCVarGetPointer (conf.fetchCustom ("AMXParachuteCvar").chars ());
|
||||
|
||||
// if no cvar or it's not enabled do not bother
|
||||
if (parachute && parachute->value > 0.0f) {
|
||||
|
|
@ -5460,7 +5460,7 @@ edict_t *Bot::correctGrenadeVelocity (const char *model) {
|
|||
edict_t *result = nullptr;
|
||||
|
||||
game.searchEntities ("classname", "grenade", [&] (edict_t *ent) {
|
||||
if (ent->v.owner == this->ent () && strcmp (ent->v.model.chars (9), model) == 0) {
|
||||
if (ent->v.owner == this->ent () && util.isModel (ent, model)) {
|
||||
result = ent;
|
||||
|
||||
// set the correct velocity for the grenade
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ void Bot::prepareChatMessage (StringRef message) {
|
|||
}
|
||||
|
||||
// get the humanized name out of client
|
||||
auto humanizedName = [] (int index) -> StringRef {
|
||||
auto humanizedName = [] (int index) -> String {
|
||||
auto ent = game.playerOfIndex (index);
|
||||
|
||||
if (!util.isPlayer (ent)) {
|
||||
|
|
@ -157,7 +157,7 @@ void Bot::prepareChatMessage (StringRef message) {
|
|||
};
|
||||
|
||||
// find highfrag player
|
||||
auto getHighfragPlayer = [&] () -> StringRef {
|
||||
auto getHighfragPlayer = [&] () -> String {
|
||||
int highestFrags = -1;
|
||||
int index = 0;
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ void Bot::prepareChatMessage (StringRef message) {
|
|||
};
|
||||
|
||||
// get roundtime
|
||||
auto getRoundTime = [] () -> StringRef {
|
||||
auto getRoundTime = [] () -> String {
|
||||
auto roundTimeSecs = static_cast <int> (bots.getRoundEndTime () - game.time ());
|
||||
|
||||
String roundTime;
|
||||
|
|
@ -188,12 +188,12 @@ void Bot::prepareChatMessage (StringRef message) {
|
|||
};
|
||||
|
||||
// get bot's victim
|
||||
auto getMyVictim = [&] () -> StringRef {;
|
||||
auto getMyVictim = [&] () -> String {;
|
||||
return humanizedName (game.indexOfPlayer (m_lastVictim));
|
||||
};
|
||||
|
||||
// get the game name alias
|
||||
auto getGameName = [] () -> StringRef {
|
||||
auto getGameName = [] () -> String {
|
||||
String gameName;
|
||||
|
||||
if (game.is (GameFlags::ConditionZero)) {
|
||||
|
|
@ -216,7 +216,7 @@ void Bot::prepareChatMessage (StringRef message) {
|
|||
};
|
||||
|
||||
// get enemy or teammate alive
|
||||
auto getPlayerAlive = [&] (bool needsEnemy) -> StringRef {
|
||||
auto getPlayerAlive = [&] (bool needsEnemy) -> String {
|
||||
for (const auto &client : util.getClients ()) {
|
||||
if (!(client.flags & ClientFlags::Used) || !(client.flags & ClientFlags::Alive) || client.ent == ent ()) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// YaPB - Counter-Strike Bot based on PODBot by Markus Klinge.
|
||||
// Copyright Š 2004-2020 YaPB Project <yapb@jeefo.net>.
|
||||
// Copyright © 2004-2020 YaPB Project <yapb@jeefo.net>.
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
|
|
@ -28,6 +28,7 @@ void BotConfig::loadConfigs () {
|
|||
loadLogosConfig ();
|
||||
loadAvatarsConfig ();
|
||||
loadDifficultyConfig ();
|
||||
loadCustomConfig ();
|
||||
}
|
||||
|
||||
void BotConfig::loadMainConfig (bool isFirstLoad) {
|
||||
|
|
@ -614,6 +615,38 @@ void BotConfig::loadMapSpecificConfig () {
|
|||
}
|
||||
}
|
||||
|
||||
void BotConfig::loadCustomConfig () {
|
||||
String line;
|
||||
MemFile file;
|
||||
|
||||
m_custom["C4ModelName"] = "c4.mdl";
|
||||
m_custom["AMXParachuteCvar"] = "sv_parachute";
|
||||
|
||||
// custom inititalization
|
||||
if (util.openConfig ("custom.cfg", "Custom config file not found. Loading defaults.", &file)) {
|
||||
m_custom.clear ();
|
||||
|
||||
while (file.getLine (line)) {
|
||||
line.trim ();
|
||||
|
||||
if (isCommentLine (line)) {
|
||||
continue;
|
||||
}
|
||||
auto values = line.split ("=");
|
||||
|
||||
if (values.length () != 2) {
|
||||
logger.error ("Bad configuration for custom.cfg");
|
||||
return;
|
||||
}
|
||||
auto kv = Twin <String, String> (values[0].trim (), values[1].trim ());
|
||||
|
||||
if (!kv.first.empty () && !kv.second.empty ()) {
|
||||
m_custom[kv.first] = kv.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BotConfig::loadLogosConfig () {
|
||||
setupMemoryFiles ();
|
||||
|
||||
|
|
@ -750,6 +783,14 @@ const char *BotConfig::translate (StringRef input) {
|
|||
return input.chars (); // nothing found
|
||||
}
|
||||
|
||||
void BotConfig::showCustomValues () {
|
||||
game.print ("Current values for custom config items:");
|
||||
|
||||
m_custom.foreach ([&](const String &key, const String &val) {
|
||||
game.print (" %s = %s", key, val);
|
||||
});
|
||||
}
|
||||
|
||||
uint32 BotConfig::hashLangString (StringRef str) {
|
||||
auto test = [] (const char ch) {
|
||||
return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
|
||||
|
|
|
|||
|
|
@ -262,6 +262,14 @@ int BotControl::cmdCvars () {
|
|||
return BotCommandResult::Handled;
|
||||
}
|
||||
|
||||
int BotControl::cmdShowCustom () {
|
||||
enum args { alias = 1 };
|
||||
|
||||
conf.showCustomValues ();
|
||||
|
||||
return BotCommandResult::Handled;
|
||||
}
|
||||
|
||||
int BotControl::cmdNode () {
|
||||
enum args { root, alias, cmd, cmd2 };
|
||||
|
||||
|
|
@ -1895,6 +1903,7 @@ BotControl::BotControl () {
|
|||
m_cmds.emplace ("list/listbots", "list [noarguments]", "Lists the bots currently playing on server.", &BotControl::cmdList);
|
||||
m_cmds.emplace ("graph/g/wp/wpt/waypoint", "graph [help]", "Handles graph operations.", &BotControl::cmdNode);
|
||||
m_cmds.emplace ("cvars", "cvars [save|cvar]", "Display all the cvars with their descriptions.", &BotControl::cmdCvars);
|
||||
m_cmds.emplace ("show_custom", "show_custom [noarguments]", "Show's the curent values from custom.cfg.", &BotControl::cmdShowCustom);
|
||||
|
||||
// declare the menus
|
||||
createMenus ();
|
||||
|
|
|
|||
|
|
@ -799,6 +799,9 @@ bool Game::postload () {
|
|||
// set out user agent for http stuff
|
||||
http.setUserAgent (strings.format ("%s/%s", product.name, product.version));
|
||||
|
||||
// startup the sockets
|
||||
http.startup ();
|
||||
|
||||
// set the app name
|
||||
plat.setAppName (product.name.chars ());
|
||||
|
||||
|
|
|
|||
|
|
@ -2806,9 +2806,10 @@ void BotGraph::setBombOrigin (bool reset, const Vector &pos) {
|
|||
return;
|
||||
}
|
||||
bool wasFound = false;
|
||||
auto bombModel = conf.getBombModelName ();
|
||||
|
||||
game.searchEntities ("classname", "grenade", [&] (edict_t *ent) {
|
||||
if (strcmp (ent->v.model.chars (9), "c4.mdl") == 0) {
|
||||
if (util.isModel (ent, bombModel)) {
|
||||
m_bombOrigin = game.getEntityWorldOrigin (ent);
|
||||
wasFound = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -1628,10 +1628,13 @@ void BotManager::updateActiveGrenade () {
|
|||
}
|
||||
m_activeGrenades.clear (); // clear previously stored grenades
|
||||
|
||||
// need to ignore bomb model in active grenades...
|
||||
auto bombModel = conf.getBombModelName ();
|
||||
|
||||
// search the map for any type of grenade
|
||||
game.searchEntities ("classname", "grenade", [&] (edict_t *e) {
|
||||
// do not count c4 as a grenade
|
||||
if (strcmp (e->v.model.chars (9), "c4.mdl") != 0) {
|
||||
if (!util.isModel (e, bombModel)) {
|
||||
m_activeGrenades.push (e);
|
||||
}
|
||||
return EntitySearchResult::Continue; // continue iteration
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ int Bot::findBestGoal () {
|
|||
int result = kInvalidNodeIndex;
|
||||
|
||||
game.searchEntities ("classname", "weaponbox", [&] (edict_t *ent) {
|
||||
if (strcmp (ent->v.model.chars (9), "backpack.mdl") == 0) {
|
||||
if (util.isModel (ent, "backpack.mdl")) {
|
||||
result = graph.getNearest (game.getEntityWorldOrigin (ent));
|
||||
|
||||
if (graph.exists (result)) {
|
||||
|
|
@ -2965,11 +2965,13 @@ int Bot::getNearestToPlantedBomb () {
|
|||
if (!game.mapIs (MapFlags::Demolition)) {
|
||||
return kInvalidNodeIndex; // don't search for bomb if the player is CT, or it's not defusing bomb
|
||||
}
|
||||
int result = kInvalidNodeIndex;
|
||||
|
||||
auto bombModel = conf.getBombModelName ();
|
||||
auto result = kInvalidNodeIndex;
|
||||
|
||||
// search the bomb on the map
|
||||
game.searchEntities ("classname", "grenade", [&result] (edict_t *ent) {
|
||||
if (strcmp (ent->v.model.chars (9), "c4.mdl") == 0) {
|
||||
game.searchEntities ("classname", "grenade", [&result, &bombModel] (edict_t *ent) {
|
||||
if (util.isModel (ent, bombModel)) {
|
||||
result = graph.getNearest (game.getEntityWorldOrigin (ent));
|
||||
|
||||
if (graph.exists (result)) {
|
||||
|
|
|
|||
|
|
@ -687,6 +687,10 @@ bool BotSupport::isObjectInsidePlane (FrustumPlane &plane, const Vector ¢er,
|
|||
return isPointInsidePlane (top) || isPointInsidePlane (bottom);
|
||||
}
|
||||
|
||||
bool BotSupport::isModel (const edict_t *ent, StringRef model) {
|
||||
return model == ent->v.model.chars (9);
|
||||
}
|
||||
|
||||
int32 BotSupport::sendTo (int socket, const void *message, size_t length, int flags, const sockaddr *dest, int destLength) {
|
||||
const auto send = [&] (const Twin <const uint8 *, size_t> &msg) -> int32 {
|
||||
return Socket::sendto (socket, msg.first, msg.second, flags, dest, destLength);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue