fixed macro bug in the sdk

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401655
This commit is contained in:
David Anderson 2007-10-28 08:24:47 +00:00
parent f60369a005
commit afb4bd6d8b
3 changed files with 45 additions and 6 deletions

View File

@ -368,6 +368,28 @@ namespace SourceMod
*/ */
virtual bool UnloadExtension(IExtension *pExt) =0; virtual bool UnloadExtension(IExtension *pExt) =0;
}; };
#define SM_IFACEPAIR(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION
#define SM_FIND_IFACE_OR_FAIL(prefix, variable, errbuf, errsize) \
if (!sharesys->RequestInterface(SM_IFACEPAIR(prefix), myself, (SMInterface **)&variable)) \
{ \
if (errbuf) \
{ \
size_t len = snprintf(errbuf, \
errsize, \
"Could not find interface: %s (version: %d)", \
SM_IFACEPAIR(prefix)); \
if (len >= errsize) \
{ \
buffer[errsize - 1] = '\0'; \
} \
} \
return false; \
}
#define SM_FIND_IFACE(prefix, variable) \
sharesys->RequestInterface(SM_IFACEPAIR(prefix), myself, (SMInterface **)&variable));
} }
#endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_ #endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_

View File

@ -280,7 +280,11 @@ IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */
/** Exposes the extension to Metamod */ /** Exposes the extension to Metamod */
SMM_API void *PL_EXPOSURE(const char *name, int *code) SMM_API void *PL_EXPOSURE(const char *name, int *code)
{ {
#if defined METAMOD_PLAPI_VERSION
if (name && !strcmp(name, METAMOD_PLAPI_NAME))
#else
if (name && !strcmp(name, PLAPI_NAME)) if (name && !strcmp(name, PLAPI_NAME))
#endif
{ {
if (code) if (code)
{ {
@ -301,8 +305,13 @@ bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen,
{ {
PLUGIN_SAVEVARS(); PLUGIN_SAVEVARS();
#if defined METAMOD_PLAPI_VERSION
GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL); GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
#else
GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
#endif
m_SourceMMLoaded = true; m_SourceMMLoaded = true;

View File

@ -290,11 +290,15 @@ extern IServerGameDLL *gamedll;
#define SM_GET_IFACE(prefix, addr) \ #define SM_GET_IFACE(prefix, addr) \
if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \ if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \
{ \ { \
if (error) \ if (error != NULL && maxlength) \
{ \ { \
snprintf(error, maxlength, "Could not find interface: %s (version: %d)", SMINTERFACE_##prefix##_NAME, SMINTERFACE_##prefix##_VERSION); \ size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
return false; \ if (len >= maxlength) \
{ \
error[maxlength - 1] = '\0'; \
} \ } \
} \
return false; \
} }
/** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */ /** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */
#define SM_GET_LATE_IFACE(prefix, addr) \ #define SM_GET_LATE_IFACE(prefix, addr) \
@ -303,11 +307,15 @@ extern IServerGameDLL *gamedll;
#define SM_CHECK_IFACE(prefix, addr) \ #define SM_CHECK_IFACE(prefix, addr) \
if (!addr) \ if (!addr) \
{ \ { \
if (error) \ if (error != NULL && maxlength) \
{ \ { \
snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \
return false; \ if (len >= maxlength) \
{ \
error[maxlength - 1] = '\0'; \
} \ } \
} \
return false; \
} }
#endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ #endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_