Remove unused code.
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,
28 #include "cssdm_main.h"
29 #include "cssdm_headers.h"
30 #include "cssdm_utils.h"
31 #include "cssdm_events.h"
32 #include "cssdm_players.h"
33 #include "cssdm_ctrl.h"
34 #include "cssdm_config.h"
35 #include "cssdm_ffa.h"
36 #include "cssdm_callbacks.h"
37 #include "cssdm_weapons.h"
38 #include "cssdm_detours.h"
39 #include "cssdm_version.h"
41 SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
42 SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, 0)
43 SH_DECL_HOOK0_void(IServerGameDLL, DLLShutdown, SH_NOATTRIB, false);
44 SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, false, edict_t *, const CCommand &);
47 IGameEventManager2 *gameevents = NULL;
48 IBaseFileSystem *basefilesystem = NULL;
49 IBinTools *bintools = NULL;
50 IGameConfig *g_pDmConf = NULL;
51 CGlobalVars *gpGlobals = NULL;
52 IPlayerInfoManager *playerinfomngr = NULL;
53 IServerGameEnts *gameents = NULL;
54 IServerGameClients *gameclients = NULL;
55 ISourcePawnEngine *spengine = NULL;
56 IBotManager *botmanager = NULL;
57 char g_GlobError[255] = {0};
58 bool g_IsLoadedOkay = false;
59 bool g_Startup = false;
60 bool g_IsInGlobalShutdown = false;
64 #define VERIFY_SIGNATURE(name) \
65 if (!g_pDmConf->GetMemSig(name, &addr) || !addr) { \
66 snprintf(error, maxlength, "Could not find signature \"%s\"", name); \
70 #define VERIFY_OFFSET(name) \
71 if (!g_pDmConf->GetOffset(name, &offset) || !offset) { \
72 snprintf(error, maxlength, "Could not find offset \"%s\"", name); \
76 #define HOOK_EVENT2(name) \
77 if (!gameevents->AddListener(&g_cls_event_##name, #name, true)) { \
78 snprintf(error, maxlength, "Could not hook event \"%s\"", #name); \
82 #define UNHOOK_EVENT2(name) gameevents->RemoveListener(&g_cls_event_##name);
84 bool Deathmatch::SDK_OnLoad(char *error, size_t maxlength, bool late)
86 sharesys->AddDependency(myself, "bintools.ext", true, true);
87 sharesys->AddNatives(myself, g_BaseNatives);
88 if (!gameconfs->LoadGameConfigFile("cssdm.games", &g_pDmConf, error, maxlength))
95 VERIFY_OFFSET("CSWeaponDropPatch");
96 VERIFY_SIGNATURE("UTIL_Remove");
97 VERIFY_SIGNATURE("RoundRespawn");
98 VERIFY_SIGNATURE("CSWeaponDrop");
99 VERIFY_SIGNATURE("DropWeapons");
100 VERIFY_OFFSET("Weapon_GetSlot");
101 VERIFY_OFFSET("RemoveAllItems");
102 VERIFY_OFFSET("DropWeaponsPatch");
103 VERIFY_OFFSET("GiveAmmo");
105 if (!DM_ParseWeapons(error, maxlength))
110 gpGlobals = g_SMAPI->GetCGlobals();
112 SM_InitConCommandBase();
114 spengine = g_pSM->GetScriptingEngine();
119 bool Deathmatch::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
121 GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
122 GET_V_IFACE_CURRENT(GetFileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
123 GET_V_IFACE_ANY(GetServerFactory, playerinfomngr, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
124 GET_V_IFACE_ANY(GetServerFactory, gameents,IServerGameEnts, INTERFACEVERSION_SERVERGAMEENTS);
125 GET_V_IFACE_ANY(GetServerFactory, botmanager, IBotManager, INTERFACEVERSION_PLAYERBOTMANAGER);
126 GET_V_IFACE_ANY(GetServerFactory, gameclients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
127 GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
134 g_IsInGlobalShutdown = true;
135 RETURN_META(MRES_IGNORED);
138 void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
140 OnLevelInitialized();
141 RETURN_META(MRES_IGNORED);
147 RETURN_META(MRES_IGNORED);
150 bool Startup(char *error, size_t maxlength)
152 playerhelpers->AddClientListener(&g_ClientListener);
154 HOOK_EVENT2(player_death);
155 HOOK_EVENT2(player_spawn);
156 HOOK_EVENT2(player_team);
157 HOOK_EVENT2(round_start);
158 HOOK_EVENT2(round_end);
159 HOOK_EVENT2(server_shutdown);
160 HOOK_EVENT2(item_pickup);
164 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, gamedll, ServerActivate, true);
165 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelShutdown, gamedll, LevelShutdown, false);
166 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLShutdown, gamedll, OnDLLShutdown, false);
167 SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, gameclients, OnClientCommand_Post, true);
172 if (!DM_Prepare_FFA(ffa_error, sizeof(ffa_error)))
174 g_pSM->LogError(myself, "FFA will not work: %s", ffa_error);
179 return InitializeUtils(error, maxlength);
184 /* Remove hooks that could have happened whether we got started up or not */
185 playerhelpers->RemoveClientListener(&g_ClientListener);
187 UNHOOK_EVENT2(player_death);
188 UNHOOK_EVENT2(player_spawn);
189 UNHOOK_EVENT2(player_team);
190 UNHOOK_EVENT2(round_start);
191 UNHOOK_EVENT2(round_end);
192 UNHOOK_EVENT2(server_shutdown);
193 UNHOOK_EVENT2(item_pickup);
195 /* If we were never started up, the rest of this is invalid */
201 /* Make sure stuff like FFA is cleaned up */
204 /* Destroy various internal things */
205 DM_ShutdownDetours();
206 DM_ShutdownCallbacks();
210 /* Unhook everything from SourceHook */
211 SH_REMOVE_HOOK_STATICFUNC(IServerGameClients, ClientCommand, gameclients, OnClientCommand_Post, true);
212 SH_REMOVE_HOOK_STATICFUNC(IServerGameDLL, DLLShutdown, gamedll, OnDLLShutdown, false);
213 SH_REMOVE_HOOK_STATICFUNC(IServerGameDLL, LevelShutdown, gamedll, LevelShutdown, false);
214 SH_REMOVE_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, gamedll, ServerActivate, true);
217 void Deathmatch::SDK_OnAllLoaded()
219 SM_GET_LATE_IFACE(BINTOOLS, bintools);
221 g_IsLoadedOkay = Startup(g_GlobError, sizeof(g_GlobError));
223 if (!QueryRunning(NULL, 0))
229 void Deathmatch::SDK_OnUnload()
233 gameconfs->CloseGameConfigFile(g_pDmConf);
236 bool Deathmatch::QueryRunning(char *error, size_t maxlength)
238 SM_CHECK_IFACE(BINTOOLS, bintools);
240 if (!g_IsLoadedOkay && g_GlobError[0] != '\0')
242 snprintf(error, maxlength, "%s", g_GlobError);
249 bool Deathmatch::QueryInterfaceDrop(SMInterface *pInterface)
251 if (pInterface == bintools)
259 void Deathmatch::NotifyInterfaceDrop(SMInterface *pInterface)
261 /* We have to take care of bintools early then... */
262 if (pInterface == bintools)
269 const char *Deathmatch::GetExtensionVerString()
271 return CSSDM_FULL_VERSION;