diff -r 1667580b0c91 -r 179336f55ff6 sourcemm/stub_mm/stub_mm.cpp --- a/sourcemm/stub_mm/stub_mm.cpp Tue Dec 06 06:01:16 2005 +0000 +++ b/sourcemm/stub_mm/stub_mm.cpp Tue Dec 06 07:59:18 2005 +0000 @@ -18,6 +18,21 @@ //This has all of the necessary hook declarations. Read it! #include "meta_hooks.h" +#define FIND_IFACE(func, assn_var, num_var, name, type) \ + do { \ + if ( (assn_var=(type)((ismm->func())(name, NULL))) != NULL ) { \ + num = 0; \ + break; \ + } \ + if (num >= 999) \ + break; \ + } while ( num_var=ismm->FormatIface(name, sizeof(name)-1) ); \ + if (!assn_var) { \ + if (error) \ + snprintf(error, maxlen, "Could not find interface %s", name); \ + return false; \ + } + void ServerActivate_handler(edict_t *pEdictList, int edictCount, int clientMax) { META_LOG(g_PLAPI, "ServerActivate() called: edictCount=%d, clientMax=%d", edictCount, clientMax); @@ -28,13 +43,11 @@ { PLUGIN_SAVEVARS(); - m_ServerDll = (IServerGameDLL *)((ismm->serverFactory())(INTERFACEVERSION_SERVERGAMEDLL, NULL)); + char iface_buffer[255]; + int num; - if (!m_ServerDll) - { - snprintf(error, maxlen, "Could not find interface %s", INTERFACEVERSION_SERVERGAMEDLL); - return false; - } + strcpy(iface_buffer, INTERFACEVERSION_SERVERGAMEDLL); + FIND_IFACE(serverFactory, m_ServerDll, num, iface_buffer, IServerGameDLL *) SH_ADD_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, m_ServerDll, ServerActivate_handler, true); @@ -60,7 +73,15 @@ void StubPlugin::AllPluginsLoaded() { - + //This is an example of inter-plugin communication + PluginId id; + void *ptr = g_SMAPI->MetaFactory("SamplePlugin", NULL, &id); + if (ptr) + { + META_LOG(g_PLAPI, "Found Sample Plugin[%d] at (%p)!", id, ptr); + } else { + META_LOG(g_PLAPI, "Did not find Sample Plugin!"); + } } const char *StubPlugin::GetAuthor() @@ -102,3 +123,4 @@ { return "STUB"; } +