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

@ -699,6 +699,12 @@ cell_t Native_SetParam(IPluginContext *pContext, const cell_t *params)
*(bool *)addr = (params[3] ? true : false); *(bool *)addr = (params[3] ? true : false);
break; break;
case HookParamType_CBaseEntity: case HookParamType_CBaseEntity:
{
if(params[2] == -1)
{
*(CBaseEntity **)addr = nullptr;
}
else
{ {
CBaseEntity *pEnt = gamehelpers->ReferenceToEntity(params[2]); CBaseEntity *pEnt = gamehelpers->ReferenceToEntity(params[2]);
@ -708,6 +714,7 @@ cell_t Native_SetParam(IPluginContext *pContext, const cell_t *params)
} }
*(CBaseEntity **)addr = pEnt; *(CBaseEntity **)addr = pEnt;
}
break; break;
} }
case HookParamType_Edict: case HookParamType_Edict:

View File

@ -273,6 +273,8 @@ methodmap DHookParam < Handle
// Set the value of a parameter. // Set the value of a parameter.
// Use only for: int, entity, edict, bool or float parameter types. // 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 // The changes are only applied when MRES_ChangedHandled or MRES_ChangedOverride
// is returned in the callback. // is returned in the callback.
// //
@ -390,6 +392,8 @@ methodmap DHookReturn < Handle
// Retrieves or sets the return value. // Retrieves or sets the return value.
// Use only for: int, entity, edict, bool or float return types. // 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 return value is only readable in a post hook.
// The value is only applied when MRES_Override or MRES_Supercede is returned // The value is only applied when MRES_Override or MRES_Supercede is returned
// in the callback. // in the callback.
@ -781,7 +785,7 @@ native int DHookRaw(Handle setup, bool post, Address addr, DHookRemovalCB remova
native bool DHookRemoveHookID(int hookid); 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 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 * @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); 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 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 * @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) * 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 hReturn Handle to return structure
* @param value Value to set return as * @param value Value to set return as
* *