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 engine->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 engine->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 defined ORANGEBOX_BUILD
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 = engine->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 engine->IndexOfEdict(pEdict);
645 static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
647 static ValveCall *pCall = NULL;
650 ValvePassInfo pass[3];
651 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
652 InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL);
653 InitPass(pass[2], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
654 if (!CreateBaseCall("CreateEntityByName", ValveCall_Static, &pass[2], pass, 2, &pCall))
656 return pContext->ThrowNativeError("\"CreateEntityByName\" not supported by this mod");
658 return pContext->ThrowNativeError("\"CreateEntityByName\" wrapper failed to initialized");
662 CBaseEntity *pEntity = NULL;
664 DECODE_VALVE_PARAM(1, vparams, 0);
665 DECODE_VALVE_PARAM(2, vparams, 1);
666 FINISH_CALL_SIMPLE(&pEntity);
673 edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
679 return engine->IndexOfEdict(pEdict);
682 static cell_t DispatchSpawn(IPluginContext *pContext, const cell_t *params)
684 static ValveCall *pCall = NULL;
687 ValvePassInfo pass[2];
688 InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
689 InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL);
690 if (!CreateBaseCall("DispatchSpawn", ValveCall_Static, &pass[1], pass, 1, &pCall))
692 return pContext->ThrowNativeError("\"DispatchSpawn\" not supported by this mod");
694 return pContext->ThrowNativeError("\"DispatchSpawn\" wrapper failed to initialized");
700 DECODE_VALVE_PARAM(1, vparams, 0);
701 FINISH_CALL_SIMPLE(&ret);
703 return (ret == -1) ? 0 : 1;
706 static cell_t DispatchKeyValue(IPluginContext *pContext, const cell_t *params)
708 static ValveCall *pCall = NULL;
711 ValvePassInfo pass[3];
712 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
713 InitPass(pass[1], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
714 InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
715 if (!CreateBaseCall("DispatchKeyValue", ValveCall_Entity, &pass[2], pass, 2, &pCall))
717 return pContext->ThrowNativeError("\"DispatchKeyValue\" not supported by this mod");
719 return pContext->ThrowNativeError("\"DispatchKeyValue\" wrapper failed to initialized");
725 DECODE_VALVE_PARAM(1, thisinfo, 0);
726 DECODE_VALVE_PARAM(2, vparams, 0);
727 DECODE_VALVE_PARAM(3, vparams, 1);
728 FINISH_CALL_SIMPLE(&ret);
730 return (ret) ? 1 : 0;
733 static cell_t DispatchKeyValueFloat(IPluginContext *pContext, const cell_t *params)
735 static ValveCall *pCall = NULL;
738 ValvePassInfo pass[3];
739 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
740 InitPass(pass[1], Valve_Float, PassType_Float, PASSFLAG_BYVAL);
741 InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
742 if (!CreateBaseCall("DispatchKeyValueFloat", ValveCall_Entity, &pass[2], pass, 2, &pCall))
744 return pContext->ThrowNativeError("\"DispatchKeyValueFloat\" not supported by this mod");
746 return pContext->ThrowNativeError("\"DispatchKeyValueFloat\" wrapper failed to initialized");
752 DECODE_VALVE_PARAM(1, thisinfo, 0);
753 DECODE_VALVE_PARAM(2, vparams, 0);
754 DECODE_VALVE_PARAM(3, vparams, 1);
755 FINISH_CALL_SIMPLE(&ret);
757 return (ret) ? 1 : 0;
760 static cell_t DispatchKeyValueVector(IPluginContext *pContext, const cell_t *params)
762 static ValveCall *pCall = NULL;
765 ValvePassInfo pass[3];
766 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
767 #if defined ORANGEBOX_BUILD
768 InitPass(pass[1], Valve_Vector, PassType_Basic, PASSFLAG_BYVAL);
770 InitPass(pass[1], Valve_Vector, PassType_Object, PASSFLAG_BYVAL|PASSFLAG_OCTOR|PASSFLAG_OASSIGNOP);
772 InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL);
773 if (!CreateBaseCall("DispatchKeyValueVector", ValveCall_Entity, &pass[2], pass, 2, &pCall))
775 return pContext->ThrowNativeError("\"DispatchKeyValueVector\" not supported by this mod");
777 return pContext->ThrowNativeError("\"DispatchKeyValueVector\" wrapper failed to initialized");
783 DECODE_VALVE_PARAM(1, thisinfo, 0);
784 DECODE_VALVE_PARAM(2, vparams, 0);
785 DECODE_VALVE_PARAM(3, vparams, 1);
786 FINISH_CALL_SIMPLE(&ret);
788 return (ret) ? 1 : 0;
791 static cell_t sm_GetClientAimTarget(IPluginContext *pContext, const cell_t *params)
793 int client = params[1];
794 IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
798 return pContext->ThrowNativeError("Invalid client index %d", client);
800 else if (!pPlayer->IsInGame())
802 return pContext->ThrowNativeError("Client %d is not in game", client);
805 return GetClientAimTarget(pPlayer->GetEdict(), params[2] ? true : false);
808 static cell_t sm_SetEntityModel(IPluginContext *pContext, const cell_t *params)
810 static ValveCall *pCall = NULL;
813 ValvePassInfo pass[1];
814 InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
815 if (!CreateBaseCall("SetEntityModel", ValveCall_Entity, NULL, pass, 1, &pCall))
817 return pContext->ThrowNativeError("\"SetEntityModel\" not supported by this mod");
819 return pContext->ThrowNativeError("\"SetEntityModel\" wrapper failed to initialized");
824 DECODE_VALVE_PARAM(1, thisinfo, 0);
825 DECODE_VALVE_PARAM(2, vparams, 0);
826 FINISH_CALL_SIMPLE(NULL);
831 static cell_t GetPlayerDecalFile(IPluginContext *pContext, const cell_t *params)
833 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
836 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
838 if (!player->IsInGame())
840 return pContext->ThrowNativeError("Client %d is not in game", params[1]);
846 if (!GetPlayerInfo(params[1], &info) || !info.customFiles[0])
851 pContext->LocalToString(params[2], &buffer);
852 Q_binarytohex((byte *)&info.customFiles[0], sizeof(info.customFiles[0]), buffer, params[3]);
857 static cell_t GetServerNetStats(IPluginContext *pContext, const cell_t *params)
861 return pContext->ThrowNativeError("IServer interface not supported, file a bug report.");
867 pContext->LocalToPhysAddr(params[1], &pIn);
868 pContext->LocalToPhysAddr(params[2], &pOut);
869 iserver->GetNetStats(in, out);
872 *pOut = sp_ftoc(out);
877 static cell_t WeaponEquip(IPluginContext *pContext, const cell_t *params)
879 static ValveCall *pCall = NULL;
882 ValvePassInfo pass[1];
883 InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL);
884 if (!CreateBaseCall("WeaponEquip", ValveCall_Player, NULL, pass, 1, &pCall))
886 return pContext->ThrowNativeError("\"WeaponEquip\" not supported by this mod");
888 return pContext->ThrowNativeError("\"WeaponEquip\" wrapper failed to initialized");
893 DECODE_VALVE_PARAM(1, thisinfo, 0);
894 DECODE_VALVE_PARAM(2, vparams, 0);
895 FINISH_CALL_SIMPLE(NULL);
900 static cell_t ActivateEntity(IPluginContext *pContext, const cell_t *params)
902 static ValveCall *pCall = NULL;
905 if (!CreateBaseCall("Activate", ValveCall_Entity, NULL, NULL, 0, &pCall))
907 return pContext->ThrowNativeError("\"Activate\" not supported by this mod");
911 return pContext->ThrowNativeError("\"Activate\" wrapper failed to initialized");
916 DECODE_VALVE_PARAM(1, thisinfo, 0);
917 FINISH_CALL_SIMPLE(NULL);
922 static cell_t SetClientInfo(IPluginContext *pContext, const cell_t *params)
924 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
925 IClient *pClient = iserver->GetClient(params[1]-1);
926 if (player == NULL || pClient == NULL)
928 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
930 if (!player->IsConnected())
932 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
935 static ValveCall *pCall = NULL;
938 ValvePassInfo params[2];
939 InitPass(params[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
940 InitPass(params[1], Valve_String, PassType_Basic, PASSFLAG_BYVAL);
942 if (!CreateBaseCall("SetUserCvar", ValveCall_Entity, NULL, params, 2, &pCall))
944 return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod");
948 return pContext->ThrowNativeError("\"SetUserCvar\" wrapper failed to initialized");
952 static int changedOffset = -1;
954 if (changedOffset == -1)
956 if (!g_pGameConf->GetOffset("InfoChanged", &changedOffset))
958 return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod");
962 unsigned char *CGameClient = (unsigned char *)pClient - 4;
965 /* Not really a CBaseEntity* but this works */
966 CBaseEntity **ebuf = (CBaseEntity **)vptr;
967 *ebuf = (CBaseEntity *)CGameClient;
968 DECODE_VALVE_PARAM(2, vparams, 0);
969 DECODE_VALVE_PARAM(3, vparams, 1);
970 FINISH_CALL_SIMPLE(NULL);
972 uint8_t* changed = (uint8_t *)(CGameClient + changedOffset);
978 sp_nativeinfo_t g_Natives[] =
980 {"ExtinguishEntity", ExtinguishEntity},
981 {"ForcePlayerSuicide", ForcePlayerSuicide},
982 {"GivePlayerItem", GiveNamedItem},
983 {"GetPlayerWeaponSlot", GetPlayerWeaponSlot},
984 {"IgniteEntity", IgniteEntity},
985 {"RemovePlayerItem", RemovePlayerItem},
986 {"TeleportEntity", TeleportEntity},
987 {"SetClientViewEntity", SetClientViewEntity},
988 {"SetLightStyle", SetLightStyle},
989 {"SlapPlayer", SlapPlayer},
990 {"GetClientEyePosition", GetClientEyePosition},
991 {"GetClientEyeAngles", GetClientEyeAngles},
992 {"FindEntityByClassname", FindEntityByClassname},
993 {"CreateEntityByName", CreateEntityByName},
994 {"DispatchSpawn", DispatchSpawn},
995 {"DispatchKeyValue", DispatchKeyValue},
996 {"DispatchKeyValueFloat", DispatchKeyValueFloat},
997 {"DispatchKeyValueVector", DispatchKeyValueVector},
998 {"GetClientAimTarget", sm_GetClientAimTarget},
999 {"SetEntityModel", sm_SetEntityModel},
1000 {"GetPlayerDecalFile", GetPlayerDecalFile},
1001 {"GetServerNetStats", GetServerNetStats},
1002 {"EquipPlayerWeapon", WeaponEquip},
1003 {"ActivateEntity", ActivateEntity},
1004 {"SetClientInfo", SetClientInfo},