DHooks: Allow setting CBaseEntity* param to NULL #1751 (#1754)

* DHooks: Allow setting CBaseEntity* param to NULL #1751

The param had to be a valid entity and wasn't allowed to be set to NULL. Behave similar to SetReturn which maps INVALID_ENT_REFERENCE (or -1) to NULL.

* Update include documentation
This commit is contained in:
peace-maker 2022-04-20 15:32:37 +02:00 committed by GitHub
parent a7cb35c2af
commit 39d604ae6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View File

@ -700,14 +700,21 @@ cell_t Native_SetParam(IPluginContext *pContext, const cell_t *params)
break;
case HookParamType_CBaseEntity:
{
CBaseEntity *pEnt = gamehelpers->ReferenceToEntity(params[2]);
if(!pEnt)
if(params[2] == -1)
{
return pContext->ThrowNativeError("Invalid entity index passed for param value");
*(CBaseEntity **)addr = nullptr;
}
else
{
CBaseEntity *pEnt = gamehelpers->ReferenceToEntity(params[2]);
*(CBaseEntity **)addr = pEnt;
if(!pEnt)
{
return pContext->ThrowNativeError("Invalid entity index passed for param value");
}
*(CBaseEntity **)addr = pEnt;
}
break;
}
case HookParamType_Edict:

View File

@ -273,6 +273,8 @@ methodmap DHookParam < Handle
// Set the value of a parameter.
// Use only for: int, entity, edict, bool or float parameter types.
//
// An entity parameter type can be set to NULL using INVALID_ENT_REFERENCE (-1).
//
// The changes are only applied when MRES_ChangedHandled or MRES_ChangedOverride
// is returned in the callback.
//
@ -390,6 +392,8 @@ methodmap DHookReturn < Handle
// Retrieves or sets the return value.
// Use only for: int, entity, edict, bool or float return types.
//
// An entity return type can be set to NULL using INVALID_ENT_REFERENCE (-1).
//
// The return value is only readable in a post hook.
// The value is only applied when MRES_Override or MRES_Supercede is returned
// in the callback.
@ -781,7 +785,7 @@ native int DHookRaw(Handle setup, bool post, Address addr, DHookRemovalCB remova
native bool DHookRemoveHookID(int hookid);
/**
* Get param value (Use only for: int, entity, bool or float param types)
* Get param value (Use only for: int, entity, edict, bool or float param types)
*
* @param hParams Handle to params structure
* @param num Param number to get. (Example if the function has 2 params and you need the value of the first
@ -818,7 +822,9 @@ native void DHookGetParamVector(Handle hParams, int num, float vec[3]);
native void DHookGetParamString(Handle hParams, int num, char[] buffer, int size);
/**
* Set param value (Use only for: int, entity, bool or float param types)
* Set param value (Use only for: int, entity, edict, bool or float param types)
*
* An entity param type can be set to NULL using INVALID_ENT_REFERENCE (-1).
*
* @param hParams Handle to params structure
* @param num Param number to set (Example if the function has 2 params and you need to set the value of the
@ -887,6 +893,8 @@ native void DHookGetReturnString(Handle hReturn, char[] buffer, int size);
/**
* Set return value (Use only for: int, entity, bool or float return types)
*
* An entity return type can be set to NULL using INVALID_ENT_REFERENCE (-1).
*
* @param hReturn Handle to return structure
* @param value Value to set return as
*