From 9980b7ac62a41f2efe9b1a932b0beed5a19c0367 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Tue, 6 Oct 2015 16:45:35 +0200 Subject: [PATCH] Fix some natives relying on a known engine bug related to last player's edict being invalid --- amxmodx/amxmodx.cpp | 2 +- amxmodx/amxmodx.h | 1 + amxmodx/messages.cpp | 4 ++-- modules/dod/dodfun/NPD.cpp | 2 +- modules/dod/dodfun/usermsg.cpp | 2 +- modules/dod/dodx/NBase.cpp | 2 +- modules/fakemeta/fm_tr.cpp | 2 +- modules/fakemeta/fm_tr2.cpp | 2 +- modules/fakemeta/pev.cpp | 4 ++-- modules/tfcx/NBase.cpp | 4 ++-- 10 files changed, 13 insertions(+), 12 deletions(-) diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 64fec1ef..70def496 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -83,7 +83,7 @@ static cell AMX_NATIVE_CALL emit_sound(AMX *amx, cell *params) /* 7 param */ EMIT_SOUND_DYN2(pPlayer->pEdict, channel, szSample, vol, att, flags, pitch); } } else { - edict_t* pEdict = INDEXENT(params[1]); + edict_t* pEdict = GETEDICT(params[1]); if (!FNullEnt(pEdict)) EMIT_SOUND_DYN2(pEdict, channel, szSample, vol, att, flags, pitch); diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index c07d2367..1ecafcf5 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -145,6 +145,7 @@ void UTIL_TrimRight(char *buffer); #define GET_PLAYER_POINTER(e) (&g_players[ENTINDEX(e)]) //#define GET_PLAYER_POINTER(e) (&g_players[(((int)e-g_edict_point)/sizeof(edict_t))]) #define GET_PLAYER_POINTER_I(i) (&g_players[i]) +#define GETEDICT(n) ((n >= 1 && n <= gpGlobals->maxClients) ? GET_PLAYER_POINTER_I(n)->pEdict : INDEXENT(n)) struct WeaponsVault { diff --git a/amxmodx/messages.cpp b/amxmodx/messages.cpp index ff8861c2..7e105e38 100755 --- a/amxmodx/messages.cpp +++ b/amxmodx/messages.cpp @@ -423,7 +423,7 @@ static cell _message_begin(AMX *amx, cell *params, bool useFloat) /* 4 param */ return 0; } - MESSAGE_BEGIN(params[1], params[2], NULL, INDEXENT(params[4])); + MESSAGE_BEGIN(params[1], params[2], NULL, GETEDICT(params[4])); break; } @@ -771,7 +771,7 @@ static cell _emessage_begin(AMX *amx, cell *params, bool useFloat) return 0; } - g_pEngTable->pfnMessageBegin(params[1], params[2], NULL, INDEXENT(params[4])); + g_pEngTable->pfnMessageBegin(params[1], params[2], NULL, GETEDICT(params[4])); break; } diff --git a/modules/dod/dodfun/NPD.cpp b/modules/dod/dodfun/NPD.cpp index 4af5eda2..1d671756 100644 --- a/modules/dod/dodfun/NPD.cpp +++ b/modules/dod/dodfun/NPD.cpp @@ -662,7 +662,7 @@ static cell AMX_NATIVE_CALL objectives_reinit(AMX *amx, cell *params){ // index MF_LogError(amx, AMX_ERR_NATIVE, "Index out of range (%d)", player); return 0; } - mObjects.InitObj( player == 0 ? MSG_ALL:MSG_ONE, player == 0 ? NULL:INDEXENT(player) ); + mObjects.InitObj( player == 0 ? MSG_ALL:MSG_ONE, player == 0 ? NULL: GETEDICT(player) ); return 1; } diff --git a/modules/dod/dodfun/usermsg.cpp b/modules/dod/dodfun/usermsg.cpp index ca592fe8..ba648dd7 100644 --- a/modules/dod/dodfun/usermsg.cpp +++ b/modules/dod/dodfun/usermsg.cpp @@ -44,7 +44,7 @@ void Client_InitObj(void* mValue){ mObjects.Clear(); break; case 1: - mObjects.obj[num].pEdict = INDEXENT(*(int*)mValue); + mObjects.obj[num].pEdict = GETEDICT(*(int*)mValue); break; case 2: mObjects.obj[num].index = *(int*)mValue; diff --git a/modules/dod/dodx/NBase.cpp b/modules/dod/dodx/NBase.cpp index 66b51d82..3e9adfd5 100644 --- a/modules/dod/dodx/NBase.cpp +++ b/modules/dod/dodx/NBase.cpp @@ -577,7 +577,7 @@ static cell AMX_NATIVE_CALL dod_weaponlist(AMX *amx, cell *params) // player return 0; } - MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "WeaponList", NULL), NULL, INDEXENT(id)); + MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "WeaponList", NULL), NULL, pPlayer->pEdict); WRITE_BYTE(weaponlist[wpnID].grp); WRITE_BYTE(totalrds); WRITE_BYTE(-1); diff --git a/modules/fakemeta/fm_tr.cpp b/modules/fakemeta/fm_tr.cpp index bf0c6c34..00f4bef8 100644 --- a/modules/fakemeta/fm_tr.cpp +++ b/modules/fakemeta/fm_tr.cpp @@ -85,7 +85,7 @@ static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params) } case TR_pHit: { - e = INDEXENT(*ptr); + e = INDEXENT2(*ptr); if (!e || FNullEnt(e)) return 0; //TODO: return error gfm_tr->pHit = e; diff --git a/modules/fakemeta/fm_tr2.cpp b/modules/fakemeta/fm_tr2.cpp index 754ab261..e04d3759 100644 --- a/modules/fakemeta/fm_tr2.cpp +++ b/modules/fakemeta/fm_tr2.cpp @@ -98,7 +98,7 @@ static cell AMX_NATIVE_CALL set_tr2(AMX *amx, cell *params) } case TR_pHit: { - edict_t *e = INDEXENT(*ptr); + edict_t *e = INDEXENT2(*ptr); if (!e || FNullEnt(e)) return 0; //TODO: return error tr->pHit = e; diff --git a/modules/fakemeta/pev.cpp b/modules/fakemeta/pev.cpp index 97579aa4..8c02c568 100644 --- a/modules/fakemeta/pev.cpp +++ b/modules/fakemeta/pev.cpp @@ -382,7 +382,7 @@ static cell AMX_NATIVE_CALL amx_set_pev(AMX *amx, cell *params) *(string_t *)EDICT_OFFS(v, offs) = value; } else if ( (iSwitch > pev_edict_start && iSwitch < pev_edict_end) || (iSwitch > pev_edict2_start && iSwitch < pev_absolute_end) ) { - edict_t *e = INDEXENT((int)*blah); + edict_t *e = INDEXENT2((int)*blah); *(edict_t **)EDICT_OFFS(v, offs) = e; } else if (iSwitch > pev_vecarray_start && iSwitch < pev_vecarray_end) { vec3_t vec; @@ -455,7 +455,7 @@ static cell AMX_NATIVE_CALL amx_pev_valid(AMX *amx, cell *params) { int idx = static_cast(params[1]); - edict_t *e = INDEXENT(idx); + edict_t *e = INDEXENT2(idx); if (FNullEnt(e)) return 0; diff --git a/modules/tfcx/NBase.cpp b/modules/tfcx/NBase.cpp index bc7d2251..d7e085b9 100644 --- a/modules/tfcx/NBase.cpp +++ b/modules/tfcx/NBase.cpp @@ -31,7 +31,7 @@ static cell AMX_NATIVE_CALL TFC_SetModel(AMX *amx, cell *params) { char *szModel = MF_GetAmxString(amx, params[2],0, &iLen); // Get Player's edict pointer - edict_t* pPlayer = INDEXENT(iIndex); + edict_t* pPlayer = MF_GetPlayerEdict(iIndex); // Set key on client, replacement_model is for the model we want. KeyValueData pkvd; @@ -62,7 +62,7 @@ static cell AMX_NATIVE_CALL TFC_ClearModel(AMX *amx, cell *params) { CHECK_PLAYER(iIndex) - edict_t* pPlayer = INDEXENT(iIndex); + edict_t* pPlayer = MF_GetPlayerEdict(iIndex); if (pPlayer->pvPrivateData == NULL) {