Engine: Add safe get_global_edict2() and entity_get_edict2()
This commit is contained in:
@ -1057,7 +1057,7 @@ static cell AMX_NATIVE_CALL entity_set_string(AMX *amx, cell *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL entity_get_edict(AMX *amx, cell *params)
|
||||
static cell AMX_NATIVE_CALL entity_get_edict2(AMX *amx, cell *params)
|
||||
{
|
||||
int iEnt = params[1];
|
||||
int idx = params[2];
|
||||
@ -1103,16 +1103,26 @@ static cell AMX_NATIVE_CALL entity_get_edict(AMX *amx, cell *params)
|
||||
pRet = pEnt->v.euser4;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (FNullEnt(pRet))
|
||||
return 0;
|
||||
return -1;
|
||||
|
||||
return ENTINDEX(pRet);
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL entity_get_edict(AMX *amx, cell *params)
|
||||
{
|
||||
cell res = entity_get_edict2(amx, params);
|
||||
|
||||
if (res == -1)
|
||||
res = 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL entity_set_edict(AMX *amx, cell *params)
|
||||
{
|
||||
int iEnt = params[1];
|
||||
@ -1602,6 +1612,7 @@ AMX_NATIVE_INFO ent_Natives[] = {
|
||||
{"entity_get_string", entity_get_string},
|
||||
{"entity_set_string", entity_set_string},
|
||||
{"entity_get_edict", entity_get_edict},
|
||||
{"entity_get_edict2", entity_get_edict2},
|
||||
{"entity_set_edict", entity_set_edict},
|
||||
{"entity_get_byte", entity_get_byte},
|
||||
{"entity_set_byte", entity_set_byte},
|
||||
|
@ -157,7 +157,7 @@ static cell AMX_NATIVE_CALL get_global_vector(AMX *amx, cell *params) // globals
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL get_global_edict(AMX *amx, cell *params) // globals_get_edict(variable); = 1 param
|
||||
static cell AMX_NATIVE_CALL get_global_edict2(AMX *amx, cell *params)
|
||||
{
|
||||
edict_t* pReturnEntity;
|
||||
|
||||
@ -167,14 +167,24 @@ static cell AMX_NATIVE_CALL get_global_edict(AMX *amx, cell *params) // globals_
|
||||
break;
|
||||
default:
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Undefined global_edict index %d", params[1]);
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Will crash if ENTINDEX() is called on bad pointer?
|
||||
if(!FNullEnt(pReturnEntity))
|
||||
return ENTINDEX(pReturnEntity);
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL get_global_edict(AMX *amx, cell *params) // globals_get_edict(variable); = 1 param
|
||||
{
|
||||
cell res = get_global_edict2(amx, params);
|
||||
|
||||
if (res == -1)
|
||||
res = 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
AMX_NATIVE_INFO global_Natives[] = {
|
||||
@ -182,6 +192,7 @@ AMX_NATIVE_INFO global_Natives[] = {
|
||||
{"get_global_int", get_global_int},
|
||||
{"get_global_string", get_global_string},
|
||||
{"get_global_edict", get_global_edict},
|
||||
{"get_global_edict2", get_global_edict2},
|
||||
{"get_global_vector", get_global_vector},
|
||||
{NULL, NULL},
|
||||
///////////////////
|
||||
|
Reference in New Issue
Block a user