Skip to content

Commit

Permalink
Updated GameName function
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileYzn committed Jan 29, 2025
1 parent 649bf69 commit 9d9f832
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 45 deletions.
70 changes: 35 additions & 35 deletions MatchBot/MatchBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,57 +1165,57 @@ void CMatchBot::RoundEnd(int winStatus, ScenarioEventEndRound event, float tmDel
// Update Game Name
void CMatchBot::UpdateGameName()
{
// Game Name
static char GameDesc[33];

// If has CSGameRules loaded
if (g_pGameRules)
{
// Store original game description
if (this->m_GameDesc.empty())
// Check if is empty
if (this->m_GameDesc[0u] == '\0')
{
// Get default game name
if (CSGameRules()->GetGameDescription())
{
this->m_GameDesc = CSGameRules()->GetGameDescription();
}
else
{
this->m_GameDesc = "Counter-Strike";
}
// Store original game description
Q_strncpy(this->m_GameDesc, "Counter-Strike", sizeof(this->m_GameDesc));
}

// If is enabled
if (this->m_GameName && this->m_GameName->value)
if (this->m_GameName)
{
// Get match state
auto State = gMatchBot.GetState();

// If is not running, set default name
if (State == STATE_DEAD)
{
// Restore default game name
Q_strcpy(GameDesc, this->m_GameDesc.c_str());
}
else if (State == STATE_WARMUP || State == STATE_START)
// If is enabled
if (this->m_GameName->value > 0.0f)
{
// Set game name from state name
Q_strcpy(GameDesc, gMatchBot.GetState(State));
}
else if (State >= STATE_FIRST_HALF && State <= STATE_END)
{
// Format game name with teams and scores
Q_sprintf(GameDesc, "%s %d : %d %s", gMatchBot.GetTeam(TERRORIST, true), gMatchBot.GetScore(TERRORIST), gMatchBot.GetScore(CT), gMatchBot.GetTeam(CT, true));
// Get match state
auto State = gMatchBot.GetState();

// Warmuo or Start
if (State == STATE_WARMUP || State == STATE_START)
{
// Set game name from state name
Q_snprintf(this->m_GameDesc, sizeof(this->m_GameDesc), "%s", gMatchBot.GetState(State));
}
else if (State >= STATE_FIRST_HALF && State <= STATE_END)
{
// Format game name with teams and scores
Q_snprintf(this->m_GameDesc, sizeof(this->m_GameDesc), "%s %d : %d %s", gMatchBot.GetTeam(TERRORIST, true), gMatchBot.GetScore(TERRORIST), gMatchBot.GetScore(CT), gMatchBot.GetTeam(CT, true));
}
else
{
// Restore default game name
Q_strncpy(this->m_GameDesc, "Counter-Strike", sizeof(this->m_GameDesc));
}
}
}
else
{
// Restore default game name
Q_strcpy(GameDesc, this->m_GameDesc.c_str());
Q_strncpy(this->m_GameDesc, "Counter-Strike", sizeof(this->m_GameDesc));
}

// Set
CSGameRules()->m_GameDesc = GameDesc;
if (g_pGameRules)
{
// If has Game description
if (g_pGameRules->m_GameDesc)
{
g_ReGameFuncs->ChangeString(g_pGameRules->m_GameDesc, this->m_GameDesc);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion MatchBot/MatchBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class CMatchBot
std::array<int, SPECTATOR + 1U> m_ScoreOvertime;

// Defaut game description
std::string m_GameDesc;
char m_GameDesc[32] = { 0 };

// Match Bot Config Variables
std::array<cvar_t*, STATE_END + 1U> m_Config;
Expand Down
12 changes: 7 additions & 5 deletions MatchBot/MatchUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ int CMatchUtil::MakeDirectory(const char* Path)
// Register console variable
cvar_t* CMatchUtil::CvarRegister(const char* Name, const char* Value)
{
static std::map<std::string, cvar_t> CvarData;

cvar_t* Pointer = g_engfuncs.pfnCVarGetPointer(Name);

if (!Pointer)
{
if (Name)
{
this->m_CvarData[Name].name = Name;
CvarData[Name].name = Name;

this->m_CvarData[Name].string = _strdup(Value);
CvarData[Name].string = _strdup(Value);

this->m_CvarData[Name].flags = (FCVAR_SERVER | FCVAR_PROTECTED | FCVAR_SPONLY | FCVAR_UNLOGGED);
CvarData[Name].flags = (FCVAR_SERVER | FCVAR_PROTECTED | FCVAR_SPONLY | FCVAR_UNLOGGED);

g_engfuncs.pfnCVarRegister(&this->m_CvarData[Name]);
g_engfuncs.pfnCVarRegister(&CvarData[Name]);

Pointer = g_engfuncs.pfnCVarGetPointer(this->m_CvarData[Name].name);
Pointer = g_engfuncs.pfnCVarGetPointer(Name);

if (Pointer)
{
Expand Down
4 changes: 0 additions & 4 deletions MatchBot/MatchUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ class CMatchUtil

// Get Steam ID with bots check
const char* GetPlayerAuthId(edict_t* pEntity);

private:
// Variables Pointer
std::map<std::string, cvar_t> m_CvarData;
};

extern CMatchUtil gMatchUtil;
Expand Down

0 comments on commit 9d9f832

Please sign in to comment.