Fix some natives relying on a known engine bug related to last player's edict being invalid

This commit is contained in:
Arkshine 2015-10-06 16:45:35 +02:00
parent fd0f6cc429
commit 9980b7ac62
10 changed files with 13 additions and 12 deletions

View File

@ -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);

View File

@ -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
{

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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<int>(params[1]);
edict_t *e = INDEXENT(idx);
edict_t *e = INDEXENT2(idx);
if (FNullEnt(e))
return 0;

View File

@ -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)
{