2
0
mirror of https://github.com/rehlds/reapi.git synced 2025-01-16 08:38:08 +03:00

Fix crash rg_find_item_bpack_by_name

This commit is contained in:
s1lentq 2016-06-22 21:39:58 +07:00
parent 272b2fc709
commit 6cf5c99ded
4 changed files with 37 additions and 5 deletions

View File

@ -297,7 +297,7 @@ native rg_find_ent_by_owner(&start_index, const classname[], owner);
* @return Entity-index of item, 0 otherwise * @return Entity-index of item, 0 otherwise
* *
*/ */
native rg_find_bpack_item_by_name(const index, const item[]); native rg_find_item_bpack_by_name(const index, const item[]);
/* /*
* Returns some information about a weapon. * Returns some information about a weapon.

View File

@ -88,6 +88,14 @@ enum WpnInfo
*/ */
WI_AMMO_TYPE, WI_AMMO_TYPE,
/*
* Description: -
* Return type: -
* Get params: rg_get_weapon_info(const weapon_id, WI_AMMO_NAME, const output[], maxlenght);
* Set params: -
*/
WI_AMMO_NAME,
/* /*
* Description: - * Description: -
* Return type: - * Return type: -

View File

@ -547,7 +547,7 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params)
* *
* @return Entity-index of item, 0 otherwise * @return Entity-index of item, 0 otherwise
* *
* native rg_find_bpack_item_by_name(const index, const item[]); * native rg_find_item_bpack_by_name(const index, const item[]);
*/ */
cell AMX_NATIVE_CALL rg_find_item_bpack_by_name(AMX *amx, cell *params) cell AMX_NATIVE_CALL rg_find_item_bpack_by_name(AMX *amx, cell *params)
{ {
@ -563,8 +563,11 @@ cell AMX_NATIVE_CALL rg_find_item_bpack_by_name(AMX *amx, cell *params)
const char *itemName = getAmxString(amx, params[arg_item]); const char *itemName = getAmxString(amx, params[arg_item]);
auto pInfo = g_ReGameApi->GetWeaponSlot(itemName); auto pInfo = g_ReGameApi->GetWeaponSlot(itemName);
auto pItem = pPlayer->m_rgpPlayerItems[ pInfo->slot ]; if (pInfo == nullptr) {
return 0;
}
auto pItem = pPlayer->m_rgpPlayerItems[ pInfo->slot ];
while (pItem) { while (pItem) {
if (FClassnameIs(pItem->pev, itemName)) { if (FClassnameIs(pItem->pev, itemName)) {
return indexOfEdict(pItem->pev); return indexOfEdict(pItem->pev);
@ -626,6 +629,25 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params)
return info->maxRounds; return info->maxRounds;
case WI_AMMO_TYPE: case WI_AMMO_TYPE:
return info->ammoType; return info->ammoType;
case WI_AMMO_NAME:
{
if (PARAMS_COUNT != arg_4) {
MF_LogError(amx, AMX_ERR_NATIVE, "%s: bad parameter count, got %i, expected %i", __FUNCTION__, PARAMS_COUNT, arg_4);
return -1;
}
// native rg_get_weapon_info(id, WI_AMMO_NAME, output[], maxlength);
cell* dest = getAmxAddr(amx, params[arg_3]);
size_t length = *getAmxAddr(amx, params[arg_4]);
if (info->ammoName == nullptr) {
setAmxString(dest, "", 1);
return 0;
}
setAmxString(dest, info->ammoName, length);
return 1;
}
case WI_NAME: case WI_NAME:
{ {
if (PARAMS_COUNT != arg_4) { if (PARAMS_COUNT != arg_4) {
@ -688,8 +710,9 @@ cell AMX_NATIVE_CALL rg_set_weapon_info(AMX *amx, cell *params)
case WI_GUN_CLIP_SIZE: case WI_GUN_CLIP_SIZE:
case WI_MAX_ROUNDS: case WI_MAX_ROUNDS:
case WI_AMMO_TYPE: case WI_AMMO_TYPE:
case WI_AMMO_NAME:
case WI_NAME: case WI_NAME:
MF_LogError(amx, AMX_ERR_NATIVE, "%s: this change will have no effect", __FUNCTION__); MF_LogError(amx, AMX_ERR_NATIVE, "%s: this change will have no effect, type statement %i", __FUNCTION__, info_type);
return 0; return 0;
default: default:
MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT); MF_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT);

View File

@ -9,7 +9,8 @@ enum WpnInfo
WI_GUN_CLIP_SIZE, WI_GUN_CLIP_SIZE,
WI_MAX_ROUNDS, WI_MAX_ROUNDS,
WI_AMMO_TYPE, WI_AMMO_TYPE,
WI_NAME WI_AMMO_NAME,
WI_NAME,
}; };
void RegisterNatives_Misc(); void RegisterNatives_Misc();