Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dystopm committed Jul 11, 2024
2 parents 4526ff5 + 8005dd9 commit 4d50957
Show file tree
Hide file tree
Showing 46 changed files with 949 additions and 364 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
| mp_freezetime_duck | 1 | 0 | 1 | Allow players to duck during freezetime.<br/> `0` disabled<br/>`1` enabled |
| mp_freezetime_jump | 1 | 0 | 1 | Allow players to jump during freezetime.<br/> `0` disabled<br/>`1` enabled |
| mp_defuser_allocation | 0 | 0 | 2 | Give defuser on player spawn.<br/> `0` disabled<br/>`1` Random players. <br/>`2` All players. |
| mp_location_area_info | 0 | 0 | 3 | Enable location area info.<br/> `0` disabled<br/>`1` show location below HUD radar.<br/>`2` show location in HUD chat. `NOT RECOMMENDED!` [:speech_balloon:](## "Not all client builds are compatible")<br/>`3` both displayed. `NOT RECOMMENDED!` [:speech_balloon:](## "Not all client builds are compatible")<br/><br/>`NOTE`: Navigation `maps/.nav` file required and should contain place names<br/>`NOTE`: If option `2` or `3` is enabled, be sure to enable `mp_chat_loc_fallback 1` |
</details>

## How to install zBot for CS 1.6?
Expand Down
12 changes: 12 additions & 0 deletions dist/game.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,15 @@ mp_freezetime_jump "1"
//
// Default value: "0"
mp_defuser_allocation "0"

// Enable location area info
// 0 - disabled (default behavior)
// 1 - show location below HUD radar
// 2 - show location in HUD chat (NOT RECOMMENDED! Not all client builds are compatible)
// 3 - both displayed (NOT RECOMMENDED! Not all client builds are compatible)
//
// NOTE: Navigation maps/.nav file required and should contain place names
// NOTE: If option 2 or 3 is enabled, be sure to enable mp_chat_loc_fallback 1
//
// Default value: "0"
mp_location_area_info "0"
1 change: 1 addition & 0 deletions regamedll/dlls/API/CAPI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ GAMEHOOK_REGISTRY(CSGameRules_SendDeathMessage);

GAMEHOOK_REGISTRY(CBasePlayer_PlayerDeathThink);
GAMEHOOK_REGISTRY(CBasePlayer_Observer_Think);
GAMEHOOK_REGISTRY(CBasePlayer_RemoveAllItems);

int CReGameApi::GetMajorVersion() {
return REGAMEDLL_API_VERSION_MAJOR;
Expand Down
6 changes: 6 additions & 0 deletions regamedll/dlls/API/CAPI_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ typedef IHookChainRegistryClassImpl<void, CBasePlayer> CReGameHookRegistry_CBase
typedef IHookChainClassImpl<void, CBasePlayer> CReGameHook_CBasePlayer_Observer_Think;
typedef IHookChainRegistryClassImpl<void, CBasePlayer> CReGameHookRegistry_CBasePlayer_Observer_Think;

// CBasePlayer::RemoveAllItems hook
typedef IHookChainClassImpl<void, CBasePlayer, BOOL> CReGameHook_CBasePlayer_RemoveAllItems;
typedef IHookChainRegistryClassImpl<void, CBasePlayer, BOOL> CReGameHookRegistry_CBasePlayer_RemoveAllItems;

class CReGameHookchains: public IReGameHookchains {
public:
// CBasePlayer virtual
Expand Down Expand Up @@ -905,6 +909,7 @@ class CReGameHookchains: public IReGameHookchains {

CReGameHookRegistry_CBasePlayer_PlayerDeathThink m_CBasePlayer_PlayerDeathThink;
CReGameHookRegistry_CBasePlayer_Observer_Think m_CBasePlayer_Observer_Think;
CReGameHookRegistry_CBasePlayer_RemoveAllItems m_CBasePlayer_RemoveAllItems;

public:
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
Expand Down Expand Up @@ -1064,6 +1069,7 @@ class CReGameHookchains: public IReGameHookchains {

virtual IReGameHookRegistry_CBasePlayer_PlayerDeathThink *CBasePlayer_PlayerDeathThink();
virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think();
virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems();
};

extern CReGameHookchains g_ReGameHookchains;
Expand Down
10 changes: 2 additions & 8 deletions regamedll/dlls/bot/cs_bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ int GetBotFollowCount(CBasePlayer *pLeader)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (FStrEq(STRING(pPlayer->pev->netname), ""))
Expand Down Expand Up @@ -685,10 +682,7 @@ CBasePlayer *CCSBot::GetImportantEnemy(bool checkVisibility) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (FStrEq(STRING(pPlayer->pev->netname), ""))
Expand Down
15 changes: 7 additions & 8 deletions regamedll/dlls/bot/cs_bot_chatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ void BotMeme::Transmit(CCSBot *pSender) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (FStrEq(STRING(pPlayer->pev->netname), ""))
Expand Down Expand Up @@ -540,8 +537,13 @@ bool BotPhraseManager::Initialize(const char *filename, int bankIndex)
else if (!Q_stricmp("UNDEFINED", token))
placeCriteria = UNDEFINED_PLACE;
else
{
placeCriteria = TheBotPhrases->NameToID(token);

if (!TheBotPhrases->IsValid() && placeCriteria == UNDEFINED_PLACE)
placeCriteria = TheNavAreaGrid.NameToID(token);
}

continue;
}

Expand Down Expand Up @@ -1520,10 +1522,7 @@ BotStatement *BotChatterInterface::GetActiveStatement()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (FStrEq(STRING(pPlayer->pev->netname), ""))
Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/bot/cs_bot_chatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ class BotPhraseManager
Place NameToID(const char *name) const;
const char *IDToName(Place id) const;

bool IsValid() const { return !m_placeList.empty(); }

// given a name, return the associated phrase collection
const BotPhrase *GetPhrase(const char *name) const;

Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/bot/cs_bot_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ cvar_t cv_bot_deathmatch = { "bot_deathmatch", "0", FCVAR_SERVER, 0.
cvar_t cv_bot_quota_mode = { "bot_quota_mode", "normal", FCVAR_SERVER, 0.0f, nullptr };
cvar_t cv_bot_join_delay = { "bot_join_delay", "0", FCVAR_SERVER, 0.0f, nullptr };
cvar_t cv_bot_freeze = { "bot_freeze", "0", 0, 0.0f, nullptr };
cvar_t cv_bot_mimic = { "bot_mimic", "0", 0, 0.0f, nullptr };
cvar_t cv_bot_mimic_yaw_offset = { "bot_mimic_yaw_offset", "0", 0, 0.0f, nullptr };
#else
// Migrated to bot_quota_mode, use "match"
cvar_t cv_bot_quota_match = { "bot_quota_match", "0", FCVAR_SERVER, 0.0f, nullptr };
Expand Down Expand Up @@ -131,6 +133,8 @@ void Bot_RegisterCVars()
CVAR_REGISTER(&cv_bot_quota_mode);
CVAR_REGISTER(&cv_bot_join_delay);
CVAR_REGISTER(&cv_bot_freeze);
CVAR_REGISTER(&cv_bot_mimic);
CVAR_REGISTER(&cv_bot_mimic_yaw_offset);
#endif

}
Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/bot/cs_bot_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ extern cvar_t cv_bot_deathmatch;
extern cvar_t cv_bot_quota_mode;
extern cvar_t cv_bot_join_delay;
extern cvar_t cv_bot_freeze;
extern cvar_t cv_bot_mimic;
extern cvar_t cv_bot_mimic_yaw_offset;
#else
extern cvar_t cv_bot_quota_match;
#endif
83 changes: 66 additions & 17 deletions regamedll/dlls/bot/cs_bot_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ void CCSBotManager::ClientDisconnect(CBasePlayer *pPlayer)
pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pevTemp);
AddEntityHashValue(pPlayer->pev, STRING(pPlayer->pev->classname), CLASSNAME);
pPlayer->pev->flags = FL_DORMANT;

#ifdef REGAMEDLL_FIXES
pPlayer->has_disconnected = true;
#endif
}

void PrintAllEntities()
Expand Down Expand Up @@ -396,16 +400,19 @@ void CCSBotManager::ServerCommand(const char *pcmd)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

const char *name = STRING(pPlayer->pev->netname);
if (FStrEq(name, ""))
continue;

#ifdef REGAMEDLL_FIXES
if (pPlayer->pev->deadflag != DEAD_NO)
continue;
#endif

if (pPlayer->IsBot())
{
CCSBot *pBot = static_cast<CCSBot *>(pPlayer);
Expand All @@ -422,13 +429,17 @@ void CCSBotManager::ServerCommand(const char *pcmd)
else
kickThemAll = false;

#ifdef REGAMEDLL_ADD
bool fillMode = FStrEq(cv_bot_quota_mode.string, "fill");
#else
bool fillMode = false;
#endif

for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

const char *name = STRING(pPlayer->pev->netname);
Expand All @@ -443,7 +454,11 @@ void CCSBotManager::ServerCommand(const char *pcmd)
// adjust bot quota so kicked bot is not immediately added back in
int newQuota = cv_bot_quota.value - 1;
SERVER_COMMAND(UTIL_VarArgs("kick \"%s\"\n", name));
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, int(cv_bot_quota.value)));

