Fix internal player's team id returning -1 in a specific but valid situation (#772)

* Fix internal player's team id returning -1 in a specific but valid situation

* Use a local variable

* Fix spaces
This commit is contained in:
Vincent Herbet 2020-06-03 23:53:26 +02:00 committed by GitHub
parent 6d6a41b894
commit ed1ab00faf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 13 deletions

View File

@ -180,6 +180,18 @@ class CGameConfigManager : public IGameConfigManager
member = type.fieldOffset; \ member = type.fieldOffset; \
} }
#define GET_OFFSET_NO_ERROR(classname, member) \
static int member = -1; \
if (member == -1) \
{ \
TypeDescription type; \
if (!CommonConfig->GetOffsetByClass(classname, #member, &type) || type.fieldOffset < 0)\
{ \
return; \
} \
member = type.fieldOffset; \
}
extern CGameConfigManager ConfigManager; extern CGameConfigManager ConfigManager;
extern IGameConfig *CommonConfig; extern IGameConfig *CommonConfig;

View File

@ -88,21 +88,44 @@ void Client_TeamInfo(void* mValue)
if (index < 1 || index > gpGlobals->maxClients) break; if (index < 1 || index > gpGlobals->maxClients) break;
char* msg = (char*)mValue; char* msg = (char*)mValue;
if (!msg) break; if (!msg) break;
g_players[index].team = msg;
g_teamsIds.registerTeam(msg, -1);
g_players[index].teamId = g_teamsIds.findTeamId(msg);
/** auto pPlayer = GET_PLAYER_POINTER_I(index);
* CS fix for SPECTATOR team.
* - pPlayer->team = msg;
* When a player chooses spectator, ScoreInfo is sent before TeamInfo and with 0 as index. g_teamsIds.registerTeam(msg, -1);
* This means for the first round of first spectator, SPECTATOR name is not associated with its index. pPlayer->teamId = g_teamsIds.findTeamId(msg);
* The following fix manually sets the team index when we hit SPECTATOR team.
*/ if (pPlayer->teamId == -1)
if (g_players[index].teamId == -1 && g_bmod_cstrike && !strcmp(msg, "SPECTATOR"))
{ {
g_players[index].teamId = 3; /**
g_teamsIds.registerTeam(msg, 3); * CS fix for SPECTATOR team.
* -
* When a player chooses spectator, ScoreInfo is sent before TeamInfo and with 0 as index.
* This means for the first round of first spectator, SPECTATOR name is not associated with its index.
* The following fix manually sets the team index when we hit SPECTATOR team.
*/
if (g_bmod_cstrike && !strcmp(msg, "SPECTATOR"))
{
pPlayer->teamId = 3;
g_teamsIds.registerTeam(msg, 3);
}
/**
* Fixes in-between situation where the team name is not yet associated with a valid index
* and ScoreInfo is executed later (used to retrieve the index). E.g. a player is dead,
* then changes team. Index will return -1 until ScoreInfo is sent, usually at the next spawn.
*/
else if ((g_bmod_cstrike || g_bmod_dod || g_bmod_tfc || g_bmod_gearbox || g_bmod_valve)
&& pPlayer->pEdict->pvPrivateData
&& !pPlayer->IsAlive())
{
GET_OFFSET_NO_ERROR("CBasePlayer", m_iTeam);
const auto teamId = get_pdata<int>(pPlayer->pEdict, m_iTeam);
pPlayer->teamId = teamId;
g_teamsIds.registerTeam(msg, teamId);
}
} }
break; break;