Added new CS_GetWeaponPrice native to cstrike extension (bug 4985, r=psychonic).

This commit is contained in:
Drifter
2011-06-28 20:32:55 -04:00
parent 91368e5656
commit ee1bbd5994
5 changed files with 137 additions and 13 deletions
+3
View File
@@ -42,6 +42,8 @@
#include <IBinTools.h>
#include <ISDKTools.h>
int CallPriceForward(int client, const char *weapon_name, int price);
/**
* @brief Sample implementation of the SDK Extension.
* Note: Uncomment one of the pre-defined virtual functions in order to use it.
@@ -146,5 +148,6 @@ extern bool g_pIgnoreTerminateDetour;
extern bool g_pIgnoreCSWeaponDropDetour;
extern bool g_pTerminateRoundDetoured;
extern bool g_pCSWeaponDropDetoured;
extern int weaponNameOffset;
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_
+17 -13
View File
@@ -51,19 +51,7 @@ DETOUR_DECL_MEMBER0(DetourWeaponPrice, int)
const char *weapon_name = reinterpret_cast<char *>(this+weaponNameOffset);
int original = price;
cell_t result = Pl_Continue;
g_pPriceForward->PushCell(lastclient);
g_pPriceForward->PushString(weapon_name);
g_pPriceForward->PushCellByRef(&price);
g_pPriceForward->Execute(&result);
if (result == Pl_Continue)
return original;
return price;
return CallPriceForward(lastclient, weapon_name, price);
}
DETOUR_DECL_MEMBER2(DetourTerminateRound, void, float, delay, int, reason)
@@ -232,3 +220,19 @@ void RemoveCSWeaponDropDetour()
}
g_pCSWeaponDropDetoured = false;
}
int CallPriceForward(int client, const char *weapon_name, int price)
{
int changedprice = price;
cell_t result = Pl_Continue;
g_pPriceForward->PushCell(client);
g_pPriceForward->PushString(weapon_name);
g_pPriceForward->PushCellByRef(&changedprice);
g_pPriceForward->Execute(&result);
if (result == Pl_Continue)
return price;
return changedprice;
}
+53
View File
@@ -325,6 +325,58 @@ static cell_t CS_GetTranslatedWeaponAlias(IPluginContext *pContext, const cell_t
return 1;
}
static cell_t CS_GetWeaponPrice(IPluginContext *pContext, const cell_t *params)
{
static ICallWrapper *pWrapper = NULL;
static int priceOffset = -1;
if (!pWrapper)
{
REGISTER_NATIVE_ADDR("GetWeaponInfo",
PassInfo pass[1]; \
PassInfo retpass[1]; \
pass[0].flags = PASSFLAG_BYVAL; \
pass[0].type = PassType_Basic; \
pass[0].size = sizeof(int); \
retpass[0].flags = PASSFLAG_BYVAL; \
retpass[0].type = PassType_Basic; \
retpass[0].size = sizeof(void *); \
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass[0], pass, 1))
}
if (priceOffset == -1)
{
if (!g_pGameConf->GetOffset("WeaponPrice", &priceOffset))
{
return pContext->ThrowNativeError("Failed to get WeaponPrice offset");
}
}
CBaseEntity *pEntity;
if (!(pEntity = GetCBaseEntity(params[1], true)))
{
return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
}
void *info;
unsigned char vstk[sizeof(int)];
unsigned char *vptr = vstk;
*(int *)vptr = params[2];
pWrapper->Execute(vstk, &info);
if (!info)
return pContext->ThrowNativeError("Failed to get weaponinfo");
int price = *(int *)((intptr_t)info + priceOffset);
if (params[3] || weaponNameOffset == -1)
return price;
const char *weapon_name = (const char *)((intptr_t)info + weaponNameOffset);
return CallPriceForward(params[1], weapon_name, price);
}
sp_nativeinfo_t g_CSNatives[] =
{
@@ -333,6 +385,7 @@ sp_nativeinfo_t g_CSNatives[] =
{"CS_DropWeapon", CS_DropWeapon},
{"CS_TerminateRound", CS_TerminateRound},
{"CS_GetTranslatedWeaponAlias", CS_GetTranslatedWeaponAlias},
{"CS_GetWeaponPrice", CS_GetWeaponPrice},
{NULL, NULL}
};