if (kickThemAll || !fillMode)
{
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, int(cv_bot_quota.value)));
}
}
}
}
Expand Down Expand Up @@ -665,6 +680,9 @@ void CCSBotManager::ServerCommand(const char *pcmd)
CBaseEntity *pEntity = nullptr;
while ((pEntity = UTIL_FindEntityByClassname(pEntity, "player")))
{
if (FNullEnt(pEntity->edict()))
break;

if (!pEntity->IsPlayer())
continue;

Expand Down Expand Up @@ -745,6 +763,23 @@ void CCSBotManager::ServerCommand(const char *pcmd)

BOOL CCSBotManager::ClientCommand(CBasePlayer *pPlayer, const char *pcmd)
{
#ifdef REGAMEDLL_ADD
if (pPlayer->IsBot())
return FALSE;

if (cv_bot_mimic.value == pPlayer->entindex())
{
// Bots mimic our client commands
ForEachPlayer([pPlayer, pcmd](CBasePlayer *bot)
{
if (pPlayer != bot && bot->IsBot())
bot->ClientCommand(pcmd, CMD_ARGV_(1));

return true;
});
}
#endif

return FALSE;
}

Expand Down Expand Up @@ -787,7 +822,8 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
// decrease the bot quota
if (!isFromConsole)
{
CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value - 1);
int newQuota = cv_bot_quota.value - 1;
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, (int)cv_bot_quota.value));
}
#endif

