Added CS_IsValidWeaponID native and validity checks to other natives (bug 5566, r=psychonic).

This commit is contained in:
Drifter
2013-07-31 22:11:15 -04:00
parent 1a8be6344a
commit fa0df413f4
4 changed files with 44 additions and 4 deletions
+17 -3
View File
@@ -296,6 +296,9 @@ static cell_t CS_TerminateRound(IPluginContext *pContext, const cell_t *params)
static cell_t CS_WeaponIDToAlias(IPluginContext *pContext, const cell_t *params)
{
if (!IsValidWeaponID(params[1]))
return pContext->ThrowNativeError("Invalid WeaponID passed for this game");
char *dest;
pContext->LocalToString(params[2], &dest);
@@ -326,8 +329,8 @@ static cell_t CS_GetTranslatedWeaponAlias(IPluginContext *pContext, const cell_t
static cell_t CS_GetWeaponPrice(IPluginContext *pContext, const cell_t *params)
{
if (params[2] == (int)SMCSWeapon_NONE)
return pContext->ThrowNativeError("Invalid Weapon ID passed");
if (!IsValidWeaponID(params[2]))
return pContext->ThrowNativeError("Invalid WeaponID passed for this game");
int id = GetRealWeaponID(params[2]);
@@ -466,7 +469,12 @@ static cell_t CS_AliasToWeaponID(IPluginContext *pContext, const cell_t *params)
pContext->LocalToString(params[1], &weapon);
return GetFakeWeaponID(AliasToWeaponID(weapon));
int id = GetFakeWeaponID(AliasToWeaponID(weapon));
if (!IsValidWeaponID(id))
return SMCSWeapon_NONE;
return id;
}
static cell_t CS_SetTeamScore(IPluginContext *pContext, const cell_t *params)
@@ -603,6 +611,11 @@ static cell_t CS_GetTeamScore(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid team index passed (%i).", params[1]);
}
static cell_t CS_IsValidWeaponID(IPluginContext *pContext, const cell_t *params)
{
return IsValidWeaponID(params[1]) ? 1 : 0;
}
template <typename T>
static inline T *GetPlayerVarAddressOrError(const char *pszGamedataName, IPluginContext *pContext, CBaseEntity *pPlayerEntity)
{
@@ -755,6 +768,7 @@ sp_nativeinfo_t g_CSNatives[] =
{"CS_SetClientContributionScore", CS_SetClientContributionScore},
{"CS_GetClientAssists", CS_GetClientAssists},
{"CS_SetClientAssists", CS_SetClientAssists},
{"CS_IsValidWeaponID", CS_IsValidWeaponID},
{NULL, NULL}
};
+15
View File
@@ -406,3 +406,18 @@ int GetFakeWeaponID(int weaponId)
return weaponId;
#endif
}
bool IsValidWeaponID(int id)
{
if (id == (int)SMCSWeapon_NONE || id > (int)SMCSWeapon_DEFUSER)
return false;
//Why are these even HERE!?! They dont exist in CS:GO but have valid ID's still
#if SOURCE_ENGINE == SE_CSGO
else if (id == (int)SMCSWeapon_P228 || id == (int)SMCSWeapon_SCOUT || id == (int)SMCSWeapon_SG550 || id == (int)SMCSWeapon_GALIL || id == (int)SMCSWeapon_SCAR17 ||
id == (int)SMCSWeapon_USP || id == (int)SMCSWeapon_M3 || id == (int)SMCSWeapon_MP5NAVY || id == (int)SMCSWeapon_TMP || id == (int)SMCSWeapon_SG552)
return false;
#else
else if (id > (int)SMCSWeapon_NIGHTVISION || id < (int)SMCSWeapon_NONE)
return false;
#endif
return true;
}
+3 -1
View File
@@ -90,6 +90,7 @@ enum CSGOWeapon
CSGOWeapon_NVG,
CSGOWeapon_DEFUSER
};
#endif
enum SMCSWeapon
{
SMCSWeapon_NONE = 0,
@@ -148,7 +149,6 @@ enum SMCSWeapon
SMCSWeapon_INCGRENADE,
SMCSWeapon_DEFUSER
};
#endif
void *GetWeaponInfo(int weaponID);
const char *GetTranslatedWeaponAlias(const char *weapon);
@@ -161,4 +161,6 @@ int GetRealWeaponID(int weaponId);
int GetFakeWeaponID(int weaponId);
bool IsValidWeaponID(int weaponId);
#endif