extensions/cstrike/natives.cpp
changeset 3405 f3404440ef4a
parent 3359 7c8cc9db0328
child 3519 a116c415c73e
     1.1 --- a/extensions/cstrike/natives.cpp	Thu Oct 13 13:17:22 2011 -0400
     1.2 +++ b/extensions/cstrike/natives.cpp	Thu Oct 13 13:17:29 2011 -0400
     1.3 @@ -325,6 +325,7 @@
     1.4  	
     1.5  	return 1;
     1.6  }
     1.7 +
     1.8  static cell_t CS_GetWeaponPrice(IPluginContext *pContext, const cell_t *params)
     1.9  {
    1.10  	//Hard code return values for weapons that dont call GetWeaponPrice and always use default value.
    1.11 @@ -388,6 +389,83 @@
    1.12  	return CallPriceForward(params[1], weapon_name, price);
    1.13  }
    1.14  
    1.15 +static cell_t CS_GetClientClanTag(IPluginContext *pContext, const cell_t *params)
    1.16 +{
    1.17 +	static void *addr;
    1.18 +	if (!addr)
    1.19 +	{
    1.20 +		if (!g_pGameConf->GetMemSig("SetClanTag", &addr) || !addr)
    1.21 +		{
    1.22 +			return pContext->ThrowNativeError("Failed to locate function");
    1.23 +		}
    1.24 +	}
    1.25 +
    1.26 +	CBaseEntity *pEntity;
    1.27 +	if (!(pEntity = GetCBaseEntity(params[1], true)))
    1.28 +	{
    1.29 +		return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
    1.30 +	}
    1.31 +
    1.32 +	static int tagOffsetOffset = -1;
    1.33 +	static int tagOffset;
    1.34 +
    1.35 +	if (tagOffsetOffset == -1)
    1.36 +	{
    1.37 +		if (!g_pGameConf->GetOffset("ClanTagOffset", &tagOffsetOffset))
    1.38 +		{
    1.39 +			tagOffsetOffset = -1;
    1.40 +			return pContext->ThrowNativeError("Unable to find ClanTagOffset gamedata");
    1.41 +		}
    1.42 +
    1.43 +		tagOffset = *(int *)((intptr_t)addr + tagOffsetOffset);
    1.44 +	}
    1.45 +
    1.46 +	size_t len;
    1.47 +
    1.48 +	const char *src = (char *)((intptr_t)pEntity + tagOffset);
    1.49 +	pContext->StringToLocalUTF8(params[2], params[3], src, &len);
    1.50 +
    1.51 +	return len;
    1.52 +}
    1.53 +
    1.54 +static cell_t CS_SetClientClanTag(IPluginContext *pContext, const cell_t *params)
    1.55 +{
    1.56 +	static ICallWrapper *pWrapper = NULL;
    1.57 +
    1.58 +	if (!pWrapper)
    1.59 +	{
    1.60 +		REGISTER_NATIVE_ADDR("SetClanTag",
    1.61 +			PassInfo pass[2]; \
    1.62 +			pass[0].flags = PASSFLAG_BYVAL; \
    1.63 +			pass[0].type  = PassType_Basic; \
    1.64 +			pass[0].size  = sizeof(CBaseEntity *); \
    1.65 +			pass[1].flags = PASSFLAG_BYVAL; \
    1.66 +			pass[1].type  = PassType_Basic; \
    1.67 +			pass[1].size  = sizeof(char *); \
    1.68 +			pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))
    1.69 +	}
    1.70 +
    1.71 +	CBaseEntity *pEntity;
    1.72 +	if (!(pEntity = GetCBaseEntity(params[1], true)))
    1.73 +	{
    1.74 +		return pContext->ThrowNativeError("Client index %d is not valid", params[1]);
    1.75 +	}
    1.76 +
    1.77 +	char *szNewTag;
    1.78 +	pContext->LocalToString(params[2], &szNewTag);
    1.79 +
    1.80 +	unsigned char vstk[sizeof(CBaseEntity *) + sizeof(char *)];
    1.81 +	unsigned char *vptr = vstk;
    1.82 +
    1.83 +	*(CBaseEntity **)vptr = pEntity;
    1.84 +	vptr += sizeof(CBaseEntity *);
    1.85 +	*(char **)vptr = szNewTag;
    1.86 +
    1.87 +	pWrapper->Execute(vstk, NULL);
    1.88 +
    1.89 +	return 1;
    1.90 +}
    1.91 +
    1.92  sp_nativeinfo_t g_CSNatives[] = 
    1.93  {
    1.94  	{"CS_RespawnPlayer",			CS_RespawnPlayer}, 
    1.95 @@ -396,6 +474,8 @@
    1.96  	{"CS_TerminateRound",			CS_TerminateRound},
    1.97  	{"CS_GetTranslatedWeaponAlias",	CS_GetTranslatedWeaponAlias},
    1.98  	{"CS_GetWeaponPrice",			CS_GetWeaponPrice},
    1.99 +	{"CS_GetClientClanTag",			CS_GetClientClanTag},
   1.100 +	{"CS_SetClientClanTag",			CS_SetClientClanTag},
   1.101  	{NULL,							NULL}
   1.102  };
   1.103