Expand Down Expand Up @@ -821,7 +857,8 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
if (isFromConsole)
{
// increase the bot quota to account for manually added bot
CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value + 1);
int newQuota = cv_bot_quota.value + 1;
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, gpGlobals->maxClients));
}
}
#ifdef REGAMEDLL_FIXES
Expand All @@ -830,7 +867,8 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
// decrease the bot quota
if (!isFromConsole)
{
CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value - 1);
int newQuota = cv_bot_quota.value - 1;
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, (int)cv_bot_quota.value));
}
}
#endif
Expand Down Expand Up @@ -860,10 +898,17 @@ void CCSBotManager::MaintainBotQuota()
int desiredBotCount = int(cv_bot_quota.value);
int occupiedBotSlots = UTIL_BotsInGame();

bool isRoundInDeathmatch = false;

#ifdef REGAMEDLL_ADD
if (round_infinite.value > 0)
isRoundInDeathmatch = true; // is no round end gameplay
#endif

// isRoundInProgress is true if the round has progressed far enough that new players will join as dead.
bool isRoundInProgress = CSGameRules()->IsGameStarted() &&
!TheCSBots()->IsRoundOver() &&
(CSGameRules()->GetRoundElapsedTime() >= CSGameRules()->GetRoundRespawnTime());
(CSGameRules()->GetRoundRespawnTime() != -1 && CSGameRules()->GetRoundElapsedTime() >= CSGameRules()->GetRoundRespawnTime()) && !isRoundInDeathmatch;

