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:
parent
6d6a41b894
commit
ed1ab00faf
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -88,10 +88,15 @@ 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);
|
||||||
|
|
||||||
|
pPlayer->team = msg;
|
||||||
|
g_teamsIds.registerTeam(msg, -1);
|
||||||
|
pPlayer->teamId = g_teamsIds.findTeamId(msg);
|
||||||
|
|
||||||
|
if (pPlayer->teamId == -1)
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* CS fix for SPECTATOR team.
|
* CS fix for SPECTATOR team.
|
||||||
* -
|
* -
|
||||||
|
@ -99,12 +104,30 @@ void Client_TeamInfo(void* mValue)
|
||||||
* This means for the first round of first spectator, SPECTATOR name is not associated with its 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.
|
* The following fix manually sets the team index when we hit SPECTATOR team.
|
||||||
*/
|
*/
|
||||||
if (g_players[index].teamId == -1 && g_bmod_cstrike && !strcmp(msg, "SPECTATOR"))
|
if (g_bmod_cstrike && !strcmp(msg, "SPECTATOR"))
|
||||||
{
|
{
|
||||||
g_players[index].teamId = 3;
|
pPlayer->teamId = 3;
|
||||||
g_teamsIds.registerTeam(msg, 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user