mirror of
https://github.com/rehlds/reapi.git
synced 2024-12-28 15:45:31 +03:00
Rework native rg_get_weapon_info
This commit is contained in:
parent
136efa87ab
commit
86aead4b02
@ -61,7 +61,7 @@ void setupToolchain(NativeBinarySpec b) {
|
||||
'_snprintf': 'snprintf'
|
||||
])
|
||||
|
||||
cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp', '-msse2', '-fp-model fast=2', '-fomit-frame-pointer', '-inline-forceinline', '-fvisibility=default', '-fvisibility-inlines-hidden', '-fno-rtti', '-g0', '-s'
|
||||
cfg.compilerOptions.args '-Qoption,cpp,--treat_func_as_string_literal_cpp', '-msse2', '-fomit-frame-pointer', '-inline-forceinline', '-fvisibility=default', '-fvisibility-inlines-hidden', '-fno-rtti', '-g0', '-s'
|
||||
}
|
||||
|
||||
ToolchainConfigUtils.apply(project, cfg, b)
|
||||
|
@ -236,14 +236,15 @@ native rg_find_ent_by_owner(&start_index, const classname[], owner);
|
||||
/**
|
||||
* Returns some information about a weapon.
|
||||
*
|
||||
* @param weapon_id Weapon id, see WEAPON_* constants
|
||||
* @param type Info type, see WPINFO_* constants
|
||||
* @param weapon name or id Weapon id, see WEAPON_* constants WeaponIdType or weapon_* name
|
||||
* @param WpnInfo:type Info type, see WI_* constants
|
||||
*
|
||||
* @return Weapon information value
|
||||
* @error If weapon_id and type are out of bound, an error will be thrown.
|
||||
* @return Weapon information value
|
||||
* @error If weapon_id and type are out of bound, an error will be thrown.
|
||||
*
|
||||
* native rg_get_weapon_info(any:...);
|
||||
*/
|
||||
native rg_get_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...);
|
||||
native rg_get_weapon_info(any:...);
|
||||
|
||||
/**
|
||||
* Sets specific values of weapons info.
|
||||
|
@ -54,6 +54,7 @@ enum WeaponIdType
|
||||
// Weapon info types for use with rg_get_weapon_info()
|
||||
enum WpnInfo
|
||||
{
|
||||
WI_ID,
|
||||
WI_COST,
|
||||
WI_CLIP_COST,
|
||||
WI_BUY_CLIP_SIZE,
|
||||
|
@ -504,30 +504,48 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params)
|
||||
/**
|
||||
* Returns some information about a weapon.
|
||||
*
|
||||
* @param weapon_id Weapon id, see WEAPON_* constants
|
||||
* @param type Info type, see WI_* constants
|
||||
* @param weapon name or id Weapon id, see WEAPON_* constants or weapon_* name
|
||||
* @param WpnInfo:type Info type, see WI_* constants
|
||||
*
|
||||
* @return Weapon information value
|
||||
* @error If weapon_id and type are out of bound, an error will be thrown.
|
||||
* @return Weapon information value
|
||||
* @error If weapon_id and type are out of bound, an error will be thrown.
|
||||
*
|
||||
* native rg_get_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:...);
|
||||
* native rg_get_weapon_info(any:...);
|
||||
*/
|
||||
cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params)
|
||||
{
|
||||
enum args_e { arg_count, arg_weapon_id, arg_type, arg_3, arg_4 };
|
||||
|
||||
int weapon_id = params[arg_weapon_id];
|
||||
if (weapon_id <= WEAPON_NONE || weapon_id == WEAPON_C4 || weapon_id == WEAPON_KNIFE || weapon_id > WEAPON_P90)
|
||||
WeaponIdType weaponID = static_cast<WeaponIdType>(params[arg_weapon_id]);
|
||||
WpnInfo info_type = static_cast<WpnInfo>(*getAmxAddr(amx, params[arg_type]));
|
||||
|
||||
if (!GetWeaponInfoRange(weaponID) && info_type != WI_ID)
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weapon_id);
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weaponID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
WeaponInfoStruct *info = g_ReGameApi->GetGameData()->GetWeaponInfo(weapon_id);
|
||||
WpnInfo info_type = static_cast<WpnInfo>(params[arg_type]);
|
||||
WeaponInfoStruct* info = g_ReGameApi->GetGameData()->GetWeaponInfo(weaponID);
|
||||
char* szWeaponName = getAmxString(amx, params[arg_weapon_id]);
|
||||
|
||||
switch (info_type)
|
||||
{
|
||||
case WI_ID:
|
||||
if (szWeaponName == nullptr) {
|
||||
return WEAPON_NONE;
|
||||
}
|
||||
|
||||
_strlwr(szWeaponName);
|
||||
for (int i = 0; i < MAX_WEAPONS; ++i) {
|
||||
info = g_ReGameApi->GetGameData()->GetWeaponInfo(i);
|
||||
if (info == nullptr || info->id == WEAPON_NONE)
|
||||
continue;
|
||||
|
||||
if (strcmp(info->entityName, szWeaponName) == 0) {
|
||||
return info->id;
|
||||
}
|
||||
}
|
||||
return WEAPON_NONE;
|
||||
case WI_COST:
|
||||
return info->cost;
|
||||
case WI_CLIP_COST:
|
||||
@ -579,15 +597,15 @@ cell AMX_NATIVE_CALL rg_set_weapon_info(AMX *amx, cell *params)
|
||||
{
|
||||
enum args_e { arg_count, arg_weapon_id, arg_type, arg_value };
|
||||
|
||||
int weapon_id = params[arg_weapon_id];
|
||||
if (weapon_id <= WEAPON_NONE || weapon_id == WEAPON_C4 || weapon_id == WEAPON_KNIFE || weapon_id > WEAPON_P90)
|
||||
WeaponIdType weaponID = static_cast<WeaponIdType>(params[arg_weapon_id]);
|
||||
if (!GetWeaponInfoRange(weaponID))
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weapon_id);
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weaponID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cell* value = getAmxAddr(amx, params[arg_value]);
|
||||
WeaponInfoStruct *info = g_ReGameApi->GetGameData()->GetWeaponInfo(weapon_id);
|
||||
WeaponInfoStruct *info = g_ReGameApi->GetGameData()->GetWeaponInfo(weaponID);
|
||||
WpnInfo info_type = static_cast<WpnInfo>(params[arg_type]);
|
||||
|
||||
switch (info_type)
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
enum WpnInfo
|
||||
{
|
||||
WI_ID,
|
||||
WI_COST,
|
||||
WI_CLIP_COST,
|
||||
WI_BUY_CLIP_SIZE,
|
||||
|
@ -7,6 +7,10 @@ char(&ArraySizeHelper(T(&array)[N]))[N];
|
||||
#define INDEXENT edictByIndex
|
||||
#define ENTINDEX indexOfEdict
|
||||
|
||||
#ifndef _WIN32
|
||||
#define _strlwr(p) for (int i = 0; p[i] != 0; i++) p[i] = tolower(p[i]);
|
||||
#endif
|
||||
|
||||
extern enginefuncs_t* g_pengfuncsTable;
|
||||
|
||||
inline size_t indexOfEdict(edict_t* ed)
|
||||
@ -86,6 +90,17 @@ inline T get_member_direct(edict_t *pEntity, int offset, int element = 0, int si
|
||||
return get_member_direct<T>(pEntity->pvPrivateData, offset, element, size);
|
||||
}
|
||||
|
||||
inline bool GetWeaponInfoRange(WeaponIdType wpnid)
|
||||
{
|
||||
if (wpnid == WEAPON_SHIELDGUN)
|
||||
return true;
|
||||
|
||||
if (wpnid > WEAPON_NONE && wpnid != WEAPON_C4 && wpnid != WEAPON_KNIFE && wpnid <= WEAPON_P90)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Broadcast(const char *sentence);
|
||||
void UpdateTeamScores();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user