From 39d604ae6ccdb8b1fed477216643ff96615a39bb Mon Sep 17 00:00:00 2001 From: peace-maker Date: Wed, 20 Apr 2022 15:32:37 +0200 Subject: [PATCH] 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 --- extensions/dhooks/natives.cpp | 17 ++++++++++++----- plugins/include/dhooks.inc | 12 ++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/extensions/dhooks/natives.cpp b/extensions/dhooks/natives.cpp index 72abe9e7..db1384f8 100644 --- a/extensions/dhooks/natives.cpp +++ b/extensions/dhooks/natives.cpp @@ -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: diff --git a/plugins/include/dhooks.inc b/plugins/include/dhooks.inc index a2611dc4..76ff8c4d 100644 --- a/plugins/include/dhooks.inc +++ b/plugins/include/dhooks.inc @@ -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 *