Added CS_IsValidWeaponID native and validity checks to other natives (bug 5566, r=psychonic).
authorDrifter <drifter01620@gmail.com>
Wed Jul 31 22:11:15 2013 -0400 (2013-07-31)
changeset 396586dedf4462d8
parent 3964 8052afb00b69
child 3966 5d8b87f98355
Added CS_IsValidWeaponID native and validity checks to other natives (bug 5566, r=psychonic).
extensions/cstrike/natives.cpp
extensions/cstrike/util_cstrike.cpp
extensions/cstrike/util_cstrike.h
plugins/include/cstrike.inc
     1.1 --- a/extensions/cstrike/natives.cpp	Wed Jul 31 22:08:23 2013 -0400
     1.2 +++ b/extensions/cstrike/natives.cpp	Wed Jul 31 22:11:15 2013 -0400
     1.3 @@ -296,6 +296,9 @@
     1.4  
     1.5  static cell_t CS_WeaponIDToAlias(IPluginContext *pContext, const cell_t *params)
     1.6  {
     1.7 +	if (!IsValidWeaponID(params[1]))
     1.8 +		return pContext->ThrowNativeError("Invalid WeaponID passed for this game");
     1.9 +
    1.10  	char *dest;
    1.11  
    1.12  	pContext->LocalToString(params[2], &dest);
    1.13 @@ -326,8 +329,8 @@
    1.14  
    1.15  static cell_t CS_GetWeaponPrice(IPluginContext *pContext, const cell_t *params)
    1.16  {
    1.17 -	if (params[2] == (int)SMCSWeapon_NONE)
    1.18 -		return pContext->ThrowNativeError("Invalid Weapon ID passed");
    1.19 +	if (!IsValidWeaponID(params[2]))
    1.20 +		return pContext->ThrowNativeError("Invalid WeaponID passed for this game");
    1.21  
    1.22  	int id = GetRealWeaponID(params[2]);
    1.23  
    1.24 @@ -466,7 +469,12 @@
    1.25  
    1.26  	pContext->LocalToString(params[1], &weapon);
    1.27  
    1.28 -	return GetFakeWeaponID(AliasToWeaponID(weapon));
    1.29 +	int id = GetFakeWeaponID(AliasToWeaponID(weapon));
    1.30 +
    1.31 +	if (!IsValidWeaponID(id))
    1.32 +		return SMCSWeapon_NONE;
    1.33 +
    1.34 +	return id;
    1.35  }
    1.36  
    1.37  static cell_t CS_SetTeamScore(IPluginContext *pContext, const cell_t *params)
    1.38 @@ -603,6 +611,11 @@
    1.39  	return pContext->ThrowNativeError("Invalid team index passed (%i).", params[1]);
    1.40  }
    1.41  
    1.42 +static cell_t CS_IsValidWeaponID(IPluginContext *pContext, const cell_t *params)
    1.43 +{
    1.44 +	return IsValidWeaponID(params[1]) ? 1 : 0;
    1.45 +}
    1.46 +
    1.47  template <typename T>
    1.48  static inline T *GetPlayerVarAddressOrError(const char *pszGamedataName, IPluginContext *pContext, CBaseEntity *pPlayerEntity)
    1.49  {
    1.50 @@ -755,6 +768,7 @@
    1.51  	{"CS_SetClientContributionScore",	CS_SetClientContributionScore},
    1.52  	{"CS_GetClientAssists",			CS_GetClientAssists},
    1.53  	{"CS_SetClientAssists",			CS_SetClientAssists},
    1.54 +	{"CS_IsValidWeaponID",			CS_IsValidWeaponID},
    1.55  	{NULL,							NULL}
    1.56  };
    1.57  
     2.1 --- a/extensions/cstrike/util_cstrike.cpp	Wed Jul 31 22:08:23 2013 -0400
     2.2 +++ b/extensions/cstrike/util_cstrike.cpp	Wed Jul 31 22:11:15 2013 -0400
     2.3 @@ -406,3 +406,18 @@
     2.4  		return weaponId;
     2.5  #endif
     2.6  }
     2.7 +bool IsValidWeaponID(int id)
     2.8 +{
     2.9 +	if (id == (int)SMCSWeapon_NONE || id > (int)SMCSWeapon_DEFUSER)
    2.10 +		return false;
    2.11 +	//Why are these even HERE!?! They dont exist in CS:GO but have valid ID's still
    2.12 +#if SOURCE_ENGINE == SE_CSGO
    2.13 +	else if (id == (int)SMCSWeapon_P228 || id == (int)SMCSWeapon_SCOUT || id == (int)SMCSWeapon_SG550 || id == (int)SMCSWeapon_GALIL || id == (int)SMCSWeapon_SCAR17 ||
    2.14 +			id == (int)SMCSWeapon_USP || id == (int)SMCSWeapon_M3 || id == (int)SMCSWeapon_MP5NAVY || id == (int)SMCSWeapon_TMP || id == (int)SMCSWeapon_SG552)
    2.15 +			return false;
    2.16 +#else
    2.17 +	else if (id > (int)SMCSWeapon_NIGHTVISION || id < (int)SMCSWeapon_NONE)
    2.18 +		return false;
    2.19 +#endif
    2.20 +	return true;
    2.21 +}
     3.1 --- a/extensions/cstrike/util_cstrike.h	Wed Jul 31 22:08:23 2013 -0400
     3.2 +++ b/extensions/cstrike/util_cstrike.h	Wed Jul 31 22:11:15 2013 -0400
     3.3 @@ -90,6 +90,7 @@
     3.4  	CSGOWeapon_NVG,
     3.5  	CSGOWeapon_DEFUSER
     3.6  };
     3.7 +#endif
     3.8  enum SMCSWeapon
     3.9  {
    3.10  	SMCSWeapon_NONE = 0,
    3.11 @@ -148,7 +149,6 @@
    3.12  	SMCSWeapon_INCGRENADE,
    3.13  	SMCSWeapon_DEFUSER
    3.14  };
    3.15 -#endif
    3.16  void *GetWeaponInfo(int weaponID);
    3.17  
    3.18  const char *GetTranslatedWeaponAlias(const char *weapon);
    3.19 @@ -161,4 +161,6 @@
    3.20  
    3.21  int GetFakeWeaponID(int weaponId);
    3.22  
    3.23 +bool IsValidWeaponID(int weaponId);
    3.24 +
    3.25  #endif
     4.1 --- a/plugins/include/cstrike.inc	Wed Jul 31 22:08:23 2013 -0400
     4.2 +++ b/plugins/include/cstrike.inc	Wed Jul 31 22:11:15 2013 -0400
     4.3 @@ -359,6 +359,15 @@
     4.4  native CS_WeaponIDToAlias(CSWeaponID:weaponID, String:destination[], len);
     4.5  
     4.6  /**
     4.7 + * Returns weather a WeaponID is valid on the current mod (css or csgo)
     4.8 + * @param weaponID		WeaponID to check
     4.9 + * @return				Returns true if its a valid WeaponID false otherwise.
    4.10 + *
    4.11 + * @note This will return false always for CSWeapon_NONE
    4.12 + */
    4.13 +native bool:CS_IsValidWeaponID(CSWeaponID:id);
    4.14 +
    4.15 +/**
    4.16   * Do not edit below this line!
    4.17   */
    4.18  public Extension:__ext_cstrike =