Fix for SDKTools TeamScore natives crash on CS:GO (bug 5319, r=psychonic).
This commit is contained in:
parent
6f55c3e75a
commit
02277225d7
@ -38,6 +38,8 @@ struct TeamInfo
|
||||
CBaseEntity *pEnt;
|
||||
};
|
||||
|
||||
const char *m_iScore;
|
||||
|
||||
SourceHook::CVector<TeamInfo> g_Teams;
|
||||
|
||||
bool FindTeamEntities(SendTable *pTable, const char *name)
|
||||
@ -157,7 +159,27 @@ static cell_t GetTeamScore(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeError("Team index %d is invalid", teamindex);
|
||||
}
|
||||
|
||||
static int offset = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_iScore")->GetOffset();
|
||||
if (!m_iScore)
|
||||
{
|
||||
m_iScore = g_pGameConf->GetKeyValue("m_iScore");
|
||||
if (!m_iScore)
|
||||
{
|
||||
return pContext->ThrowNativeError("Failed to get m_iScore key");
|
||||
}
|
||||
}
|
||||
|
||||
static int offset = -1;
|
||||
|
||||
if (offset == -1)
|
||||
{
|
||||
SendProp *prop = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, m_iScore);
|
||||
if (!prop)
|
||||
{
|
||||
return pContext->ThrowNativeError("Failed to get m_iScore prop");
|
||||
}
|
||||
offset = prop->GetOffset();
|
||||
}
|
||||
|
||||
|
||||
return *(int *)((unsigned char *)g_Teams[teamindex].pEnt + offset);
|
||||
}
|
||||
@ -170,7 +192,26 @@ static cell_t SetTeamScore(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeError("Team index %d is invalid", teamindex);
|
||||
}
|
||||
|
||||
static int offset = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_iScore")->GetOffset();
|
||||
if (m_iScore == NULL)
|
||||
{
|
||||
m_iScore = g_pGameConf->GetKeyValue("m_iScore");
|
||||
if (m_iScore == NULL)
|
||||
{
|
||||
return pContext->ThrowNativeError("Failed to get m_iScore key");
|
||||
}
|
||||
}
|
||||
|
||||
static int offset = -1;
|
||||
|
||||
if (offset == -1)
|
||||
{
|
||||
SendProp *prop = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, m_iScore);
|
||||
if (!prop)
|
||||
{
|
||||
return pContext->ThrowNativeError("Failed to get m_iScore prop");
|
||||
}
|
||||
offset = prop->GetOffset();
|
||||
}
|
||||
|
||||
CBaseEntity *pTeam = g_Teams[teamindex].pEnt;
|
||||
*(int *)((unsigned char *)pTeam + offset) = params[2];
|
||||
|
@ -18,6 +18,8 @@
|
||||
"Keys"
|
||||
{
|
||||
"m_iFrags" "m_iFrags"
|
||||
// Netprop on the team entity for team score
|
||||
"m_iScore" "m_iScore"
|
||||
}
|
||||
|
||||
"Offsets"
|
||||
|
@ -225,6 +225,11 @@
|
||||
|
||||
"csgo"
|
||||
{
|
||||
"Keys"
|
||||
{
|
||||
// Netprop on the team entity for team score
|
||||
"m_iScore" "m_scoreTotal"
|
||||
}
|
||||
"Offsets"
|
||||
{
|
||||
"GiveNamedItem"
|
||||
|
Loading…
Reference in New Issue
Block a user