sourcemm/stub_mm/stub_mm.cpp
changeset 152 179336f55ff6
parent 140 800dc9ba92c5
child 187 d81c2fc9a708
     1.1 --- a/sourcemm/stub_mm/stub_mm.cpp	Tue Dec 06 06:01:16 2005 +0000
     1.2 +++ b/sourcemm/stub_mm/stub_mm.cpp	Tue Dec 06 07:59:18 2005 +0000
     1.3 @@ -18,6 +18,21 @@
     1.4  //This has all of the necessary hook declarations.  Read it!
     1.5  #include "meta_hooks.h"
     1.6  
     1.7 +#define	FIND_IFACE(func, assn_var, num_var, name, type) \
     1.8 +	do { \
     1.9 +		if ( (assn_var=(type)((ismm->func())(name, NULL))) != NULL ) { \
    1.10 +			num = 0; \
    1.11 +			break; \
    1.12 +		} \
    1.13 +		if (num >= 999) \
    1.14 +			break; \
    1.15 +	} while ( num_var=ismm->FormatIface(name, sizeof(name)-1) ); \
    1.16 +	if (!assn_var) { \
    1.17 +		if (error) \
    1.18 +			snprintf(error, maxlen, "Could not find interface %s", name); \
    1.19 +		return false; \
    1.20 +	}
    1.21 +
    1.22  void ServerActivate_handler(edict_t *pEdictList, int edictCount, int clientMax)
    1.23  {
    1.24  	META_LOG(g_PLAPI, "ServerActivate() called: edictCount=%d, clientMax=%d", edictCount, clientMax);
    1.25 @@ -28,13 +43,11 @@
    1.26  {
    1.27  	PLUGIN_SAVEVARS();
    1.28  
    1.29 -	m_ServerDll = (IServerGameDLL *)((ismm->serverFactory())(INTERFACEVERSION_SERVERGAMEDLL, NULL));
    1.30 +	char iface_buffer[255];
    1.31 +	int num;
    1.32  
    1.33 -	if (!m_ServerDll)
    1.34 -	{
    1.35 -		snprintf(error, maxlen, "Could not find interface %s", INTERFACEVERSION_SERVERGAMEDLL);
    1.36 -		return false;
    1.37 -	}
    1.38 +	strcpy(iface_buffer, INTERFACEVERSION_SERVERGAMEDLL);
    1.39 +	FIND_IFACE(serverFactory, m_ServerDll, num, iface_buffer, IServerGameDLL *)
    1.40  
    1.41  	SH_ADD_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, m_ServerDll, ServerActivate_handler, true);
    1.42  
    1.43 @@ -60,7 +73,15 @@
    1.44  
    1.45  void StubPlugin::AllPluginsLoaded()
    1.46  {
    1.47 -
    1.48 +	//This is an example of inter-plugin communication
    1.49 +	PluginId id;
    1.50 +	void *ptr = g_SMAPI->MetaFactory("SamplePlugin", NULL, &id);
    1.51 +	if (ptr)
    1.52 +	{
    1.53 +		META_LOG(g_PLAPI, "Found Sample Plugin[%d] at (%p)!", id, ptr);
    1.54 +	} else {
    1.55 +		META_LOG(g_PLAPI, "Did not find Sample Plugin!");
    1.56 +	}
    1.57  }
    1.58  
    1.59  const char *StubPlugin::GetAuthor()
    1.60 @@ -102,3 +123,4 @@
    1.61  {
    1.62  	return "STUB";
    1.63  }
    1.64 +