Added WeaponIDToAlias native to CStrike extension (bug 5460, r=psychonic).

This commit is contained in:
Kyle Sanderson 2012-12-14 15:12:22 -05:00
parent eb230a45f6
commit 2e3c5e367e
6 changed files with 72 additions and 1 deletions

View File

@ -294,6 +294,22 @@ static cell_t CS_TerminateRound(IPluginContext *pContext, const cell_t *params)
return 1;
}
static cell_t CS_WeaponIDToAlias(IPluginContext *pContext, const cell_t *params)
{
char *dest;
pContext->LocalToString(params[2], &dest);
const char *ret = WeaponIDToAlias(params[1]);
if (ret == NULL)
{
return 0;
}
return strncopy(dest, ret, params[3]);
}
static cell_t CS_GetTranslatedWeaponAlias(IPluginContext *pContext, const cell_t *params)
{
char *weapon;
@ -669,6 +685,7 @@ sp_nativeinfo_t g_CSNatives[] =
{"CS_SetTeamScore", CS_SetTeamScore},
{"CS_GetMVPCount", CS_GetMVPCount},
{"CS_SetMVPCount", CS_SetMVPCount},
{"CS_WeaponIDToAlias", CS_WeaponIDToAlias},
{NULL, NULL}
};

View File

@ -129,6 +129,35 @@ int AliasToWeaponID(const char *weapon)
pWrapper->Execute(vstk, &weaponID);
return weaponID;
}
const char *WeaponIDToAlias(int weaponID)
{
static ICallWrapper *pWrapper = NULL;
if (!pWrapper)
{
REGISTER_ADDR("WeaponIDToAlias", 0,
PassInfo pass[1]; \
PassInfo retpass; \
pass[0].flags = PASSFLAG_BYVAL; \
pass[0].type = PassType_Basic; \
pass[0].size = sizeof(int); \
retpass.flags = PASSFLAG_BYVAL; \
retpass.type = PassType_Basic; \
retpass.size = sizeof(const char *); \
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
}
const char *ret = NULL;
unsigned char vstk[sizeof(int)];
unsigned char *vptr = vstk;
*(int *)vptr = GetRealWeaponID(weaponID);
pWrapper->Execute(vstk, &ret);
return ret;
}
int GetRealWeaponID(int weaponId)
{

View File

@ -153,7 +153,9 @@ void *GetWeaponInfo(int weaponID);
const char *GetTranslatedWeaponAlias(const char *weapon);
int AliasToWeaponID(const char *weapon);
int AliasToWeaponID(const char *weapon);
const char *WeaponIDToAlias(int weaponID);
int GetRealWeaponID(int weaponId);

View File

@ -129,6 +129,13 @@
"linux" "@_Z15AliasToWeaponIDPKc"
"mac" "@_Z15AliasToWeaponIDPKc"
}
"WeaponIDToAlias"
{
"library" "server"
"windows" "\x55\x8B\xEC\x8B\x4D\x08\x33\xC0\xEB\x2A\x8D\x9B\x00\x00\x00\x00\x39\x0C\xC5\x2A\x2A\x2A\x2A\x74\x2A\x40\x83\xF8\x37\x72\x2A\x33\xC0\x5D"
"linux" "@_Z15WeaponIDToAliasi"
"mac" "@_Z15WeaponIDToAliasi"
}
"SetClanTag"
{
"library" "server"

View File

@ -129,6 +129,13 @@
"linux" "@_Z15AliasToWeaponIDPKc"
"mac" "@_Z15AliasToWeaponIDPKc"
}
"WeaponIDToAlias"
{
"library" "server"
"windows" "\x55\x8B\xEC\x8B\x4D\x08\x33\xC0\xEB\x2A\x8D\x9B\x00\x00\x00\x00\x39\x0C\xC5\x2A\x2A\x2A\x2A\x74\x2A\x40\x83\xF8\x26\x72\x2A\x33\xC0\x5D"
"linux" "@_Z15WeaponIDToAliasi"
"mac" "@_Z15WeaponIDToAliasi"
}
//For mac we use think since CheckWinLimit dosnt exist on mac.
"CheckWinLimit"

View File

@ -311,6 +311,15 @@ native CS_SetMVPCount(client, value);
*/
native CSWeaponID:CS_AliasToWeaponID(const String:alias[]);
/**
* Gets a alias from a weaponID
* @param weaponID WeaponID to get alias for.
* @param destination Destination string to hold the weapon alias.
* @param len Length of the destination array.
* @return Returns number of cells written.
*/
native CS_WeaponIDToAlias(weaponID, String:destination[], len);
/**
* Do not edit below this line!
*/