2005-04-16 21:59:26 +02:00
|
|
|
/* ======== SourceMM ========
|
2007-03-02 03:43:22 +01:00
|
|
|
* Copyright (C) 2004-2007 Metamod:Source Development Team
|
2005-04-16 21:59:26 +02:00
|
|
|
* No warranties of any kind
|
|
|
|
*
|
|
|
|
* License: zlib/libpng
|
|
|
|
*
|
|
|
|
* Author(s): David "BAILOPAN" Anderson
|
|
|
|
* ============================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE_CPLUGIN_H
|
|
|
|
#define _INCLUDE_CPLUGIN_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Implementation of Plugin API and Management routines
|
|
|
|
* @file CPlugin.cpp
|
|
|
|
*/
|
|
|
|
|
2005-05-26 10:06:23 +02:00
|
|
|
#include <interface.h>
|
|
|
|
#include <eiface.h>
|
2007-02-08 10:19:19 +01:00
|
|
|
#include "convar_smm.h"
|
2005-04-16 21:59:26 +02:00
|
|
|
#include "IPluginManager.h"
|
|
|
|
#include "oslink.h"
|
2005-08-12 19:44:53 +02:00
|
|
|
#include "sh_list.h"
|
|
|
|
#include "sh_string.h"
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2005-05-01 20:24:48 +02:00
|
|
|
/**
|
|
|
|
* History of plugin versions: (M=min, C=current)
|
2007-02-10 01:31:34 +01:00
|
|
|
* 1: Initial interface
|
|
|
|
* 2: Added GetLogTag()
|
|
|
|
* 3: Moved GetApiVersion() to top (2005-04-16)
|
|
|
|
* 4: Added AllPluginsLoaded() callback (2005-04-18)
|
|
|
|
* 5: Bumped version for SourceHook V4 (2005-05-01)
|
|
|
|
* 6: Added functions for console printing (2005-05-26)
|
|
|
|
* M 7: Changed template libraries (2005-08-11)
|
|
|
|
* New loading structure mechanism
|
|
|
|
* New SourceHook version
|
|
|
|
* 8: New SourceHook version (2005-12-23)
|
|
|
|
* New ISmmAPI additions
|
|
|
|
* 9: New ISmmPluginManager additions
|
|
|
|
* C 10: Added VSP listen functions to ISmmAPI and IMetamodListener (2007-02-09)
|
2005-05-01 20:24:48 +02:00
|
|
|
*/
|
|
|
|
|
2005-09-13 21:31:25 +02:00
|
|
|
#define PLAPI_MIN_VERSION 7
|
2005-05-01 20:24:48 +02:00
|
|
|
|
2005-04-16 21:59:26 +02:00
|
|
|
namespace SourceMM
|
|
|
|
{
|
2006-05-25 06:49:47 +02:00
|
|
|
struct CNameAlias
|
|
|
|
{
|
|
|
|
SourceHook::String alias;
|
|
|
|
SourceHook::String value;
|
|
|
|
};
|
2005-04-16 21:59:26 +02:00
|
|
|
/**
|
|
|
|
* @brief Implements Plugin Manager API
|
|
|
|
*/
|
|
|
|
class CPluginManager : public ISmmPluginManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Internal structure for holding plugin data
|
|
|
|
*/
|
|
|
|
class CPlugin
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CPlugin();
|
|
|
|
public:
|
|
|
|
PluginId m_Id;
|
2005-08-12 19:44:53 +02:00
|
|
|
SourceHook::String m_File;
|
2005-04-16 21:59:26 +02:00
|
|
|
Pl_Status m_Status;
|
|
|
|
PluginId m_Source;
|
|
|
|
ISmmPlugin *m_API;
|
|
|
|
HINSTANCE m_Lib;
|
2005-08-12 19:44:53 +02:00
|
|
|
SourceHook::List<ConCommandBase *> m_Cvars;
|
|
|
|
SourceHook::List<ConCommandBase *> m_Cmds;
|
2005-10-20 16:37:47 +02:00
|
|
|
SourceHook::List<IMetamodListener *> m_Events;
|
2005-04-16 21:59:26 +02:00
|
|
|
};
|
|
|
|
public:
|
|
|
|
CPluginManager();
|
|
|
|
~CPluginManager();
|
2005-04-18 20:21:57 +02:00
|
|
|
void SetAllLoaded();
|
2005-04-16 21:59:26 +02:00
|
|
|
public:
|
|
|
|
PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
|
2005-04-17 01:33:39 +02:00
|
|
|
bool Unload(PluginId id, bool force, char *error, size_t maxlen);
|
2005-04-16 21:59:26 +02:00
|
|
|
bool Pause(PluginId id, char *error, size_t maxlen);
|
|
|
|
bool Unpause(PluginId id, char *error, size_t maxlen);
|
|
|
|
bool UnloadAll();
|
2006-05-25 06:49:47 +02:00
|
|
|
void SetAlias(const char *alias, const char *value);
|
2005-04-16 21:59:26 +02:00
|
|
|
public:
|
2005-10-20 16:37:47 +02:00
|
|
|
bool Query(PluginId id, const char *&file, Pl_Status &status, PluginId &source);
|
2005-10-06 02:59:01 +02:00
|
|
|
bool QueryRunning(PluginId id, char *error, size_t maxlength);
|
2006-08-01 04:09:19 +02:00
|
|
|
bool QueryHandle(PluginId id, void *&handle);
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2005-05-26 10:06:23 +02:00
|
|
|
void AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
|
|
|
|
void AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
|
|
|
|
void RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
|
|
|
|
void RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
|
|
|
|
|
2005-04-16 21:59:26 +02:00
|
|
|
/**
|
|
|
|
* @brief Finds a plugin by Id
|
|
|
|
*
|
|
|
|
* @param id Id of plugin
|
|
|
|
* @return CPlugin on success, NULL otherwise
|
|
|
|
*/
|
|
|
|
CPlugin *FindById(PluginId id);
|
|
|
|
|
2005-05-26 10:06:23 +02:00
|
|
|
CPlugin *FindByAPI(ISmmPlugin *api);
|
|
|
|
|
2005-04-19 09:41:07 +02:00
|
|
|
/**
|
|
|
|
* @brief Attempts to reload a failed plugin
|
|
|
|
*
|
|
|
|
* @param id Id of plugin
|
|
|
|
* @param error Error message buffer
|
|
|
|
* @param len Maximum length of buffer
|
|
|
|
* @return True on success, false otherwise
|
|
|
|
*/
|
|
|
|
bool Retry(PluginId id, char *error, size_t len);
|
|
|
|
|
2006-05-25 06:49:47 +02:00
|
|
|
//get alias info
|
|
|
|
const char *LookupAlias(const char *alias);
|
|
|
|
SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_begin();
|
|
|
|
SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_end();
|
|
|
|
|
2005-04-16 21:59:26 +02:00
|
|
|
//Internal iterators
|
2005-08-12 19:44:53 +02:00
|
|
|
SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _begin();
|
|
|
|
SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _end();
|
2005-04-16 21:59:26 +02:00
|
|
|
private:
|
|
|
|
//These are identical internal functions for the wrappers above.
|
|
|
|
CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
|
2005-04-17 01:33:39 +02:00
|
|
|
bool _Unload(CPlugin *pl, bool force, char *error, size_t maxlen);
|
2005-04-16 21:59:26 +02:00
|
|
|
bool _Pause(CPlugin *pl, char *error, size_t maxlen);
|
|
|
|
bool _Unpause(CPlugin *pl, char *error, size_t maxlen);
|
2005-05-26 10:06:23 +02:00
|
|
|
void UnregAllConCmds(CPlugin *pl);
|
2005-04-16 21:59:26 +02:00
|
|
|
private:
|
|
|
|
PluginId m_LastId;
|
2005-08-12 19:44:53 +02:00
|
|
|
SourceHook::List<CPlugin *> m_Plugins;
|
2006-05-25 06:49:47 +02:00
|
|
|
SourceHook::List<CNameAlias *> m_Aliases;
|
2005-04-18 20:21:57 +02:00
|
|
|
bool m_AllLoaded;
|
2005-04-16 21:59:26 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2005-08-12 19:44:53 +02:00
|
|
|
typedef SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator PluginIter;
|
2005-04-16 21:59:26 +02:00
|
|
|
|
|
|
|
/** @brief Singleton for plugin manager */
|
|
|
|
extern SourceMM::CPluginManager g_PluginMngr;
|
|
|
|
|
|
|
|
#endif //_INCLUDE_CPLUGIN_H
|