Added CS_IsValidWeaponID native and validity checks to other natives (bug 5566, r=psychonic).
This commit is contained in:
parent
1a8be6344a
commit
fa0df413f4
@ -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)
|
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;
|
char *dest;
|
||||||
|
|
||||||
pContext->LocalToString(params[2], &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)
|
static cell_t CS_GetWeaponPrice(IPluginContext *pContext, const cell_t *params)
|
||||||
{
|
{
|
||||||
if (params[2] == (int)SMCSWeapon_NONE)
|
if (!IsValidWeaponID(params[2]))
|
||||||
return pContext->ThrowNativeError("Invalid Weapon ID passed");
|
return pContext->ThrowNativeError("Invalid WeaponID passed for this game");
|
||||||
|
|
||||||
int id = GetRealWeaponID(params[2]);
|
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);
|
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)
|
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]);
|
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>
|
template <typename T>
|
||||||
static inline T *GetPlayerVarAddressOrError(const char *pszGamedataName, IPluginContext *pContext, CBaseEntity *pPlayerEntity)
|
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_SetClientContributionScore", CS_SetClientContributionScore},
|
||||||
{"CS_GetClientAssists", CS_GetClientAssists},
|
{"CS_GetClientAssists", CS_GetClientAssists},
|
||||||
{"CS_SetClientAssists", CS_SetClientAssists},
|
{"CS_SetClientAssists", CS_SetClientAssists},
|
||||||
|
{"CS_IsValidWeaponID", CS_IsValidWeaponID},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -406,3 +406,18 @@ int GetFakeWeaponID(int weaponId)
|
|||||||
return weaponId;
|
return weaponId;
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
@ -90,6 +90,7 @@ enum CSGOWeapon
|
|||||||
CSGOWeapon_NVG,
|
CSGOWeapon_NVG,
|
||||||
CSGOWeapon_DEFUSER
|
CSGOWeapon_DEFUSER
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
enum SMCSWeapon
|
enum SMCSWeapon
|
||||||
{
|
{
|
||||||
SMCSWeapon_NONE = 0,
|
SMCSWeapon_NONE = 0,
|
||||||
@ -148,7 +149,6 @@ enum SMCSWeapon
|
|||||||
SMCSWeapon_INCGRENADE,
|
SMCSWeapon_INCGRENADE,
|
||||||
SMCSWeapon_DEFUSER
|
SMCSWeapon_DEFUSER
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
void *GetWeaponInfo(int weaponID);
|
void *GetWeaponInfo(int weaponID);
|
||||||
|
|
||||||
const char *GetTranslatedWeaponAlias(const char *weapon);
|
const char *GetTranslatedWeaponAlias(const char *weapon);
|
||||||
@ -161,4 +161,6 @@ int GetRealWeaponID(int weaponId);
|
|||||||
|
|
||||||
int GetFakeWeaponID(int weaponId);
|
int GetFakeWeaponID(int weaponId);
|
||||||
|
|
||||||
|
bool IsValidWeaponID(int weaponId);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -358,6 +358,15 @@ native CSWeaponID:CS_AliasToWeaponID(const String:alias[]);
|
|||||||
*/
|
*/
|
||||||
native CS_WeaponIDToAlias(CSWeaponID:weaponID, String:destination[], len);
|
native CS_WeaponIDToAlias(CSWeaponID:weaponID, String:destination[], len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns weather a WeaponID is valid on the current mod (css or csgo)
|
||||||
|
* @param weaponID WeaponID to check
|
||||||
|
* @return Returns true if its a valid WeaponID false otherwise.
|
||||||
|
*
|
||||||
|
* @note This will return false always for CSWeapon_NONE
|
||||||
|
*/
|
||||||
|
native bool:CS_IsValidWeaponID(CSWeaponID:id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do not edit below this line!
|
* Do not edit below this line!
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user