Add templated helper class to promote type-safety (#965)
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "forwards.h"
|
||||
#include "util_cstrike.h"
|
||||
#include <server_class.h>
|
||||
#include <sm_argbuffer.h>
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#include "itemdef-hash.h"
|
||||
@@ -178,12 +179,8 @@ static cell_t CS_SwitchTeam(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
|
||||
}
|
||||
|
||||
unsigned char vstk[sizeof(CBaseEntity *) + sizeof(int)];
|
||||
unsigned char *vptr = vstk;
|
||||
ArgBuffer<CBaseEntity*, int> vstk(pEntity, params[2]);
|
||||
|
||||
*(CBaseEntity **)vptr = pEntity;
|
||||
vptr += sizeof(CBaseEntity *);
|
||||
*(int *)vptr = params[2];
|
||||
pWrapper->Execute(vstk, NULL);
|
||||
#else
|
||||
if (g_pSDKTools == NULL)
|
||||
@@ -273,20 +270,10 @@ static cell_t CS_DropWeapon(IPluginContext *pContext, const cell_t *params)
|
||||
if (params[4] == 1 && g_pCSWeaponDropDetoured)
|
||||
g_pIgnoreCSWeaponDropDetour = true;
|
||||
|
||||
unsigned char vstk[sizeof(CBaseEntity *) * 2 + sizeof(bool) * 2];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
// <psychonic> first one is always false. second is true to toss, false to just drop
|
||||
*(CBaseEntity **)vptr = pEntity;
|
||||
vptr += sizeof(CBaseEntity *);
|
||||
*(CBaseEntity **)vptr = pWeapon;
|
||||
vptr += sizeof(CBaseEntity *);
|
||||
*(bool *)vptr = false;
|
||||
vptr += sizeof(bool);
|
||||
*(bool *)vptr = (params[3]) ? true : false;
|
||||
|
||||
pWrapper->Execute(vstk, NULL);
|
||||
ArgBuffer<CBaseEntity*, CBaseEntity*, bool, bool> vstk(pEntity, pWeapon, false, (params[3]) ? true : false);
|
||||
|
||||
pWrapper->Execute(vstk, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -333,14 +320,7 @@ static cell_t CS_TerminateRound(IPluginContext *pContext, const cell_t *params)
|
||||
if (params[3] == 1 && g_pTerminateRoundDetoured)
|
||||
g_pIgnoreTerminateDetour = true;
|
||||
|
||||
unsigned char vstk[sizeof(void *) + sizeof(float)+ sizeof(int)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(void **)vptr = gamerules;
|
||||
vptr += sizeof(void *);
|
||||
*(float *)vptr = sp_ctof(params[1]);
|
||||
vptr += sizeof(float);
|
||||
*(int*)vptr = reason;
|
||||
ArgBuffer<void*, float, int> vstk(gamerules, sp_ctof(params[1]), reason);
|
||||
|
||||
pWrapper->Execute(vstk, NULL);
|
||||
#elif SOURCE_ENGINE == SE_CSGO && !defined(WIN32)
|
||||
@@ -368,18 +348,7 @@ static cell_t CS_TerminateRound(IPluginContext *pContext, const cell_t *params)
|
||||
if (params[3] == 1 && g_pTerminateRoundDetoured)
|
||||
g_pIgnoreTerminateDetour = true;
|
||||
|
||||
unsigned char vstk[sizeof(void *) + sizeof(float) + (sizeof(int)*3)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(void **)vptr = gamerules;
|
||||
vptr += sizeof(void *);
|
||||
*(float *)vptr = sp_ctof(params[1]);
|
||||
vptr += sizeof(float);
|
||||
*(int*)vptr = reason;
|
||||
vptr += sizeof(int);
|
||||
*(int*)vptr = 0;
|
||||
vptr += sizeof(int);
|
||||
*(int*)vptr = 0;
|
||||
ArgBuffer<void*, float, int, int, int> vstk(gamerules, sp_ctof(params[1]), reason, 0, 0);
|
||||
|
||||
pWrapper->Execute(vstk, NULL);
|
||||
#else // CSGO Win32
|
||||
@@ -881,15 +850,9 @@ static cell_t CS_SetClientClanTag(IPluginContext *pContext, const cell_t *params
|
||||
char *szNewTag;
|
||||
pContext->LocalToString(params[2], &szNewTag);
|
||||
|
||||
unsigned char vstk[sizeof(CBaseEntity *) + sizeof(char *)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(CBaseEntity **)vptr = pEntity;
|
||||
vptr += sizeof(CBaseEntity *);
|
||||
*(char **)vptr = szNewTag;
|
||||
ArgBuffer<CBaseEntity*, char*> vstk(pEntity, szNewTag);
|
||||
|
||||
pWrapper->Execute(vstk, NULL);
|
||||
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <iplayerinfo.h>
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#include "itemdef-hash.h"
|
||||
#include <sm_argbuffer.h>
|
||||
|
||||
ClassnameMap g_mapClassToDefIdx;
|
||||
ItemIndexMap g_mapDefIdxToClass;
|
||||
@@ -134,16 +135,9 @@ CEconItemView *GetEconItemView(CBaseEntity *pEntity, int iSlot)
|
||||
if (team != 2 && team != 3)
|
||||
return NULL;
|
||||
|
||||
CEconItemView *ret;
|
||||
unsigned char vstk[sizeof(void *) + sizeof(int) * 2];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(void **)vptr = (void *)((intptr_t)pEntity + thisPtrOffset);
|
||||
vptr += sizeof(void *);
|
||||
*(int *)vptr = team;
|
||||
vptr += sizeof(int);
|
||||
*(int *)vptr = iSlot;
|
||||
ArgBuffer<void*, int> vstk(reinterpret_cast<void*>(((intptr_t)pEntity + thisPtrOffset)), iSlot);
|
||||
|
||||
CEconItemView *ret = nullptr;
|
||||
pWrapper->Execute(vstk, &ret);
|
||||
|
||||
return ret;
|
||||
@@ -163,13 +157,9 @@ CCSWeaponData *GetCCSWeaponData(CEconItemView *view)
|
||||
pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, &retpass, NULL, 0))
|
||||
}
|
||||
|
||||
unsigned char vstk[sizeof(CEconItemView *)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(CEconItemView **)vptr = view;
|
||||
|
||||
CCSWeaponData *pWpnData = NULL;
|
||||
ArgBuffer<CEconItemView*> vstk(view);
|
||||
|
||||
CCSWeaponData *pWpnData = nullptr;
|
||||
pWrapper->Execute(vstk, &pWpnData);
|
||||
|
||||
return pWpnData;
|
||||
@@ -234,14 +224,9 @@ CEconItemDefinition *GetItemDefintionByName(const char *classname)
|
||||
g_RegNatives.Register(pWrapper);
|
||||
}
|
||||
|
||||
unsigned char vstk[sizeof(void *) + sizeof(const char *)];
|
||||
unsigned char *vptr = vstk;
|
||||
ArgBuffer<void*, const char *> vstk(pSchema, classname);
|
||||
|
||||
*(void **)vptr = pSchema;
|
||||
vptr += sizeof(void *);
|
||||
*(const char **)vptr = classname;
|
||||
|
||||
CEconItemDefinition *pItemDef = NULL;
|
||||
CEconItemDefinition *pItemDef = nullptr;
|
||||
pWrapper->Execute(vstk, &pItemDef);
|
||||
|
||||
return pItemDef;
|
||||
@@ -390,8 +375,6 @@ ItemDefHashValue *GetHashValueFromWeapon(const char *szWeapon)
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
void *GetWeaponInfo(int weaponID)
|
||||
{
|
||||
void *info;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
if (!pWrapper)
|
||||
{
|
||||
@@ -407,11 +390,9 @@ void *GetWeaponInfo(int weaponID)
|
||||
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
|
||||
}
|
||||
|
||||
unsigned char vstk[sizeof(int)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(int *)vptr = weaponID;
|
||||
ArgBuffer<int> vstk(weaponID);
|
||||
|
||||
void *info = nullptr;
|
||||
pWrapper->Execute(vstk, &info);
|
||||
|
||||
return info;
|
||||
@@ -435,7 +416,6 @@ const char *GetWeaponNameFromClassname(const char *weapon)
|
||||
const char *GetTranslatedWeaponAlias(const char *weapon)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
const char *alias = NULL;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
@@ -453,12 +433,11 @@ const char *GetTranslatedWeaponAlias(const char *weapon)
|
||||
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
|
||||
}
|
||||
|
||||
unsigned char vstk[sizeof(const char *)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(const char **)vptr = GetWeaponNameFromClassname(weapon);
|
||||
ArgBuffer<const char *> vstk(GetWeaponNameFromClassname(weapon));
|
||||
|
||||
const char *alias = nullptr;
|
||||
pWrapper->Execute(vstk, &alias);
|
||||
|
||||
return alias;
|
||||
#else //this should work for both games maybe replace both?
|
||||
static const char *szAliases[] =
|
||||
@@ -492,8 +471,6 @@ const char *GetTranslatedWeaponAlias(const char *weapon)
|
||||
int AliasToWeaponID(const char *weapon)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
int weaponID = 0;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
@@ -510,11 +487,9 @@ int AliasToWeaponID(const char *weapon)
|
||||
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
|
||||
}
|
||||
|
||||
unsigned char vstk[sizeof(const char *)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(const char **)vptr = GetWeaponNameFromClassname(weapon);
|
||||
ArgBuffer<const char *> vstk(GetWeaponNameFromClassname(weapon));
|
||||
|
||||
int weaponID = 0;
|
||||
pWrapper->Execute(vstk, &weaponID);
|
||||
|
||||
return weaponID;
|
||||
@@ -531,10 +506,8 @@ int AliasToWeaponID(const char *weapon)
|
||||
const char *WeaponIDToAlias(int weaponID)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
const char *alias = NULL;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("WeaponIDToAlias", 0,
|
||||
@@ -549,11 +522,9 @@ const char *WeaponIDToAlias(int weaponID)
|
||||
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
|
||||
}
|
||||
|
||||
unsigned char vstk[sizeof(int)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(int *)vptr = weaponID;
|
||||
ArgBuffer<int> vstk(weaponID);
|
||||
|
||||
const char *alias = nullptr;
|
||||
pWrapper->Execute(vstk, &alias);
|
||||
|
||||
return alias;
|
||||
|
||||
Reference in New Issue
Block a user