Debug build fixes.
3 * =============================================================================
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>.
32 #include "sourcemod.h"
33 #include "sourcemm_api.h"
34 #include <sourcemod_version.h>
36 #include "concmd_cleaner.h"
37 #include "compat_wrappers.h"
38 #include "logic_bridge.h"
40 SourceMod_Core g_SourceMod_Core;
41 IVEngineServer *engine = NULL;
42 IServerGameDLL *gamedll = NULL;
43 IServerGameClients *serverClients = NULL;
44 ISmmPluginManager *g_pMMPlugins = NULL;
45 CGlobalVars *gpGlobals = NULL;
47 IGameEventManager2 *gameevents = NULL;
48 IUniformRandomStream *engrandom = NULL;
49 CallClass<IVEngineServer> *enginePatch = NULL;
50 CallClass<IServerGameDLL> *gamedllPatch = NULL;
51 IPlayerInfoManager *playerinfo = NULL;
52 IBaseFileSystem *basefilesystem = NULL;
53 IFileSystem *filesystem = NULL;
54 IEngineSound *enginesound = NULL;
55 IServerPluginHelpers *serverpluginhelpers = NULL;
56 IServerPluginCallbacks *vsp_interface = NULL;
59 PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
61 bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
65 GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
66 GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
67 GET_V_IFACE_CURRENT(GetServerFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
68 GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
69 GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
70 GET_V_IFACE_CURRENT(GetEngineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
71 GET_V_IFACE_CURRENT(GetFileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
72 GET_V_IFACE_CURRENT(GetFileSystemFactory, filesystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);
73 GET_V_IFACE_CURRENT(GetEngineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
74 #if SOURCE_ENGINE != SE_DOTA
75 GET_V_IFACE_CURRENT(GetEngineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
78 /* :TODO: Make this optional and... make it find earlier versions [?] */
79 GET_V_IFACE_CURRENT(GetServerFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
81 if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
85 snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
90 gpGlobals = ismm->GetCGlobals();
92 ismm->AddListener(this, this);
94 #if defined METAMOD_PLAPI_VERSION || PLAPI_VERSION >= 11
95 if ((vsp_interface = g_SMAPI->GetVSPInfo(&vsp_version)) == NULL)
98 g_SMAPI->EnableVSPListener();
101 return g_SourceMod.InitializeSourceMod(error, maxlen, late);
104 bool SourceMod_Core::Unload(char *error, size_t maxlen)
106 g_SourceMod.CloseSourceMod();
110 bool SourceMod_Core::Pause(char *error, size_t maxlen)
115 bool SourceMod_Core::Unpause(char *error, size_t maxlen)
120 void SourceMod_Core::AllPluginsLoaded()
122 g_SourceMod.AllPluginsLoaded();
125 const char *SourceMod_Core::GetAuthor()
127 return "AlliedModders LLC";
130 const char *SourceMod_Core::GetName()
135 const char *SourceMod_Core::GetDescription()
137 return "Extensible administration and scripting system";
140 const char *SourceMod_Core::GetURL()
142 return "http://www.sourcemod.net/";
145 const char *SourceMod_Core::GetLicense()
147 return "See LICENSE.txt";
150 const char *SourceMod_Core::GetVersion()
152 return SM_VERSION_STRING;
155 const char *SourceMod_Core::GetDate()
160 const char *SourceMod_Core::GetLogTag()
165 void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
167 /* This shouldn't happen */
170 g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4.2 or greater.");
174 if (vsp_interface == NULL)
176 vsp_interface = iface;
184 #if defined METAMOD_PLAPI_VERSION || PLAPI_VERSION >= 11
185 if (vsp_version == 0)
187 g_SMAPI->GetVSPInfo(&vsp_version);
190 if (vsp_version == 0)
192 if (strcmp(g_SourceMod.GetGameFolderName(), "ship") == 0)
204 SMGlobalClass *pBase = SMGlobalClass::head;
207 pBase->OnSourceModVSPReceived();
208 pBase = pBase->m_pGlobalClassNext;
212 #if defined METAMOD_PLAPI_VERSION || PLAPI_VERSION >= 11
214 void SourceMod_Core::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
216 #if SOURCE_ENGINE < SE_ORANGEBOX
217 Global_OnUnlinkConCommandBase(pCommand);
223 void SourceMod_Core::OnPluginUnload(PluginId id)
225 Global_OnUnlinkConCommandBase(NULL);
230 void *SourceMod_Core::OnMetamodQuery(const char *iface, int *ret)
234 if (strcmp(iface, SOURCEMOD_INTERFACE_EXTENSIONS) == 0)
241 *ret = (ptr == NULL) ? IFACE_FAILED : IFACE_OK;