From 2e3c5e367ed737dc7309a77262deb1fecd17062c Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Fri, 14 Dec 2012 15:12:22 -0500 Subject: [PATCH] Added WeaponIDToAlias native to CStrike extension (bug 5460, r=psychonic). --- extensions/cstrike/natives.cpp | 17 +++++++++++++++ extensions/cstrike/util_cstrike.cpp | 29 +++++++++++++++++++++++++ extensions/cstrike/util_cstrike.h | 4 +++- gamedata/sm-cstrike.games/game.csgo.txt | 7 ++++++ gamedata/sm-cstrike.games/game.css.txt | 7 ++++++ plugins/include/cstrike.inc | 9 ++++++++ 6 files changed, 72 insertions(+), 1 deletion(-) diff --git a/extensions/cstrike/natives.cpp b/extensions/cstrike/natives.cpp index 9c6a474f..b36dd9e1 100644 --- a/extensions/cstrike/natives.cpp +++ b/extensions/cstrike/natives.cpp @@ -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} }; diff --git a/extensions/cstrike/util_cstrike.cpp b/extensions/cstrike/util_cstrike.cpp index d0d1ac86..4a01f251 100644 --- a/extensions/cstrike/util_cstrike.cpp +++ b/extensions/cstrike/util_cstrike.cpp @@ -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) { diff --git a/extensions/cstrike/util_cstrike.h b/extensions/cstrike/util_cstrike.h index d6381046..ddafb663 100644 --- a/extensions/cstrike/util_cstrike.h +++ b/extensions/cstrike/util_cstrike.h @@ -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); diff --git a/gamedata/sm-cstrike.games/game.csgo.txt b/gamedata/sm-cstrike.games/game.csgo.txt index c1bac211..99000ae3 100644 --- a/gamedata/sm-cstrike.games/game.csgo.txt +++ b/gamedata/sm-cstrike.games/game.csgo.txt @@ -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" diff --git a/gamedata/sm-cstrike.games/game.css.txt b/gamedata/sm-cstrike.games/game.css.txt index 8d3549d1..2fe56cc3 100644 --- a/gamedata/sm-cstrike.games/game.css.txt +++ b/gamedata/sm-cstrike.games/game.css.txt @@ -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" diff --git a/plugins/include/cstrike.inc b/plugins/include/cstrike.inc index 240297d7..93d0b0f2 100644 --- a/plugins/include/cstrike.inc +++ b/plugins/include/cstrike.inc @@ -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! */