From cdc837fbbb22b0329f5754eac42ec6d29e6fde75 Mon Sep 17 00:00:00 2001 From: bottiger1 <55270538+bottiger1@users.noreply.github.com> Date: Wed, 8 May 2024 20:31:03 -0700 Subject: [PATCH 1/3] fix sdktools crash on 64 bits --- extensions/sdktools/hooks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/sdktools/hooks.cpp b/extensions/sdktools/hooks.cpp index 79094702b3..83588c99fa 100644 --- a/extensions/sdktools/hooks.cpp +++ b/extensions/sdktools/hooks.cpp @@ -234,7 +234,7 @@ void CHookManager::OnClientConnected(int client) } } - int hookid = SH_ADD_VPHOOK(IClientMessageHandler, ProcessVoiceData, (IClientMessageHandler *)((intptr_t)(pClient) + 4), SH_MEMBER(this, &CHookManager::ProcessVoiceData), true); + int hookid = SH_ADD_VPHOOK(IClientMessageHandler, ProcessVoiceData, (IClientMessageHandler *)((intptr_t)(pClient) + sizeof(intptr_t)), SH_MEMBER(this, &CHookManager::ProcessVoiceData), true); hook.SetHookID(hookid); netProcessVoiceData.push_back(new CVTableHook(hook)); } From 8612720108312b33982c431f88a1acae5a24ee48 Mon Sep 17 00:00:00 2001 From: bottiger1 <55270538+bottiger1@users.noreply.github.com> Date: Wed, 8 May 2024 20:46:52 -0700 Subject: [PATCH 2/3] remove other 32bit-isms from sdktools --- extensions/sdktools/hooks.cpp | 2 +- extensions/sdktools/vhelpers.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/sdktools/hooks.cpp b/extensions/sdktools/hooks.cpp index 83588c99fa..c758575314 100644 --- a/extensions/sdktools/hooks.cpp +++ b/extensions/sdktools/hooks.cpp @@ -584,7 +584,7 @@ bool CHookManager::SendFile(const char *filename, unsigned int transferID) #if !defined CLIENTVOICE_HOOK_SUPPORT bool CHookManager::ProcessVoiceData(CLC_VoiceData *msg) { - IClient *pClient = (IClient *)((intptr_t)(META_IFACEPTR(IClient)) - 4); + IClient *pClient = (IClient *)((intptr_t)(META_IFACEPTR(IClient)) - sizeof(intptr_t)); if (pClient == NULL) { return true; diff --git a/extensions/sdktools/vhelpers.cpp b/extensions/sdktools/vhelpers.cpp index 7d5c5545d0..ceeaa76ae5 100644 --- a/extensions/sdktools/vhelpers.cpp +++ b/extensions/sdktools/vhelpers.cpp @@ -754,7 +754,7 @@ CEntityFactoryDictionary *GetEntityFactoryDictionary() // Get real address of function // Address of signature + offset of relative offset + sizeof(int32_t) offset + relative offset - addr = (void *)((intptr_t)addr + offset + 4 + funcOffset); + addr = (void *)((intptr_t)addr + offset + sizeof(intptr_t) + funcOffset); } pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retData, NULL, 0); From 3fb09e8d44e5537c25867ce893db2ae6f377a720 Mon Sep 17 00:00:00 2001 From: bottiger1 <55270538+bottiger1@users.noreply.github.com> Date: Thu, 23 May 2024 17:04:22 -0700 Subject: [PATCH 3/3] add pointer sdktools type --- extensions/sdktools/vcaller.cpp | 13 +++++---- extensions/sdktools/vdecoder.cpp | 45 ++++++++++++++++++++++++++++++++ extensions/sdktools/vdecoder.h | 1 + plugins/include/sdktools.inc | 4 ++- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/extensions/sdktools/vcaller.cpp b/extensions/sdktools/vcaller.cpp index 3cabcc40ae..a6fb0098af 100644 --- a/extensions/sdktools/vcaller.cpp +++ b/extensions/sdktools/vcaller.cpp @@ -63,7 +63,8 @@ inline void DecodePassMethod(ValveType vtype, SDKPassMethod method, PassType &ty type = PassType_Basic; if (vtype == Valve_POD || vtype == Valve_Float - || vtype == Valve_Bool) + || vtype == Valve_Bool + || vtype == Valve_Pointer) { flags = PASSFLAG_BYVAL | PASSFLAG_ASPOINTER; } else { @@ -394,8 +395,8 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params) } //note: varargs pawn args are passed by-ref - cell_t *cell; - pContext->LocalToPhysAddr(params[startparam], &cell); + intptr_t *cell; + pContext->LocalToPhysAddr(params[startparam], reinterpret_cast(&cell)); void *thisptr = reinterpret_cast(*cell); if (thisptr == nullptr) @@ -429,7 +430,8 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params) { startparam += 2; } else if (vc->retinfo->vtype == Valve_Vector - || vc->retinfo->vtype == Valve_QAngle) + || vc->retinfo->vtype == Valve_QAngle + || vc->retinfo->vtype == Valve_Pointer) { startparam += 1; } @@ -506,7 +508,8 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params) pContext->StringToLocalUTF8(params[retparam], *addr, *(char **)vc->retbuf, &written); return (cell_t)written; } else if (vc->retinfo->vtype == Valve_Vector - || vc->retinfo->vtype == Valve_QAngle) + || vc->retinfo->vtype == Valve_QAngle + || vc->retinfo->vtype == Valve_Pointer) { if (numparams < 2) { diff --git a/extensions/sdktools/vdecoder.cpp b/extensions/sdktools/vdecoder.cpp index 7bdf2ef0eb..a07e59e148 100644 --- a/extensions/sdktools/vdecoder.cpp +++ b/extensions/sdktools/vdecoder.cpp @@ -164,6 +164,20 @@ size_t ValveParamToBinParam(ValveType type, return sizeof(float); } } + case Valve_Pointer: + { + info->type = PassType_Basic; + info->flags = flags; + if (flags & PASSFLAG_ASPOINTER) + { + needs_extra = true; + info->size = sizeof(void*); + return sizeof(void*) * 2; + } else { + info->size = sizeof(void*); + return sizeof(void*); + } + } } return 0; @@ -278,6 +292,20 @@ DataStatus EncodeValveParam(IPluginContext *pContext, return Data_Okay; } + case Valve_Pointer: // buffer -> sourcepawn + { + intptr_t *addr; + pContext->LocalToPhysAddr(param, reinterpret_cast(&addr)); + + if (data->flags & PASSFLAG_ASPOINTER) + { + buffer = *(intptr_t **)buffer; + } + + *addr = *(intptr_t *)buffer; + + return Data_Okay; + } } return Data_Fail; @@ -573,6 +601,23 @@ DataStatus DecodeValveParam(IPluginContext *pContext, *(char **)buffer = addr; return Data_Okay; } + case Valve_Pointer: // sourcepawn -> buffer + { + intptr_t *addr; + pContext->LocalToPhysAddr(param, reinterpret_cast(&addr)); + + if (data->decflags & VDECODE_FLAG_BYREF) + { + addr = reinterpret_cast(*addr); + } + if (data->flags & PASSFLAG_ASPOINTER) + { + *(void **)buffer = (unsigned char *)_buffer + pCall->stackEnd + data->obj_offset; + buffer = *(void **)buffer; + } + *(intptr_t *)buffer = *addr; + return Data_Okay; + } } return Data_Fail; diff --git a/extensions/sdktools/vdecoder.h b/extensions/sdktools/vdecoder.h index 16478cf101..bd4ad8233a 100644 --- a/extensions/sdktools/vdecoder.h +++ b/extensions/sdktools/vdecoder.h @@ -54,6 +54,7 @@ enum ValveType Valve_String, /**< String */ Valve_Bool, /**< Boolean */ Valve_Object, /**< Object, not matching one of the above types */ + Valve_Pointer, /**< 64 bit or 32 bit array */ }; enum DataStatus diff --git a/plugins/include/sdktools.inc b/plugins/include/sdktools.inc index 07fc55f82f..3d47d140d8 100644 --- a/plugins/include/sdktools.inc +++ b/plugins/include/sdktools.inc @@ -88,7 +88,9 @@ enum SDKType SDKType_Float, /**< Float (any) */ SDKType_Edict, /**< edict_t (always as pointer) */ SDKType_String, /**< NULL-terminated string (always as pointer) */ - SDKType_Bool /**< Boolean (any) */ + SDKType_Bool, /**< Boolean (any) */ + SDKType_Object, + SDKType_Pointer, /**< Pointer (pass in an array) */ }; enum SDKPassMethod