Merge branch 'master' into csgo-hashmap
This commit is contained in:
+346
-346
@@ -31,35 +31,35 @@
|
||||
|
||||
#include "extension.h"
|
||||
#include "util_cstrike.h"
|
||||
#include "RegNatives.h"
|
||||
#include <iplayerinfo.h>
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#include "itemdef-hash.h"
|
||||
|
||||
#include "RegNatives.h"
|
||||
#include <iplayerinfo.h>
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#include "itemdef-hash.h"
|
||||
|
||||
ClassnameMap g_mapClassToDefIdx;
|
||||
ItemIndexMap g_mapDefIdxToClass;
|
||||
WeaponIDMap g_mapWeaponIDToDefIdx;
|
||||
#endif
|
||||
|
||||
#define REGISTER_ADDR(name, defaultret, code) \
|
||||
void *addr; \
|
||||
if (!g_pGameConf->GetMemSig(name, &addr) || !addr) \
|
||||
{ \
|
||||
g_pSM->LogError(myself, "Failed to lookup %s signature.", name); \
|
||||
return defaultret; \
|
||||
} \
|
||||
code; \
|
||||
g_RegNatives.Register(pWrapper);
|
||||
|
||||
ItemIndexMap g_mapDefIdxToClass;
|
||||
WeaponIDMap g_mapWeaponIDToDefIdx;
|
||||
#endif
|
||||
|
||||
#define REGISTER_ADDR(name, defaultret, code) \
|
||||
void *addr; \
|
||||
if (!g_pGameConf->GetMemSig(name, &addr) || !addr) \
|
||||
{ \
|
||||
g_pSM->LogError(myself, "Failed to lookup %s signature.", name); \
|
||||
return defaultret; \
|
||||
} \
|
||||
code; \
|
||||
g_RegNatives.Register(pWrapper);
|
||||
|
||||
#define GET_MEMSIG(name, defaultret) \
|
||||
if (!g_pGameConf->GetMemSig(name, &addr) || !addr) \
|
||||
{ \
|
||||
g_pSM->LogError(myself, "Failed to lookup %s signature.", name); \
|
||||
return defaultret;\
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
|
||||
// Get a CEconItemView for the m4
|
||||
// Found in CCSPlayer::HandleCommand_Buy_Internal
|
||||
// Linux a1 - CCSPlayer *pEntity, v5 - Player Team, a3 - ItemLoadoutSlot -1 use default loadoutslot:
|
||||
@@ -70,16 +70,16 @@ WeaponIDMap g_mapWeaponIDToDefIdx;
|
||||
// The function is CCSPlayerInventory::GetItemInLoadout(int, int)
|
||||
// We can pass NULL view to the GetAttribute to use default loadoutslot.
|
||||
// We only really care about m4a1/m4a4 as price differs between them
|
||||
// thisPtrOffset = 9472/9492
|
||||
|
||||
CEconItemView *GetEconItemView(CBaseEntity *pEntity, int iSlot)
|
||||
{
|
||||
if (!pEntity)
|
||||
return NULL;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
static int thisPtrOffset = -1;
|
||||
|
||||
// thisPtrOffset = 9472/9492
|
||||
|
||||
CEconItemView *GetEconItemView(CBaseEntity *pEntity, int iSlot)
|
||||
{
|
||||
if (!pEntity)
|
||||
return NULL;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
static int thisPtrOffset = -1;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
int offset = -1;
|
||||
@@ -119,22 +119,22 @@ CEconItemView *GetEconItemView(CBaseEntity *pEntity, int iSlot)
|
||||
|
||||
pWrapper = g_pBinTools->CreateVCall(offset, 0, 0, &ret, pass, 2);
|
||||
g_RegNatives.Register(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
int client = gamehelpers->EntityToBCompatRef(pEntity);
|
||||
|
||||
IPlayerInfo *playerinfo = playerhelpers->GetGamePlayer(client)->GetPlayerInfo();
|
||||
|
||||
if (!playerinfo)
|
||||
return NULL;
|
||||
|
||||
int team = playerinfo->GetTeamIndex();
|
||||
|
||||
if (team != 2 && team != 3)
|
||||
return NULL;
|
||||
|
||||
CEconItemView *ret;
|
||||
}
|
||||
}
|
||||
|
||||
int client = gamehelpers->EntityToBCompatRef(pEntity);
|
||||
|
||||
IPlayerInfo *playerinfo = playerhelpers->GetGamePlayer(client)->GetPlayerInfo();
|
||||
|
||||
if (!playerinfo)
|
||||
return NULL;
|
||||
|
||||
int team = playerinfo->GetTeamIndex();
|
||||
|
||||
if (team != 2 && team != 3)
|
||||
return NULL;
|
||||
|
||||
CEconItemView *ret;
|
||||
unsigned char vstk[sizeof(void *) + sizeof(int) * 2];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
@@ -144,51 +144,51 @@ CEconItemView *GetEconItemView(CBaseEntity *pEntity, int iSlot)
|
||||
vptr += sizeof(int);
|
||||
*(int *)vptr = iSlot;
|
||||
|
||||
pWrapper->Execute(vstk, &ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCSWeaponData *GetCCSWeaponData(CEconItemView *view)
|
||||
{
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("GetCCSWeaponData", NULL,
|
||||
PassInfo retpass; \
|
||||
retpass.flags = PASSFLAG_BYVAL; \
|
||||
retpass.type = PassType_Basic; \
|
||||
retpass.size = sizeof(CCSWeaponData *); \
|
||||
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;
|
||||
|
||||
pWrapper->Execute(vstk, &pWpnData);
|
||||
|
||||
return pWpnData;
|
||||
}
|
||||
|
||||
CEconItemSchema *GetItemSchema()
|
||||
{
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("GetItemSchema", NULL,
|
||||
PassInfo retpass; \
|
||||
retpass.flags = PASSFLAG_BYVAL; \
|
||||
retpass.type = PassType_Basic; \
|
||||
retpass.size = sizeof(void *); \
|
||||
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, NULL, 0))
|
||||
}
|
||||
|
||||
pWrapper->Execute(vstk, &ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCSWeaponData *GetCCSWeaponData(CEconItemView *view)
|
||||
{
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("GetCCSWeaponData", NULL,
|
||||
PassInfo retpass; \
|
||||
retpass.flags = PASSFLAG_BYVAL; \
|
||||
retpass.type = PassType_Basic; \
|
||||
retpass.size = sizeof(CCSWeaponData *); \
|
||||
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;
|
||||
|
||||
pWrapper->Execute(vstk, &pWpnData);
|
||||
|
||||
return pWpnData;
|
||||
}
|
||||
|
||||
CEconItemSchema *GetItemSchema()
|
||||
{
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("GetItemSchema", NULL,
|
||||
PassInfo retpass; \
|
||||
retpass.flags = PASSFLAG_BYVAL; \
|
||||
retpass.type = PassType_Basic; \
|
||||
retpass.size = sizeof(void *); \
|
||||
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, NULL, 0))
|
||||
}
|
||||
|
||||
void *pSchema = NULL;
|
||||
pWrapper->Execute(NULL, &pSchema);
|
||||
|
||||
@@ -197,28 +197,28 @@ CEconItemSchema *GetItemSchema()
|
||||
return (CEconItemSchema *)((intptr_t)pSchema + 4);
|
||||
#else
|
||||
return (CEconItemSchema *)pSchema;
|
||||
#endif
|
||||
}
|
||||
|
||||
CEconItemDefinition *GetItemDefintionByName(const char *classname)
|
||||
{
|
||||
CEconItemSchema *pSchema = GetItemSchema();
|
||||
|
||||
if (!pSchema)
|
||||
return NULL;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
#endif
|
||||
}
|
||||
|
||||
CEconItemDefinition *GetItemDefintionByName(const char *classname)
|
||||
{
|
||||
CEconItemSchema *pSchema = GetItemSchema();
|
||||
|
||||
if (!pSchema)
|
||||
return NULL;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
int offset = -1;
|
||||
|
||||
if (!g_pGameConf->GetOffset("GetItemDefintionByName", &offset) || offset == -1)
|
||||
{
|
||||
smutils->LogError(myself, "Failed to get GetItemDefintionByName offset.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PassInfo pass[1];
|
||||
PassInfo ret;
|
||||
pass[0].flags = PASSFLAG_BYVAL;
|
||||
@@ -229,11 +229,11 @@ CEconItemDefinition *GetItemDefintionByName(const char *classname)
|
||||
ret.type = PassType_Basic;
|
||||
ret.size = sizeof(CEconItemDefinition *);
|
||||
|
||||
pWrapper = g_pBinTools->CreateVCall(offset, 0, 0, &ret, pass, 1);
|
||||
|
||||
g_RegNatives.Register(pWrapper);
|
||||
}
|
||||
|
||||
pWrapper = g_pBinTools->CreateVCall(offset, 0, 0, &ret, pass, 1);
|
||||
|
||||
g_RegNatives.Register(pWrapper);
|
||||
}
|
||||
|
||||
unsigned char vstk[sizeof(void *) + sizeof(const char *)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
@@ -244,16 +244,16 @@ CEconItemDefinition *GetItemDefintionByName(const char *classname)
|
||||
CEconItemDefinition *pItemDef = NULL;
|
||||
pWrapper->Execute(vstk, &pItemDef);
|
||||
|
||||
return pItemDef;
|
||||
}
|
||||
|
||||
void CreateHashMaps()
|
||||
{
|
||||
CEconItemSchema *pSchema = GetItemSchema();
|
||||
|
||||
if (!pSchema)
|
||||
return;
|
||||
|
||||
return pItemDef;
|
||||
}
|
||||
|
||||
void CreateHashMaps()
|
||||
{
|
||||
CEconItemSchema *pSchema = GetItemSchema();
|
||||
|
||||
if (!pSchema)
|
||||
return;
|
||||
|
||||
static const char *pPriceKey = NULL;
|
||||
|
||||
if (!pPriceKey)
|
||||
@@ -263,18 +263,18 @@ void CreateHashMaps()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static int iHashMapOffset = -1;
|
||||
|
||||
if (iHashMapOffset == -1)
|
||||
{
|
||||
}
|
||||
|
||||
static int iHashMapOffset = -1;
|
||||
|
||||
if (iHashMapOffset == -1)
|
||||
{
|
||||
if (!g_pGameConf->GetOffset("ItemDefHashOffset", &iHashMapOffset) || iHashMapOffset == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
g_mapClassToDefIdx.init();
|
||||
g_mapDefIdxToClass.init();
|
||||
g_mapWeaponIDToDefIdx.init();
|
||||
@@ -314,112 +314,112 @@ void CreateHashMaps()
|
||||
g_mapWeaponIDToDefIdx.add(t, iWeaponID, ItemDefHashValue(iLoadoutslot, price, iWeaponID, iItemDefIdx, classname));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClearHashMaps()
|
||||
{
|
||||
g_mapClassToDefIdx.clear();
|
||||
g_mapDefIdxToClass.clear();
|
||||
g_mapWeaponIDToDefIdx.clear();
|
||||
}
|
||||
|
||||
SMCSWeapon GetWeaponIdFromDefIdx(uint16_t iDefIdx)
|
||||
{
|
||||
//DEAR GOD THIS IS HIDEOUS
|
||||
//None in the middle are weapons that dont exist.
|
||||
//If they are added and use the same idx they should be changed to their respective ones
|
||||
static SMCSWeapon weaponIDMap[SMCSWeapon_MAXWEAPONIDS] =
|
||||
{
|
||||
SMCSWeapon_NONE, SMCSWeapon_DEAGLE, SMCSWeapon_ELITE, SMCSWeapon_FIVESEVEN,
|
||||
SMCSWeapon_GLOCK, SMCSWeapon_NONE, SMCSWeapon_NONE, SMCSWeapon_AK47,
|
||||
SMCSWeapon_AUG, SMCSWeapon_AWP, SMCSWeapon_FAMAS, SMCSWeapon_G3SG1,
|
||||
SMCSWeapon_NONE, SMCSWeapon_GALILAR, SMCSWeapon_M249, SMCSWeapon_NONE,
|
||||
SMCSWeapon_M4A1, SMCSWeapon_MAC10, SMCSWeapon_NONE, SMCSWeapon_P90,
|
||||
SMCSWeapon_NONE, SMCSWeapon_NONE, SMCSWeapon_NONE, SMCSWeapon_NONE,
|
||||
SMCSWeapon_UMP45, SMCSWeapon_XM1014, SMCSWeapon_BIZON, SMCSWeapon_MAG7,
|
||||
SMCSWeapon_NEGEV, SMCSWeapon_SAWEDOFF, SMCSWeapon_TEC9, SMCSWeapon_TASER,
|
||||
SMCSWeapon_HKP2000, SMCSWeapon_MP7, SMCSWeapon_MP9, SMCSWeapon_NOVA,
|
||||
SMCSWeapon_P250, SMCSWeapon_NONE, SMCSWeapon_SCAR20, SMCSWeapon_SG556,
|
||||
SMCSWeapon_SSG08, SMCSWeapon_KNIFE_GG, SMCSWeapon_KNIFE, SMCSWeapon_FLASHBANG,
|
||||
SMCSWeapon_HEGRENADE, SMCSWeapon_SMOKEGRENADE, SMCSWeapon_MOLOTOV, SMCSWeapon_DECOY,
|
||||
SMCSWeapon_INCGRENADE, SMCSWeapon_C4, SMCSWeapon_KEVLAR, SMCSWeapon_ASSAULTSUIT,
|
||||
SMCSWeapon_HEAVYASSAULTSUIT, SMCSWeapon_NONE, SMCSWeapon_NIGHTVISION, SMCSWeapon_DEFUSER
|
||||
};
|
||||
|
||||
if (iDefIdx >= SMCSWeapon_MAXWEAPONIDS)
|
||||
return (SMCSWeapon)iDefIdx;
|
||||
else
|
||||
return weaponIDMap[iDefIdx];
|
||||
}
|
||||
|
||||
ItemDefHashValue *GetHashValueFromWeapon(const char *szWeapon)
|
||||
{
|
||||
char tempWeapon[MAX_WEAPON_NAME_LENGTH];
|
||||
|
||||
Q_strncpy(tempWeapon, szWeapon, sizeof(tempWeapon));
|
||||
Q_strlower(tempWeapon);
|
||||
|
||||
if (strstr(tempWeapon, "weapon_") == NULL && strstr(tempWeapon, "item_") == NULL)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void ClearHashMaps()
|
||||
{
|
||||
g_mapClassToDefIdx.clear();
|
||||
g_mapDefIdxToClass.clear();
|
||||
g_mapWeaponIDToDefIdx.clear();
|
||||
}
|
||||
|
||||
SMCSWeapon GetWeaponIdFromDefIdx(uint16_t iDefIdx)
|
||||
{
|
||||
//DEAR GOD THIS IS HIDEOUS
|
||||
//None in the middle are weapons that dont exist.
|
||||
//If they are added and use the same idx they should be changed to their respective ones
|
||||
static SMCSWeapon weaponIDMap[SMCSWeapon_MAXWEAPONIDS] =
|
||||
{
|
||||
SMCSWeapon_NONE, SMCSWeapon_DEAGLE, SMCSWeapon_ELITE, SMCSWeapon_FIVESEVEN,
|
||||
SMCSWeapon_GLOCK, SMCSWeapon_NONE, SMCSWeapon_NONE, SMCSWeapon_AK47,
|
||||
SMCSWeapon_AUG, SMCSWeapon_AWP, SMCSWeapon_FAMAS, SMCSWeapon_G3SG1,
|
||||
SMCSWeapon_NONE, SMCSWeapon_GALILAR, SMCSWeapon_M249, SMCSWeapon_NONE,
|
||||
SMCSWeapon_M4A1, SMCSWeapon_MAC10, SMCSWeapon_NONE, SMCSWeapon_P90,
|
||||
SMCSWeapon_NONE, SMCSWeapon_NONE, SMCSWeapon_NONE, SMCSWeapon_NONE,
|
||||
SMCSWeapon_UMP45, SMCSWeapon_XM1014, SMCSWeapon_BIZON, SMCSWeapon_MAG7,
|
||||
SMCSWeapon_NEGEV, SMCSWeapon_SAWEDOFF, SMCSWeapon_TEC9, SMCSWeapon_TASER,
|
||||
SMCSWeapon_HKP2000, SMCSWeapon_MP7, SMCSWeapon_MP9, SMCSWeapon_NOVA,
|
||||
SMCSWeapon_P250, SMCSWeapon_NONE, SMCSWeapon_SCAR20, SMCSWeapon_SG556,
|
||||
SMCSWeapon_SSG08, SMCSWeapon_KNIFE_GG, SMCSWeapon_KNIFE, SMCSWeapon_FLASHBANG,
|
||||
SMCSWeapon_HEGRENADE, SMCSWeapon_SMOKEGRENADE, SMCSWeapon_MOLOTOV, SMCSWeapon_DECOY,
|
||||
SMCSWeapon_INCGRENADE, SMCSWeapon_C4, SMCSWeapon_KEVLAR, SMCSWeapon_ASSAULTSUIT,
|
||||
SMCSWeapon_HEAVYASSAULTSUIT, SMCSWeapon_NONE, SMCSWeapon_NIGHTVISION, SMCSWeapon_DEFUSER
|
||||
};
|
||||
|
||||
if (iDefIdx >= SMCSWeapon_MAXWEAPONIDS)
|
||||
return (SMCSWeapon)iDefIdx;
|
||||
else
|
||||
return weaponIDMap[iDefIdx];
|
||||
}
|
||||
|
||||
ItemDefHashValue *GetHashValueFromWeapon(const char *szWeapon)
|
||||
{
|
||||
char tempWeapon[MAX_WEAPON_NAME_LENGTH];
|
||||
|
||||
Q_strncpy(tempWeapon, szWeapon, sizeof(tempWeapon));
|
||||
Q_strlower(tempWeapon);
|
||||
|
||||
if (strstr(tempWeapon, "weapon_") == NULL && strstr(tempWeapon, "item_") == NULL)
|
||||
{
|
||||
static const char *szClassPrefixs[] = { "weapon_", "item_" };
|
||||
|
||||
|
||||
for (unsigned int i = 0; i < SM_ARRAYSIZE(szClassPrefixs); i++)
|
||||
{
|
||||
char classname[MAX_WEAPON_NAME_LENGTH];
|
||||
Q_snprintf(classname, sizeof(classname), "%s%s", szClassPrefixs[i], tempWeapon);
|
||||
|
||||
ClassnameMap::Result res = g_mapClassToDefIdx.find(classname);
|
||||
|
||||
if (res.found())
|
||||
ClassnameMap::Result res = g_mapClassToDefIdx.find(classname);
|
||||
|
||||
if (res.found())
|
||||
return &res->value;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ClassnameMap::Result res = g_mapClassToDefIdx.find(tempWeapon);
|
||||
|
||||
if (res.found())
|
||||
return &res->value;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
void *GetWeaponInfo(int weaponID)
|
||||
{
|
||||
void *info;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("GetWeaponInfo", NULL,
|
||||
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(void *); \
|
||||
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
|
||||
}
|
||||
|
||||
unsigned char vstk[sizeof(int)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(int *)vptr = weaponID;
|
||||
|
||||
pWrapper->Execute(vstk, &info);
|
||||
|
||||
return info;
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *GetWeaponNameFromClassname(const char *weapon)
|
||||
{
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ClassnameMap::Result res = g_mapClassToDefIdx.find(tempWeapon);
|
||||
|
||||
if (res.found())
|
||||
return &res->value;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
void *GetWeaponInfo(int weaponID)
|
||||
{
|
||||
void *info;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("GetWeaponInfo", NULL,
|
||||
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(void *); \
|
||||
pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retpass, pass, 1))
|
||||
}
|
||||
|
||||
unsigned char vstk[sizeof(int)];
|
||||
unsigned char *vptr = vstk;
|
||||
|
||||
*(int *)vptr = weaponID;
|
||||
|
||||
pWrapper->Execute(vstk, &info);
|
||||
|
||||
return info;
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *GetWeaponNameFromClassname(const char *weapon)
|
||||
{
|
||||
char *szTemp = strstr((char *)weapon, "_");
|
||||
|
||||
if (!szTemp)
|
||||
@@ -429,103 +429,103 @@ const char *GetWeaponNameFromClassname(const char *weapon)
|
||||
else
|
||||
{
|
||||
return (const char *)((intptr_t)szTemp + 1);
|
||||
}
|
||||
}
|
||||
|
||||
const char *GetTranslatedWeaponAlias(const char *weapon)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
const char *alias = NULL;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("GetTranslatedWeaponAlias", weapon,
|
||||
PassInfo pass[1]; \
|
||||
PassInfo retpass; \
|
||||
pass[0].flags = PASSFLAG_BYVAL; \
|
||||
pass[0].type = PassType_Basic; \
|
||||
pass[0].size = sizeof(const char *); \
|
||||
retpass.flags = PASSFLAG_BYVAL; \
|
||||
retpass.type = PassType_Basic; \
|
||||
retpass.size = sizeof(const char *); \
|
||||
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);
|
||||
|
||||
pWrapper->Execute(vstk, &alias);
|
||||
return alias;
|
||||
#else //this should work for both games maybe replace both?
|
||||
static const char *szAliases[] =
|
||||
{
|
||||
"cv47", "ak47",
|
||||
"magnum", "awp",
|
||||
"d3au1", "g3sg1",
|
||||
"clarion", "famas",
|
||||
"bullpup", "aug",
|
||||
"9x19mm", "glock",
|
||||
"nighthawk", "deagle",
|
||||
"elites", "elite",
|
||||
"fn57", "fiveseven",
|
||||
"autoshotgun", "xm1014",
|
||||
"c90", "p90",
|
||||
"vest", "kevlar",
|
||||
"vesthelm", "assaultsuit",
|
||||
"nvgs", "nightvision"
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < SM_ARRAYSIZE(szAliases) / 2; i++)
|
||||
{
|
||||
if (Q_stristr(GetWeaponNameFromClassname(weapon), szAliases[i * 2]) != 0)
|
||||
return szAliases[i * 2 + 1];
|
||||
}
|
||||
|
||||
return GetWeaponNameFromClassname(weapon);
|
||||
#endif
|
||||
}
|
||||
|
||||
int AliasToWeaponID(const char *weapon)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
int weaponID = 0;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("AliasToWeaponID", 0,
|
||||
PassInfo pass[1]; \
|
||||
PassInfo retpass; \
|
||||
pass[0].flags = PASSFLAG_BYVAL; \
|
||||
pass[0].type = PassType_Basic; \
|
||||
pass[0].size = sizeof(const char *); \
|
||||
retpass.flags = PASSFLAG_BYVAL; \
|
||||
retpass.type = PassType_Basic; \
|
||||
retpass.size = sizeof(int); \
|
||||
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);
|
||||
|
||||
pWrapper->Execute(vstk, &weaponID);
|
||||
|
||||
return weaponID;
|
||||
#else
|
||||
ItemDefHashValue *pHashValue = GetHashValueFromWeapon(weapon);
|
||||
|
||||
if (pHashValue)
|
||||
return pHashValue->m_iWeaponID;
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
const char *GetTranslatedWeaponAlias(const char *weapon)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
const char *alias = NULL;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("GetTranslatedWeaponAlias", weapon,
|
||||
PassInfo pass[1]; \
|
||||
PassInfo retpass; \
|
||||
pass[0].flags = PASSFLAG_BYVAL; \
|
||||
pass[0].type = PassType_Basic; \
|
||||
pass[0].size = sizeof(const char *); \
|
||||
retpass.flags = PASSFLAG_BYVAL; \
|
||||
retpass.type = PassType_Basic; \
|
||||
retpass.size = sizeof(const char *); \
|
||||
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);
|
||||
|
||||
pWrapper->Execute(vstk, &alias);
|
||||
return alias;
|
||||
#else //this should work for both games maybe replace both?
|
||||
static const char *szAliases[] =
|
||||
{
|
||||
"cv47", "ak47",
|
||||
"magnum", "awp",
|
||||
"d3au1", "g3sg1",
|
||||
"clarion", "famas",
|
||||
"bullpup", "aug",
|
||||
"9x19mm", "glock",
|
||||
"nighthawk", "deagle",
|
||||
"elites", "elite",
|
||||
"fn57", "fiveseven",
|
||||
"autoshotgun", "xm1014",
|
||||
"c90", "p90",
|
||||
"vest", "kevlar",
|
||||
"vesthelm", "assaultsuit",
|
||||
"nvgs", "nightvision"
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < SM_ARRAYSIZE(szAliases) / 2; i++)
|
||||
{
|
||||
if (Q_stristr(GetWeaponNameFromClassname(weapon), szAliases[i * 2]) != 0)
|
||||
return szAliases[i * 2 + 1];
|
||||
}
|
||||
|
||||
return GetWeaponNameFromClassname(weapon);
|
||||
#endif
|
||||
}
|
||||
|
||||
int AliasToWeaponID(const char *weapon)
|
||||
{
|
||||
#if SOURCE_ENGINE != SE_CSGO
|
||||
int weaponID = 0;
|
||||
|
||||
static ICallWrapper *pWrapper = NULL;
|
||||
|
||||
if (!pWrapper)
|
||||
{
|
||||
REGISTER_ADDR("AliasToWeaponID", 0,
|
||||
PassInfo pass[1]; \
|
||||
PassInfo retpass; \
|
||||
pass[0].flags = PASSFLAG_BYVAL; \
|
||||
pass[0].type = PassType_Basic; \
|
||||
pass[0].size = sizeof(const char *); \
|
||||
retpass.flags = PASSFLAG_BYVAL; \
|
||||
retpass.type = PassType_Basic; \
|
||||
retpass.size = sizeof(int); \
|
||||
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);
|
||||
|
||||
pWrapper->Execute(vstk, &weaponID);
|
||||
|
||||
return weaponID;
|
||||
#else
|
||||
ItemDefHashValue *pHashValue = GetHashValueFromWeapon(weapon);
|
||||
|
||||
if (pHashValue)
|
||||
return pHashValue->m_iWeaponID;
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *WeaponIDToAlias(int weaponID)
|
||||
@@ -565,19 +565,19 @@ const char *WeaponIDToAlias(int weaponID)
|
||||
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IsValidWeaponID(int id)
|
||||
{
|
||||
if (id <= (int)SMCSWeapon_NONE)
|
||||
return false;
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
WeaponIDMap::Result res = g_mapWeaponIDToDefIdx.find((SMCSWeapon)id);
|
||||
if (!res.found())
|
||||
return false;
|
||||
#else
|
||||
else if (id > SMCSWeapon_NIGHTVISION || !GetWeaponInfo(id))
|
||||
return false;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsValidWeaponID(int id)
|
||||
{
|
||||
if (id <= (int)SMCSWeapon_NONE)
|
||||
return false;
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
WeaponIDMap::Result res = g_mapWeaponIDToDefIdx.find((SMCSWeapon)id);
|
||||
if (!res.found())
|
||||
return false;
|
||||
#else
|
||||
else if (id > SMCSWeapon_NIGHTVISION || !GetWeaponInfo(id))
|
||||
return false;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user