Added CS_GetClanTag and CS_SetClanTag natives to cstrike ext (bug 5122, r=fyren).
Added CS_GetClanTag and CS_SetClanTag natives to cstrike ext (
bug 5122, r=fyren).
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
2.1 --- a/gamedata/sm-cstrike.games.txt Thu Oct 13 13:17:22 2011 -0400
2.2 +++ b/gamedata/sm-cstrike.games.txt Thu Oct 13 13:17:29 2011 -0400
2.3 @@ -28,6 +28,13 @@
2.4 "linux" "2308"
2.5 "mac" "2308"
2.6 }
2.7 + //Offset into SetClanTag to find clan tag's offset from player
2.8 + "ClanTagOffset"
2.9 + {
2.10 + "windows" "24"
2.11 + "linux" "41"
2.12 + "mac" "29"
2.13 + }
2.14 }
2.15 "Signatures"
2.16 {
2.17 @@ -87,6 +94,13 @@
2.18 "linux" "@_Z13GetWeaponInfo10CSWeaponID"
2.19 "mac" "@_Z13GetWeaponInfo10CSWeaponID"
2.20 }
2.21 + "SetClanTag"
2.22 + {
2.23 + "library" "server"
2.24 + "windows" "\x55\x8B\xEC\x51\x89\x2A\x2A\x83\x2A\x2A\x2A\x74\x2A\x6A\x2A\x8B\x2A\x2A\x50"
2.25 + "linux" "@_ZN9CCSPlayer10SetClanTagEPKc"
2.26 + "mac" "@_ZN9CCSPlayer10SetClanTagEPKc"
2.27 + }
2.28 }
2.29 }
2.30 }
3.1 --- a/plugins/include/cstrike.inc Thu Oct 13 13:17:22 2011 -0400
3.2 +++ b/plugins/include/cstrike.inc Thu Oct 13 13:17:29 2011 -0400
3.3 @@ -191,7 +191,7 @@
3.4 */
3.5 native CS_TerminateRound(Float:delay, CSRoundEndReason:reason, bool:blockhook = false);
3.6
3.7 - /**
3.8 +/**
3.9 * Gets a weapon name from a weapon alias
3.10 *
3.11 * @param alias Weapons alias to get weapon name for.
3.12 @@ -203,7 +203,7 @@
3.13 */
3.14 native CS_GetTranslatedWeaponAlias(const String:alias[], String:weapon[], size);
3.15
3.16 - /**
3.17 +/**
3.18 * Gets a weapon's price
3.19 *
3.20 * @param client Client to check weapon price for.
3.21 @@ -217,6 +217,27 @@
3.22 native CS_GetWeaponPrice(client, CSWeaponID:id, bool:defaultprice = false);
3.23
3.24 /**
3.25 + * Gets a clients clan tag
3.26 + * @param client Client index to get clan tag for.
3.27 + * @param buffer Buffer to store clients clan tag in.
3.28 + * @param size Size of the buffer.
3.29 + * @return Number of non-null bytes written.
3.30 + *
3.31 + * @error Invalid client.
3.32 + */
3.33 + native CS_GetClientClanTag(client, String:buffer[], size);
3.34 +
3.35 +/**
3.36 + * Sets a clients clan tag
3.37 + * @param client Client index to set clan tag for.
3.38 + * @param tag Tag to set clients clan tag as.
3.39 + * @noreturn
3.40 + *
3.41 + * @error Invalid client.
3.42 + */
3.43 + native CS_SetClientClanTag(client, const String:tag[]);
3.44 +
3.45 +/**
3.46 * Do not edit below this line!
3.47 */
3.48 public Extension:__ext_cstrike =
3.49 @@ -240,6 +261,8 @@
3.50 MarkNativeAsOptional("CS_TerminateRound");
3.51 MarkNativeAsOptional("CS_GetTranslatedWeaponAlias");
3.52 MarkNativeAsOptional("CS_GetWeaponPrice");
3.53 + MarkNativeAsOptional("CS_GetClientClanTag");
3.54 + MarkNativeAsOptional("CS_SetClientClanTag");
3.55 }
3.56 #endif
3.57