Skip to content

Commit 29aa1ff

Browse files
committed
Add SDKCall_VirtualAddress
1 parent 7b89db2 commit 29aa1ff

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

extensions/sdktools/vcaller.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ inline void DecodePassMethod(ValveType vtype, SDKPassMethod method, PassType &ty
8686

8787
static cell_t StartPrepSDKCall(IPluginContext *pContext, const cell_t *params)
8888
{
89+
auto call_type = (ValveCallType)params[1];
90+
if (call_type == ValveCall_Raw && pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
91+
return pContext->ThrowNativeError("SDKCall_Raw is unavailable for plugins that have enabled virtual address.");
92+
}
93+
if (call_type == ValveCall_VirtualAddress && pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) != SP_ERROR_NONE) {
94+
return pContext->ThrowNativeError("SDKCall_VirtualAddress is unavailable for plugins that haven't enabled virtual address.");
95+
}
8996
s_numparams = 0;
9097
s_vtbl_index = -1;
9198
s_call_addr = NULL;
@@ -412,6 +419,36 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
412419
startparam++;
413420
}
414421
break;
422+
case ValveCall_VirtualAddress:
423+
{
424+
//params[startparam] is an address to a pointer to THIS
425+
//params following this are params to the method we will invoke later
426+
if (startparam > numparams)
427+
{
428+
vc->stk_put(ptr);
429+
return pContext->ThrowNativeError("Expected a ThisPtr address, it wasn't found");
430+
}
431+
432+
//note: varargs pawn args are passed by-ref
433+
cell_t *cell;
434+
pContext->LocalToPhysAddr(params[startparam], &cell);
435+
void* thisptr = reinterpret_cast<void*>(g_pSM->FromPseudoAddress(*cell));
436+
437+
if (thisptr == nullptr)
438+
{
439+
vc->stk_put(ptr);
440+
return pContext->ThrowNativeError("ThisPtr address cannot be null");
441+
}
442+
else if (reinterpret_cast<uintptr_t>(thisptr) < VALID_MINIMUM_MEMORY_ADDRESS)
443+
{
444+
vc->stk_put(ptr);
445+
return pContext->ThrowNativeError("Invalid ThisPtr address %p is pointing to reserved memory.", thisptr);
446+
}
447+
448+
*(void **)ptr = thisptr;
449+
startparam++;
450+
}
451+
break;
415452
default:
416453
{
417454
vc->stk_put(ptr);

extensions/sdktools/vdecoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ enum ValveCallType
8585
ValveCall_Raw, /**< Thiscall (address explicit first parameter) */
8686
ValveCall_Server, /**< Thiscall (CBaseServer implicit first parameter) */
8787
ValveCall_Engine, /**< Thiscall (CVEngineServer implicit first parameter) */
88+
ValveCall_VirtualAddress /**< Thiscall (address explicit first parameter) */
8889
};
8990

9091
/**

plugins/include/sdktools.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ enum SDKCallType
6060
SDKCall_Player, /**< CBasePlayer call */
6161
SDKCall_GameRules, /**< CGameRules call */
6262
SDKCall_EntityList, /**< CGlobalEntityList call */
63-
SDKCall_Raw, /**< |this| pointer with an arbitrary address */
63+
SDKCall_Raw, /**< |this| pointer with an arbitrary address. This is not available if SM's virtual addresses are enabled */
6464
SDKCall_Server, /**< CBaseServer call */
65-
SDKCall_Engine /**< CVEngineServer call */
65+
SDKCall_Engine, /**< CVEngineServer call */
66+
SDKCall_VirtualAddress /**< |this| pointer with an arbitrary SM virtual address */
6667
};
6768

6869
enum SDKLibrary

0 commit comments

Comments
 (0)