mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2024-12-10 22:24:12 +01:00
fixed the VInterfaceMatch API
--HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40282
This commit is contained in:
parent
6b30a4f852
commit
3b6dee2782
@ -357,10 +357,11 @@ void *CSmmAPI::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max,
|
|||||||
return pf;
|
return pf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *CSmmAPI::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, bool chop)
|
void *CSmmAPI::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
|
||||||
{
|
{
|
||||||
char buffer[256]; /* assume no interface will go beyond this */
|
char buffer[256]; /* assume no interface will go beyond this */
|
||||||
int len = static_cast<int>(strlen(iface));
|
int len = static_cast<int>(strlen(iface));
|
||||||
|
int ret; /* just in case something doesn't handle NULL properly */
|
||||||
|
|
||||||
if (len > static_cast<int>(sizeof(buffer) - 4))
|
if (len > static_cast<int>(sizeof(buffer) - 4))
|
||||||
{
|
{
|
||||||
@ -369,7 +370,7 @@ void *CSmmAPI::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, bool cho
|
|||||||
|
|
||||||
strcpy(buffer, iface);
|
strcpy(buffer, iface);
|
||||||
|
|
||||||
if (chop)
|
if (min != -1)
|
||||||
{
|
{
|
||||||
char *ptr = &buffer[len-1];
|
char *ptr = &buffer[len-1];
|
||||||
int digits = 0;
|
int digits = 0;
|
||||||
@ -383,12 +384,15 @@ void *CSmmAPI::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, bool cho
|
|||||||
{
|
{
|
||||||
/* for now, assume this is an error */
|
/* for now, assume this is an error */
|
||||||
strcpy(buffer, iface);
|
strcpy(buffer, iface);
|
||||||
|
} else {
|
||||||
|
char num[4];
|
||||||
|
min = (min == 0) ? 1 : min;
|
||||||
|
snprintf(num, sizeof(num), "%03d", min);
|
||||||
|
strcat(buffer, num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strcat(buffer, "001");
|
return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
|
||||||
|
|
||||||
return InterfaceSearch(fn, buffer, IFACE_MAXNUM, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *CSmmAPI::GetBaseDir()
|
const char *CSmmAPI::GetBaseDir()
|
||||||
|
@ -55,7 +55,7 @@ namespace SourceMM
|
|||||||
virtual const char *GetBaseDir();
|
virtual const char *GetBaseDir();
|
||||||
virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...);
|
virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...);
|
||||||
void ClientConPrintf(edict_t *client, const char *fmt, ...);
|
void ClientConPrintf(edict_t *client, const char *fmt, ...);
|
||||||
void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, bool chop=true);
|
void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1);
|
||||||
public:
|
public:
|
||||||
bool CacheCmds();
|
bool CacheCmds();
|
||||||
private:
|
private:
|
||||||
|
@ -254,11 +254,14 @@ public: // Added in 1.3 (1:4)
|
|||||||
*
|
*
|
||||||
* @param fn Interface factory function.
|
* @param fn Interface factory function.
|
||||||
* @param iface Interface string.
|
* @param iface Interface string.
|
||||||
* @param chop If true, chops an interface version number off and searches
|
* @param min Minimum value to search from. If zero, searching begins from the
|
||||||
* from the beginning.
|
* first available version regardless of the interface.
|
||||||
|
* Note that this can return interfaces EARLIER than the version specified.
|
||||||
|
* A value of -1 (default) specifies the string version as the minimum.
|
||||||
|
* Any other value specifices the minimum value to search from.
|
||||||
* @return Interface pointer, or NULL if not found.
|
* @return Interface pointer, or NULL if not found.
|
||||||
*/
|
*/
|
||||||
virtual void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, bool chop=true) =0;
|
virtual void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1) =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,4 +248,43 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
#endif //!defined SMM_API
|
#endif //!defined SMM_API
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Macro for automatically getting a current or newer Valve interface.
|
||||||
|
*
|
||||||
|
* @param v_factory Factory method to use from ISmmAPI (such as engineFactory).
|
||||||
|
* @param v_var Variable name to store into.
|
||||||
|
* @param v_type Interface type (do not include the pointer/asterisk).
|
||||||
|
* @param v_name Inteface name.
|
||||||
|
*/
|
||||||
|
#define GET_V_IFACE_CURRENT(v_factory, v_var, v_type, v_name) \
|
||||||
|
v_var = (v_type *)ismm->VInterfaceMatch(ismm->v_factory(), v_name); \
|
||||||
|
if (!v_var) \
|
||||||
|
{ \
|
||||||
|
if (error && maxlen) \
|
||||||
|
{ \
|
||||||
|
snprintf(error, maxlen, "Could not find interface: %s", v_name); \
|
||||||
|
} \
|
||||||
|
return false; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Same as GET_V_IFACE, except searches for any.
|
||||||
|
*
|
||||||
|
* @param v_factory Factory method to use from ISmmAPI (such as engineFactory).
|
||||||
|
* @param v_var Variable name to store into.
|
||||||
|
* @param v_type Interface type (do not include the pointer/asterisk).
|
||||||
|
* @param v_name Inteface name.
|
||||||
|
*/
|
||||||
|
#define GET_V_IFACE_ANY(v_factory, v_var, v_type, v_name) \
|
||||||
|
v_var = (v_type *)ismm->VInterfaceMatch(ismm->v_factory(), v_name, 0); \
|
||||||
|
if (!v_var) \
|
||||||
|
{ \
|
||||||
|
if (error && maxlen) \
|
||||||
|
{ \
|
||||||
|
snprintf(error, maxlen, "Could not find interface: %s", v_name); \
|
||||||
|
} \
|
||||||
|
return false; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif //_INCLUDE_ISMM_PLUGIN_H
|
#endif //_INCLUDE_ISMM_PLUGIN_H
|
||||||
|
@ -61,7 +61,7 @@ bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength);
|
|||||||
#if defined __WIN32__ || defined _WIN32 || defined WIN32
|
#if defined __WIN32__ || defined _WIN32 || defined WIN32
|
||||||
#define SMM_API extern "C" __declspec(dllexport)
|
#define SMM_API extern "C" __declspec(dllexport)
|
||||||
#elif defined __GNUC__
|
#elif defined __GNUC__
|
||||||
#if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)
|
#if (__GNUC__ == 4)
|
||||||
#define SMM_API extern "C" __attribute__ ((visibility("default")))
|
#define SMM_API extern "C" __attribute__ ((visibility("default")))
|
||||||
#else
|
#else
|
||||||
#define SMM_API extern "C"
|
#define SMM_API extern "C"
|
||||||
|
@ -125,26 +125,14 @@ bool FireEvent_Handler(IGameEvent *event, bool bDontBroadcast)
|
|||||||
RETURN_META_VALUE(MRES_IGNORED, true);
|
RETURN_META_VALUE(MRES_IGNORED, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GET_V_IFACE(v_factory, v_var, v_type, v_name) \
|
|
||||||
v_var = (v_type *)ismm->VInterfaceMatch(ismm->v_factory(), v_name); \
|
|
||||||
if (!v_var) \
|
|
||||||
{ \
|
|
||||||
if (error && maxlen) \
|
|
||||||
{ \
|
|
||||||
snprintf(error, maxlen, "Could not find interface: %s", v_name); \
|
|
||||||
} \
|
|
||||||
return false; \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool SamplePlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
bool SamplePlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
||||||
{
|
{
|
||||||
PLUGIN_SAVEVARS();
|
PLUGIN_SAVEVARS();
|
||||||
|
|
||||||
GET_V_IFACE(serverFactory, m_ServerDll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
|
GET_V_IFACE_ANY(serverFactory, m_ServerDll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
|
||||||
GET_V_IFACE(engineFactory, m_Engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
|
GET_V_IFACE_CURRENT(engineFactory, m_Engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
|
||||||
GET_V_IFACE(serverFactory, m_ServerClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
|
GET_V_IFACE_ANY(serverFactory, m_ServerClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
|
||||||
GET_V_IFACE(engineFactory, m_GameEventManager, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
|
GET_V_IFACE_CURRENT(engineFactory, m_GameEventManager, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
|
||||||
|
|
||||||
META_LOG(g_PLAPI, "Starting plugin.\n");
|
META_LOG(g_PLAPI, "Starting plugin.\n");
|
||||||
|
|
||||||
|
@ -23,20 +23,11 @@ void ServerActivate_handler(edict_t *pEdictList, int edictCount, int clientMax)
|
|||||||
RETURN_META(MRES_IGNORED);
|
RETURN_META(MRES_IGNORED);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GET_V_IFACE(v_factory, v_var, v_type, v_name) \
|
|
||||||
v_var = (v_type *)ismm->VInterfaceMatch(ismm->v_factory(), v_name); \
|
|
||||||
if (!v_var) { \
|
|
||||||
if (error && maxlen) { \
|
|
||||||
snprintf(error, maxlen, "Could not find interface: %s", v_name); \
|
|
||||||
} \
|
|
||||||
return false; \
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StubPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
bool StubPlugin::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
||||||
{
|
{
|
||||||
PLUGIN_SAVEVARS();
|
PLUGIN_SAVEVARS();
|
||||||
|
|
||||||
GET_V_IFACE(serverFactory, m_ServerDll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
|
GET_V_IFACE_ANY(serverFactory, m_ServerDll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
|
||||||
|
|
||||||
SH_ADD_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, m_ServerDll, ServerActivate_handler, true);
|
SH_ADD_HOOK_STATICFUNC(IServerGameDLL, ServerActivate, m_ServerDll, ServerActivate_handler, true);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user