extensions/sdktools/vcaller.cpp
changeset 1065 11756fc9fb63
parent 1042 a435a9c324df
child 1130 ff50b695a042
     1.1 --- a/extensions/sdktools/vcaller.cpp	Sun Jul 08 09:34:20 2007 +0000
     1.2 +++ b/extensions/sdktools/vcaller.cpp	Sun Jul 08 09:46:27 2007 +0000
     1.3 @@ -23,6 +23,7 @@
     1.4  
     1.5  #include "extension.h"
     1.6  #include "vcallbuilder.h"
     1.7 +#include "gamerules.h"
     1.8  
     1.9  enum SDKLibrary
    1.10  {
    1.11 @@ -245,25 +246,50 @@
    1.12  	unsigned int startparam = 2;
    1.13  	/* Do we need to write a thispointer?  */
    1.14  
    1.15 -	if (vc->thisinfo && 
    1.16 -		(vc->thisinfo->vtype == Valve_CBaseEntity
    1.17 -		 || vc->thisinfo->vtype == Valve_CBasePlayer))
    1.18 +	if (vc->thisinfo)
    1.19  	{
    1.20 -		if (startparam > numparams)
    1.21 +		switch (vc->type)
    1.22  		{
    1.23 -			vc->stk_put(ptr);
    1.24 -			return pContext->ThrowNativeError("Expected 1 parameter for entity pointer; found none");
    1.25 +		case ValveCall_Entity:
    1.26 +		case ValveCall_Player:
    1.27 +			{
    1.28 +				if (startparam > numparams)
    1.29 +				{
    1.30 +					vc->stk_put(ptr);
    1.31 +					return pContext->ThrowNativeError("Expected 1 parameter for entity pointer; found none");
    1.32 +				}
    1.33 +
    1.34 +				if (DecodeValveParam(pContext, 
    1.35 +					params[startparam],
    1.36 +					vc,
    1.37 +					vc->thisinfo,
    1.38 +					ptr) == Data_Fail)
    1.39 +				{
    1.40 +					vc->stk_put(ptr);
    1.41 +					return 0;
    1.42 +				}
    1.43 +				startparam++;
    1.44 +			}
    1.45 +			break;
    1.46 +		case ValveCall_GameRules:
    1.47 +			{
    1.48 +				if (g_pGameRules == NULL)
    1.49 +				{
    1.50 +					vc->stk_put(ptr);
    1.51 +					return pContext->ThrowNativeError("GameRules unsupported or not available; file a bug report");
    1.52 +				}
    1.53 +
    1.54 +				void *gamerules = *g_pGameRules;
    1.55 +
    1.56 +				if (gamerules == NULL)
    1.57 +				{
    1.58 +					vc->stk_put(ptr);
    1.59 +					return pContext->ThrowNativeError("GameRules not available before map is loaded");
    1.60 +				}
    1.61 +				*(void **)ptr = gamerules;
    1.62 +			}
    1.63 +			break;
    1.64  		}
    1.65 -		if (DecodeValveParam(pContext, 
    1.66 -			params[startparam],
    1.67 -			vc,
    1.68 -			vc->thisinfo,
    1.69 -			ptr) == Data_Fail)
    1.70 -		{
    1.71 -			vc->stk_put(ptr);
    1.72 -			return 0;
    1.73 -		}
    1.74 -		startparam++;
    1.75  	}
    1.76  
    1.77  	/* See if we need to skip any more parameters */