Fix linux CSGO build for latest update.
3 * ===============================================================
4 * CS:S DM, Copyright (C) 2004-2007 AlliedModders LLC.
5 * By David "BAILOPAN" Anderson
7 * ===============================================================
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYING; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
27 #include "cssdm_headers.h"
28 #include "cssdm_callbacks.h"
29 #include "cssdm_config.h"
30 #include "cssdm_weapons.h"
31 #include "cssdm_players.h"
32 #include "cssdm_utils.h"
34 IForward *g_pOnClientDeath = NULL;
35 IForward *g_pOnClientSpawned = NULL;
36 IForward *g_pOnClientPostSpawned = NULL;
37 IForward *g_pOnSetSpawnMethod = NULL;
38 IForward *g_pOnStartup = NULL;
39 IForward *g_pOnShutdown = NULL;
41 void DM_InitCallbacks()
43 g_pOnClientDeath = forwards->CreateForward("DM_OnClientDeath", ET_Hook, 1, NULL, Param_Cell);
44 g_pOnClientSpawned = forwards->CreateForward("DM_OnClientSpawned", ET_Ignore, 1, NULL, Param_Cell);
45 g_pOnClientPostSpawned = forwards->CreateForward("DM_OnClientPostSpawned", ET_Ignore, 1, NULL, Param_Cell);
46 g_pOnSetSpawnMethod = forwards->CreateForward("DM_OnSetSpawnMethod", ET_Hook, 1, NULL, Param_String);
47 g_pOnStartup = forwards->CreateForward("DM_OnStartup", ET_Ignore, 0, NULL);
48 g_pOnShutdown = forwards->CreateForward("DM_OnShutdown", ET_Ignore, 0, NULL);
51 void DM_ShutdownCallbacks()
53 forwards->ReleaseForward(g_pOnClientDeath);
54 forwards->ReleaseForward(g_pOnClientSpawned);
55 forwards->ReleaseForward(g_pOnClientPostSpawned);
56 forwards->ReleaseForward(g_pOnSetSpawnMethod);
57 forwards->ReleaseForward(g_pOnStartup);
58 forwards->ReleaseForward(g_pOnShutdown);
61 bool DM_OnClientDeath(int client)
64 g_pOnClientDeath->PushCell(client);
65 g_pOnClientDeath->Execute(&res);
67 return (res == (cell_t)Pl_Continue);
70 void DM_OnClientSpawned(int client, bool wasDead)
72 g_pOnClientSpawned->PushCell(client);
73 g_pOnClientSpawned->Execute(NULL);
74 g_pOnClientPostSpawned->PushCell(client);
75 g_pOnClientPostSpawned->Execute(NULL);
78 void DM_OnSetSpawnMethod(const char *method)
80 g_pOnSetSpawnMethod->PushString(method);
81 g_pOnSetSpawnMethod->Execute(NULL);
86 g_pOnStartup->Execute(NULL);
91 g_pOnShutdown->Execute(NULL);
94 static cell_t DMN_GetSpawnMethod(IPluginContext *pContext, const cell_t *params)
96 pContext->StringToLocal(params[1], params[2], DM_GetSpawnMethod());
100 static cell_t DMN_GetWeaponID(IPluginContext *pContext, const cell_t *params)
105 pContext->LocalToString(params[1], &str);
106 if ((weapon = DM_FindWeapon(str)) == NULL)
114 static cell_t DMN_GetWeaponType(IPluginContext *pContext, const cell_t *params)
118 if ((weapon = DM_GetWeapon(params[1])) == NULL)
120 return pContext->ThrowNativeError("Invalid CS:S DM weapon id (%d)", params[1]);
123 return (cell_t)weapon->type;
126 static cell_t DMN_GetWeaponClassname(IPluginContext *pContext, const cell_t *params)
130 if ((weapon = DM_GetWeapon(params[1])) == NULL)
132 return pContext->ThrowNativeError("Invalid CS:S DM weapon id (%d)", params[1]);
135 pContext->StringToLocal(params[2], params[3], weapon->classname);
140 static cell_t DMN_GetWeaponName(IPluginContext *pContext, const cell_t *params)
144 if ((weapon = DM_GetWeapon(params[1])) == NULL)
146 return pContext->ThrowNativeError("Invalid CS:S DM weapon id (%d)", params[1]);
149 pContext->StringToLocal(params[2], params[3], weapon->display);
154 static cell_t DMN_StripBotItems(IPluginContext *pContext, const cell_t *params)
156 if (params[1] < 1 || params[1] > gpGlobals->maxClients)
158 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
161 dm_player_t *player = DM_GetPlayer(params[1]);
162 if (!player->pEntity)
164 return pContext->ThrowNativeError("Client %d is not in game", params[1]);
169 return pContext->ThrowNativeError("Client %d is not a bot", params[1]);
172 player->pBot->RemoveAllItems(false);
177 static cell_t DMN_GetClientWeapon(IPluginContext *pContext, const cell_t *params)
179 if (params[1] < 1 || params[1] > gpGlobals->maxClients)
181 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
184 dm_player_t *player = DM_GetPlayer(params[1]);
185 if (!player->pEntity)
187 return pContext->ThrowNativeError("Client %d is not in game", params[1]);
190 CBaseEntity *pEntity = DM_GetWeaponFromSlot(player->pEntity, params[2]);
196 edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
202 return gamehelpers->IndexOfEdict(pEdict);
205 static cell_t DMN_DropWeapon(IPluginContext *pContext, const cell_t *params)
207 if (params[1] < 1 || params[1] > gpGlobals->maxClients)
209 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
212 dm_player_t *player = DM_GetPlayer(params[1]);
213 if (!player->pEntity)
215 return pContext->ThrowNativeError("Client %d is not in game", params[1]);
218 CBaseEntity *pWeapon = DM_GetBaseEntity(params[2]);
221 return pContext->ThrowNativeError("Entity %d is not a valid entity", params[2]);
224 DM_DropWeapon(player->pEntity, pWeapon);
229 static cell_t DMN_IsRunning(IPluginContext *pContext, const cell_t *params)
231 return g_IsRunning ? true : false;
234 static cell_t DMN_GetSpawnWaitTime(IPluginContext *pContext, const cell_t *params)
236 float f = DM_GetRespawnWait();
240 static cell_t DMN_RespawnClient(IPluginContext *pContext, const cell_t *params)
242 if (params[1] < 1 || params[1] > gpGlobals->maxClients)
244 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
247 dm_player_t *player = DM_GetPlayer(params[1]);
248 if (!player->pEntity)
250 return pContext->ThrowNativeError("Client %d is not in game", params[1]);
253 player->is_spawned = params[2] ? false : true;
255 DM_RespawnPlayer(params[1]);
260 static cell_t DMN_IsClientAlive(IPluginContext *pContext, const cell_t *params)
262 if (params[1] < 1 || params[1] > gpGlobals->maxClients)
264 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
267 dm_player_t *player = DM_GetPlayer(params[1]);
268 if (!player->pEntity)
270 return pContext->ThrowNativeError("Client %d is not in game", params[1]);
273 return DM_IsPlayerAlive(params[1]) ? 1 : 0;
276 static cell_t DMN_GiveAmmo(IPluginContext *pContext, const cell_t *params)
278 if (params[1] < 1 || params[1] > gpGlobals->maxClients)
280 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
283 dm_player_t *player = DM_GetPlayer(params[1]);
284 if (!player->pEntity)
286 return pContext->ThrowNativeError("Client %d is not in game", params[1]);
289 return DM_GiveAmmo(player->pEntity, params[2], params[3], params[4] ? true : false);
292 sp_nativeinfo_t g_BaseNatives[] =
294 {"DM_GetSpawnMethod", DMN_GetSpawnMethod},
295 {"DM_GetWeaponID", DMN_GetWeaponID},
296 {"DM_GetWeaponType", DMN_GetWeaponType},
297 {"DM_StripBotItems", DMN_StripBotItems},
298 {"DM_GetWeaponClassname", DMN_GetWeaponClassname},
299 {"DM_GetClientWeapon", DMN_GetClientWeapon},
300 {"DM_DropWeapon", DMN_DropWeapon},
301 {"DM_GetWeaponName", DMN_GetWeaponName},
302 {"DM_IsRunning", DMN_IsRunning},
303 {"DM_GetSpawnWaitTime", DMN_GetSpawnWaitTime},
304 {"DM_RespawnClient", DMN_RespawnClient},
305 {"DM_IsClientAlive", DMN_IsClientAlive},
306 {"DM_GiveClientAmmo", DMN_GiveAmmo},