@@ -86,6 +86,13 @@ inline void DecodePassMethod(ValveType vtype, SDKPassMethod method, PassType &ty
8686
8787static 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);
0 commit comments