#ifdef REGAMEDLL_ADD
if (FStrEq(cv_bot_quota_mode.string, "fill"))
Expand All @@ -872,7 +917,7 @@ void CCSBotManager::MaintainBotQuota()
// unless the round is already in progress, in which case we play with what we've been dealt
if (!isRoundInProgress)
{
desiredBotCount = Q_max(0, desiredBotCount - humanPlayersInGame + spectatorPlayersInGame);
desiredBotCount = Q_max(0, desiredBotCount - humanPlayersInGame);
}
else
{
Expand Down Expand Up @@ -919,13 +964,15 @@ void CCSBotManager::MaintainBotQuota()
if (cv_bot_auto_vacate.value > 0.0)
desiredBotCount = Q_min(desiredBotCount, gpGlobals->maxClients - (humanPlayersInGame + 1));
else
desiredBotCount = Q_min(desiredBotCount, gpGlobals->maxClients - humanPlayersInGame + spectatorPlayersInGame);
desiredBotCount = Q_min(desiredBotCount, gpGlobals->maxClients - humanPlayersInGame);

#ifdef REGAMEDLL_FIXES
// Try to balance teams, if we are in the first specified seconds of a round and bots can join either team.
if (occupiedBotSlots > 0 && desiredBotCount == occupiedBotSlots && CSGameRules()->IsGameStarted())
if (occupiedBotSlots > 0 && desiredBotCount == occupiedBotSlots && (CSGameRules()->IsGameStarted() || isRoundInDeathmatch))
{
if (CSGameRules()->GetRoundElapsedTime() < CSGameRules()->GetRoundRespawnTime()) // new bots can still spawn during this time
if (isRoundInDeathmatch ||
(CSGameRules()->GetRoundRespawnTime() == -1 || // means no time limit
CSGameRules()->GetRoundElapsedTime() < CSGameRules()->GetRoundRespawnTime())) // new bots can still spawn during this time
{
if (autoteambalance.value > 0.0f)
{
Expand Down Expand Up @@ -1042,7 +1089,8 @@ void CCSBotManager::MaintainBotQuota()
UTIL_KickBotFromTeam(TERRORIST);
}

CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value - 1.0f);
int newQuota = cv_bot_quota.value - 1;
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, (int)cv_bot_quota.value));
}
}

Expand Down Expand Up @@ -1580,7 +1628,8 @@ void CCSBotManager::OnFreeEntPrivateData(CBaseEntity *pEntity)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || pPlayer->IsDormant())

if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (pPlayer->IsBot())
Expand Down
5 changes: 1 addition & 4 deletions regamedll/dlls/bot/cs_bot_pathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,10 +1118,7 @@ bool CCSBot::IsFriendInTheWay(const Vector *goalPos) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (!pPlayer->IsAlive())
Expand Down
6 changes: 6 additions & 0 deletions regamedll/dlls/bot/cs_bot_statemachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ void CCSBot::Attack(CBasePlayer *victim)
if (cv_bot_zombie.value != 0.0f)
return;

#ifdef REGAMEDLL_ADD
// If mimicing the player, don't attack state
if (cv_bot_mimic.value)
return;
#endif

// cannot attack if we are reloading
if (IsActiveWeaponReloading())
return;
Expand Down
Loading

0 comments on commit 4d50957

Please sign in to comment.