Merge from sourcemod-1.1 branch.
3 * =============================================================================
4 * SourceMod SDKTools Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
33 #include <sh_string.h>
34 #include "extension.h"
35 #include "vcallbuilder.h"
39 #include "CellRecipientFilter.h"
40 #include <inetchannel.h>
44 SourceHook::List<ValveCall *> g_RegCalls;
45 SourceHook::List<ICallWrapper *> g_CallWraps;
47 inline void InitPass(ValvePassInfo &info, ValveType vtype, PassType type, unsigned int flags, unsigned int decflags=0)
49 info.decflags = decflags;
56 #define START_CALL() \
57 unsigned char *vptr = pCall->stk_get();
59 #define FINISH_CALL_SIMPLE(vret) \
60 pCall->call->Execute(vptr, vret); \
63 #define ENCODE_VALVE_PARAM(num, which, vnum) \
64 if (EncodeValveParam(pContext, \
67 &pCall->which[vnum], \
74 #define DECODE_VALVE_PARAM(num, which, vnum) \
75 if (DecodeValveParam(pContext, \
78 &pCall->which[vnum], \
85 bool CreateBaseCall(const char *name,
86 ValveCallType vcalltype,
87 const ValvePassInfo *retinfo,
88 const ValvePassInfo params[],
89 unsigned int numParams,
94 if (g_pGameConf->GetOffset(name, &offset))
96 call = CreateValveVCall(offset, vcalltype, retinfo, params, numParams);
99 g_RegCalls.push_back(call);
105 if (g_pGameConf->GetMemSig(name, &addr) && addr != NULL)
107 call = CreateValveCall(addr, vcalltype, retinfo, params, numParams);
110 g_RegCalls.push_back(call);
119 static cell_t RemovePlayerItem(IPluginContext *pContext, const cell_t *params)
121 static ValveCall *pCall = NULL;
124 ValvePassInfo pass[2];
125 InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
126 InitPass(pass[1], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
127 if (!CreateBaseCall("RemovePlayerItem", ValveCall_Player, &pass[1], pass, 1, &pCall))
129 return pContext->ThrowNativeError("\"RemovePlayerItem\" not supported by this mod");
131 return pContext->ThrowNativeError("\"RemovePlayerItem\" wrapper failed to initialized");
137 DECODE_VALVE_PARAM(1, thisinfo, 0);
138 DECODE_VALVE_PARAM(2, vparams, 0);
139 FINISH_CALL_SIMPLE(&ret);
143 static cell_t GiveNamedItem(IPluginContext *pContext, const cell_t *params)
145 static ValveCall *pCall = NULL;
148 ValvePassInfo pass[3];
149 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
150 InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL);
151 InitPass(pass[2], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
152 if (!CreateBaseCall("GiveNamedItem", ValveCall_Player, &pass[2], pass, 2, &pCall))
154 return pContext->ThrowNativeError("\"GiveNamedItem\" not supported by this mod");
156 return pContext->ThrowNativeError("\"GiveNamedItem\" wrapper failed to initialized");
160 CBaseEntity *pEntity = NULL;
162 DECODE_VALVE_PARAM(1, thisinfo, 0);
163 DECODE_VALVE_PARAM(2, vparams, 0);
164 DECODE_VALVE_PARAM(3, vparams, 1);
165 FINISH_CALL_SIMPLE(&pEntity);
172 edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
178 return IndexOfEdict(pEdict);
181 static cell_t GetPlayerWeaponSlot(IPluginContext *pContext, const cell_t *params)
183 static ValveCall *pCall = NULL;
186 ValvePassInfo pass[2];
187 InitPass(pass[0], Valve_POD, PassType_Basic, PASSFLAG_BYVAL);
188 InitPass(pass[1], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
189 if (!CreateBaseCall("Weapon_GetSlot", ValveCall_Player, &pass[1], pass, 1, &pCall))
191 return pContext->ThrowNativeError("\"Weapon_GetSlot\" not supported by this mod");
193 return pContext->ThrowNativeError("\"Weapon_GetSlot\" wrapper failed to initialized");
197 CBaseEntity *pEntity;
199 DECODE_VALVE_PARAM(1, thisinfo, 0);
200 DECODE_VALVE_PARAM(2, vparams, 0);
201 FINISH_CALL_SIMPLE(&pEntity);
208 edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
214 return IndexOfEdict(pEdict);
217 static cell_t IgniteEntity(IPluginContext *pContext, const cell_t *params)
219 static ValveCall *pCall = NULL;
222 ValvePassInfo pass[4];
223 InitPass(pass[0], Valve_Float, PassType_Float, PASSFLAG_BYVAL);
224 InitPass(pass[1], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
225 InitPass(pass[2], Valve_Float, PassType_Float, PASSFLAG_BYVAL);
226 InitPass(pass[3], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
227 if (!CreateBaseCall("Ignite", ValveCall_Entity, NULL, pass, 4, &pCall))
229 return pContext->ThrowNativeError("\"Ignite\" not supported by this mod");
231 return pContext->ThrowNativeError("\"Ignite\" wrapper failed to initialized");
236 DECODE_VALVE_PARAM(1, thisinfo, 0);
237 DECODE_VALVE_PARAM(2, vparams, 0);
238 DECODE_VALVE_PARAM(3, vparams, 1);
239 DECODE_VALVE_PARAM(4, vparams, 2);
240 DECODE_VALVE_PARAM(5, vparams, 3);
241 FINISH_CALL_SIMPLE(NULL);
246 static cell_t ExtinguishEntity(IPluginContext *pContext, const cell_t *params)
248 static ValveCall *pCall = NULL;
251 if (!CreateBaseCall("Extinguish", ValveCall_Entity, NULL, NULL, 0, &pCall))
253 return pContext->ThrowNativeError("\"Extinguish\" not supported by this mod");
255 return pContext->ThrowNativeError("\"Extinguish\" wrapper failed to initialized");
260 DECODE_VALVE_PARAM(1, thisinfo, 0);
261 FINISH_CALL_SIMPLE(NULL);
266 static cell_t TeleportEntity(IPluginContext *pContext, const cell_t *params)
268 static ValveCall *pCall = NULL;
271 ValvePassInfo pass[3];
272 InitPass(pass[0], Valve_Vector, PassType_Basic, PASSFLAG_BYVAL, VDECODE_FLAG_ALLOWNULL);
273 InitPass(pass[1], Valve_QAngle, PassType_Basic, PASSFLAG_BYVAL, VDECODE_FLAG_ALLOWNULL);
274 InitPass(pass[2], Valve_Vector, PassType_Basic, PASSFLAG_BYVAL, VDECODE_FLAG_ALLOWNULL);
275 if (!CreateBaseCall("Teleport", ValveCall_Entity, NULL, pass, 3, &pCall))
277 return pContext->ThrowNativeError("\"Teleport\" not supported by this mod");
279 return pContext->ThrowNativeError("\"Teleport\" wrapper failed to initialized");
284 DECODE_VALVE_PARAM(1, thisinfo, 0);
285 DECODE_VALVE_PARAM(2, vparams, 0);
286 DECODE_VALVE_PARAM(3, vparams, 1);
287 DECODE_VALVE_PARAM(4, vparams, 2);
288 FINISH_CALL_SIMPLE(NULL);
293 #if SOURCE_ENGINE >= SE_ORANGEBOX
294 /* :TODO: This is Team Fortress 2 specific */
295 static cell_t ForcePlayerSuicide(IPluginContext *pContext, const cell_t *params)
297 static ValveCall *pCall = NULL;
300 ValvePassInfo pass[2];
301 InitPass(pass[0], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
302 InitPass(pass[1], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
303 if (!CreateBaseCall("CommitSuicide", ValveCall_Player, NULL, pass, 2, &pCall))
305 return pContext->ThrowNativeError("\"CommitSuicide\" not supported by this mod");
309 return pContext->ThrowNativeError("\"CommitSuicide\" wrapper failed to initialized");
314 DECODE_VALVE_PARAM(1, thisinfo, 0);
315 *(bool *)(vptr + 4) = false;
316 *(bool *)(vptr + 5) = false;
317 FINISH_CALL_SIMPLE(NULL);
322 static cell_t ForcePlayerSuicide(IPluginContext *pContext, const cell_t *params)
324 static ValveCall *pCall = NULL;
327 if (!CreateBaseCall("CommitSuicide", ValveCall_Player, NULL, NULL, 0, &pCall))
329 return pContext->ThrowNativeError("\"CommitSuicide\" not supported by this mod");
331 return pContext->ThrowNativeError("\"CommitSuicide\" wrapper failed to initialized");
336 DECODE_VALVE_PARAM(1, thisinfo, 0);
337 FINISH_CALL_SIMPLE(NULL);
343 static cell_t SetClientViewEntity(IPluginContext *pContext, const cell_t *params)
345 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
348 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
350 if (!player->IsInGame())
352 return pContext->ThrowNativeError("Client %d is not in game", params[1]);
355 edict_t *pEdict = PEntityOfEntIndex(params[2]);
356 if (!pEdict || pEdict->IsFree())
358 return pContext->ThrowNativeError("Entity %d is not valid", params[2]);
361 engine->SetView(player->GetEdict(), pEdict);
366 static SourceHook::String *g_lightstyle[MAX_LIGHTSTYLES] = {NULL};
367 static cell_t SetLightStyle(IPluginContext *pContext, const cell_t *params)
369 int style = params[1];
370 if (style >= MAX_LIGHTSTYLES)
372 return pContext->ThrowNativeError("Light style %d is invalid (range: 0-%d)", style, MAX_LIGHTSTYLES - 1);
375 if (g_lightstyle[style] == NULL)
377 /* We allocate and never free this because the Engine wants to hold onto it :\
378 * in theory we could hook light style and know whether we're supposed to free
379 * this or not on shutdown, but for ~4K of memory MAX, it doesn't seem worth it yet.
382 g_lightstyle[style] = new SourceHook::String();
386 pContext->LocalToString(params[2], &str);
388 g_lightstyle[style]->assign(str);
390 engine->LightStyle(style, g_lightstyle[style]->c_str());
395 static cell_t SlapPlayer(IPluginContext *pContext, const cell_t *params)
397 static bool s_slap_supported = false;
398 static bool s_slap_setup = false;
399 static ICallWrapper *s_teleport = NULL;
400 static int s_health_offs = 0;
401 static int s_sound_count = 0;
402 static int s_frag_offs = 0;
410 if (IsTeleportSupported())
414 if (IsGetVelocitySupported())
420 if (g_pGameConf->GetOffset("m_iHealth", &s_health_offs) && s_health_offs)
427 s_slap_supported = true;
430 if ((key = g_pGameConf->GetKeyValue("SlapSoundCount")) != NULL)
432 s_sound_count = atoi(key);
437 if (!s_slap_supported)
439 return pContext->ThrowNativeError("This function is not supported on this mod");
442 /* First check if the client is valid */
443 int client = params[1];
444 IGamePlayer *player = playerhelpers->GetGamePlayer(client);
447 return pContext->ThrowNativeError("Client %d is not valid", client);
448 } else if (!player->IsInGame()) {
449 return pContext->ThrowNativeError("Client %d is not in game", client);
452 edict_t *pEdict = player->GetEdict();
453 CBaseEntity *pEntity = pEdict->GetUnknown()->GetBaseEntity();
455 /* See if we should be taking away health */
456 bool should_slay = false;
459 int *health = (int *)((char *)pEntity + s_health_offs);
460 if (*health - params[2] <= 0)
465 *health -= params[2];
469 /* Teleport in a random direction - thank you, Mani!*/
471 GetVelocity(pEntity, &velocity, NULL);
472 velocity.x += ((rand() % 180) + 50) * (((rand() % 2) == 1) ? -1 : 1);
473 velocity.y += ((rand() % 180) + 50) * (((rand() % 2) == 1) ? -1 : 1);
474 velocity.z += rand() % 200 + 100;
475 Teleport(pEntity, NULL, NULL, &velocity);
477 /* Play a random sound */
478 if (params[3] && s_sound_count > 0)
481 const char *sound_name;
482 cell_t player_list[256], total_players = 0;
483 int maxClients = playerhelpers->GetMaxClients();
485 int r = (rand() % s_sound_count) + 1;
486 snprintf(name, sizeof(name), "SlapSound%d", r);
488 if ((sound_name = g_pGameConf->GetKeyValue(name)) != NULL)
491 for (int i=1; i<=maxClients; i++)
493 other = playerhelpers->GetGamePlayer(i);
494 if (other->IsInGame())
496 player_list[total_players++] = i;
500 const Vector & pos = pEdict->GetCollideable()->GetCollisionOrigin();
501 CellRecipientFilter rf;
502 rf.SetToReliable(true);
503 rf.Initialize(player_list, total_players);
504 engsound->EmitSound(rf, client, CHAN_AUTO, sound_name, VOL_NORM, ATTN_NORM, 0, PITCH_NORM, &pos);
510 const char *frag_prop = g_pGameConf->GetKeyValue("m_iFrags");
513 datamap_t *pMap = gamehelpers->GetDataMap(pEntity);
514 typedescription_t *pType = gamehelpers->FindInDataMap(pMap, frag_prop);
517 s_frag_offs = pType->fieldOffset[TD_OFFSET_NORMAL];
529 old_frags = *(int *)((char *)pEntity + s_frag_offs);
535 pluginhelpers->ClientCommand(pEdict, "kill\n");
540 *(int *)((char *)pEntity + s_frag_offs) = old_frags;
546 static cell_t GetClientEyePosition(IPluginContext *pContext, const cell_t *params)
548 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
551 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
553 if (!player->IsInGame())
555 return pContext->ThrowNativeError("Client %d is not in game", params[1]);
559 serverClients->ClientEarPosition(player->GetEdict(), &pos);
562 pContext->LocalToPhysAddr(params[2], &addr);
563 addr[0] = sp_ftoc(pos.x);
564 addr[1] = sp_ftoc(pos.y);
565 addr[2] = sp_ftoc(pos.z);
570 static cell_t GetClientEyeAngles(IPluginContext *pContext, const cell_t *params)
572 int client = params[1];
573 IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
577 return pContext->ThrowNativeError("Invalid client index %d", client);
579 else if (!pPlayer->IsInGame())
581 return pContext->ThrowNativeError("Client %d is not in game", client);
584 edict_t *pEdict = pPlayer->GetEdict();
585 CBaseEntity *pEntity = pEdict->GetUnknown() ? pEdict->GetUnknown()->GetBaseEntity() : NULL;
587 /* We always set the angles for backwards compatibility --
588 * The original function had no return value.
591 bool got_angles = false;
595 got_angles = GetEyeAngles(pEntity, &angles);
599 pContext->LocalToPhysAddr(params[2], &addr);
600 addr[0] = sp_ftoc(angles.x);
601 addr[1] = sp_ftoc(angles.y);
602 addr[2] = sp_ftoc(angles.z);
604 return got_angles ? 1 : 0;
607 static cell_t FindEntityByClassname(IPluginContext *pContext, const cell_t *params)
609 static ValveCall *pCall = NULL;
612 ValvePassInfo pass[3];
613 InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL, VDECODE_FLAG_ALLOWNULL|VDECODE_FLAG_ALLOWWORLD);
614 InitPass(pass[1], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
615 InitPass(pass[2], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
616 if (!CreateBaseCall("FindEntityByClassname", ValveCall_EntityList, &pass[2], pass, 2, &pCall))
618 return pContext->ThrowNativeError("\"FindEntityByClassname\" not supported by this mod");
620 return pContext->ThrowNativeError("\"FindEntityByClassname\" wrapper failed to initialized");
624 CBaseEntity *pEntity;
626 *(void **)vptr = g_EntList;
627 DECODE_VALVE_PARAM(1, vparams, 0);
628 DECODE_VALVE_PARAM(2, vparams, 1);
629 FINISH_CALL_SIMPLE(&pEntity);
636 edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
642 return IndexOfEdict(pEdict);
645 #if SOURCE_ENGINE == SE_LEFT4DEAD
646 static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
648 static ValveCall *pCall = NULL;
651 ValvePassInfo pass[4];
652 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
653 InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL);
654 InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
655 InitPass(pass[3], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
656 if (!CreateBaseCall("CreateEntityByName", ValveCall_Static, &pass[3], pass, 3, &pCall))
658 return pContext->ThrowNativeError("\"CreateEntityByName\" not supported by this mod");
660 return pContext->ThrowNativeError("\"CreateEntityByName\" wrapper failed to initialized");
664 CBaseEntity *pEntity = NULL;
666 DECODE_VALVE_PARAM(1, vparams, 0);
667 DECODE_VALVE_PARAM(2, vparams, 1);
668 *(bool *)(vptr + 8) = true;
669 FINISH_CALL_SIMPLE(&pEntity);
676 edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
682 return IndexOfEdict(pEdict);
685 static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
687 static ValveCall *pCall = NULL;
690 ValvePassInfo pass[3];
691 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
692 InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL);
693 InitPass(pass[2], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
694 if (!CreateBaseCall("CreateEntityByName", ValveCall_Static, &pass[2], pass, 2, &pCall))
696 return pContext->ThrowNativeError("\"CreateEntityByName\" not supported by this mod");
698 return pContext->ThrowNativeError("\"CreateEntityByName\" wrapper failed to initialized");
702 CBaseEntity *pEntity = NULL;
704 DECODE_VALVE_PARAM(1, vparams, 0);
705 DECODE_VALVE_PARAM(2, vparams, 1);
706 FINISH_CALL_SIMPLE(&pEntity);
713 edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
719 return IndexOfEdict(pEdict);
723 static cell_t DispatchSpawn(IPluginContext *pContext, const cell_t *params)
725 static ValveCall *pCall = NULL;
728 ValvePassInfo pass[2];
729 InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
730 InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL);
731 if (!CreateBaseCall("DispatchSpawn", ValveCall_Static, &pass[1], pass, 1, &pCall))
733 return pContext->ThrowNativeError("\"DispatchSpawn\" not supported by this mod");
735 return pContext->ThrowNativeError("\"DispatchSpawn\" wrapper failed to initialized");
741 DECODE_VALVE_PARAM(1, vparams, 0);
742 FINISH_CALL_SIMPLE(&ret);
744 return (ret == -1) ? 0 : 1;
747 static cell_t DispatchKeyValue(IPluginContext *pContext, const cell_t *params)
749 static ValveCall *pCall = NULL;
752 ValvePassInfo pass[3];
753 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
754 InitPass(pass[1], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
755 InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
756 if (!CreateBaseCall("DispatchKeyValue", ValveCall_Entity, &pass[2], pass, 2, &pCall))
758 return pContext->ThrowNativeError("\"DispatchKeyValue\" not supported by this mod");
760 return pContext->ThrowNativeError("\"DispatchKeyValue\" wrapper failed to initialized");
766 DECODE_VALVE_PARAM(1, thisinfo, 0);
767 DECODE_VALVE_PARAM(2, vparams, 0);
768 DECODE_VALVE_PARAM(3, vparams, 1);
769 FINISH_CALL_SIMPLE(&ret);
771 return (ret) ? 1 : 0;
774 static cell_t DispatchKeyValueFloat(IPluginContext *pContext, const cell_t *params)
776 static ValveCall *pCall = NULL;
779 ValvePassInfo pass[3];
780 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
781 InitPass(pass[1], Valve_Float, PassType_Float, PASSFLAG_BYVAL);
782 InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
783 if (!CreateBaseCall("DispatchKeyValueFloat", ValveCall_Entity, &pass[2], pass, 2, &pCall))
785 return pContext->ThrowNativeError("\"DispatchKeyValueFloat\" not supported by this mod");
787 return pContext->ThrowNativeError("\"DispatchKeyValueFloat\" wrapper failed to initialized");
793 DECODE_VALVE_PARAM(1, thisinfo, 0);
794 DECODE_VALVE_PARAM(2, vparams, 0);
795 DECODE_VALVE_PARAM(3, vparams, 1);
796 FINISH_CALL_SIMPLE(&ret);
798 return (ret) ? 1 : 0;
801 static cell_t DispatchKeyValueVector(IPluginContext *pContext, const cell_t *params)
803 static ValveCall *pCall = NULL;
806 ValvePassInfo pass[3];
807 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
808 #if SOURCE_ENGINE >= SE_ORANGEBOX
809 InitPass(pass[1], Valve_Vector, PassType_Basic, PASSFLAG_BYVAL);
811 InitPass(pass[1], Valve_Vector, PassType_Object, PASSFLAG_BYVAL|PASSFLAG_OCTOR|PASSFLAG_OASSIGNOP);
813 InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
814 if (!CreateBaseCall("DispatchKeyValueVector", ValveCall_Entity, &pass[2], pass, 2, &pCall))
816 return pContext->ThrowNativeError("\"DispatchKeyValueVector\" not supported by this mod");
818 return pContext->ThrowNativeError("\"DispatchKeyValueVector\" wrapper failed to initialized");
824 DECODE_VALVE_PARAM(1, thisinfo, 0);
825 DECODE_VALVE_PARAM(2, vparams, 0);
826 DECODE_VALVE_PARAM(3, vparams, 1);
827 FINISH_CALL_SIMPLE(&ret);
829 return (ret) ? 1 : 0;
832 static cell_t sm_GetClientAimTarget(IPluginContext *pContext, const cell_t *params)
834 int client = params[1];
835 IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
839 return pContext->ThrowNativeError("Invalid client index %d", client);
841 else if (!pPlayer->IsInGame())
843 return pContext->ThrowNativeError("Client %d is not in game", client);
846 return GetClientAimTarget(pPlayer->GetEdict(), params[2] ? true : false);
849 static cell_t sm_SetEntityModel(IPluginContext *pContext, const cell_t *params)
851 static ValveCall *pCall = NULL;
854 ValvePassInfo pass[1];
855 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
856 if (!CreateBaseCall("SetEntityModel", ValveCall_Entity, NULL, pass, 1, &pCall))
858 return pContext->ThrowNativeError("\"SetEntityModel\" not supported by this mod");
860 return pContext->ThrowNativeError("\"SetEntityModel\" wrapper failed to initialized");
865 DECODE_VALVE_PARAM(1, thisinfo, 0);
866 DECODE_VALVE_PARAM(2, vparams, 0);
867 FINISH_CALL_SIMPLE(NULL);
872 static cell_t GetPlayerDecalFile(IPluginContext *pContext, const cell_t *params)
874 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
877 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
879 if (!player->IsInGame())
881 return pContext->ThrowNativeError("Client %d is not in game", params[1]);
887 if (!GetPlayerInfo(params[1], &info) || !info.customFiles[0])
892 pContext->LocalToString(params[2], &buffer);
893 Q_binarytohex((byte *)&info.customFiles[0], sizeof(info.customFiles[0]), buffer, params[3]);
898 static cell_t GetServerNetStats(IPluginContext *pContext, const cell_t *params)
902 return pContext->ThrowNativeError("IServer interface not supported, file a bug report.");
908 pContext->LocalToPhysAddr(params[1], &pIn);
909 pContext->LocalToPhysAddr(params[2], &pOut);
910 iserver->GetNetStats(in, out);
913 *pOut = sp_ftoc(out);
918 static cell_t WeaponEquip(IPluginContext *pContext, const cell_t *params)
920 static ValveCall *pCall = NULL;
923 ValvePassInfo pass[1];
924 InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
925 if (!CreateBaseCall("WeaponEquip", ValveCall_Player, NULL, pass, 1, &pCall))
927 return pContext->ThrowNativeError("\"WeaponEquip\" not supported by this mod");
929 return pContext->ThrowNativeError("\"WeaponEquip\" wrapper failed to initialized");
934 DECODE_VALVE_PARAM(1, thisinfo, 0);
935 DECODE_VALVE_PARAM(2, vparams, 0);
936 FINISH_CALL_SIMPLE(NULL);
941 static cell_t ActivateEntity(IPluginContext *pContext, const cell_t *params)
943 static ValveCall *pCall = NULL;
946 if (!CreateBaseCall("Activate", ValveCall_Entity, NULL, NULL, 0, &pCall))
948 return pContext->ThrowNativeError("\"Activate\" not supported by this mod");
952 return pContext->ThrowNativeError("\"Activate\" wrapper failed to initialized");
957 DECODE_VALVE_PARAM(1, thisinfo, 0);
958 FINISH_CALL_SIMPLE(NULL);
963 static cell_t SetClientInfo(IPluginContext *pContext, const cell_t *params)
965 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
966 IClient *pClient = iserver->GetClient(params[1]-1);
967 if (player == NULL || pClient == NULL)
969 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
971 if (!player->IsConnected())
973 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
976 static ValveCall *pCall = NULL;
979 ValvePassInfo params[2];
980 InitPass(params[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
981 InitPass(params[1], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
983 if (!CreateBaseCall("SetUserCvar", ValveCall_Entity, NULL, params, 2, &pCall))
985 return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod");
989 return pContext->ThrowNativeError("\"SetUserCvar\" wrapper failed to initialized");
993 static int changedOffset = -1;
995 if (changedOffset == -1)
997 if (!g_pGameConf->GetOffset("InfoChanged", &changedOffset))
999 return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod");
1003 unsigned char *CGameClient = (unsigned char *)pClient - 4;
1006 /* Not really a CBaseEntity* but this works */
1007 CBaseEntity **ebuf = (CBaseEntity **)vptr;
1008 *ebuf = (CBaseEntity *)CGameClient;
1009 DECODE_VALVE_PARAM(2, vparams, 0);
1010 DECODE_VALVE_PARAM(3, vparams, 1);
1011 FINISH_CALL_SIMPLE(NULL);
1013 uint8_t* changed = (uint8_t *)(CGameClient + changedOffset);
1019 sp_nativeinfo_t g_Natives[] =
1021 {"ExtinguishEntity", ExtinguishEntity},
1022 {"ForcePlayerSuicide", ForcePlayerSuicide},
1023 {"GivePlayerItem", GiveNamedItem},
1024 {"GetPlayerWeaponSlot", GetPlayerWeaponSlot},
1025 {"IgniteEntity", IgniteEntity},
1026 {"RemovePlayerItem", RemovePlayerItem},
1027 {"TeleportEntity", TeleportEntity},
1028 {"SetClientViewEntity", SetClientViewEntity},
1029 {"SetLightStyle", SetLightStyle},
1030 {"SlapPlayer", SlapPlayer},
1031 {"GetClientEyePosition", GetClientEyePosition},
1032 {"GetClientEyeAngles", GetClientEyeAngles},
1033 {"FindEntityByClassname", FindEntityByClassname},
1034 {"CreateEntityByName", CreateEntityByName},
1035 {"DispatchSpawn", DispatchSpawn},
1036 {"DispatchKeyValue", DispatchKeyValue},
1037 {"DispatchKeyValueFloat", DispatchKeyValueFloat},
1038 {"DispatchKeyValueVector", DispatchKeyValueVector},
1039 {"GetClientAimTarget", sm_GetClientAimTarget},
1040 {"SetEntityModel", sm_SetEntityModel},
1041 {"GetPlayerDecalFile", GetPlayerDecalFile},
1042 {"GetServerNetStats", GetServerNetStats},
1043 {"EquipPlayerWeapon", WeaponEquip},
1044 {"ActivateEntity", ActivateEntity},
1045 {"SetClientInfo", SetClientInfo},