2013-08-16 05:53:38 +02:00
# include "vhook.h"
2013-08-20 04:33:44 +02:00
# include "vfunc_call.h"
2016-08-30 22:40:24 +02:00
# include "util.h"
2016-12-12 06:02:10 +01:00
# include <macro-assembler-x86.h>
2013-08-16 05:53:38 +02:00
SourceHook : : IHookManagerAutoGen * g_pHookManager = NULL ;
2016-08-27 16:20:38 +02:00
ke : : Vector < DHooksManager * > g_pHooks ;
2013-08-16 05:53:38 +02:00
2013-08-19 17:07:25 +02:00
using namespace SourceHook ;
2019-05-06 18:29:40 +02:00
using namespace sp ;
2013-08-19 17:07:25 +02:00
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-29 21:18:43 +02:00
# define OBJECT_OFFSET sizeof(void *)
# else
# define OBJECT_OFFSET (sizeof(void *)*2)
# endif
2016-08-30 22:40:24 +02:00
2016-12-12 06:02:10 +01:00
# ifndef WIN32
void * GenerateThunk ( ReturnType type )
{
sp : : MacroAssembler masm ;
static const size_t kStackNeeded = ( 2 ) * 4 ; // 2 args max
static const size_t kReserve = ke : : Align ( kStackNeeded + 8 , 16 ) - 8 ;
masm . push ( ebp ) ;
masm . movl ( ebp , esp ) ;
masm . subl ( esp , kReserve ) ;
if ( type ! = ReturnType_String & & type ! = ReturnType_Vector )
{
masm . lea ( eax , Operand ( ebp , 12 ) ) ; // grab the incoming caller argument vector
masm . movl ( Operand ( esp , 1 * 4 ) , eax ) ; // set that as the 2nd argument
masm . movl ( eax , Operand ( ebp , 8 ) ) ; // grab the |this|
masm . movl ( Operand ( esp , 0 * 4 ) , eax ) ; // set |this| as the 1st argument*/
}
else
{
masm . lea ( eax , Operand ( ebp , 8 ) ) ; // grab the incoming caller argument vector
masm . movl ( Operand ( esp , 1 * 4 ) , eax ) ; // set that as the 2nd argument
masm . movl ( eax , Operand ( ebp , 12 ) ) ; // grab the |this|
masm . movl ( Operand ( esp , 0 * 4 ) , eax ) ; // set |this| as the 1st argument*/
}
if ( type = = ReturnType_Float )
{
masm . call ( ExternalAddress ( ( void * ) Callback_float ) ) ;
}
else if ( type = = ReturnType_Vector )
{
masm . call ( ExternalAddress ( ( void * ) Callback_vector ) ) ;
}
else if ( type = = ReturnType_String )
{
masm . call ( ExternalAddress ( ( void * ) Callback_stringt ) ) ;
}
else
{
masm . call ( ExternalAddress ( ( void * ) Callback ) ) ;
}
masm . addl ( esp , kReserve ) ;
masm . pop ( ebp ) ; // restore ebp
masm . ret ( ) ;
void * base = g_pSM - > GetScriptingEngine ( ) - > AllocatePageMemory ( masm . length ( ) ) ;
masm . emitToExecutableMemory ( base ) ;
return base ;
}
# else
// HUGE THANKS TO BAILOPAN (dvander)!
void * GenerateThunk ( ReturnType type )
{
sp : : MacroAssembler masm ;
static const size_t kStackNeeded = ( 3 + 1 ) * 4 ; // 3 args max, 1 locals max
static const size_t kReserve = ke : : Align ( kStackNeeded + 8 , 16 ) - 8 ;
masm . push ( ebp ) ;
masm . movl ( ebp , esp ) ;
masm . subl ( esp , kReserve ) ;
masm . lea ( eax , Operand ( esp , 3 * 4 ) ) ; // ptr to 2nd var after argument space
masm . movl ( Operand ( esp , 2 * 4 ) , eax ) ; // set the ptr as the third argument
masm . lea ( eax , Operand ( ebp , 8 ) ) ; // grab the incoming caller argument vector
masm . movl ( Operand ( esp , 1 * 4 ) , eax ) ; // set that as the 2nd argument
masm . movl ( Operand ( esp , 0 * 4 ) , ecx ) ; // set |this| as the 1st argument
if ( type = = ReturnType_Float )
{
masm . call ( ExternalAddress ( Callback_float ) ) ;
}
else if ( type = = ReturnType_Vector )
{
masm . call ( ExternalAddress ( Callback_vector ) ) ;
}
else
{
masm . call ( ExternalAddress ( Callback ) ) ;
}
masm . movl ( ecx , Operand ( esp , 3 * 4 ) ) ;
masm . addl ( esp , kReserve ) ;
masm . pop ( ebp ) ; // restore ebp
masm . pop ( edx ) ; // grab return address in edx
masm . addl ( esp , ecx ) ; // remove arguments
masm . jmp ( edx ) ; // return to caller
void * base = g_pSM - > GetScriptingEngine ( ) - > AllocatePageMemory ( masm . length ( ) ) ;
masm . emitToExecutableMemory ( base ) ;
return base ;
}
# endif
2018-01-27 16:08:44 +01:00
DHooksManager : : DHooksManager ( HookSetup * setup , void * iface , IPluginFunction * remove_callback , IPluginFunction * plugincb , bool post )
2013-08-16 05:53:38 +02:00
{
2013-08-19 17:07:25 +02:00
this - > callback = MakeHandler ( setup - > returnType ) ;
this - > hookid = 0 ;
this - > remove_callback = remove_callback ;
this - > callback - > offset = setup - > offset ;
2018-01-27 16:08:44 +01:00
this - > callback - > plugin_callback = plugincb ;
2013-08-19 17:07:25 +02:00
this - > callback - > returnFlag = setup - > returnFlag ;
this - > callback - > thisType = setup - > thisType ;
this - > callback - > post = post ;
this - > callback - > hookType = setup - > hookType ;
this - > callback - > params = setup - > params ;
2014-08-19 19:14:48 +02:00
2013-08-22 04:18:52 +02:00
this - > addr = 0 ;
2013-08-16 05:53:38 +02:00
2013-08-19 17:07:25 +02:00
if ( this - > callback - > hookType = = HookType_Entity )
2013-08-16 05:53:38 +02:00
{
2013-08-19 17:07:25 +02:00
this - > callback - > entity = gamehelpers - > EntityToBCompatRef ( ( CBaseEntity * ) iface ) ;
2013-08-16 05:53:38 +02:00
}
else
{
2013-08-22 04:18:52 +02:00
if ( this - > callback - > hookType = = HookType_Raw )
{
this - > addr = ( intptr_t ) iface ;
}
2013-08-19 17:07:25 +02:00
this - > callback - > entity = - 1 ;
2013-08-16 05:53:38 +02:00
}
2013-08-19 17:07:25 +02:00
CProtoInfoBuilder protoInfo ( ProtoInfo : : CallConv_ThisCall ) ;
2013-08-16 05:53:38 +02:00
2014-08-19 19:14:48 +02:00
for ( int i = this - > callback - > params . size ( ) - 1 ; i > = 0 ; i - - )
2013-08-19 17:07:25 +02:00
{
2016-08-30 16:58:04 +02:00
protoInfo . AddParam ( this - > callback - > params . at ( i ) . size , this - > callback - > params . at ( i ) . pass_type , PASSFLAG_BYVAL , NULL , NULL , NULL , NULL ) ; //This seems like we need to do something about it at some point...
2013-08-19 17:07:25 +02:00
}
2013-08-16 05:53:38 +02:00
2013-08-19 17:07:25 +02:00
if ( this - > callback - > returnType = = ReturnType_Void )
{
protoInfo . SetReturnType ( 0 , SourceHook : : PassInfo : : PassType_Unknown , 0 , NULL , NULL , NULL , NULL ) ;
}
2013-08-26 04:45:42 +02:00
else if ( this - > callback - > returnType = = ReturnType_Float )
2013-08-19 17:07:25 +02:00
{
2013-08-27 04:19:05 +02:00
protoInfo . SetReturnType ( sizeof ( float ) , SourceHook : : PassInfo : : PassType_Float , setup - > returnFlag , NULL , NULL , NULL , NULL ) ;
2013-08-26 04:45:42 +02:00
}
else if ( this - > callback - > returnType = = ReturnType_String )
{
2013-08-27 04:19:05 +02:00
protoInfo . SetReturnType ( sizeof ( string_t ) , SourceHook : : PassInfo : : PassType_Object , setup - > returnFlag , NULL , NULL , NULL , NULL ) ; //We have to be 4 really... or else RIP
2013-08-19 17:07:25 +02:00
}
2013-08-28 20:20:20 +02:00
else if ( this - > callback - > returnType = = ReturnType_Vector )
{
2016-06-26 19:00:27 +02:00
protoInfo . SetReturnType ( sizeof ( SDKVector ) , SourceHook : : PassInfo : : PassType_Object , setup - > returnFlag , NULL , NULL , NULL , NULL ) ;
2013-08-28 20:20:20 +02:00
}
2013-08-22 04:18:52 +02:00
else
{
2013-08-26 04:45:42 +02:00
protoInfo . SetReturnType ( sizeof ( void * ) , SourceHook : : PassInfo : : PassType_Basic , setup - > returnFlag , NULL , NULL , NULL , NULL ) ;
2013-08-22 04:18:52 +02:00
}
2014-08-19 19:14:48 +02:00
this - > pManager = g_pHookManager - > MakeHookMan ( protoInfo , 0 , this - > callback - > offset ) ;
2013-08-19 17:07:25 +02:00
2014-08-19 19:14:48 +02:00
this - > hookid = g_SHPtr - > AddHook ( g_PLID , ISourceHook : : Hook_Normal , iface , 0 , this - > pManager , this - > callback , this - > callback - > post ) ;
2013-08-19 17:07:25 +02:00
}
2013-08-16 05:53:38 +02:00
2013-08-19 17:07:25 +02:00
void CleanupHooks ( IPluginContext * pContext )
{
2016-08-27 16:20:38 +02:00
for ( int i = g_pHooks . length ( ) - 1 ; i > = 0 ; i - - )
2013-08-16 05:53:38 +02:00
{
2014-08-19 19:14:48 +02:00
DHooksManager * manager = g_pHooks . at ( i ) ;
2013-08-19 17:07:25 +02:00
2013-08-22 04:18:52 +02:00
if ( pContext = = NULL | | pContext = = manager - > callback - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) )
2013-08-16 05:53:38 +02:00
{
2013-08-19 17:07:25 +02:00
delete manager ;
2016-08-27 16:20:38 +02:00
g_pHooks . remove ( i ) ;
2013-08-16 05:53:38 +02:00
}
}
2013-08-19 17:07:25 +02:00
}
bool SetupHookManager ( ISmmAPI * ismm )
{
g_pHookManager = static_cast < SourceHook : : IHookManagerAutoGen * > ( ismm - > MetaFactory ( MMIFACE_SH_HOOKMANAUTOGEN , NULL , NULL ) ) ;
return g_pHookManager ! = NULL ;
}
SourceHook : : PassInfo : : PassType GetParamTypePassType ( HookParamType type )
{
switch ( type )
{
case HookParamType_Float :
2013-08-20 04:33:44 +02:00
return SourceHook : : PassInfo : : PassType_Float ;
2013-08-21 02:18:50 +02:00
case HookParamType_Object :
return SourceHook : : PassInfo : : PassType_Object ;
2013-08-19 17:07:25 +02:00
}
2013-08-20 04:33:44 +02:00
return SourceHook : : PassInfo : : PassType_Basic ;
2013-08-19 17:07:25 +02:00
}
2016-08-30 22:40:24 +02:00
2013-08-19 17:07:25 +02:00
size_t GetStackArgsSize ( DHooksCallback * dg )
{
2016-08-30 22:40:24 +02:00
size_t res = GetParamsSize ( dg ) ;
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-28 20:20:20 +02:00
if ( dg - > returnType = = ReturnType_Vector ) //Account for result vector ptr.
2013-08-29 21:18:43 +02:00
# else
if ( dg - > returnType = = ReturnType_Vector | | dg - > returnType = = ReturnType_String )
# endif
2013-08-28 20:20:20 +02:00
{
2013-08-29 21:18:43 +02:00
res + = OBJECT_OFFSET ;
2013-08-28 20:20:20 +02:00
}
2013-08-19 17:07:25 +02:00
return res ;
}
2016-08-30 22:40:24 +02:00
2016-12-12 06:02:10 +01:00
HookReturnStruct : : ~ HookReturnStruct ( )
{
if ( this - > type = = ReturnType_String | | this - > type = = ReturnType_Int | | this - > type = = ReturnType_Bool | | this - > type = = ReturnType_Float | | this - > type = = ReturnType_Vector )
{
free ( this - > newResult ) ;
free ( this - > orgResult ) ;
}
}
2016-08-30 22:40:24 +02:00
HookParamsStruct : : ~ HookParamsStruct ( )
{
if ( this - > orgParams ! = NULL )
{
free ( this - > orgParams ) ;
}
if ( this - > isChanged ! = NULL )
{
free ( this - > isChanged ) ;
}
if ( this - > newParams ! = NULL )
{
free ( this - > newParams ) ;
}
}
2013-08-19 17:07:25 +02:00
HookParamsStruct * GetParamStruct ( DHooksCallback * dg , void * * argStack , size_t argStackSize )
{
2013-08-22 04:18:52 +02:00
HookParamsStruct * params = new HookParamsStruct ( ) ;
params - > dg = dg ;
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-28 20:20:20 +02:00
if ( dg - > returnType ! = ReturnType_Vector )
2013-08-29 21:18:43 +02:00
# else
if ( dg - > returnType ! = ReturnType_Vector & & dg - > returnType ! = ReturnType_String )
# endif
2013-08-28 20:20:20 +02:00
{
params - > orgParams = ( void * * ) malloc ( argStackSize ) ;
memcpy ( params - > orgParams , argStack , argStackSize ) ;
}
else //Offset result ptr
{
2013-08-29 21:18:43 +02:00
params - > orgParams = ( void * * ) malloc ( argStackSize - OBJECT_OFFSET ) ;
memcpy ( params - > orgParams , argStack + OBJECT_OFFSET , argStackSize - OBJECT_OFFSET ) ;
2013-08-28 20:20:20 +02:00
}
2016-08-30 22:40:24 +02:00
size_t paramsSize = GetParamsSize ( dg ) ;
params - > newParams = ( void * * ) malloc ( paramsSize ) ;
2014-08-19 19:14:48 +02:00
params - > isChanged = ( bool * ) malloc ( dg - > params . size ( ) * sizeof ( bool ) ) ;
2016-08-30 22:40:24 +02:00
for ( unsigned int i = 0 ; i < dg - > params . size ( ) ; i + + )
2013-08-19 17:07:25 +02:00
{
2016-08-31 17:45:47 +02:00
* ( void * * ) ( ( intptr_t ) params - > newParams + GetParamOffset ( params , i ) ) = NULL ;
2013-08-22 04:18:52 +02:00
params - > isChanged [ i ] = false ;
2013-08-19 17:07:25 +02:00
}
2016-08-30 22:40:24 +02:00
2013-08-22 04:18:52 +02:00
return params ;
2013-08-19 17:07:25 +02:00
}
2016-08-30 22:40:24 +02:00
2013-08-26 23:44:18 +02:00
HookReturnStruct * GetReturnStruct ( DHooksCallback * dg )
2013-08-19 17:07:25 +02:00
{
HookReturnStruct * res = new HookReturnStruct ( ) ;
res - > isChanged = false ;
res - > type = dg - > returnType ;
2015-05-14 18:03:48 +02:00
res - > orgResult = NULL ;
res - > newResult = NULL ;
2013-08-20 04:33:44 +02:00
2013-08-26 23:44:18 +02:00
if ( g_SHPtr - > GetOrigRet ( ) & & dg - > post )
2013-08-20 04:33:44 +02:00
{
switch ( dg - > returnType )
{
2013-08-22 22:14:32 +02:00
case ReturnType_String :
2015-05-14 18:03:48 +02:00
res - > orgResult = malloc ( sizeof ( string_t ) ) ;
res - > newResult = malloc ( sizeof ( string_t ) ) ;
2013-08-26 23:44:18 +02:00
* ( string_t * ) res - > orgResult = META_RESULT_ORIG_RET ( string_t ) ;
2013-08-22 22:14:32 +02:00
break ;
2013-08-20 04:33:44 +02:00
case ReturnType_Int :
2015-05-14 18:03:48 +02:00
res - > orgResult = malloc ( sizeof ( int ) ) ;
res - > newResult = malloc ( sizeof ( int ) ) ;
2013-08-26 23:44:18 +02:00
* ( int * ) res - > orgResult = META_RESULT_ORIG_RET ( int ) ;
2013-08-22 04:37:54 +02:00
break ;
2013-08-21 02:18:50 +02:00
case ReturnType_Bool :
2015-05-14 18:03:48 +02:00
res - > orgResult = malloc ( sizeof ( bool ) ) ;
res - > newResult = malloc ( sizeof ( bool ) ) ;
2013-08-26 23:44:18 +02:00
* ( bool * ) res - > orgResult = META_RESULT_ORIG_RET ( bool ) ;
2013-08-20 04:33:44 +02:00
break ;
case ReturnType_Float :
2015-05-14 18:03:48 +02:00
res - > orgResult = malloc ( sizeof ( float ) ) ;
res - > newResult = malloc ( sizeof ( float ) ) ;
2013-08-26 23:44:18 +02:00
* ( float * ) res - > orgResult = META_RESULT_ORIG_RET ( float ) ;
2013-08-21 02:18:50 +02:00
break ;
2013-08-28 20:20:20 +02:00
case ReturnType_Vector :
{
2016-06-26 19:00:27 +02:00
res - > orgResult = malloc ( sizeof ( SDKVector ) ) ;
res - > newResult = malloc ( sizeof ( SDKVector ) ) ;
SDKVector vec = META_RESULT_ORIG_RET ( SDKVector ) ;
* ( SDKVector * ) res - > orgResult = vec ;
2013-08-28 20:20:20 +02:00
break ;
}
2013-08-20 04:33:44 +02:00
default :
2015-05-14 18:03:48 +02:00
res - > orgResult = META_RESULT_ORIG_RET ( void * ) ;
2013-08-21 02:18:50 +02:00
break ;
2013-08-20 04:33:44 +02:00
}
}
else
{
2013-08-22 04:18:52 +02:00
switch ( dg - > returnType )
{
2013-08-22 22:14:32 +02:00
case ReturnType_String :
2015-05-14 18:03:48 +02:00
res - > orgResult = malloc ( sizeof ( string_t ) ) ;
res - > newResult = malloc ( sizeof ( string_t ) ) ;
2013-08-22 22:14:32 +02:00
* ( string_t * ) res - > orgResult = NULL_STRING ;
break ;
2015-05-14 18:03:48 +02:00
case ReturnType_Vector :
2016-06-26 19:00:27 +02:00
res - > orgResult = malloc ( sizeof ( SDKVector ) ) ;
res - > newResult = malloc ( sizeof ( SDKVector ) ) ;
* ( SDKVector * ) res - > orgResult = SDKVector ( ) ;
2015-05-14 18:03:48 +02:00
break ;
2013-08-22 04:18:52 +02:00
case ReturnType_Int :
2015-05-14 18:03:48 +02:00
res - > orgResult = malloc ( sizeof ( int ) ) ;
res - > newResult = malloc ( sizeof ( int ) ) ;
2013-08-22 04:18:52 +02:00
* ( int * ) res - > orgResult = 0 ;
2013-08-22 04:37:54 +02:00
break ;
2013-08-22 04:18:52 +02:00
case ReturnType_Bool :
2015-05-14 18:03:48 +02:00
res - > orgResult = malloc ( sizeof ( bool ) ) ;
res - > newResult = malloc ( sizeof ( bool ) ) ;
2013-08-22 04:18:52 +02:00
* ( bool * ) res - > orgResult = false ;
break ;
case ReturnType_Float :
2015-05-14 18:03:48 +02:00
res - > orgResult = malloc ( sizeof ( float ) ) ;
res - > newResult = malloc ( sizeof ( float ) ) ;
2013-08-22 04:18:52 +02:00
* ( float * ) res - > orgResult = 0.0 ;
break ;
}
2013-08-20 04:33:44 +02:00
}
2013-08-16 05:53:38 +02:00
2013-08-19 17:07:25 +02:00
return res ;
}
2015-05-14 18:03:48 +02:00
2013-08-19 17:07:25 +02:00
cell_t GetThisPtr ( void * iface , ThisPointerType type )
{
2014-05-30 00:10:17 +02:00
if ( type = = ThisPointer_CBaseEntity )
2013-08-19 17:07:25 +02:00
{
2018-10-05 14:23:38 +02:00
if ( ! iface )
return - 1 ;
2013-08-19 17:07:25 +02:00
return gamehelpers - > EntityToBCompatRef ( ( CBaseEntity * ) iface ) ;
}
2013-08-16 05:53:38 +02:00
2013-08-19 17:07:25 +02:00
return ( cell_t ) iface ;
2013-08-16 05:53:38 +02:00
}
2013-08-20 04:33:44 +02:00
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-19 17:07:25 +02:00
void * Callback ( DHooksCallback * dg , void * * argStack , size_t * argsizep )
2013-08-20 04:33:44 +02:00
# else
void * Callback ( DHooksCallback * dg , void * * argStack )
# endif
2013-08-16 05:53:38 +02:00
{
2013-08-19 17:07:25 +02:00
HookReturnStruct * returnStruct = NULL ;
HookParamsStruct * paramStruct = NULL ;
Handle_t rHndl ;
Handle_t pHndl ;
2013-08-16 05:53:38 +02:00
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-19 17:07:25 +02:00
* argsizep = GetStackArgsSize ( dg ) ;
2013-08-20 04:33:44 +02:00
# else
size_t argsize = GetStackArgsSize ( dg ) ;
# endif
2013-08-16 05:53:38 +02:00
2013-08-19 17:07:25 +02:00
if ( dg - > thisType = = ThisPointer_CBaseEntity | | dg - > thisType = = ThisPointer_Address )
{
dg - > plugin_callback - > PushCell ( GetThisPtr ( g_SHPtr - > GetIfacePtr ( ) , dg - > thisType ) ) ;
}
if ( dg - > returnType ! = ReturnType_Void )
2013-08-16 05:53:38 +02:00
{
2013-08-26 23:44:18 +02:00
returnStruct = GetReturnStruct ( dg ) ;
2013-08-19 17:07:25 +02:00
rHndl = handlesys - > CreateHandle ( g_HookReturnHandle , returnStruct , dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) , NULL ) ;
if ( ! rHndl )
2013-08-16 05:53:38 +02:00
{
2013-08-21 19:36:23 +02:00
dg - > plugin_callback - > Cancel ( ) ;
2013-08-19 17:07:25 +02:00
if ( returnStruct )
2013-08-16 05:53:38 +02:00
{
2013-08-19 17:07:25 +02:00
delete returnStruct ;
2013-08-16 05:53:38 +02:00
}
2013-08-19 17:07:25 +02:00
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
2013-08-22 04:18:52 +02:00
return NULL ;
2013-08-16 05:53:38 +02:00
}
2013-08-19 17:07:25 +02:00
dg - > plugin_callback - > PushCell ( rHndl ) ;
2013-08-16 05:53:38 +02:00
}
2013-08-20 04:33:44 +02:00
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-19 17:07:25 +02:00
if ( * argsizep > 0 )
2013-08-16 05:53:38 +02:00
{
2013-08-19 17:07:25 +02:00
paramStruct = GetParamStruct ( dg , argStack , * argsizep ) ;
2013-08-20 04:33:44 +02:00
# else
if ( argsize > 0 )
{
paramStruct = GetParamStruct ( dg , argStack , argsize ) ;
# endif
2013-08-19 17:07:25 +02:00
pHndl = handlesys - > CreateHandle ( g_HookParamsHandle , paramStruct , dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) , NULL ) ;
if ( ! pHndl )
{
2013-08-21 19:36:23 +02:00
dg - > plugin_callback - > Cancel ( ) ;
2013-08-19 17:07:25 +02:00
if ( returnStruct )
{
2016-12-12 06:02:10 +01:00
HandleSecurity sec ( dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) ) ;
handlesys - > FreeHandle ( rHndl , & sec ) ;
2013-08-19 17:07:25 +02:00
}
if ( paramStruct )
{
delete paramStruct ;
}
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
2013-08-22 04:18:52 +02:00
return NULL ;
2013-08-19 17:07:25 +02:00
}
dg - > plugin_callback - > PushCell ( pHndl ) ;
2013-08-16 05:53:38 +02:00
}
2013-08-19 17:07:25 +02:00
cell_t result = ( cell_t ) MRES_Ignored ;
2013-08-22 04:18:52 +02:00
META_RES mres = MRES_IGNORED ;
2013-08-19 17:07:25 +02:00
dg - > plugin_callback - > Execute ( & result ) ;
2013-08-16 05:53:38 +02:00
2013-08-19 17:07:25 +02:00
void * ret = g_SHPtr - > GetOverrideRetPtr ( ) ;
switch ( ( MRESReturn ) result )
2013-08-16 05:53:38 +02:00
{
2013-08-19 17:07:25 +02:00
case MRES_Handled :
case MRES_ChangedHandled :
g_SHPtr - > DoRecall ( ) ;
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
2013-08-22 04:18:52 +02:00
mres = MRES_SUPERCEDE ;
2013-08-28 20:20:20 +02:00
ret = CallVFunction < void * > ( dg , paramStruct , g_SHPtr - > GetIfacePtr ( ) ) ;
2019-09-25 18:57:27 +02:00
g_SHPtr - > EndContext ( NULL ) ;
2013-08-19 17:07:25 +02:00
break ;
case MRES_ChangedOverride :
if ( dg - > returnType ! = ReturnType_Void )
2013-08-16 05:53:38 +02:00
{
2013-08-19 17:07:25 +02:00
if ( returnStruct - > isChanged )
{
2015-05-14 18:03:48 +02:00
if ( dg - > returnType = = ReturnType_String | | dg - > returnType = = ReturnType_Int | | dg - > returnType = = ReturnType_Bool )
{
ret = * ( void * * ) returnStruct - > newResult ;
}
else
{
ret = returnStruct - > newResult ;
}
2013-08-21 19:36:23 +02:00
}
else //Throw an error if no override was set
{
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
2013-08-22 04:18:52 +02:00
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-21 19:36:23 +02:00
break ;
2013-08-19 17:07:25 +02:00
}
2013-08-16 05:53:38 +02:00
}
2013-08-21 19:36:23 +02:00
g_SHPtr - > DoRecall ( ) ;
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
2013-08-22 04:18:52 +02:00
mres = MRES_SUPERCEDE ;
2013-08-28 20:20:20 +02:00
CallVFunction < void * > ( dg , paramStruct , g_SHPtr - > GetIfacePtr ( ) ) ;
2019-09-25 18:57:27 +02:00
g_SHPtr - > EndContext ( NULL ) ;
2013-08-19 17:07:25 +02:00
break ;
case MRES_Override :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
2013-08-26 04:45:42 +02:00
{
g_SHPtr - > SetRes ( MRES_OVERRIDE ) ;
mres = MRES_OVERRIDE ;
2015-05-14 18:03:48 +02:00
if ( dg - > returnType = = ReturnType_String | | dg - > returnType = = ReturnType_Int | | dg - > returnType = = ReturnType_Bool )
{
ret = * ( void * * ) returnStruct - > newResult ;
}
else
{
ret = returnStruct - > newResult ;
}
2013-08-19 17:07:25 +02:00
}
2013-08-21 19:36:23 +02:00
else //Throw an error if no override was set
2013-08-19 17:07:25 +02:00
{
2013-08-21 19:36:23 +02:00
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
2013-08-22 04:18:52 +02:00
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-19 17:07:25 +02:00
}
}
break ;
case MRES_Supercede :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
2013-08-26 04:45:42 +02:00
{
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
2015-05-14 18:03:48 +02:00
if ( dg - > returnType = = ReturnType_String | | dg - > returnType = = ReturnType_Int | | dg - > returnType = = ReturnType_Bool )
{
ret = * ( void * * ) returnStruct - > newResult ;
}
else
{
ret = returnStruct - > newResult ;
}
2013-08-19 17:07:25 +02:00
}
2013-08-21 19:36:23 +02:00
else //Throw an error if no override was set
2013-08-19 17:07:25 +02:00
{
2013-08-21 19:36:23 +02:00
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
2013-08-22 04:18:52 +02:00
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-19 17:07:25 +02:00
}
}
2015-06-05 14:44:28 +02:00
else
{
g_SHPtr - > DoRecall ( ) ;
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
2019-09-25 18:57:27 +02:00
g_SHPtr - > EndContext ( NULL ) ;
2015-06-05 14:44:28 +02:00
}
2013-08-19 17:07:25 +02:00
break ;
default :
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
2013-08-22 04:18:52 +02:00
mres = MRES_IGNORED ;
2013-08-19 17:07:25 +02:00
break ;
2013-08-16 05:53:38 +02:00
}
2013-08-22 04:18:52 +02:00
HandleSecurity sec ( dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) ) ;
2013-08-16 05:53:38 +02:00
2013-08-19 17:07:25 +02:00
if ( returnStruct )
{
handlesys - > FreeHandle ( rHndl , & sec ) ;
}
if ( paramStruct )
{
handlesys - > FreeHandle ( pHndl , & sec ) ;
}
2013-08-16 05:53:38 +02:00
2013-08-22 04:18:52 +02:00
if ( dg - > returnType = = ReturnType_Void | | mres < = MRES_HANDLED )
2013-08-21 04:21:29 +02:00
{
return NULL ;
}
2013-08-20 04:33:44 +02:00
return ret ;
2013-08-21 02:18:50 +02:00
}
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-22 04:18:52 +02:00
float Callback_float ( DHooksCallback * dg , void * * argStack , size_t * argsizep )
# else
2013-08-28 21:22:15 +02:00
float Callback_float ( DHooksCallback * dg , void * * argStack )
2013-08-22 04:18:52 +02:00
# endif
{
HookReturnStruct * returnStruct = NULL ;
HookParamsStruct * paramStruct = NULL ;
Handle_t rHndl ;
Handle_t pHndl ;
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-22 04:18:52 +02:00
* argsizep = GetStackArgsSize ( dg ) ;
# else
size_t argsize = GetStackArgsSize ( dg ) ;
# endif
if ( dg - > thisType = = ThisPointer_CBaseEntity | | dg - > thisType = = ThisPointer_Address )
{
dg - > plugin_callback - > PushCell ( GetThisPtr ( g_SHPtr - > GetIfacePtr ( ) , dg - > thisType ) ) ;
}
2013-08-26 23:44:18 +02:00
returnStruct = GetReturnStruct ( dg ) ;
2013-08-22 04:18:52 +02:00
rHndl = handlesys - > CreateHandle ( g_HookReturnHandle , returnStruct , dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) , NULL ) ;
if ( ! rHndl )
{
dg - > plugin_callback - > Cancel ( ) ;
if ( returnStruct )
{
delete returnStruct ;
}
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
2013-08-28 21:22:15 +02:00
return 0.0 ;
2013-08-22 04:18:52 +02:00
}
dg - > plugin_callback - > PushCell ( rHndl ) ;
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-22 04:18:52 +02:00
if ( * argsizep > 0 )
{
paramStruct = GetParamStruct ( dg , argStack , * argsizep ) ;
# else
if ( argsize > 0 )
{
paramStruct = GetParamStruct ( dg , argStack , argsize ) ;
# endif
pHndl = handlesys - > CreateHandle ( g_HookParamsHandle , paramStruct , dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) , NULL ) ;
if ( ! pHndl )
{
dg - > plugin_callback - > Cancel ( ) ;
if ( returnStruct )
{
delete returnStruct ;
}
if ( paramStruct )
{
delete paramStruct ;
}
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
2013-08-28 21:22:15 +02:00
return 0.0 ;
2013-08-22 04:18:52 +02:00
}
dg - > plugin_callback - > PushCell ( pHndl ) ;
}
cell_t result = ( cell_t ) MRES_Ignored ;
META_RES mres = MRES_IGNORED ;
dg - > plugin_callback - > Execute ( & result ) ;
void * ret = g_SHPtr - > GetOverrideRetPtr ( ) ;
switch ( ( MRESReturn ) result )
{
case MRES_Handled :
case MRES_ChangedHandled :
g_SHPtr - > DoRecall ( ) ;
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
2013-08-28 20:20:20 +02:00
* ( float * ) ret = CallVFunction < float > ( dg , paramStruct , g_SHPtr - > GetIfacePtr ( ) ) ;
2019-09-25 18:57:27 +02:00
g_SHPtr - > EndContext ( NULL ) ;
2013-08-22 04:18:52 +02:00
break ;
case MRES_ChangedOverride :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
{
* ( float * ) ret = * ( float * ) returnStruct - > newResult ;
}
else //Throw an error if no override was set
{
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-22 04:18:52 +02:00
break ;
}
}
g_SHPtr - > DoRecall ( ) ;
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
2013-08-28 20:20:20 +02:00
CallVFunction < float > ( dg , paramStruct , g_SHPtr - > GetIfacePtr ( ) ) ;
2019-09-25 18:57:27 +02:00
g_SHPtr - > EndContext ( NULL ) ;
2013-08-22 04:18:52 +02:00
break ;
case MRES_Override :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
2013-08-26 04:45:42 +02:00
{
g_SHPtr - > SetRes ( MRES_OVERRIDE ) ;
mres = MRES_OVERRIDE ;
2013-08-22 04:18:52 +02:00
* ( float * ) ret = * ( float * ) returnStruct - > newResult ;
}
else //Throw an error if no override was set
{
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-22 04:18:52 +02:00
}
}
break ;
case MRES_Supercede :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
2013-08-26 04:45:42 +02:00
{
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
2013-08-22 04:18:52 +02:00
* ( float * ) ret = * ( float * ) returnStruct - > newResult ;
}
else //Throw an error if no override was set
{
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-22 04:18:52 +02:00
}
}
break ;
default :
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
break ;
}
HandleSecurity sec ( dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) ) ;
if ( returnStruct )
{
handlesys - > FreeHandle ( rHndl , & sec ) ;
}
if ( paramStruct )
{
handlesys - > FreeHandle ( pHndl , & sec ) ;
}
if ( dg - > returnType = = ReturnType_Void | | mres < = MRES_HANDLED )
{
2013-08-28 21:22:15 +02:00
return 0.0 ;
2013-08-22 04:18:52 +02:00
}
return * ( float * ) ret ;
}
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2016-06-26 19:00:27 +02:00
SDKVector * Callback_vector ( DHooksCallback * dg , void * * argStack , size_t * argsizep )
2013-08-28 21:22:15 +02:00
# else
2016-06-26 19:00:27 +02:00
SDKVector * Callback_vector ( DHooksCallback * dg , void * * argStack )
2013-08-28 21:22:15 +02:00
# endif
2013-08-28 20:20:20 +02:00
{
2016-06-26 19:00:27 +02:00
SDKVector * vec_result = ( SDKVector * ) argStack [ 0 ] ; // Save the result
2013-08-28 20:20:20 +02:00
HookReturnStruct * returnStruct = NULL ;
HookParamsStruct * paramStruct = NULL ;
Handle_t rHndl ;
Handle_t pHndl ;
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-28 20:20:20 +02:00
* argsizep = GetStackArgsSize ( dg ) ;
# else
size_t argsize = GetStackArgsSize ( dg ) ;
# endif
if ( dg - > thisType = = ThisPointer_CBaseEntity | | dg - > thisType = = ThisPointer_Address )
{
dg - > plugin_callback - > PushCell ( GetThisPtr ( g_SHPtr - > GetIfacePtr ( ) , dg - > thisType ) ) ;
}
returnStruct = GetReturnStruct ( dg ) ;
rHndl = handlesys - > CreateHandle ( g_HookReturnHandle , returnStruct , dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) , NULL ) ;
if ( ! rHndl )
{
dg - > plugin_callback - > Cancel ( ) ;
if ( returnStruct )
{
delete returnStruct ;
}
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
return NULL ;
}
dg - > plugin_callback - > PushCell ( rHndl ) ;
2014-08-19 19:14:48 +02:00
# ifdef WIN32
2013-08-28 20:20:20 +02:00
if ( * argsizep > 0 )
{
paramStruct = GetParamStruct ( dg , argStack , * argsizep ) ;
# else
if ( argsize > 0 )
{
paramStruct = GetParamStruct ( dg , argStack , argsize ) ;
# endif
pHndl = handlesys - > CreateHandle ( g_HookParamsHandle , paramStruct , dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) , NULL ) ;
if ( ! pHndl )
{
dg - > plugin_callback - > Cancel ( ) ;
if ( returnStruct )
{
delete returnStruct ;
}
if ( paramStruct )
{
delete paramStruct ;
}
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
return NULL ;
}
dg - > plugin_callback - > PushCell ( pHndl ) ;
}
cell_t result = ( cell_t ) MRES_Ignored ;
META_RES mres = MRES_IGNORED ;
dg - > plugin_callback - > Execute ( & result ) ;
void * ret = g_SHPtr - > GetOverrideRetPtr ( ) ;
ret = vec_result ;
switch ( ( MRESReturn ) result )
{
case MRES_Handled :
case MRES_ChangedHandled :
g_SHPtr - > DoRecall ( ) ;
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
2016-06-26 19:00:27 +02:00
* vec_result = CallVFunction < SDKVector > ( dg , paramStruct , g_SHPtr - > GetIfacePtr ( ) ) ;
2019-09-25 18:57:27 +02:00
g_SHPtr - > EndContext ( NULL ) ;
2013-08-28 20:20:20 +02:00
break ;
case MRES_ChangedOverride :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
{
2019-04-21 12:00:01 +02:00
* vec_result = * ( SDKVector * ) returnStruct - > newResult ;
2013-08-28 20:20:20 +02:00
}
else //Throw an error if no override was set
{
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-28 20:20:20 +02:00
break ;
}
}
g_SHPtr - > DoRecall ( ) ;
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
2016-06-26 19:00:27 +02:00
CallVFunction < SDKVector > ( dg , paramStruct , g_SHPtr - > GetIfacePtr ( ) ) ;
2019-09-25 18:57:27 +02:00
g_SHPtr - > EndContext ( NULL ) ;
2013-08-28 20:20:20 +02:00
break ;
case MRES_Override :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
{
g_SHPtr - > SetRes ( MRES_OVERRIDE ) ;
mres = MRES_OVERRIDE ;
2019-04-21 12:00:01 +02:00
* vec_result = * ( SDKVector * ) returnStruct - > newResult ;
2013-08-28 20:20:20 +02:00
}
else //Throw an error if no override was set
{
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-28 20:20:20 +02:00
}
}
break ;
case MRES_Supercede :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
{
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
2019-05-24 11:06:33 +02:00
* vec_result = * ( SDKVector * ) returnStruct - > newResult ;
2013-08-28 20:20:20 +02:00
}
else //Throw an error if no override was set
{
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-28 20:20:20 +02:00
}
}
break ;
default :
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
break ;
}
HandleSecurity sec ( dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) ) ;
if ( returnStruct )
{
handlesys - > FreeHandle ( rHndl , & sec ) ;
}
if ( paramStruct )
{
handlesys - > FreeHandle ( pHndl , & sec ) ;
}
if ( dg - > returnType = = ReturnType_Void | | mres < = MRES_HANDLED )
{
vec_result - > x = 0 ;
vec_result - > y = 0 ;
vec_result - > z = 0 ;
return vec_result ;
}
return vec_result ;
}
2013-08-29 21:18:43 +02:00
2014-08-19 19:30:12 +02:00
# ifndef WIN32
2013-08-29 21:18:43 +02:00
string_t * Callback_stringt ( DHooksCallback * dg , void * * argStack )
{
string_t * string_result = ( string_t * ) argStack [ 0 ] ; // Save the result
HookReturnStruct * returnStruct = NULL ;
HookParamsStruct * paramStruct = NULL ;
Handle_t rHndl ;
Handle_t pHndl ;
size_t argsize = GetStackArgsSize ( dg ) ;
if ( dg - > thisType = = ThisPointer_CBaseEntity | | dg - > thisType = = ThisPointer_Address )
{
dg - > plugin_callback - > PushCell ( GetThisPtr ( g_SHPtr - > GetIfacePtr ( ) , dg - > thisType ) ) ;
}
returnStruct = GetReturnStruct ( dg ) ;
rHndl = handlesys - > CreateHandle ( g_HookReturnHandle , returnStruct , dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) , NULL ) ;
if ( ! rHndl )
{
dg - > plugin_callback - > Cancel ( ) ;
if ( returnStruct )
{
delete returnStruct ;
}
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
return NULL ;
}
dg - > plugin_callback - > PushCell ( rHndl ) ;
if ( argsize > 0 )
{
paramStruct = GetParamStruct ( dg , argStack , argsize ) ;
pHndl = handlesys - > CreateHandle ( g_HookParamsHandle , paramStruct , dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) , NULL ) ;
if ( ! pHndl )
{
dg - > plugin_callback - > Cancel ( ) ;
if ( returnStruct )
{
delete returnStruct ;
}
if ( paramStruct )
{
delete paramStruct ;
}
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
return NULL ;
}
dg - > plugin_callback - > PushCell ( pHndl ) ;
}
cell_t result = ( cell_t ) MRES_Ignored ;
META_RES mres = MRES_IGNORED ;
dg - > plugin_callback - > Execute ( & result ) ;
void * ret = g_SHPtr - > GetOverrideRetPtr ( ) ;
ret = string_result ;
switch ( ( MRESReturn ) result )
{
case MRES_Handled :
case MRES_ChangedHandled :
g_SHPtr - > DoRecall ( ) ;
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
* string_result = CallVFunction < string_t > ( dg , paramStruct , g_SHPtr - > GetIfacePtr ( ) ) ;
2019-09-25 18:57:27 +02:00
g_SHPtr - > EndContext ( NULL ) ;
2013-08-29 21:18:43 +02:00
break ;
case MRES_ChangedOverride :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
{
* string_result = * ( string_t * ) returnStruct - > newResult ;
}
else //Throw an error if no override was set
{
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-29 21:18:43 +02:00
break ;
}
}
g_SHPtr - > DoRecall ( ) ;
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
2016-06-26 19:00:27 +02:00
CallVFunction < SDKVector > ( dg , paramStruct , g_SHPtr - > GetIfacePtr ( ) ) ;
2019-09-25 18:57:27 +02:00
g_SHPtr - > EndContext ( NULL ) ;
2013-08-29 21:18:43 +02:00
break ;
case MRES_Override :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
{
g_SHPtr - > SetRes ( MRES_OVERRIDE ) ;
mres = MRES_OVERRIDE ;
* string_result = * ( string_t * ) returnStruct - > newResult ;
}
else //Throw an error if no override was set
{
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-29 21:18:43 +02:00
}
}
break ;
case MRES_Supercede :
if ( dg - > returnType ! = ReturnType_Void )
{
if ( returnStruct - > isChanged )
{
g_SHPtr - > SetRes ( MRES_SUPERCEDE ) ;
mres = MRES_SUPERCEDE ;
* string_result = * ( string_t * ) returnStruct - > newResult ;
}
else //Throw an error if no override was set
{
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
2016-06-26 16:59:32 +02:00
dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > BlamePluginError ( dg - > plugin_callback , " Tried to override return value without return value being set " ) ;
2013-08-29 21:18:43 +02:00
}
}
break ;
default :
g_SHPtr - > SetRes ( MRES_IGNORED ) ;
mres = MRES_IGNORED ;
break ;
}
HandleSecurity sec ( dg - > plugin_callback - > GetParentRuntime ( ) - > GetDefaultContext ( ) - > GetIdentity ( ) , myself - > GetIdentity ( ) ) ;
if ( returnStruct )
{
handlesys - > FreeHandle ( rHndl , & sec ) ;
}
if ( paramStruct )
{
handlesys - > FreeHandle ( pHndl , & sec ) ;
}
if ( dg - > returnType = = ReturnType_Void | | mres < = MRES_HANDLED )
{
* string_result = NULL_STRING ;
return string_result ;
}
return string_result ;
}
# endif