diff --git a/modules/engine/engine.cpp b/modules/engine/engine.cpp index c9e52c60..71df442f 100644 --- a/modules/engine/engine.cpp +++ b/modules/engine/engine.cpp @@ -269,6 +269,7 @@ static cell AMX_NATIVE_CALL PointContents(AMX *amx, cell *params) static cell AMX_NATIVE_CALL trace_normal(AMX *amx, cell *params) { int iEnt = params[1]; + CHECK_ENTITY(iEnt); cell *cStart = MF_GetAmxAddr(amx, params[2]); cell *cEnd = MF_GetAmxAddr(amx, params[3]); @@ -299,6 +300,8 @@ static cell AMX_NATIVE_CALL trace_normal(AMX *amx, cell *params) static cell AMX_NATIVE_CALL trace_line(AMX *amx, cell *params) { int iEnt = params[1]; + if (iEnt != -1) + CHECK_ENTITY(iEnt); cell *cStart = MF_GetAmxAddr(amx, params[2]); cell *cEnd = MF_GetAmxAddr(amx, params[3]); @@ -397,6 +400,7 @@ static cell AMX_NATIVE_CALL attach_view(AMX *amx, cell *params) int iTargetIndex = params[2]; CHECK_ENTITY(iIndex); + CHECK_ENTITY(iTargetIndex); SET_VIEW(INDEXENT2(iIndex), INDEXENT2(iTargetIndex)); @@ -568,6 +572,10 @@ static cell AMX_NATIVE_CALL set_lights(AMX *amx, cell *params) { //(mahnsawce) static cell AMX_NATIVE_CALL trace_hull(AMX *amx,cell *params) { + int iEnt = params[3]; + if (iEnt > 0) + CHECK_ENTITY(iEnt); + int iResult=0; Vector vStart; Vector vEnd; @@ -589,7 +597,8 @@ static cell AMX_NATIVE_CALL trace_hull(AMX *amx,cell *params) else vEnd = vStart; - TRACE_HULL(vStart, vEnd, params[4], params[2], params[3] > 0 ? INDEXENT2(params[3]) : 0, &g_tr); + + TRACE_HULL(vStart, vEnd, params[4], params[2], iEnt > 0 ? INDEXENT2(iEnt) : NULL, &g_tr); if (g_tr.fStartSolid) { iResult += 1; @@ -623,6 +632,7 @@ static cell AMX_NATIVE_CALL playback_event(AMX *amx, cell *params) int bparam1; int bparam2; flags = params[1]; + CHECK_ENTITY(params[2]); pInvoker=INDEXENT2(params[2]); eventindex=params[3]; delay=amx_ctof(params[4]); @@ -940,6 +950,9 @@ static cell AMX_NATIVE_CALL trace_forward(AMX *amx, cell *params) cell *cAngles = MF_GetAmxAddr(amx, params[2]); REAL fGive = amx_ctof(params[3]); int iIgnoreEnt = params[4]; + if (iIgnoreEnt != -1) + CHECK_ENTITY(iIgnoreEnt); + cell *hitX = MF_GetAmxAddr(amx, params[5]); cell *hitY = MF_GetAmxAddr(amx, params[6]); cell *shortestDistance = MF_GetAmxAddr(amx, params[7]); diff --git a/modules/engine/entity.cpp b/modules/engine/entity.cpp index 440d8c9f..4449c145 100644 --- a/modules/engine/entity.cpp +++ b/modules/engine/entity.cpp @@ -120,7 +120,7 @@ static cell AMX_NATIVE_CALL create_entity(AMX *amx, cell *params) static cell AMX_NATIVE_CALL remove_entity(AMX *amx, cell *params) { int id = params[1]; - if (id >= 0 && id <= gpGlobals->maxClients) + if (id <= gpGlobals->maxClients || id > gpGlobals->maxEntities) { MF_LogError(amx, AMX_ERR_NATIVE, "Entity %d can not be removed", id); return 0; @@ -156,11 +156,7 @@ static cell AMX_NATIVE_CALL DispatchKeyValue(AMX *amx, cell *params) cell *cVal = MF_GetAmxAddr(amx, params[1]); int iValue = *cVal; - if (iValue != 0 && (FNullEnt(INDEXENT2(iValue)) || iValue < 0 || iValue > gpGlobals->maxEntities)) - { - MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", iValue); - return 0; - } + CHECK_ENTITY_SIMPLE(iValue); edict_t *pEntity = INDEXENT2(iValue); KeyValueData kvd; @@ -1342,6 +1338,7 @@ static cell AMX_NATIVE_CALL get_entity_pointer(AMX *amx, cell *params) // get_en static cell AMX_NATIVE_CALL find_ent_in_sphere(AMX *amx, cell *params) { int idx = params[1]; + CHECK_ENTITY_SIMPLE(idx); edict_t *pEnt = INDEXENT2(idx); cell *cAddr = MF_GetAmxAddr(amx, params[2]); @@ -1362,7 +1359,10 @@ static cell AMX_NATIVE_CALL find_ent_in_sphere(AMX *amx, cell *params) static cell AMX_NATIVE_CALL find_ent_by_class(AMX *amx, cell *params) /* 3 param */ { - edict_t *pEnt = INDEXENT2(params[1]); + int idx = params[1]; + CHECK_ENTITY_SIMPLE(idx); + + edict_t *pEnt = INDEXENT2(idx); int len; char* sValue = MF_GetAmxString(amx, params[2], 0, &len); @@ -1498,7 +1498,7 @@ static cell AMX_NATIVE_CALL find_ent_by_owner(AMX *amx, cell *params) // native { int iEnt = params[1]; int oEnt = params[3]; - // Check index to start searching at, 0 must be possible for iEnt. + CHECK_ENTITY_SIMPLE(iEnt); CHECK_ENTITY_SIMPLE(oEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -1534,6 +1534,7 @@ static cell AMX_NATIVE_CALL get_grenade_id(AMX *amx, cell *params) /* 4 param * int index = params[1]; const char *szModel; + CHECK_ENTITY_SIMPLE(params[4]); CHECK_ENTITY(index); edict_t* pentFind = INDEXENT2(params[4]);