From 2d008c1c58cbc8ca6ed9750ecfad74d3701eea4e Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:34:54 +0700 Subject: [PATCH 01/10] Update natives.cpp --- extensions/dhooks/natives.cpp | 221 +++++++++++++++++++++++++++------- 1 file changed, 176 insertions(+), 45 deletions(-) diff --git a/extensions/dhooks/natives.cpp b/extensions/dhooks/natives.cpp index f228fcf306..b3caf95317 100644 --- a/extensions/dhooks/natives.cpp +++ b/extensions/dhooks/natives.cpp @@ -1096,20 +1096,46 @@ cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param return 0; } - if(params[2] <= 0 || params[2] > (int)paramStruct->dg->params.size()) + void *addr = NULL; + + if(params[2] != 0) { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); - } + if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size()) + { + return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); + } - int index = params[2] - 1; + int index = params[2] - 1; - if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) - { - return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) + { + return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + } + + size_t offset = GetParamOffset(paramStruct, index); + addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); } + else + { + HookSetup *setup; - size_t offset = GetParamOffset(paramStruct, index); - void *addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); + if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) + { + return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); + } + + if(paramStruct->dg->thisType != ThisPointer_Address) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); + } + + if(setup->callConv != CallConv_THISCALL) + { + return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + } + + addr = g_SHPtr->GetIfacePtr(); + } switch((ObjectValueType)params[4]) { @@ -1167,20 +1193,46 @@ cell_t Native_SetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param return 0; } - if(params[2] <= 0 || params[2] > (int)paramStruct->dg->params.size()) + void *addr = NULL; + + if(params[2] != 0) { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); - } + if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size()) + { + return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); + } - int index = params[2] - 1; + int index = params[2] - 1; - if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) + if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) + { + return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + } + + size_t offset = GetParamOffset(paramStruct, index); + addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); + } + else { - return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + HookSetup *setup; + + if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) + { + return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); + } + + if(paramStruct->dg->thisType != ThisPointer_Address) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); + } + + if(setup->callConv != CallConv_THISCALL) + { + return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + } + + addr = g_SHPtr->GetIfacePtr(); } - - size_t offset = GetParamOffset(paramStruct, index); - void *addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); switch((ObjectValueType)params[4]) { @@ -1252,20 +1304,46 @@ cell_t Native_GetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t return 0; } - if(params[2] <= 0 || params[2] > (int)paramStruct->dg->params.size()) + void *addr = NULL; + + if(params[2] != 0) { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); - } + if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size()) + { + return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); + } - int index = params[2] - 1; + int index = params[2] - 1; - if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) - { - return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) + { + return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + } + + size_t offset = GetParamOffset(paramStruct, index); + addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); } + else + { + HookSetup *setup; - size_t offset = GetParamOffset(paramStruct, index); - void *addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); + if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) + { + return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); + } + + if(paramStruct->dg->thisType != ThisPointer_Address) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); + } + + if(setup->callConv != CallConv_THISCALL) + { + return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + } + + addr = g_SHPtr->GetIfacePtr(); + } cell_t *buffer; pContext->LocalToPhysAddr(params[5], &buffer); @@ -1305,21 +1383,47 @@ cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t { return 0; } + + void *addr = NULL; - if(params[2] <= 0 || params[2] > (int)paramStruct->dg->params.size()) + if(params[2] != 0) { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); - } + if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size()) + { + return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); + } - int index = params[2] - 1; + int index = params[2] - 1; - if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) - { - return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) + { + return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + } + + size_t offset = GetParamOffset(paramStruct, index); + addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); } + else + { + HookSetup *setup; - size_t offset = GetParamOffset(paramStruct, index); - void *addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); + if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) + { + return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); + } + + if(paramStruct->dg->thisType != ThisPointer_Address) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); + } + + if(setup->callConv != CallConv_THISCALL) + { + return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + } + + addr = g_SHPtr->GetIfacePtr(); + } cell_t *buffer; pContext->LocalToPhysAddr(params[5], &buffer); @@ -1346,6 +1450,7 @@ cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t vec->z = sp_ctof(buffer[2]); return 1; } + return pContext->ThrowNativeError("Invalid Object value type (not a type of vector)"); } @@ -1359,20 +1464,46 @@ cell_t Native_GetParamObjectPtrString(IPluginContext *pContext, const cell_t *pa return 0; } - if(params[2] <= 0 || params[2] > (int)paramStruct->dg->params.size()) + void *addr = NULL; + + if(params[2] != 0) { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); - } + if(params[2] <= 0 || params[2] > (int)paramStruct->dg->params.size()) + { + return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); + } - int index = params[2] - 1; + int index = params[2] - 1; - if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) - { - return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) + { + return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + } + + size_t offset = GetParamOffset(paramStruct, index); + addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); } + else + { + HookSetup *setup; - size_t offset = GetParamOffset(paramStruct, index); - void *addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); + if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) + { + return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); + } + + if(paramStruct->dg->thisType != ThisPointer_Address) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); + } + + if(setup->callConv != CallConv_THISCALL) + { + return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + } + + addr = g_SHPtr->GetIfacePtr(); + } switch((ObjectValueType)params[4]) { From 9c07ebe6666a1ac53ec62e7f359c9dbddebee862 Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:54:09 +0700 Subject: [PATCH 02/10] Update dhooks.inc --- plugins/include/dhooks.inc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/include/dhooks.inc b/plugins/include/dhooks.inc index 99f17e7e8f..fa36aa0102 100644 --- a/plugins/include/dhooks.inc +++ b/plugins/include/dhooks.inc @@ -310,7 +310,7 @@ methodmap DHookParam < Handle // Gets an object's variable value. // - // @param num Parameter number to get, starting at 1. + // @param num Parameter number to get, 0 for param "this", other parameters start from 1 // @param offset Byte offset within the object to the var to get. // @param type Type of var it is. // @@ -320,7 +320,7 @@ methodmap DHookParam < Handle // Gets an object's vector variable value. // - // @param num Parameter number to get, starting at 1. + // @param num Parameter number to get, 0 for param "this", other parameters start from 1. // @param offset Byte offset within the object to the var to get. // @param type Type of var it is. // @param vec Buffer to store the result vector. @@ -330,7 +330,7 @@ methodmap DHookParam < Handle // Gets an object's string variable value. // - // @param num Parameter number to get, starting at 1. + // @param num Parameter number to get, 0 for param "this", other parameters start from 1. // @param offset Byte offset within the object to the var to get. // @param type Type of var it is. // @param buffer Buffer to store the result string. @@ -344,7 +344,7 @@ methodmap DHookParam < Handle // The changes are only applied when MRES_ChangedHandled or MRES_ChangedOverride // is returned in the callback. // - // @param num Parameter number to set, starting at 1. + // @param num Parameter number to set, 0 for param "this", other parameters start from 1. // @param offset Byte offset within the object to the var to set. // @param type Type of var it is. // @param value The value to set the var to. @@ -357,7 +357,7 @@ methodmap DHookParam < Handle // The changes are only applied when MRES_ChangedHandled or MRES_ChangedOverride // is returned in the callback. // - // @param num Parameter number to set, starting at 1. + // @param num Parameter number to set, 0 for param "this", other parameters start from 1. // @param offset Byte offset within the object to the var to set. // @param type Type of var it is. // @param vec The value to set the vector var to. @@ -928,7 +928,7 @@ native void DHookSetReturnString(Handle hReturn, char[] value); * Gets an objects variable value * * @param hParams Handle to params structure - * @param num Param number to get. + * @param num Param number to get, 0 for param "this". * @param offset Offset within the object to the var to get. * @param type Type of var it is * @@ -941,7 +941,7 @@ native any DHookGetParamObjectPtrVar(Handle hParams, int num, int offset, Object * Sets an objects variable value * * @param hParams Handle to params structure - * @param num Param number to set. + * @param num Param number to set, 0 for param "this". * @param offset Offset within the object to the var to set. * @param type Type of var it is * @param value The value to set the var to. @@ -954,7 +954,7 @@ native void DHookSetParamObjectPtrVar(Handle hParams, int num, int offset, Objec * Gets an objects vector variable value * * @param hParams Handle to params structure - * @param num Param number to get. + * @param num Param number to get, 0 for param "this". * @param offset Offset within the object to the var to get. * @param type Type of var it is * @param buffer Buffer to store the result vector @@ -967,7 +967,7 @@ native void DHookGetParamObjectPtrVarVector(Handle hParams, int num, int offset, * Sets an objects vector variable value * * @param hParams Handle to params structure - * @param num Param number to set. + * @param num Param number to set, 0 for param "this". * @param offset Offset within the object to the var to set. * @param type Type of var it is * @param value The value to set the vector var to. @@ -980,7 +980,7 @@ native void DHookSetParamObjectPtrVarVector(Handle hParams, int num, int offset, * Gets an objects string variable value * * @param hParams Handle to params structure - * @param num Param number to get. + * @param num Param number to get, 0 for param "this". * @param offset Offset within the object to the var to get. * @param type Type of var it is * @param buffer Buffer to store the result vector From 358eef1e5174809e8ab1e5f5e9c4957f023a2bad Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:01:55 +0700 Subject: [PATCH 03/10] Non-working code commented out --- extensions/dhooks/natives.cpp | 65 ++++++++++++++++------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/extensions/dhooks/natives.cpp b/extensions/dhooks/natives.cpp index b3caf95317..9195602735 100644 --- a/extensions/dhooks/natives.cpp +++ b/extensions/dhooks/natives.cpp @@ -1117,21 +1117,20 @@ cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param } else { - HookSetup *setup; - + /*HookSetup* setup; if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) { return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); } - if(paramStruct->dg->thisType != ThisPointer_Address) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } - if(setup->callConv != CallConv_THISCALL) { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + }*/ + + if(paramStruct->dg->thisType != ThisPointer_Address) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } addr = g_SHPtr->GetIfacePtr(); @@ -1214,21 +1213,20 @@ cell_t Native_SetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param } else { - HookSetup *setup; - + /*HookSetup* setup; if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) { return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); } - if(paramStruct->dg->thisType != ThisPointer_Address) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } - if(setup->callConv != CallConv_THISCALL) { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + }*/ + + if(paramStruct->dg->thisType != ThisPointer_Address) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } addr = g_SHPtr->GetIfacePtr(); @@ -1325,21 +1323,20 @@ cell_t Native_GetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t } else { - HookSetup *setup; - + /*HookSetup* setup; if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) { return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); } - if(paramStruct->dg->thisType != ThisPointer_Address) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } - if(setup->callConv != CallConv_THISCALL) { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + }*/ + + if(paramStruct->dg->thisType != ThisPointer_Address) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } addr = g_SHPtr->GetIfacePtr(); @@ -1405,21 +1402,20 @@ cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t } else { - HookSetup *setup; - + /*HookSetup* setup; if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) { return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); } - if(paramStruct->dg->thisType != ThisPointer_Address) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } - if(setup->callConv != CallConv_THISCALL) { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + }*/ + + if(paramStruct->dg->thisType != ThisPointer_Address) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } addr = g_SHPtr->GetIfacePtr(); @@ -1485,21 +1481,20 @@ cell_t Native_GetParamObjectPtrString(IPluginContext *pContext, const cell_t *pa } else { - HookSetup *setup; - + /*HookSetup* setup; if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) { return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); } - if(paramStruct->dg->thisType != ThisPointer_Address) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } - if(setup->callConv != CallConv_THISCALL) { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + }*/ + + if(paramStruct->dg->thisType != ThisPointer_Address) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } addr = g_SHPtr->GetIfacePtr(); From 945499bd02ddc0533dbd12415cf8c1bca380d341 Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:34:27 +0700 Subject: [PATCH 04/10] Update natives.cpp --- extensions/dhooks/natives.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/dhooks/natives.cpp b/extensions/dhooks/natives.cpp index 9195602735..1ccf9dbde0 100644 --- a/extensions/dhooks/natives.cpp +++ b/extensions/dhooks/natives.cpp @@ -1446,7 +1446,6 @@ cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t vec->z = sp_ctof(buffer[2]); return 1; } - return pContext->ThrowNativeError("Invalid Object value type (not a type of vector)"); } From 88024a71fc7c4ffa87534ffc26a0abab2aa1da3c Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:06:34 +0700 Subject: [PATCH 05/10] Allow working with the parameter "this", which is a class CBaseEntity --- extensions/dhooks/natives.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extensions/dhooks/natives.cpp b/extensions/dhooks/natives.cpp index 1ccf9dbde0..8c3efdf5dd 100644 --- a/extensions/dhooks/natives.cpp +++ b/extensions/dhooks/natives.cpp @@ -1128,7 +1128,7 @@ cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); }*/ - if(paramStruct->dg->thisType != ThisPointer_Address) + if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } @@ -1224,7 +1224,7 @@ cell_t Native_SetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); }*/ - if(paramStruct->dg->thisType != ThisPointer_Address) + if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } @@ -1334,7 +1334,7 @@ cell_t Native_GetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); }*/ - if(paramStruct->dg->thisType != ThisPointer_Address) + if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } @@ -1413,7 +1413,7 @@ cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); }*/ - if(paramStruct->dg->thisType != ThisPointer_Address) + if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } @@ -1491,7 +1491,7 @@ cell_t Native_GetParamObjectPtrString(IPluginContext *pContext, const cell_t *pa return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); }*/ - if(paramStruct->dg->thisType != ThisPointer_Address) + if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } From 6eb540a76194caf5f74175dae2060084a9c4c578 Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Tue, 31 Dec 2024 00:51:23 +0700 Subject: [PATCH 06/10] Enable check for calling convention --- extensions/dhooks/dynhooks_sourcepawn.cpp | 1 + extensions/dhooks/natives.cpp | 50 +++++------------------ extensions/dhooks/vhook.h | 1 + 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/extensions/dhooks/dynhooks_sourcepawn.cpp b/extensions/dhooks/dynhooks_sourcepawn.cpp index 927f3d66c8..6ad744d163 100644 --- a/extensions/dhooks/dynhooks_sourcepawn.cpp +++ b/extensions/dhooks/dynhooks_sourcepawn.cpp @@ -532,6 +532,7 @@ CDynamicHooksSourcePawn::CDynamicHooksSourcePawn(HookSetup *setup, CHook *pDetou this->hookType = setup->hookType; this->m_pDetour = pDetour; this->callConv = setup->callConv; + this->thisFuncCallConv = setup->callConv; } HookReturnStruct *CDynamicHooksSourcePawn::GetReturnStruct() diff --git a/extensions/dhooks/natives.cpp b/extensions/dhooks/natives.cpp index 8c3efdf5dd..48a2112ce1 100644 --- a/extensions/dhooks/natives.cpp +++ b/extensions/dhooks/natives.cpp @@ -1117,16 +1117,10 @@ cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param } else { - /*HookSetup* setup; - if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) - { - return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); - } - - if(setup->callConv != CallConv_THISCALL) + if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL) { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - }*/ + } if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) { @@ -1213,16 +1207,10 @@ cell_t Native_SetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param } else { - /*HookSetup* setup; - if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) - { - return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); - } - - if(setup->callConv != CallConv_THISCALL) + if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL) { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - }*/ + } if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) { @@ -1323,16 +1311,10 @@ cell_t Native_GetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t } else { - /*HookSetup* setup; - if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) - { - return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); - } - - if(setup->callConv != CallConv_THISCALL) + if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL) { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - }*/ + } if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) { @@ -1402,16 +1384,10 @@ cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t } else { - /*HookSetup* setup; - if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) - { - return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); - } - - if(setup->callConv != CallConv_THISCALL) + if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL) { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - }*/ + } if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) { @@ -1480,16 +1456,10 @@ cell_t Native_GetParamObjectPtrString(IPluginContext *pContext, const cell_t *pa } else { - /*HookSetup* setup; - if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) - { - return pContext->ThrowNativeError("Cannot determine calling convention type, parameter 'this' is only available in member functions"); - } - - if(setup->callConv != CallConv_THISCALL) + if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL) { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - }*/ + } if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) { diff --git a/extensions/dhooks/vhook.h b/extensions/dhooks/vhook.h index b58f9c4ff1..92dd279e80 100644 --- a/extensions/dhooks/vhook.h +++ b/extensions/dhooks/vhook.h @@ -162,6 +162,7 @@ class DHooksInfo int entity; ThisPointerType thisType; HookType hookType; + CallingConvention thisFuncCallConv; }; class DHooksCallback : public SourceHook::ISHDelegate, public DHooksInfo From 5da5325a10bc9dfef1e6a8b7260bef32d8c68bff Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Tue, 31 Dec 2024 01:20:50 +0700 Subject: [PATCH 07/10] Allow working with the parameter 'this', which is the class gamerules --- extensions/dhooks/natives.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/dhooks/natives.cpp b/extensions/dhooks/natives.cpp index 48a2112ce1..20237fa0e6 100644 --- a/extensions/dhooks/natives.cpp +++ b/extensions/dhooks/natives.cpp @@ -1121,8 +1121,8 @@ cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param { return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); } - - if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) + + if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules)) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } @@ -1212,7 +1212,7 @@ cell_t Native_SetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); } - if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) + if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules)) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } @@ -1316,7 +1316,7 @@ cell_t Native_GetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); } - if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) + if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules)) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } @@ -1389,7 +1389,7 @@ cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); } - if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) + if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules)) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } @@ -1461,7 +1461,7 @@ cell_t Native_GetParamObjectPtrString(IPluginContext *pContext, const cell_t *pa return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); } - if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity) + if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules)) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); } From f9d175c75e277cfc0fa4d14d0a43a2db13901a29 Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Sat, 25 Oct 2025 02:07:47 +0700 Subject: [PATCH 08/10] Remove duplicate code, move it to a separate function --- extensions/dhooks/natives.cpp | 198 +++++++--------------------------- 1 file changed, 39 insertions(+), 159 deletions(-) diff --git a/extensions/dhooks/natives.cpp b/extensions/dhooks/natives.cpp index 20237fa0e6..555f1ded26 100644 --- a/extensions/dhooks/natives.cpp +++ b/extensions/dhooks/natives.cpp @@ -1086,50 +1086,58 @@ cell_t Native_RemoveEntityListener(IPluginContext *pContext, const cell_t *param return pContext->ThrowNativeError("Failed to get g_pEntityListener"); } -//native any:DHookGetParamObjectPtrVar(Handle:hParams, num, offset, ObjectValueType:type); -cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *params) +void* GetObjectAddrOrThis(HookParamsStruct* paramStruct, IPluginContext* pContext, const cell_t* params) { - HookParamsStruct *paramStruct; - - if(!GetCallbackArgHandleIfValidOrError(g_HookParamsHandle, g_HookReturnHandle, (void **)¶mStruct, pContext, params[1])) + if (params[2] != 0) { - return 0; - } - - void *addr = NULL; + const auto& paramsVec = paramStruct->dg->params; - if(params[2] != 0) - { - if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size()) + if (params[2] < 0 || params[2] > static_cast(paramsVec.size())) { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); + return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramsVec.size()); } int index = params[2] - 1; + const auto& param = paramsVec.at(index); - if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) + if (param.type != HookParamType_ObjectPtr && param.type != HookParamType_Object) { - return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); + return pContext->ThrowNativeError("Invalid object value type %i", param.type); } size_t offset = GetParamOffset(paramStruct, index); - addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); + return GetObjectAddr(param.type, param.flags, paramStruct->orgParams, offset); } - else + + const auto& dgInfo = paramStruct->dg; + + if (dgInfo->thisFuncCallConv != CallConv_THISCALL) { - if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL) - { - return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - } - - if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules)) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } + return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + } + + if (dgInfo->thisType != ThisPointer_Address + && dgInfo->thisType != ThisPointer_CBaseEntity + && !(dgInfo->thisType == ThisPointer_Ignore && dgInfo->hookType == HookType_GameRules)) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); + } + + return g_SHPtr->GetIfacePtr(); +} - addr = g_SHPtr->GetIfacePtr(); +//native any:DHookGetParamObjectPtrVar(Handle:hParams, num, offset, ObjectValueType:type); +cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *params) +{ + HookParamsStruct *paramStruct; + + if(!GetCallbackArgHandleIfValidOrError(g_HookParamsHandle, g_HookReturnHandle, (void **)¶mStruct, pContext, params[1])) + { + return 0; } + void* addr = GetObjectAddrOrThis(paramStruct, pContext, params); + switch((ObjectValueType)params[4]) { case ObjectValueType_Int: @@ -1186,39 +1194,7 @@ cell_t Native_SetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param return 0; } - void *addr = NULL; - - if(params[2] != 0) - { - if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size()) - { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); - } - - int index = params[2] - 1; - - if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) - { - return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); - } - - size_t offset = GetParamOffset(paramStruct, index); - addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); - } - else - { - if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL) - { - return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - } - - if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules)) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } - - addr = g_SHPtr->GetIfacePtr(); - } + void* addr = GetObjectAddrOrThis(paramStruct, pContext, params); switch((ObjectValueType)params[4]) { @@ -1290,39 +1266,7 @@ cell_t Native_GetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t return 0; } - void *addr = NULL; - - if(params[2] != 0) - { - if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size()) - { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); - } - - int index = params[2] - 1; - - if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) - { - return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); - } - - size_t offset = GetParamOffset(paramStruct, index); - addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); - } - else - { - if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL) - { - return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - } - - if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules)) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } - - addr = g_SHPtr->GetIfacePtr(); - } + void* addr = GetObjectAddrOrThis(paramStruct, pContext, params); cell_t *buffer; pContext->LocalToPhysAddr(params[5], &buffer); @@ -1363,39 +1307,7 @@ cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t return 0; } - void *addr = NULL; - - if(params[2] != 0) - { - if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size()) - { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); - } - - int index = params[2] - 1; - - if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) - { - return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); - } - - size_t offset = GetParamOffset(paramStruct, index); - addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); - } - else - { - if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL) - { - return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - } - - if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules)) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } - - addr = g_SHPtr->GetIfacePtr(); - } + void* addr = GetObjectAddrOrThis(paramStruct, pContext, params); cell_t *buffer; pContext->LocalToPhysAddr(params[5], &buffer); @@ -1435,39 +1347,7 @@ cell_t Native_GetParamObjectPtrString(IPluginContext *pContext, const cell_t *pa return 0; } - void *addr = NULL; - - if(params[2] != 0) - { - if(params[2] <= 0 || params[2] > (int)paramStruct->dg->params.size()) - { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size()); - } - - int index = params[2] - 1; - - if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object) - { - return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type); - } - - size_t offset = GetParamOffset(paramStruct, index); - addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset); - } - else - { - if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL) - { - return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - } - - if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules)) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } - - addr = g_SHPtr->GetIfacePtr(); - } + void* addr = GetObjectAddrOrThis(paramStruct, pContext, params); switch((ObjectValueType)params[4]) { From 220cc71c966fd6e0716ea5ec1c869a8ea80ae4d4 Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Sat, 25 Oct 2025 03:02:27 +0700 Subject: [PATCH 09/10] Fixed a compilation error and refactored code. --- extensions/dhooks/natives.cpp | 125 ++++++++++++++++------------------ 1 file changed, 60 insertions(+), 65 deletions(-) diff --git a/extensions/dhooks/natives.cpp b/extensions/dhooks/natives.cpp index 555f1ded26..430ff9730b 100644 --- a/extensions/dhooks/natives.cpp +++ b/extensions/dhooks/natives.cpp @@ -81,6 +81,56 @@ bool GetCallbackArgHandleIfValidOrError(HandleType_t type, HandleType_t otherTyp return true; } +bool GetObjectAddrOrThis(IPluginContext *pContext, const cell_t *params, void *&retAddr) +{ + HookParamsStruct *paramStruct = NULL; + retAddr = NULL; + + if(!GetCallbackArgHandleIfValidOrError(g_HookParamsHandle, g_HookReturnHandle, (void **)¶mStruct, pContext, params[1])) + { + return false; + } + + if(params[2] != 0) + { + const auto ¶msVec = paramStruct->dg->params; + + if(params[2] < 0 || params[2] > static_cast(paramsVec.size())) + { + return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramsVec.size()); + } + + int index = params[2] - 1; + const auto ¶m = paramsVec.at(index); + + if(param.type != HookParamType_ObjectPtr && param.type != HookParamType_Object) + { + return pContext->ThrowNativeError("Invalid object value type %i", param.type); + } + + size_t offset = GetParamOffset(paramStruct, index); + retAddr = GetObjectAddr(param.type, param.flags, paramStruct->orgParams, offset); + return true; + } + + const auto &dgInfo = paramStruct->dg; + + if(dgInfo->thisFuncCallConv != CallConv_THISCALL) + { + return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + } + + if(dgInfo->thisType != ThisPointer_Address + && dgInfo->thisType != ThisPointer_CBaseEntity + && !(dgInfo->thisType == ThisPointer_Ignore && dgInfo->hookType == HookType_GameRules)) + { + return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); + } + + retAddr = g_SHPtr->GetIfacePtr(); + return true; +} + IPluginFunction *GetCallback(IPluginContext *pContext, HookSetup * setup, const cell_t *params, cell_t callback_index) { IPluginFunction *ret = NULL; @@ -1086,58 +1136,15 @@ cell_t Native_RemoveEntityListener(IPluginContext *pContext, const cell_t *param return pContext->ThrowNativeError("Failed to get g_pEntityListener"); } -void* GetObjectAddrOrThis(HookParamsStruct* paramStruct, IPluginContext* pContext, const cell_t* params) -{ - if (params[2] != 0) - { - const auto& paramsVec = paramStruct->dg->params; - - if (params[2] < 0 || params[2] > static_cast(paramsVec.size())) - { - return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramsVec.size()); - } - - int index = params[2] - 1; - const auto& param = paramsVec.at(index); - - if (param.type != HookParamType_ObjectPtr && param.type != HookParamType_Object) - { - return pContext->ThrowNativeError("Invalid object value type %i", param.type); - } - - size_t offset = GetParamOffset(paramStruct, index); - return GetObjectAddr(param.type, param.flags, paramStruct->orgParams, offset); - } - - const auto& dgInfo = paramStruct->dg; - - if (dgInfo->thisFuncCallConv != CallConv_THISCALL) - { - return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); - } - - if (dgInfo->thisType != ThisPointer_Address - && dgInfo->thisType != ThisPointer_CBaseEntity - && !(dgInfo->thisType == ThisPointer_Ignore && dgInfo->hookType == HookType_GameRules)) - { - return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); - } - - return g_SHPtr->GetIfacePtr(); -} - //native any:DHookGetParamObjectPtrVar(Handle:hParams, num, offset, ObjectValueType:type); cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *params) { - HookParamsStruct *paramStruct; - - if(!GetCallbackArgHandleIfValidOrError(g_HookParamsHandle, g_HookReturnHandle, (void **)¶mStruct, pContext, params[1])) + void *addr = NULL; + if(!GetObjectAddrOrThis(pContext, params, addr)) { return 0; } - void* addr = GetObjectAddrOrThis(paramStruct, pContext, params); - switch((ObjectValueType)params[4]) { case ObjectValueType_Int: @@ -1187,15 +1194,12 @@ cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param //native DHookSetParamObjectPtrVar(Handle:hParams, num, offset, ObjectValueType:type, value) cell_t Native_SetParamObjectPtrVar(IPluginContext *pContext, const cell_t *params) { - HookParamsStruct *paramStruct; - - if(!GetCallbackArgHandleIfValidOrError(g_HookParamsHandle, g_HookReturnHandle, (void **)¶mStruct, pContext, params[1])) + void *addr = NULL; + if(!GetObjectAddrOrThis(pContext, params, addr)) { return 0; } - void* addr = GetObjectAddrOrThis(paramStruct, pContext, params); - switch((ObjectValueType)params[4]) { case ObjectValueType_Int: @@ -1259,15 +1263,12 @@ cell_t Native_SetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param //native DHookGetParamObjectPtrVarVector(Handle:hParams, num, offset, ObjectValueType:type, Float:buffer[3]); cell_t Native_GetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t *params) { - HookParamsStruct *paramStruct; - - if(!GetCallbackArgHandleIfValidOrError(g_HookParamsHandle, g_HookReturnHandle, (void **)¶mStruct, pContext, params[1])) + void *addr = NULL; + if(!GetObjectAddrOrThis(pContext, params, addr)) { return 0; } - void* addr = GetObjectAddrOrThis(paramStruct, pContext, params); - cell_t *buffer; pContext->LocalToPhysAddr(params[5], &buffer); @@ -1300,14 +1301,11 @@ cell_t Native_GetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t //native DHookSetParamObjectPtrVarVector(Handle:hParams, num, offset, ObjectValueType:type, Float:value[3]); cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t *params) { - HookParamsStruct *paramStruct; - - if(!GetCallbackArgHandleIfValidOrError(g_HookParamsHandle, g_HookReturnHandle, (void **)¶mStruct, pContext, params[1])) + void *addr = NULL; + if(!GetObjectAddrOrThis(pContext, params, addr)) { return 0; } - - void* addr = GetObjectAddrOrThis(paramStruct, pContext, params); cell_t *buffer; pContext->LocalToPhysAddr(params[5], &buffer); @@ -1340,15 +1338,12 @@ cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t //native DHookGetParamObjectPtrString(Handle:hParams, num, offset, ObjectValueType:type, String:buffer[], size) cell_t Native_GetParamObjectPtrString(IPluginContext *pContext, const cell_t *params) { - HookParamsStruct *paramStruct; - - if(!GetCallbackArgHandleIfValidOrError(g_HookParamsHandle, g_HookReturnHandle, (void **)¶mStruct, pContext, params[1])) + void *addr = NULL; + if (!GetObjectAddrOrThis(pContext, params, addr)) { return 0; } - void* addr = GetObjectAddrOrThis(paramStruct, pContext, params); - switch((ObjectValueType)params[4]) { case ObjectValueType_CharPtr: From 49ba85791509982cde218c71c49b0eafe2ceaee6 Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Wed, 29 Oct 2025 09:02:04 +0700 Subject: [PATCH 10/10] Refine error messages and type handling in GetObjectAddrOrThis --- extensions/dhooks/natives.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/extensions/dhooks/natives.cpp b/extensions/dhooks/natives.cpp index 430ff9730b..82b154ada9 100644 --- a/extensions/dhooks/natives.cpp +++ b/extensions/dhooks/natives.cpp @@ -42,6 +42,8 @@ enum SDKFuncConfSource SDKConf_Address }; +using ParamVector = SourceHook::CVector; + bool GetHandleIfValidOrError(HandleType_t type, void **object, IPluginContext *pContext, cell_t param) { if(param == BAD_HANDLE) @@ -93,7 +95,7 @@ bool GetObjectAddrOrThis(IPluginContext *pContext, const cell_t *params, void *& if(params[2] != 0) { - const auto ¶msVec = paramStruct->dg->params; + const ParamVector ¶msVec = paramStruct->dg->params; if(params[2] < 0 || params[2] > static_cast(paramsVec.size())) { @@ -101,7 +103,7 @@ bool GetObjectAddrOrThis(IPluginContext *pContext, const cell_t *params, void *& } int index = params[2] - 1; - const auto ¶m = paramsVec.at(index); + const ParamInfo ¶m = paramsVec.at(index); if(param.type != HookParamType_ObjectPtr && param.type != HookParamType_Object) { @@ -113,16 +115,16 @@ bool GetObjectAddrOrThis(IPluginContext *pContext, const cell_t *params, void *& return true; } - const auto &dgInfo = paramStruct->dg; + const DHooksInfo* dgInfo = paramStruct->dg; if(dgInfo->thisFuncCallConv != CallConv_THISCALL) { - return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'"); + return pContext->ThrowNativeError("Parameter 'this' is only available in member functions"); } if(dgInfo->thisType != ThisPointer_Address && dgInfo->thisType != ThisPointer_CBaseEntity - && !(dgInfo->thisType == ThisPointer_Ignore && dgInfo->hookType == HookType_GameRules)) + && dgInfo->hookType != HookType_GameRules) { return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available"); }