bot: allow to enable fake features with quoted value

This commit is contained in:
jeefo 2025-05-13 13:03:12 +03:00
commit 1311406544
No known key found for this signature in database
GPG key ID: D696786B81B667C8
3 changed files with 17 additions and 18 deletions

View file

@ -316,27 +316,27 @@ public:
} }
// gets edict pointer out of entity index // gets edict pointer out of entity index
CR_FORCE_INLINE edict_t *entityOfIndex (const int index) { CR_FORCE_INLINE edict_t *entityOfIndex (const int index) const {
return static_cast <edict_t *> (m_startEntity + index); return static_cast <edict_t *> (m_startEntity + index);
}; };
// gets edict pointer out of entity index (player) // gets edict pointer out of entity index (player)
CR_FORCE_INLINE edict_t *playerOfIndex (const int index) { CR_FORCE_INLINE edict_t *playerOfIndex (const int index) const {
return entityOfIndex (index) + 1; return entityOfIndex (index) + 1;
}; };
// gets edict index out of it's pointer // gets edict index out of it's pointer
CR_FORCE_INLINE int indexOfEntity (const edict_t *ent) { CR_FORCE_INLINE int indexOfEntity (const edict_t *ent) const {
return static_cast <int> (ent - m_startEntity); return static_cast <int> (ent - m_startEntity);
}; };
// gets edict index of it's pointer (player) // gets edict index of it's pointer (player)
CR_FORCE_INLINE int indexOfPlayer (const edict_t *ent) { CR_FORCE_INLINE int indexOfPlayer (const edict_t *ent) const {
return indexOfEntity (ent) - 1; return indexOfEntity (ent) - 1;
} }
// verify entity isn't null // verify entity isn't null
CR_FORCE_INLINE bool isNullEntity (const edict_t *ent) { CR_FORCE_INLINE bool isNullEntity (const edict_t *ent) const {
return !ent || !indexOfEntity (ent) || ent->free; return !ent || !indexOfEntity (ent) || ent->free;
} }
@ -351,7 +351,7 @@ public:
} }
// gets the player team // gets the player team
int getTeam (edict_t *ent) { int getTeam (edict_t *ent) const {
if (isNullEntity (ent)) { if (isNullEntity (ent)) {
return Team::Unassigned; return Team::Unassigned;
} }
@ -359,7 +359,7 @@ public:
} }
// gets the player team (real in ffa) // gets the player team (real in ffa)
int getRealTeam (edict_t *ent) { int getRealTeam (edict_t *ent) const {
if (isNullEntity (ent)) { if (isNullEntity (ent)) {
return Team::Unassigned; return Team::Unassigned;
} }

View file

@ -387,8 +387,6 @@ void Bot::checkForChat () {
} }
} }
void Bot::sendToChat (StringRef message, bool teamOnly) { void Bot::sendToChat (StringRef message, bool teamOnly) {
// this function prints saytext message to all players // this function prints saytext message to all players

View file

@ -728,7 +728,7 @@ void Game::checkCvarsBounds () {
static ConVarRef sv_forcesimulating ("sv_forcesimulating"); static ConVarRef sv_forcesimulating ("sv_forcesimulating");
if (sv_forcesimulating.exists () && !cr::fequal (sv_forcesimulating.value (), 1.0f)) { if (sv_forcesimulating.exists () && !cr::fequal (sv_forcesimulating.value (), 1.0f)) {
game.print ("Force-enable Xash3D sv_forcesimulating cvar."); print ("Force-enable Xash3D sv_forcesimulating cvar.");
sv_forcesimulating.set ("1.0"); sv_forcesimulating.set ("1.0");
} }
} }
@ -935,14 +935,14 @@ bool Game::postload () {
} }
// register fake metamod command handler if we not! under mm // register fake metamod command handler if we not! under mm
if (!(game.is (GameFlags::Metamod))) { if (!(is (GameFlags::Metamod))) {
game.registerEngineCommand ("meta", [] () { game.registerEngineCommand ("meta", [] () {
game.print ("You're launched standalone version of %s. Metamod is not installed or not enabled!", product.name); game.print ("You're launched standalone version of %s. Metamod is not installed or not enabled!", product.name);
}); });
} }
// is 25th anniversary // is 25th anniversary
if (game.is25thAnniversaryUpdate ()) { if (is25thAnniversaryUpdate ()) {
m_gameFlags |= GameFlags::AnniversaryHL25; m_gameFlags |= GameFlags::AnniversaryHL25;
} }
@ -1064,7 +1064,7 @@ void Game::slowFrame () {
graph.setBombOrigin (); graph.setBombOrigin ();
// ensure the server admin is confident about features he's using // ensure the server admin is confident about features he's using
game.ensureHealthyGameEnvironment (); ensureHealthyGameEnvironment ();
// update next update time // update next update time
m_halfSecondFrame = nextUpdate * 0.25f + time (); m_halfSecondFrame = nextUpdate * 0.25f + time ();
@ -1115,7 +1115,7 @@ void Game::slowFrame () {
void Game::searchEntities (StringRef field, StringRef value, EntitySearch functor) { void Game::searchEntities (StringRef field, StringRef value, EntitySearch functor) {
edict_t *ent = nullptr; edict_t *ent = nullptr;
while (!game.isNullEntity (ent = engfuncs.pfnFindEntityByString (ent, field.chars (), value.chars ()))) { while (!isNullEntity (ent = engfuncs.pfnFindEntityByString (ent, field.chars (), value.chars ()))) {
if ((ent->v.flags & EF_NODRAW) || (ent->v.flags & FL_CLIENT)) { if ((ent->v.flags & EF_NODRAW) || (ent->v.flags & FL_CLIENT)) {
continue; continue;
} }
@ -1130,7 +1130,7 @@ void Game::searchEntities (const Vector &position, float radius, EntitySearch fu
edict_t *ent = nullptr; edict_t *ent = nullptr;
const Vector &pos = position.empty () ? m_startEntity->v.origin : position; const Vector &pos = position.empty () ? m_startEntity->v.origin : position;
while (!game.isNullEntity (ent = engfuncs.pfnFindEntityInSphere (ent, pos, radius))) { while (!isNullEntity (ent = engfuncs.pfnFindEntityInSphere (ent, pos, radius))) {
if ((ent->v.flags & EF_NODRAW) || (ent->v.flags & FL_CLIENT)) { if ((ent->v.flags & EF_NODRAW) || (ent->v.flags & FL_CLIENT)) {
continue; continue;
} }
@ -1216,18 +1216,19 @@ void Game::printBotVersion () const {
} }
void Game::ensureHealthyGameEnvironment () { void Game::ensureHealthyGameEnvironment () {
if (!isDedicated () || game.is (GameFlags::Legacy | GameFlags::Xash3D)) { if (!isDedicated () || is (GameFlags::Legacy | GameFlags::Xash3D)) {
return; // listen servers doesn't care about it at all return; // listen servers doesn't care about it at all
} }
// magic string that's enables the features // magic string that's enables the features
constexpr auto kAllowHash = StringRef::fnv1a32 ("i'm confident for what i'm doing"); constexpr auto kAllowHash = StringRef::fnv1a32 ("i'm confident for what i'm doing");
constexpr auto kAllowHash2 = StringRef::fnv1a32 ("\"i'm confident for what i'm doing\"");
// fetch custom variable, so fake features are explicitly enabled // fetch custom variable, so fake features are explicitly enabled
static auto enableFakeFeatures = StringRef::fnv1a32 (conf.fetchCustom ("EnableFakeBotFeatures").chars ()); static auto enableFakeFeatures = StringRef::fnv1a32 (conf.fetchCustom ("EnableFakeBotFeatures").chars ());
// if string matches, do not affect the cvars // if string matches, do not affect the cvars
if (enableFakeFeatures == kAllowHash) { if (enableFakeFeatures == kAllowHash || enableFakeFeatures == kAllowHash2) {
return; return;
} }
@ -1260,7 +1261,7 @@ void Game::ensureHealthyGameEnvironment () {
edict_t *Game::createFakeClient (StringRef name) { edict_t *Game::createFakeClient (StringRef name) {
auto ent = engfuncs.pfnCreateFakeClient (name.chars ()); auto ent = engfuncs.pfnCreateFakeClient (name.chars ());
if (game.isNullEntity (ent)) { if (isNullEntity (ent)) {
return nullptr; return nullptr;
} }
auto netname = ent->v.netname; auto netname = ent->v.netname;