Cstrike: Add cs_get_weapon_info() native

This commit is contained in:
Arkshine 2015-07-25 16:17:50 +02:00
parent 60cdbeb219
commit 600a15a57b
7 changed files with 125 additions and 0 deletions

View File

@ -62,6 +62,14 @@
"linux" "@_Z23UTIL_FindEntityByStringP11CBaseEntityPKcS2_"
"mac" "@_Z23UTIL_FindEntityByStringP11CBaseEntityPKcS2_"
}
"GetWeaponInfo" // WeaponInfoStruct *GetWeaponInfo(int id);
{
"library" "server"
"windows" "\x8B\x2A\x2A\x2A\x2A\x2A\x33\x2A\x85\x2A\x56\x74\x2A\x8B"
"linux" "@_Z13GetWeaponInfoi"
"mac" "@_Z13GetWeaponInfoi"
}
}
}

View File

@ -94,6 +94,7 @@
#define CSW_VEST 31 // Brand new invention!
#define CSW_VESTHELM 32 // Brand new invention!
#define CSW_SHIELDGUN 99
#define CSW_LAST_WEAPON CSW_P90
/**
* Armoury entity ids for use with cs_get/set_armoury_type().
@ -299,6 +300,35 @@ enum CsWeaponClassType
CS_WEAPONCLASS_MAX_COUNT = 9,
};
/**
* Weapon infos.
*/
typedef struct
{
int id;
int cost;
int clipCost;
int buyClipSize;
int gunClipSize;
int maxRounds;
int ammoType;
char *entityName;
}
WeaponInfoStruct;
/**
* Weapon infos for use with cs_get_weapon_info().
*/
enum CsWeaponInfo
{
CS_WEAPONINFO_COST = 0,
CS_WEAPONINFO_CLIP_COST = 1,
CS_WEAPONINFO_BUY_CLIP_SIZE = 2,
CS_WEAPONINFO_GUN_CLIP_SIZE = 3,
CS_WEAPONINFO_MAX_ROUNDS = 4,
CS_WEAPONINFO_AMMO_TYPE = 5,
};
extern char WeaponNameList[MAX_WEAPONS][64];
#endif // CSTRIKE_DATA_H

View File

@ -36,6 +36,7 @@ CDetour *GiveDefaultItemsDetour;
CreateNamedEntityFunc CS_CreateNamedEntity;
UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString;
GetWeaponInfoFunc GetWeaponInfo;
int CurrentItemId;
@ -433,6 +434,12 @@ void CtrlDetours_Natives(bool set)
CS_UTIL_FindEntityByString = reinterpret_cast<UTIL_FindEntityByStringFunc>(address);
}
if (MainConfig->GetMemSig("GetWeaponInfo", &address)) // cs_get_weapon_info()
{
GetWeaponInfo = reinterpret_cast<GetWeaponInfoFunc>(address);
}
if (!CS_CreateNamedEntity)
{
MF_Log("CREATE_NAMED_ENITTY is not available - native cs_create_entity() has been disabled");
@ -443,6 +450,12 @@ void CtrlDetours_Natives(bool set)
MF_Log("UTIL_FindEntByString is not available - native cs_find_ent_by_class() has been disabled");
}
if (!GetWeaponInfo)
{
MF_Log("GetWeaponInfo is not available - native cs_get_weapon_info() has been disabled");
}
if (MainConfig->GetMemSig("GiveDefaultItems", &address))
{
GiveDefaultItemsDetour = DETOUR_CREATE_MEMBER_FIXED(GiveDefaultItems, address);

View File

@ -38,9 +38,11 @@ extern int ForwardOnGetItemPrice;
typedef edict_t* (*CreateNamedEntityFunc)(string_t iszClassname);
typedef void* (*UTIL_FindEntityByStringFunc)(void* pStartEntity, const char *szKeyword, const char *szValue);
typedef WeaponInfoStruct* (*GetWeaponInfoFunc)(int id);
extern CreateNamedEntityFunc CS_CreateNamedEntity;
extern UTIL_FindEntityByStringFunc CS_UTIL_FindEntityByString;
extern GetWeaponInfoFunc GetWeaponInfo;
extern CDetour *GiveDefaultItemsDetour;
extern enginefuncs_t *g_pengfuncsTable;

View File

@ -1810,6 +1810,57 @@ static cell AMX_NATIVE_CALL cs_get_translated_item_alias(AMX* amx, cell* params)
return info.itemid != CSI_NONE;
}
// native cs_get_weapon_info(weapon_id, CsWeaponInfo:type);
static cell AMX_NATIVE_CALL cs_get_weapon_info(AMX* amx, cell* params)
{
if (GetWeaponInfo <= 0)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_get_weapon_info() is disabled");
return 0;
}
int weapon_id = params[1];
if (weapon_id <= CSW_NONE || weapon_id == CSW_C4 || weapon_id == CSW_KNIFE || weapon_id > CSW_LAST_WEAPON)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id: %d", weapon_id);
return 0;
}
int info_type = params[2];
switch (info_type)
{
case CS_WEAPONINFO_COST:
{
return GetWeaponInfo(weapon_id)->cost;
}
case CS_WEAPONINFO_CLIP_COST:
{
return GetWeaponInfo(weapon_id)->clipCost;
}
case CS_WEAPONINFO_BUY_CLIP_SIZE:
{
return GetWeaponInfo(weapon_id)->buyClipSize;
}
case CS_WEAPONINFO_GUN_CLIP_SIZE:
{
return GetWeaponInfo(weapon_id)->gunClipSize;
}
case CS_WEAPONINFO_MAX_ROUNDS:
{
return GetWeaponInfo(weapon_id)->maxRounds;
}
case CS_WEAPONINFO_AMMO_TYPE:
{
return GetWeaponInfo(weapon_id)->ammoType;
}
}
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid info type: %d", info_type);
return 0;
}
AMX_NATIVE_INFO CstrikeNatives[] =
{

View File

@ -1062,6 +1062,17 @@ stock cs_get_weapon_class(weapon_id)
}
/**
* Returns some information about a weapon.
*
* @param weapon_id Weapon id, see CSW_* constants
* @param type Info type, see CS_WEAPONINFO_* constants
*
* @return Weapon information value
* @error If weapon_id and type are out of bound, an error will be thrown.
*/
native any:cs_get_weapon_info(weapon_id, CsWeaponInfo:type);
/**
* Called when CS internally fires a command to a player.
*

View File

@ -346,3 +346,13 @@ enum CsAmmoType
CS_AMMO_57MM = 8,
CS_AMMO_357SIG = 9,
};
enum CsWeaponInfo
{
CS_WEAPONINFO_COST = 0,
CS_WEAPONINFO_CLIP_COST = 1,
CS_WEAPONINFO_BUY_CLIP_SIZE = 2,
CS_WEAPONINFO_GUN_CLIP_SIZE = 3,
CS_WEAPONINFO_MAX_ROUNDS = 4,
CS_WEAPONINFO_AMMO_TYPE = 5,
};