1.1 --- a/sourcemm/CSmmAPI.cpp Thu Feb 08 11:44:11 2007 +0000
1.2 +++ b/sourcemm/CSmmAPI.cpp Sat Feb 10 00:31:34 2007 +0000
1.3 @@ -1,18 +1,19 @@
1.4 /* ======== SourceMM ========
1.5 -* Copyright (C) 2004-2006 Metamod:Source Development Team
1.6 -* No warranties of any kind
1.7 -*
1.8 -* License: zlib/libpng
1.9 -*
1.10 -* Author(s): David "BAILOPAN" Anderson
1.11 -* ============================
1.12 -*/
1.13 + * Copyright (C) 2004-2007 Metamod:Source Development Team
1.14 + * No warranties of any kind
1.15 + *
1.16 + * License: zlib/libpng
1.17 + *
1.18 + * Author(s): David "BAILOPAN" Anderson
1.19 + * ============================
1.20 + */
1.21
1.22 #include "convar_smm.h"
1.23 #include "CSmmAPI.h"
1.24 #include "sourcemm.h"
1.25 #include "concommands.h"
1.26 #include "CPlugin.h"
1.27 +#include "vsp_listener.h"
1.28
1.29 /**
1.30 * @brief Implementation of main API interface
1.31 @@ -27,6 +28,7 @@
1.32 {
1.33 m_ConPrintf = NULL;
1.34 m_Cache = false;
1.35 + m_VSP = false;
1.36 }
1.37
1.38 void CSmmAPI::LogMsg(ISmmPlugin *pl, const char *msg, ...)
1.39 @@ -140,20 +142,28 @@
1.40 void *CSmmAPI::MetaFactory(const char *iface, int *_ret, PluginId *id)
1.41 {
1.42 if (id)
1.43 + {
1.44 *id = 0;
1.45 + }
1.46
1.47 if (!iface)
1.48 + {
1.49 return NULL;
1.50 + }
1.51
1.52 //first check ours... we get first chance!
1.53 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
1.54 {
1.55 if (_ret)
1.56 + {
1.57 *_ret = IFACE_OK;
1.58 + }
1.59 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
1.60 } else if (strcmp(iface, MMIFACE_PLMANAGER) == 0) {
1.61 if (_ret)
1.62 + {
1.63 *_ret = IFACE_OK;
1.64 + }
1.65 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
1.66 }
1.67
1.68 @@ -436,3 +446,55 @@
1.69 g_Engine.engine->ClientPrintf(client, buf);
1.70 va_end(ap);
1.71 }
1.72 +
1.73 +void CSmmAPI::LoadAsVSP()
1.74 +{
1.75 + g_Engine.engine->ServerCommand("plugin_load \n");
1.76 + g_Engine.engine->ServerExecute();
1.77 +
1.78 + IServerPluginCallbacks *iface = NULL;
1.79 + if (g_VspListener.IsLoaded())
1.80 + {
1.81 + iface = &g_VspListener;
1.82 + }
1.83 +
1.84 + PluginIter iter;
1.85 + CPluginManager::CPlugin *pPlugin;
1.86 + SourceHook::List<IMetamodListener *>::iterator event;
1.87 + IMetamodListener *pML;
1.88 + for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
1.89 + {
1.90 + pPlugin = (*iter);
1.91 + if (pPlugin->m_Status < Pl_Paused)
1.92 + {
1.93 + continue;
1.94 + }
1.95 + /* Only valid for plugins >= 10 (v1:5, SourceMM 1.4) */
1.96 + if (pPlugin->m_API->GetApiVersion() < 10)
1.97 + {
1.98 + continue;
1.99 + }
1.100 + for (event=pPlugin->m_Events.begin();
1.101 + event!=pPlugin->m_Events.end();
1.102 + event++)
1.103 + {
1.104 + pML = (*event);
1.105 + pML->OnVSPListening(iface);
1.106 + }
1.107 + }
1.108 +}
1.109 +
1.110 +void CSmmAPI::EnableVSPListener()
1.111 +{
1.112 + /* If GameInit already passed and we're not already enabled or loaded, go ahead and LoadAsVSP load */
1.113 + if (bGameInit && !m_VSP && !g_VspListener.IsLoaded())
1.114 + {
1.115 + LoadAsVSP();
1.116 + }
1.117 + m_VSP = true;
1.118 +}
1.119 +
1.120 +int CSmmAPI::GetGameDLLVersion()
1.121 +{
1.122 + return g_GameDllVersion;
1.123 +}