diff --git a/dlls/engine/amxxapi.cpp b/dlls/engine/amxxapi.cpp index 80fd622f..6d273768 100755 --- a/dlls/engine/amxxapi.cpp +++ b/dlls/engine/amxxapi.cpp @@ -11,17 +11,6 @@ int AmxStringToEngine(AMX *amx, cell param, int &len) return ALLOC_STRING(szString); } -void EngineError(AMX *amx, char *fmt, ...) -{ - va_list p; - va_start(p, fmt); - char errbuf[512]; - vsprintf(errbuf, fmt, p); - va_end(p); - MF_Log("%s (\"%s\", line %d)", errbuf, MF_GetScriptName(MF_FindScriptByAmx(amx)), amx->curline); - MF_RaiseAmxError(amx, AMX_ERR_NATIVE); -} - void ClearHooks() { register unsigned int i = 0; @@ -240,7 +229,7 @@ void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) Msg.clear(); register int i = 0, j = 0; for (i=0; i<256; i++) { - for (j=0; j gpGlobals->maxClients || !is_ent_valid(iIndex)) { - EngineError(amx, "Invalid player %d", iIndex); + if (iIndex > gpGlobals->maxClients || !MF_IsPlayerIngame(iIndex)) { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", iIndex); return 0; } @@ -342,8 +339,8 @@ static cell AMX_NATIVE_CALL set_speak(AMX *amx, cell *params) { static cell AMX_NATIVE_CALL get_speak(AMX *amx, cell *params) { int iIndex = params[1]; - if (!is_ent_valid(iIndex) || iIndex > gpGlobals->maxClients) { - EngineError(amx, "Invalid player %d", iIndex); + if (iIndex > gpGlobals->maxClients || !MF_IsPlayerIngame(iIndex)) { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", iIndex); return 0; } @@ -369,10 +366,7 @@ static cell AMX_NATIVE_CALL get_info_keybuffer(AMX *amx, cell *params) { int iEnt = params[1]; - if (FNullEnt(iEnt) || iEnt < 1 || iEnt > gpGlobals->maxClients) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *e = INDEXENT2(iEnt); @@ -387,10 +381,7 @@ static cell AMX_NATIVE_CALL drop_to_floor(AMX *amx, cell *params) { int iEnt = params[1]; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *e = INDEXENT2(iEnt); @@ -413,15 +404,12 @@ static cell AMX_NATIVE_CALL attach_view(AMX *amx, cell *params) int iIndex = params[1]; int iTargetIndex = params[2]; - if (iIndex > gpGlobals->maxClients || !is_ent_valid(iIndex)) { - EngineError(amx, "Invalid player %d", iIndex); + if (iIndex > gpGlobals->maxClients || !MF_IsPlayerIngame(iIndex)) { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", iIndex); return 0; } - if (!is_ent_valid(iTargetIndex)) { - EngineError(amx, "Invalid Entity %d", iIndex); - return 0; - } + CHECK_ENTITY(iIndex); SET_VIEW(INDEXENT2(iIndex), INDEXENT2(iTargetIndex)); @@ -435,8 +423,8 @@ static cell AMX_NATIVE_CALL set_view(AMX *amx, cell *params) { int iIndex = params[1]; int iCameraType = params[2]; - if (iIndex > gpGlobals->maxClients || !is_ent_valid(iIndex)) { - EngineError(amx, "Invalid player %d", iIndex); + if (iIndex > gpGlobals->maxClients || !MF_IsPlayerIngame(iIndex)) { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", iIndex); return 0; } diff --git a/dlls/engine/engine.h b/dlls/engine/engine.h index f8e71dbf..613a42b9 100755 --- a/dlls/engine/engine.h +++ b/dlls/engine/engine.h @@ -13,8 +13,6 @@ #include "entity.h" #include "gpglobals.h" -//#define CHECK_ENTITY(x) if (x != 0 && (FNullEnt(INDEXENT2(x)) || x < 0 || x > gpGlobals->maxEntities)) { MF_RaiseAmxError(amx,AMX_ERR_NATIVE); return 0; } - extern DLL_FUNCTIONS *g_pFunctionTable; extern DLL_FUNCTIONS *g_pFunctionTable_Post; extern enginefuncs_t *g_pengfuncsTable; @@ -170,8 +168,6 @@ inline edict_t* INDEXENT2( int iEdictNum ) return (*g_engfuncs.pfnPEntityOfEntIndex)(iEdictNum); } -void EngineError(AMX *amx, char *fmt, ...); - int Spawn(edict_t *pEntity); void ChangeLevel(char* s1, char* s2); void PlaybackEvent(int flags, const edict_t *pInvoker, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2); @@ -184,7 +180,20 @@ void PlayerPostThink_Post(edict_t *pEntity); void pfnTouch(edict_t *pToucher, edict_t *pTouched); void Think(edict_t *pent); -#define CHECK_ENTITY(x) if (x != 0 && (FNullEnt(INDEXENT2(x)) || x < 0 || x > gpGlobals->maxEntities)) { EngineError(amx, "Invalid entity %d", x); return 0; } +#define CHECK_ENTITY(x) \ + if (x <= 0 || x > gpGlobals->maxEntities) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \ + } else { \ + if (x <= gpGlobals->maxClients) { \ + if (!MF_IsPlayerIngame(x)) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \ + } \ + } else { \ + if (FNullEnt(INDEXENT2(x))) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \ + } \ + } \ + } extern bool g_inKeyValue; extern KeyValueData *g_pkvd; diff --git a/dlls/engine/entity.cpp b/dlls/engine/entity.cpp index afb3b891..c417dc34 100755 --- a/dlls/engine/entity.cpp +++ b/dlls/engine/entity.cpp @@ -26,10 +26,8 @@ static cell AMX_NATIVE_CALL entity_range(AMX *amx, cell *params) int idxa = params[1]; int idxb = params[2]; - if (!is_ent_valid(idxa) || !is_ent_valid(idxb)) { - EngineError(amx, "Invalid Entity"); - return 0; - } + CHECK_ENTITY(idxa); + CHECK_ENTITY(idxb); edict_t *pEntA = INDEXENT2(idxa); edict_t *pEntB = INDEXENT2(idxb); @@ -47,10 +45,7 @@ static cell AMX_NATIVE_CALL call_think(AMX *amx, cell *params) { int iEnt = params[1]; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -65,10 +60,8 @@ static cell AMX_NATIVE_CALL fake_touch(AMX *amx, cell *params) int iPtr = params[1]; int iPtd = params[2]; - if (!is_ent_valid(iPtr) || !is_ent_valid(iPtd)) { - EngineError(amx, "Invalid Entity"); - return 0; - } + CHECK_ENTITY(iPtr); + CHECK_ENTITY(iPtd); edict_t *pToucher = INDEXENT2(iPtr); edict_t *pTouched = INDEXENT2(iPtd); @@ -83,10 +76,8 @@ static cell AMX_NATIVE_CALL force_use(AMX *amx, cell *params) int iPtr = params[1]; int iPtd = params[2]; - if (!is_ent_valid(iPtr) || !is_ent_valid(iPtd)) { - EngineError(amx, "Invalid Entity"); - return 0; - } + CHECK_ENTITY(iPtr); + CHECK_ENTITY(iPtd); edict_t *pUser = INDEXENT2(iPtr); edict_t *pUsed = INDEXENT2(iPtd); @@ -139,10 +130,7 @@ static cell AMX_NATIVE_CALL DispatchKeyValue(AMX *amx, cell *params) if (count == 3) { cell *cVal = MF_GetAmxAddr(amx, params[1]); int iValue = *cVal; - if (!is_ent_valid(iValue)) { - EngineError(amx, "Invalid Entity %d", iValue); - return 0; - } + CHECK_ENTITY(iValue); edict_t *pEntity = INDEXENT2(iValue); KeyValueData kvd; int iLength=0; @@ -172,10 +160,7 @@ static cell AMX_NATIVE_CALL DispatchKeyValue(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_keyvalue(AMX *amx, cell *params) { int idx = params[1]; - if (!is_ent_valid(idx)) { - EngineError(amx, "Invalid Entity %d", idx); - return 0; - } + CHECK_ENTITY(idx); edict_t *pEntity = INDEXENT2(idx); char *test = INFO_KEY_BUFFER(pEntity); int iLength=0; @@ -202,10 +187,7 @@ static cell AMX_NATIVE_CALL DispatchSpawn(AMX *amx, cell *params) { int iEnt = params[1]; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -224,10 +206,7 @@ static cell AMX_NATIVE_CALL entity_get_float(AMX *amx, cell *params) int idx = params[2]; REAL fVal = 0; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -358,10 +337,7 @@ static cell AMX_NATIVE_CALL entity_set_float(AMX *amx, cell *params) int idx = params[2]; REAL fVal = amx_ctof(params[3]); - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -492,10 +468,7 @@ static cell AMX_NATIVE_CALL entity_get_int(AMX *amx, cell *params) int idx = params[2]; int iRetValue = 0; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -613,7 +586,7 @@ static cell AMX_NATIVE_CALL entity_get_int(AMX *amx, cell *params) iRetValue = pEnt->v.deadflag; break; default: - EngineError(amx, "Invalid property %d", iEnt); + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid property %d", idx); return 0; break; } @@ -627,10 +600,7 @@ static cell AMX_NATIVE_CALL entity_set_int(AMX *amx, cell *params) int idx = params[2]; int iNewValue = params[3]; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -762,10 +732,7 @@ static cell AMX_NATIVE_CALL entity_get_vector(AMX *amx, cell *params) cell *vRet = MF_GetAmxAddr(amx, params[3]); Vector vRetValue = Vector(0, 0, 0); - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -858,10 +825,7 @@ static cell AMX_NATIVE_CALL entity_set_vector(AMX *amx, cell *params) int idx = params[2]; cell *vAmx = MF_GetAmxAddr(amx, params[3]); - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); REAL fX = amx_ctof(vAmx[0]); REAL fY = amx_ctof(vAmx[1]); @@ -955,10 +919,7 @@ static cell AMX_NATIVE_CALL entity_get_string(AMX *amx, cell *params) int iszString = 0; const char *szRet = NULL; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -1020,10 +981,7 @@ static cell AMX_NATIVE_CALL entity_set_string(AMX *amx, cell *params) int iLen; int iszString = AmxStringToEngine(amx, params[3], iLen); - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -1082,10 +1040,7 @@ static cell AMX_NATIVE_CALL entity_get_edict(AMX *amx, cell *params) int idx = params[2]; edict_t *pRet; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -1141,10 +1096,8 @@ static cell AMX_NATIVE_CALL entity_set_edict(AMX *amx, cell *params) int idx = params[2]; int iSetEnt = params[3]; - if (!is_ent_valid(iEnt) || !is_ent_valid(iSetEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); + CHECK_ENTITY(iSetEnt); edict_t *pEnt = INDEXENT2(iEnt); edict_t *pSetEnt = INDEXENT2(iSetEnt); @@ -1198,10 +1151,7 @@ static cell AMX_NATIVE_CALL entity_get_byte(AMX *amx, cell *params) int idx = params[2]; int iRetValue = 0; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -1239,10 +1189,7 @@ static cell AMX_NATIVE_CALL entity_set_byte(AMX *amx, cell *params) int idx = params[2]; int iNewValue = params[3]; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); if(iNewValue > 255) iNewValue = 255; @@ -1283,10 +1230,7 @@ static cell AMX_NATIVE_CALL entity_set_origin(AMX *amx, cell *params) { int iEnt = params[1]; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); cell *vVector = MF_GetAmxAddr(amx, params[2]); @@ -1305,10 +1249,7 @@ static cell AMX_NATIVE_CALL entity_set_model(AMX *amx, cell *params) { int iEnt = params[1]; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); int iLen; @@ -1327,10 +1268,7 @@ static cell AMX_NATIVE_CALL entity_set_size(AMX *amx, cell *params) { int iEnt = params[1]; - if (!is_ent_valid(iEnt)) { - EngineError(amx, "Invalid Entity %d", iEnt); - return 0; - } + CHECK_ENTITY(iEnt); edict_t *pEnt = INDEXENT2(iEnt); @@ -1411,10 +1349,7 @@ static cell AMX_NATIVE_CALL find_sphere_class(AMX *amx, cell *params) // find_sp vec3_t vecOrigin; if (params[1] > 0) { - if (!is_ent_valid(params[1])) { - EngineError(amx, "Invalid Entity %d", params[1]); - return 0; - } + CHECK_ENTITY(params[1]); edict_t* pEntity = INDEXENT2(params[1]); vecOrigin = pEntity->v.origin; @@ -1522,10 +1457,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. - if (!is_ent_valid(oEnt)) { - EngineError(amx, "Invalid Entity"); - return 0; - } + CHECK_ENTITY(oEnt); edict_t *pEnt = INDEXENT2(iEnt); edict_t *entOwner = INDEXENT2(oEnt); @@ -1560,10 +1492,7 @@ static cell AMX_NATIVE_CALL get_grenade_id(AMX *amx, cell *params) /* 4 param * int index = params[1]; char* szModel; - if (!is_ent_valid(index)) { - EngineError(amx, "Invalid Entity %d", index); - return 0; - } + CHECK_ENTITY(index); edict_t* pentFind = INDEXENT2(params[4]); edict_t* pentOwner = INDEXENT2(index); diff --git a/dlls/engine/messages.cpp b/dlls/engine/messages.cpp index e7047bea..19603666 100755 --- a/dlls/engine/messages.cpp +++ b/dlls/engine/messages.cpp @@ -2,7 +2,6 @@ CVector Msg; CVector msgHooks[256]; -//int msgHooks[256] = {0}; int msgBlocks[256] = {0}; int msgDest; int msgType;