1.1 --- a/sourcemm/sample_mm/SamplePlugin.cpp Tue Dec 06 06:01:16 2005 +0000
1.2 +++ b/sourcemm/sample_mm/SamplePlugin.cpp Tue Dec 06 07:59:18 2005 +0000
1.3 @@ -13,12 +13,28 @@
1.4 #include "cvars.h"
1.5
1.6 SamplePlugin g_SamplePlugin;
1.7 +MyListener g_Listener;
1.8
1.9 PLUGIN_EXPOSE(SamplePlugin, g_SamplePlugin);
1.10
1.11 //This has all of the necessary hook declarations. Read it!
1.12 #include "meta_hooks.h"
1.13
1.14 +#define FIND_IFACE(func, assn_var, num_var, name, type) \
1.15 + do { \
1.16 + if ( (assn_var=(type)((ismm->func())(name, NULL))) != NULL ) { \
1.17 + num = 0; \
1.18 + break; \
1.19 + } \
1.20 + if (num >= 999) \
1.21 + break; \
1.22 + } while ( num_var=ismm->FormatIface(name, sizeof(name)-1) ); \
1.23 + if (!assn_var) { \
1.24 + if (error) \
1.25 + snprintf(error, maxlen, "Could not find interface %s", name); \
1.26 + return false; \
1.27 + }
1.28 +
1.29 bool SamplePlugin::LevelInit(const char *pMapName, const char *pMapEntities, const char *pOldLevel, const char *pLandmarkName, bool loadGame, bool background)
1.30 {
1.31 META_LOG(g_PLAPI, "LevelInit() called: pMapName=%s", pMapName);
1.32 @@ -107,34 +123,22 @@
1.33 {
1.34 PLUGIN_SAVEVARS();
1.35
1.36 - m_ServerDll = (IServerGameDLL *)((ismm->serverFactory())(INTERFACEVERSION_SERVERGAMEDLL, NULL));
1.37 - m_Engine = (IVEngineServer *)((ismm->engineFactory())(INTERFACEVERSION_VENGINESERVER, NULL));
1.38 - m_ServerClients = (IServerGameClients *)((ismm->serverFactory())(INTERFACEVERSION_SERVERGAMECLIENTS, NULL));
1.39 - m_GameEventManager = (IGameEventManager2 *)((ismm->engineFactory())(INTERFACEVERSION_GAMEEVENTSMANAGER2, NULL));
1.40 + char iface_buffer[255];
1.41 + int num;
1.42
1.43 - if (!m_ServerDll)
1.44 - {
1.45 - snprintf(error, maxlen, "Could not find interface %s", INTERFACEVERSION_SERVERGAMEDLL);
1.46 - return false;
1.47 - }
1.48 - if (!m_Engine)
1.49 - {
1.50 - snprintf(error, maxlen, "Could not find interface %s", INTERFACEVERSION_VENGINESERVER);
1.51 - return false;
1.52 - }
1.53 - if (!m_ServerClients)
1.54 - {
1.55 - snprintf(error, maxlen, "Could not find interface %s", INTERFACEVERSION_SERVERGAMECLIENTS);
1.56 - return false;
1.57 - }
1.58 - if (!m_GameEventManager)
1.59 - {
1.60 - snprintf(error, maxlen, "Could not find interface %s", INTERFACEVERSION_GAMEEVENTSMANAGER2);
1.61 - return false;
1.62 - }
1.63 + strcpy(iface_buffer, INTERFACEVERSION_SERVERGAMEDLL);
1.64 + FIND_IFACE(serverFactory, m_ServerDll, num, iface_buffer, IServerGameDLL *)
1.65 + strcpy(iface_buffer, INTERFACEVERSION_VENGINESERVER);
1.66 + FIND_IFACE(engineFactory, m_Engine, num, iface_buffer, IVEngineServer *)
1.67 + strcpy(iface_buffer, INTERFACEVERSION_SERVERGAMECLIENTS);
1.68 + FIND_IFACE(serverFactory, m_ServerClients, num, iface_buffer, IServerGameClients *)
1.69 + strcpy(iface_buffer, INTERFACEVERSION_GAMEEVENTSMANAGER2);
1.70 + FIND_IFACE(engineFactory, m_GameEventManager, num, iface_buffer, IGameEventManager2 *);
1.71
1.72 META_LOG(g_PLAPI, "Starting plugin.\n");
1.73
1.74 + ismm->AddListener(this, &g_Listener);
1.75 +
1.76 //Init our cvars/concmds
1.77 ConCommandBaseMgr::OneTimeInit(&g_Accessor);
1.78
1.79 @@ -219,3 +223,19 @@
1.80 // interfaces we make. In this callback, the plugin could be assured that either
1.81 // the interfaces it requires were either loaded in another plugin or not.
1.82 }
1.83 +
1.84 +void *MyListener::OnMetamodQuery(const char *iface, int *ret)
1.85 +{
1.86 + if (strcmp(iface, "SamplePlugin")==0)
1.87 + {
1.88 + if (ret)
1.89 + *ret = IFACE_OK;
1.90 + return static_cast<void *>(&g_SamplePlugin);
1.91 + }
1.92 +
1.93 + if (ret)
1.94 + *ret = IFACE_FAILED;
1.95 +
1.96 + return NULL;
1.97 +}
1.98 +