diff --git a/extensions/sdktools/teamnatives.cpp b/extensions/sdktools/teamnatives.cpp index 786dbb1e6..3c3e21e66 100644 --- a/extensions/sdktools/teamnatives.cpp +++ b/extensions/sdktools/teamnatives.cpp @@ -38,6 +38,8 @@ struct TeamInfo CBaseEntity *pEnt; }; +const char *m_iScore; + SourceHook::CVector 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]; diff --git a/gamedata/sdktools.games/common.games.txt b/gamedata/sdktools.games/common.games.txt index 50ffee162..abf0ebcc8 100644 --- a/gamedata/sdktools.games/common.games.txt +++ b/gamedata/sdktools.games/common.games.txt @@ -18,6 +18,8 @@ "Keys" { "m_iFrags" "m_iFrags" + // Netprop on the team entity for team score + "m_iScore" "m_iScore" } "Offsets" diff --git a/gamedata/sdktools.games/engine.csgo.txt b/gamedata/sdktools.games/engine.csgo.txt index d6d6346a0..175cbeade 100644 --- a/gamedata/sdktools.games/engine.csgo.txt +++ b/gamedata/sdktools.games/engine.csgo.txt @@ -225,6 +225,11 @@ "csgo" { + "Keys" + { + // Netprop on the team entity for team score + "m_iScore" "m_scoreTotal" + } "Offsets" { "GiveNamedItem"