mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2025-12-07 02:18:30 +00:00
refactoring of API -- looks nicer and uses namespaces
--HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40482
This commit is contained in:
parent
dc59c136df
commit
b94553edb0
@ -25,130 +25,135 @@
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE_PLUGINMANAGER_H
|
||||
#define _INCLUDE_PLUGINMANAGER_H
|
||||
#ifndef _INCLUDE_METAMOD_IPLUGINMANAGER_H
|
||||
#define _INCLUDE_METAMOD_IPLUGINMANAGER_H
|
||||
|
||||
/**
|
||||
* @brief Plugin Manager interface
|
||||
* @file IPluginManager.h
|
||||
*/
|
||||
|
||||
typedef int PluginId;
|
||||
|
||||
#include "ISmmPlugin.h"
|
||||
|
||||
/**
|
||||
* @brief Load sources
|
||||
*/
|
||||
enum
|
||||
namespace SourceMM
|
||||
{
|
||||
Pl_BadLoad=0,
|
||||
Pl_Console=-1,
|
||||
Pl_File=-2,
|
||||
Pl_MinId=1,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Status of a plugin at runtime
|
||||
*/
|
||||
enum Pl_Status
|
||||
{
|
||||
Pl_NotFound=-4,
|
||||
Pl_Error=-3,
|
||||
Pl_Refused=-2,
|
||||
Pl_Paused=-1,
|
||||
Pl_Running=0,
|
||||
};
|
||||
|
||||
typedef int PluginId;
|
||||
struct factories;
|
||||
|
||||
class ISmmPluginManager
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Loads a plugin and returns its id. If this is called before DLLInit(),
|
||||
* then the plugin is considered to be "hot" - it might refuse its own load later!
|
||||
* Also, a hot plugin might not have an error message.
|
||||
*
|
||||
* @param file String containing file name
|
||||
* @param source Specifies who loaded the plugin
|
||||
* @param status Status of the plugin
|
||||
* @param ismm Pointer to Smm API
|
||||
* @param error String buffer for error messages
|
||||
* @param maxlen Maximum length of buffer
|
||||
* @return Id of plugin
|
||||
* @brief Used to uniquel identify plugins.
|
||||
*/
|
||||
virtual PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen) =0;
|
||||
typedef int PluginId;
|
||||
|
||||
/**
|
||||
* @brief Unloads a plugin
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param error String buffer for error messages
|
||||
* @param maxlen Maximum length of buffer
|
||||
* @return True on success, false otherwise
|
||||
* @brief Load sources
|
||||
*/
|
||||
virtual bool Unload(PluginId id, bool force, char *error, size_t maxlen) =0;
|
||||
|
||||
enum
|
||||
{
|
||||
Pl_BadLoad=0,
|
||||
Pl_Console=-1,
|
||||
Pl_File=-2,
|
||||
Pl_MinId=1,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Pauses a plugin
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param error String buffer for error messages
|
||||
* @param maxlen Maximum length of buffer
|
||||
* @return True on success, false otherwise
|
||||
* @brief Status of a plugin at runtime
|
||||
*/
|
||||
virtual bool Pause(PluginId id, char *error, size_t maxlen) =0;
|
||||
enum Pl_Status
|
||||
{
|
||||
Pl_NotFound=-4,
|
||||
Pl_Error=-3,
|
||||
Pl_Refused=-2,
|
||||
Pl_Paused=-1,
|
||||
Pl_Running=0,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Unpauses a plugin
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param force If true, forces the plugin to unload
|
||||
* @param error String buffer for error messages
|
||||
* @param maxlen Maximum length of buffer
|
||||
* @return True on success, false otherwise
|
||||
*/
|
||||
virtual bool Unpause(PluginId id, char *error, size_t maxlen) =0;
|
||||
class ISmmPluginManager
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Loads a plugin and returns its id. If this is called before DLLInit(),
|
||||
* then the plugin is considered to be "hot" - it might refuse its own load later!
|
||||
* Also, a hot plugin might not have an error message.
|
||||
*
|
||||
* @param file String containing file name
|
||||
* @param source Specifies who loaded the plugin
|
||||
* @param status Status of the plugin
|
||||
* @param ismm Pointer to Smm API
|
||||
* @param error String buffer for error messages
|
||||
* @param maxlen Maximum length of buffer
|
||||
* @return Id of plugin
|
||||
*/
|
||||
virtual PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen) =0;
|
||||
|
||||
/**
|
||||
* @brief Unloads all plugins forcefully
|
||||
*
|
||||
* @return True on success, false otherwise
|
||||
*/
|
||||
virtual bool UnloadAll() =0;
|
||||
/**
|
||||
* @brief Unloads a plugin
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param error String buffer for error messages
|
||||
* @param maxlen Maximum length of buffer
|
||||
* @return True on success, false otherwise
|
||||
*/
|
||||
virtual bool Unload(PluginId id, bool force, char *error, size_t maxlen) =0;
|
||||
|
||||
/**
|
||||
* @brief Pauses a plugin
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param error String buffer for error messages
|
||||
* @param maxlen Maximum length of buffer
|
||||
* @return True on success, false otherwise
|
||||
*/
|
||||
virtual bool Pause(PluginId id, char *error, size_t maxlen) =0;
|
||||
|
||||
/**
|
||||
* @brief Unpauses a plugin
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param force If true, forces the plugin to unload
|
||||
* @param error String buffer for error messages
|
||||
* @param maxlen Maximum length of buffer
|
||||
* @return True on success, false otherwise
|
||||
*/
|
||||
virtual bool Unpause(PluginId id, char *error, size_t maxlen) =0;
|
||||
|
||||
/**
|
||||
* @brief Unloads all plugins forcefully
|
||||
*
|
||||
* @return True on success, false otherwise
|
||||
*/
|
||||
virtual bool UnloadAll() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns information about a plugin
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param file Pointer to file string by reference
|
||||
* @param status By reference status of plugin
|
||||
* @param source By reference source of plugin
|
||||
* @return True on success, false if not found
|
||||
*/
|
||||
virtual bool Query(PluginId id, const char *&file, Pl_Status &status, PluginId &source) =0;
|
||||
|
||||
/**
|
||||
* @brief Checks another plugin's QueryRunning() status.
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param error Message buffer
|
||||
* @param maxlen Size of error buffer
|
||||
* @return Status value
|
||||
*/
|
||||
virtual bool QueryRunning(PluginId id, char *error, size_t maxlength) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the handle of a plugin (OS dependent meaning)
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param handle By reference handle of plugin, if any
|
||||
* @return True if plugin id is valid, false otherwise
|
||||
*/
|
||||
virtual bool QueryHandle(PluginId id, void *&handle) =0;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns information about a plugin
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param file Pointer to file string by reference
|
||||
* @param list Pointer to factories by reference
|
||||
* @param status By reference status of plugin
|
||||
* @param source By reference source of plugin
|
||||
* @return True on success, false if not found
|
||||
*/
|
||||
virtual bool Query(PluginId id, const char *&file, Pl_Status &status, PluginId &source) =0;
|
||||
|
||||
/**
|
||||
* @brief Checks another plugin's QueryRunning() status.
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param error Message buffer
|
||||
* @param maxlen Size of error buffer
|
||||
* @return Status value
|
||||
*/
|
||||
virtual bool QueryRunning(PluginId id, char *error, size_t maxlength) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the handle of a plugin (OS dependent meaning)
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @param handle By reference handle of plugin, if any
|
||||
* @return True if plugin id is valid, false otherwise
|
||||
*/
|
||||
virtual bool QueryHandle(PluginId id, void *&handle) =0;
|
||||
};
|
||||
#if !defined METAMOD_NO_AUTO_NAMESPACE
|
||||
using namespace SourceMM;
|
||||
#endif
|
||||
|
||||
#endif //_INCLUDE_PLUGINMANAGER_H
|
||||
|
||||
|
||||
@ -37,7 +37,8 @@
|
||||
#include <interface.h>
|
||||
#include <eiface.h>
|
||||
#include <sourcehook.h>
|
||||
#include "IPluginManager.h"
|
||||
#include <IPluginManager.h>
|
||||
#include <ISmmPlugin.h>
|
||||
|
||||
#if defined __GNUC__
|
||||
#if ((__GNUC__ == 3) && (__GNUC_MINOR__ < 4)) || (__GNUC__ < 3)
|
||||
@ -45,10 +46,6 @@
|
||||
#endif //version check
|
||||
#endif //__GNUC__
|
||||
|
||||
class IMetamodListener;
|
||||
class ISmmPluginManager;
|
||||
class ISmmPlugin;
|
||||
|
||||
#define MMIFACE_SOURCEHOOK "ISourceHook" /**< ISourceHook Pointer */
|
||||
#define MMIFACE_PLMANAGER "IPluginManager" /**< SourceMM Plugin Functions */
|
||||
#define IFACE_MAXNUM 999 /**< Maximum interface version */
|
||||
@ -58,299 +55,316 @@ class ISmmPlugin;
|
||||
#define SOURCE_ENGINE_EPISODEONE 2 /**< Episode 1 Source Engine (second major SDK) */
|
||||
#define SOURCE_ENGINE_ORANGEBOX 3 /**< Orange Box Source Engine (third major SDK) */
|
||||
|
||||
class ISmmAPI
|
||||
namespace SourceMM
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Logs a message through the HL2 log system.
|
||||
* Note: Newlines are appended automatically.
|
||||
*
|
||||
* @param pl Plugin API pointer (used for tagging message)
|
||||
* @param msg Formatted string.
|
||||
*/
|
||||
virtual void LogMsg(ISmmPlugin *pl, const char *msg, ...) =0;
|
||||
class ISmmPlugin;
|
||||
class IMetamodListener;
|
||||
|
||||
/**
|
||||
* @brief Returns an interface factory for the HL2 engine.
|
||||
*
|
||||
* @param syn If syn is true, the synthetic wrapper is returned.
|
||||
* If syn is false, the true function is returned.
|
||||
* @return CreateInterfaceFn function pointer.
|
||||
*/
|
||||
virtual CreateInterfaceFn GetEngineFactory(bool syn=true) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns an interface factory for the HL2 physics engine.
|
||||
*
|
||||
* @param syn If syn is true, the synthetic wrapper is returned.
|
||||
* If syn is false, the true function is returned.
|
||||
* @return CreateInterfaceFn function pointer.
|
||||
*/
|
||||
virtual CreateInterfaceFn GetPhysicsFactory(bool syn=true) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns an interface factory for the HL2 file system.
|
||||
*
|
||||
* @param syn If syn is true, the synthetic wrapper is returned.
|
||||
* If syn is false, the true function is returned.
|
||||
* @return CreateInterfaceFn function pointer.
|
||||
*/
|
||||
virtual CreateInterfaceFn GetFileSystemFactory(bool syn=true) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns an interface factory for the GameDLL.
|
||||
*
|
||||
* @param syn If syn is true, the synthetic wrapper is returned.
|
||||
* If syn is false, the true function is returned.
|
||||
* @return CreateInterfaceFn function pointer.
|
||||
*/
|
||||
virtual CreateInterfaceFn GetServerFactory(bool syn=true) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns a CGlobalVars pointer from the HL2 Engine.
|
||||
*
|
||||
* @return CGlobalVars pointer.
|
||||
*/
|
||||
virtual CGlobalVars *GetCGlobals() =0;
|
||||
|
||||
/**
|
||||
* @brief Registers a ConCommandBase.
|
||||
*
|
||||
* @param plugin Parent plugin API pointer.
|
||||
* @param pCommand ConCommandBase to register.
|
||||
* @return True if successful, false otherwise.
|
||||
*/
|
||||
virtual bool RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
|
||||
|
||||
/**
|
||||
* @brief Unregisters a ConCommandBase.
|
||||
*
|
||||
* @param plugin Parent plugin API pointer.
|
||||
* @param pCommand ConCommandBase to unlink.
|
||||
*/
|
||||
virtual void UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
|
||||
class ISmmAPI
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Logs a message through the HL2 log system.
|
||||
* Note: Newlines are appended automatically.
|
||||
*
|
||||
* @param pl Plugin API pointer (used for tagging message)
|
||||
* @param msg Formatted string.
|
||||
*/
|
||||
virtual void LogMsg(ISmmPlugin *pl, const char *msg, ...) =0;
|
||||
|
||||
/**
|
||||
* @brief Prints an unformatted string to the remote server console.
|
||||
*
|
||||
* Note: Newlines are not added automatically.
|
||||
*
|
||||
* @param str Message string.
|
||||
*/
|
||||
virtual void ConPrint(const char *str) =0;
|
||||
/**
|
||||
* @brief Returns an interface factory for the HL2 engine.
|
||||
*
|
||||
* @param syn If syn is true, the synthetic wrapper is returned.
|
||||
* If syn is false, the true function is returned.
|
||||
* @return CreateInterfaceFn function pointer.
|
||||
*/
|
||||
virtual CreateInterfaceFn GetEngineFactory(bool syn=true) =0;
|
||||
|
||||
/**
|
||||
* @brief Prints a formatted message to the remote server console.
|
||||
*
|
||||
* Note: Newlines are not added automatically.
|
||||
*
|
||||
* @param fmt Formatted message.
|
||||
*/
|
||||
virtual void ConPrintf(const char *fmt, ...) =0;
|
||||
/**
|
||||
* @brief Returns an interface factory for the HL2 physics engine.
|
||||
*
|
||||
* @param syn If syn is true, the synthetic wrapper is returned.
|
||||
* If syn is false, the true function is returned.
|
||||
* @return CreateInterfaceFn function pointer.
|
||||
*/
|
||||
virtual CreateInterfaceFn GetPhysicsFactory(bool syn=true) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the Metamod Version numbers as major version and minor (API) version.
|
||||
* Changes to minor version are guaranteed to be backwards compatible.
|
||||
* Changes to major version are not.
|
||||
*
|
||||
* @param major Filled with the major API version number.
|
||||
* @param minor Filled with the minor API version number.
|
||||
* @param plvers Filled with the current plugin API version number.
|
||||
* @param plmin Filled with the minimum plugin API version number supported.
|
||||
*/
|
||||
virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin) =0;
|
||||
/**
|
||||
* @brief Returns an interface factory for the HL2 file system.
|
||||
*
|
||||
* @param syn If syn is true, the synthetic wrapper is returned.
|
||||
* If syn is false, the true function is returned.
|
||||
* @return CreateInterfaceFn function pointer.
|
||||
*/
|
||||
virtual CreateInterfaceFn GetFileSystemFactory(bool syn=true) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns an interface factory for the GameDLL.
|
||||
*
|
||||
* If syn is false, the true function is returned.
|
||||
* @return CreateInterfaceFn function pointer.
|
||||
*/
|
||||
virtual CreateInterfaceFn GetServerFactory(bool syn=true) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns a CGlobalVars pointer from the HL2 Engine.
|
||||
*
|
||||
* @return CGlobalVars pointer.
|
||||
*/
|
||||
virtual CGlobalVars *GetCGlobals() =0;
|
||||
|
||||
/**
|
||||
* @brief Registers a ConCommandBase.
|
||||
*
|
||||
* @param plugin Parent plugin API pointer.
|
||||
* @param pCommand ConCommandBase to register.
|
||||
* @return True if successful, false otherwise.
|
||||
*/
|
||||
virtual bool RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
|
||||
|
||||
/**
|
||||
* @brief Unregisters a ConCommandBase.
|
||||
*
|
||||
* @param plugin Parent plugin API pointer.
|
||||
* @param pCommand ConCommandBase to unlink.
|
||||
*/
|
||||
virtual void UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns sourcehook API version and implementation version.
|
||||
*
|
||||
* @param shvers Filled with the SourceHook API version number.
|
||||
* @param shimpl Filled with the SourceHook implementation number.
|
||||
*/
|
||||
virtual void GetShVersions(int &shvers, int &shimpl) =0;
|
||||
/**
|
||||
* @brief Prints an unformatted string to the remote server console.
|
||||
*
|
||||
* Note: Newlines are not added automatically.
|
||||
*
|
||||
* @param str Message string.
|
||||
*/
|
||||
virtual void ConPrint(const char *str) =0;
|
||||
|
||||
/**
|
||||
* @brief Prints a formatted message to the remote server console.
|
||||
*
|
||||
* Note: Newlines are not added automatically.
|
||||
*
|
||||
* @param fmt Formatted message.
|
||||
*/
|
||||
virtual void ConPrintf(const char *fmt, ...) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the Metamod Version numbers as major version and
|
||||
* minor (API) version. Changes to minor version are guaranteed to be
|
||||
* backwards compatible. Changes to major version are not.
|
||||
*
|
||||
* @param major Filled with the major API version number.
|
||||
* @param minor Filled with the minor API version number.
|
||||
* @param plvers Filled with the current plugin API version number.
|
||||
* @param plmin Filled with the minimum plugin API version number
|
||||
* supported.
|
||||
*/
|
||||
virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin) =0;
|
||||
|
||||
/**
|
||||
* @brief Adds a Metamod listener.
|
||||
*
|
||||
* @param plugin Plugin interface pointer.
|
||||
* @param pListener Listener interface pointer to add.
|
||||
*/
|
||||
virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) =0;
|
||||
/**
|
||||
* @brief Returns sourcehook API version and implementation version.
|
||||
*
|
||||
* @param shvers Filled with the SourceHook API version number.
|
||||
* @param shimpl Filled with the SourceHook implementation number.
|
||||
*/
|
||||
virtual void GetShVersions(int &shvers, int &shimpl) =0;
|
||||
|
||||
/**
|
||||
* @brief Adds a Metamod listener.
|
||||
*
|
||||
* @param plugin Plugin interface pointer.
|
||||
* @param pListener Listener interface pointer to add.
|
||||
*/
|
||||
virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) =0;
|
||||
|
||||
/**
|
||||
* @brief Queries the metamod factory
|
||||
*
|
||||
* @param iface String containing interface name
|
||||
* @param ret Optional pointer to store return status
|
||||
* @param id Optional pointer to store id of plugin that overrode interface, 0 if none
|
||||
* @return Returned pointer
|
||||
*/
|
||||
virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
|
||||
/**
|
||||
* @brief Queries the metamod factory
|
||||
*
|
||||
* @param iface String containing interface name
|
||||
* @param ret Optional pointer to store return status
|
||||
* @param id Optional pointer to store id of plugin that
|
||||
* overrode interface, 0 if none
|
||||
* @return Returned pointer
|
||||
*/
|
||||
virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
|
||||
|
||||
/**
|
||||
* @brief Given a base interface name, such as ServerGameDLL or ServerGameDLL003,
|
||||
* reformats the string to increase the number, then returns the new number.
|
||||
* This is the base function to InterfaceSearch() and VInterfaceMatch().
|
||||
*
|
||||
* @param iface Input/output interface name. Must be writable.
|
||||
* @param maxlength Maximum length of iface buffer. Must be at least strlen(iface)+4 chars.
|
||||
* @return The newly incremented iface version number.
|
||||
*/
|
||||
virtual int FormatIface(char iface[], unsigned int maxlength) =0;
|
||||
/**
|
||||
* @brief Given a base interface name, such as ServerGameDLL or
|
||||
* ServerGameDLL003, reformats the string to increase the number, then
|
||||
* returns the new number. This is the base function to InterfaceSearch()
|
||||
* and VInterfaceMatch().
|
||||
*
|
||||
* @param iface Input/output interface name. Must be writable.
|
||||
* @param maxlength Maximum length of iface buffer. Must be at least
|
||||
* strlen(iface)+4 chars.
|
||||
* @return The newly incremented iface version number.
|
||||
*/
|
||||
virtual int FormatIface(char iface[], unsigned int maxlength) =0;
|
||||
|
||||
/**
|
||||
* @brief Searches for an interface, eliminating the need to loop through FormatIface().
|
||||
*
|
||||
* @param fn InterfaceFactory function.
|
||||
* @param iface Interface string name.
|
||||
* @param max Maximum version to look up.
|
||||
* @param ret Last return code from interface factory function.
|
||||
* @return Interface pointer, or NULL if not found.
|
||||
*/
|
||||
virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret) =0;
|
||||
/**
|
||||
* @brief Searches for an interface, eliminating the need to loop
|
||||
* through FormatIface().
|
||||
*
|
||||
* @param fn InterfaceFactory function.
|
||||
* @param iface Interface string name.
|
||||
* @param max Maximum version to look up.
|
||||
* @param ret Last return code from interface factory function.
|
||||
* @return Interface pointer, or NULL if not found.
|
||||
*/
|
||||
virtual void *InterfaceSearch(CreateInterfaceFn fn,
|
||||
const char *iface,
|
||||
int max,
|
||||
int *ret) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the base directory of the game/server, equivalent to
|
||||
* IVEngineServer::GetGameDir(), except the path is absolute.
|
||||
*
|
||||
* @return Static pointer to game's absolute basedir.
|
||||
*/
|
||||
virtual const char *GetBaseDir() =0;
|
||||
/**
|
||||
* @brief Returns the base directory of the game/server, equivalent to
|
||||
* IVEngineServer::GetGameDir(), except the path is absolute.
|
||||
*
|
||||
* @return Static pointer to game's absolute basedir.
|
||||
*/
|
||||
virtual const char *GetBaseDir() =0;
|
||||
|
||||
/**
|
||||
* @brief Formats a file path to the local OS.
|
||||
*
|
||||
* Does not include any base directories. Note that all slashes and black
|
||||
* slashes are reverted to the local OS's expectancy.
|
||||
*
|
||||
* @param buffer Destination buffer to store path.
|
||||
* @param len Maximum length of buffer, including null terminator.
|
||||
* @param fmt Formatted string.
|
||||
*/
|
||||
virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
|
||||
/**
|
||||
* @brief Formats a file path to the local OS.
|
||||
*
|
||||
* Does not include any base directories. Note that all slashes and
|
||||
* black slashes are reverted to the local OS's expectancy.
|
||||
*
|
||||
* @param buffer Destination buffer to store path.
|
||||
* @param len Maximum length of buffer, including null
|
||||
* terminator.
|
||||
* @param fmt Formatted string.
|
||||
*/
|
||||
virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
|
||||
|
||||
/**
|
||||
* @brief Prints text in the specified client's console. Same as
|
||||
* IVEngineServer::ClientPrintf except that it allows for string formatting.
|
||||
*
|
||||
* @param client Client edict pointer.
|
||||
* @param fmt Formatted string to print to the client.
|
||||
*/
|
||||
virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
|
||||
/**
|
||||
* @brief Prints text in the specified client's console. Same as
|
||||
* IVEngineServer::ClientPrintf except that it allows for string
|
||||
* formatting.
|
||||
*
|
||||
* @param client Client edict pointer.
|
||||
* @param fmt Formatted string to print to the client.
|
||||
*/
|
||||
virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
|
||||
|
||||
/**
|
||||
* @brief Wrapper around InterfaceSearch(). Assumes no maximum.
|
||||
* This is designed to replace the fact that searches only went upwards.
|
||||
* The "V" is intended to convey that this is for Valve formatted interface strings.
|
||||
*
|
||||
* @param fn Interface factory function.
|
||||
* @param iface Interface string.
|
||||
* @param min Minimum value to search from. If zero, searching
|
||||
* begins from the 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.
|
||||
*/
|
||||
virtual void *VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min=-1) =0;
|
||||
/**
|
||||
* @brief Wrapper around InterfaceSearch(). Assumes no maximum.
|
||||
* This is designed to replace the fact that searches only went upwards.
|
||||
* The "V" is intended to convey that this is for Valve formatted
|
||||
* interface strings.
|
||||
*
|
||||
* @param fn Interface factory function.
|
||||
* @param iface Interface string.
|
||||
* @param min Minimum value to search from. If zero, searching
|
||||
* begins from the 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.
|
||||
*/
|
||||
virtual void *VInterfaceMatch(CreateInterfaceFn fn,
|
||||
const char *iface,
|
||||
int min=-1) =0;
|
||||
|
||||
/**
|
||||
* @brief Tells SourceMM to add VSP hooking capability to plugins.
|
||||
*
|
||||
* Since this potentially uses more resources than it would otherwise,
|
||||
* plugins have to explicitly enable the feature. Whether requested or
|
||||
* not, if it is enabled, all plugins will get a pointer to the VSP
|
||||
* listener through IMetamodListener. This will not be called more than
|
||||
* once for a given plugin; if it is requested more than once, each
|
||||
* successive call will only give the pointer to plugins which have not
|
||||
* yet received it.
|
||||
*/
|
||||
virtual void EnableVSPListener() =0;
|
||||
/**
|
||||
* @brief Tells SourceMM to add VSP hooking capability to plugins.
|
||||
*
|
||||
* Since this potentially uses more resources than it would otherwise,
|
||||
* plugins have to explicitly enable the feature. Whether requested or
|
||||
* not, if it is enabled, all plugins will get a pointer to the VSP
|
||||
* listener through IMetamodListener. This will not be called more than
|
||||
* once for a given plugin; if it is requested more than once, each
|
||||
* successive call will only give the pointer to plugins which have not
|
||||
* yet received it.
|
||||
*/
|
||||
virtual void EnableVSPListener() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the interface version of the GameDLL's IServerGameDLL
|
||||
* implementation.
|
||||
*
|
||||
* @return Interface version of the loaded IServerGameDLL.
|
||||
*/
|
||||
virtual int GetGameDLLVersion() =0;
|
||||
/**
|
||||
* @brief Returns the interface version of the GameDLL's IServerGameDLL
|
||||
* implementation.
|
||||
*
|
||||
* @return Interface version of the loaded IServerGameDLL.
|
||||
*/
|
||||
virtual int GetGameDLLVersion() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the number of user messages in the GameDLL.
|
||||
*
|
||||
* @return Number of user messages, or -1 if SourceMM has
|
||||
* failed to get user message list.
|
||||
*/
|
||||
virtual int GetUserMessageCount() =0;
|
||||
/**
|
||||
* @brief Returns the number of user messages in the GameDLL.
|
||||
*
|
||||
* @return Number of user messages, or -1 if SourceMM has
|
||||
* failed to get user message list.
|
||||
*/
|
||||
virtual int GetUserMessageCount() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the index of the specified user message.
|
||||
*
|
||||
* @param name User message name.
|
||||
* @param size Optional pointer to store size of user message.
|
||||
* @return Message index, or -1 on failure.
|
||||
*/
|
||||
virtual int FindUserMessage(const char *name, int *size=NULL) =0;
|
||||
/**
|
||||
* @brief Returns the index of the specified user message.
|
||||
*
|
||||
* @param name User message name.
|
||||
* @param size Optional pointer to store size of user message.
|
||||
* @return Message index, or -1 on failure.
|
||||
*/
|
||||
virtual int FindUserMessage(const char *name, int *size=NULL) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the name of the specified user message.
|
||||
*
|
||||
* @param index User message index.
|
||||
* @param size Optional pointer to store size of user message.
|
||||
* @return Message name, or NULL on failure.
|
||||
*/
|
||||
virtual const char *GetUserMessage(int index, int *size=NULL) =0;
|
||||
/**
|
||||
* @brief Returns the name of the specified user message.
|
||||
*
|
||||
* @param index User message index.
|
||||
* @param size Optional pointer to store size of user message.
|
||||
* @return Message name, or NULL on failure.
|
||||
*/
|
||||
virtual const char *GetUserMessage(int index, int *size=NULL) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the highest interface version of IServerPluginCallbacks
|
||||
* that the engine supports. This is useful for games that run on older
|
||||
* versions of the Source engine, such as The Ship.
|
||||
*
|
||||
* @return Highest interface version of IServerPluginCallbacks.
|
||||
* Returns 0 if SourceMM's VSP listener isn't currently
|
||||
* enabled.
|
||||
*/
|
||||
virtual int GetVSPVersion() =0;
|
||||
/**
|
||||
* @brief Returns the highest interface version of IServerPluginCallbacks
|
||||
* that the engine supports. This is useful for games that run on older
|
||||
* versions of the Source engine, such as The Ship.
|
||||
*
|
||||
* @return Highest interface version of IServerPluginCallbacks.
|
||||
* Returns 0 if SourceMM's VSP listener isn't
|
||||
* currently enabled.
|
||||
*/
|
||||
virtual int GetVSPVersion() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the engine interface that MM:S is using as a backend.
|
||||
*
|
||||
* The values will be one of the SOURCE_ENGINE_* constants from the top
|
||||
* of this file.
|
||||
*
|
||||
* @return A SOURCE_ENGINE_* constant value.
|
||||
*/
|
||||
virtual int GetSourceEngineBuild() =0;
|
||||
/**
|
||||
* @brief Returns the engine interface that MM:S is using as a backend.
|
||||
*
|
||||
* The values will be one of the SOURCE_ENGINE_* constants from the top
|
||||
* of this file.
|
||||
*
|
||||
* @return A SOURCE_ENGINE_* constant value.
|
||||
*/
|
||||
virtual int GetSourceEngineBuild() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the VSP listener loaded.
|
||||
*
|
||||
* This is useful for late-loading plugins which need to decide whether
|
||||
* to add a listener or not (or need to get the pointer at all).
|
||||
*
|
||||
* @param Optional pointer to store the VSP version.
|
||||
* @return IServerPluginCallbacks pointer, or NULL if an
|
||||
* IMetamodListener event has yet to occur for
|
||||
* EnableVSPListener().
|
||||
*/
|
||||
virtual IServerPluginCallbacks *GetVSPInfo(int *pVersion) =0;
|
||||
/**
|
||||
* @brief Returns the VSP listener loaded.
|
||||
*
|
||||
* This is useful for late-loading plugins which need to decide whether
|
||||
* to add a listener or not (or need to get the pointer at all).
|
||||
*
|
||||
* @param Optional pointer to store the VSP version.
|
||||
* @return IServerPluginCallbacks pointer, or NULL if an
|
||||
* IMetamodListener event has yet to occur for
|
||||
* EnableVSPListener().
|
||||
*/
|
||||
virtual IServerPluginCallbacks *GetVSPInfo(int *pVersion) =0;
|
||||
|
||||
/**
|
||||
* @brief Formats a string. This is a platform safe wrapper around
|
||||
* snprintf/_snprintf.
|
||||
*
|
||||
* @param buffer Buffer to write to.
|
||||
* @param maxlength Maximum length of the buffer.
|
||||
* @param format Format specifiers.
|
||||
* @param ... Format arguments.
|
||||
* @return Number of bytes actually written, not including the
|
||||
* null terminator.
|
||||
*/
|
||||
/**
|
||||
* @brief Formats a string. This is a platform safe wrapper around
|
||||
* snprintf/_snprintf.
|
||||
*
|
||||
* @param buffer Buffer to write to.
|
||||
* @param maxlength Maximum length of the buffer.
|
||||
* @param format Format specifiers.
|
||||
* @param ... Format arguments.
|
||||
* @return Number of bytes actually written, not including
|
||||
* the null terminator.
|
||||
*/
|
||||
virtual size_t Format(char *buffer,
|
||||
size_t maxlength,
|
||||
const char *format,
|
||||
...) =0;
|
||||
size_t maxlength,
|
||||
const char *format,
|
||||
...) =0;
|
||||
|
||||
/**
|
||||
* @brief Formats a string. This is a platform safe wrapper around
|
||||
@ -364,11 +378,15 @@ public:
|
||||
* null terminator.
|
||||
*/
|
||||
virtual size_t FormatArgs(char *buffer,
|
||||
size_t maxlength,
|
||||
const char *format,
|
||||
va_list ap) =0;
|
||||
};
|
||||
size_t maxlength,
|
||||
const char *format,
|
||||
va_list ap) =0;
|
||||
};
|
||||
}
|
||||
|
||||
#if !defined METAMOD_NO_AUTO_NAMESPACE
|
||||
using namespace SourceMM;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Version History
|
||||
|
||||
@ -35,331 +35,386 @@
|
||||
|
||||
#include <interface.h>
|
||||
#include <sourcehook.h>
|
||||
#include "ISmmAPI.h"
|
||||
#include <IPluginManager.h>
|
||||
#include <ISmmAPI.h>
|
||||
|
||||
#define PLAPI_VERSION 13
|
||||
#define PLAPI_NAME "ISmmPlugin"
|
||||
#define METAMOD_PLAPI_VERSION 13 /**< Version of this header file */
|
||||
#define METAMOD_PLAPI_NAME "ISmmPlugin" /**< Name of the plugin interface */
|
||||
|
||||
class ISmmAPI;
|
||||
|
||||
class ISmmPlugin
|
||||
namespace SourceMM
|
||||
{
|
||||
public:
|
||||
virtual int GetApiVersion() { return PLAPI_VERSION; }
|
||||
virtual ~ISmmPlugin() { }
|
||||
public:
|
||||
/**
|
||||
* @brief Called on plugin load.
|
||||
*
|
||||
* NOTE - As of API 7, this is called as DLLInit() executes - after the parameters are known, but before
|
||||
* the original GameDLL function is called. Therefore, you cannot hook it, but you don't need to -
|
||||
* Load() is basically your hook.
|
||||
* NOTE - As of API 7, you can override factories before the engine and gamedll exchange them.
|
||||
* However, take care to note that if your plugin is unloaded, and the gamedll/engine have cached
|
||||
* an interface you've passed, something will definitely crash. Be careful.
|
||||
*
|
||||
* @param id Internal id of plugin. Saved globally by PLUGIN_SAVEVARS()
|
||||
* @param ismm External API for SourceMM. Saved globally by PLUGIN_SAVEVARS()
|
||||
* @param list Contains a list of factories. Hook a factory call by setting one equal to your own function.
|
||||
* @param late Set to true if your plugin was loaded late (not at server load).
|
||||
* @param error Error message buffer
|
||||
* @param maxlen Size of error message buffer
|
||||
* @return True if successful, return false to reject the load.
|
||||
*/
|
||||
virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late) =0;
|
||||
class ISmmAPI;
|
||||
|
||||
/**
|
||||
* @brief Called when your plugin is "queried".
|
||||
*
|
||||
* This is useful for rejecting a loaded state. For example, if your plugin wants
|
||||
* to stop operating, it can simply return false and copy an error message. This
|
||||
* will notify other plugins or MM:S of something bad that happened. NOTE - MM:S
|
||||
* will not cache the return state, so if you return false, your plugin will not
|
||||
* actually be paused or unloaded. This callback will be called when:
|
||||
* - Another plugin requests it
|
||||
* - Someone types "meta list", it will show up as "REFUSED"
|
||||
* - When Metamod need to re-check the plugin's status
|
||||
* - If the plugin does something like overload a factory, Metamod will make sure the Query() returns true
|
||||
* before calling it.
|
||||
* Also note that this query will only override Metamod when the plugin is running and not paused.
|
||||
*
|
||||
* @param error Buffer for error message. This can be NULL!
|
||||
* @param maxlen Maximum length of error buffer.
|
||||
* @return Status code - true for okay, false for badness.
|
||||
* @brief Callbacks that a plugin must expose.
|
||||
*/
|
||||
virtual bool QueryRunning(char *error, size_t maxlen)
|
||||
class ISmmPlugin
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called on plugin unload. You can return false if you know your plugin
|
||||
* is not capable of restoring critical states it modifies.
|
||||
*
|
||||
* @param error Error message buffer
|
||||
* @param maxlen Size of error message buffer
|
||||
* @return True on success, return false to request no unload.
|
||||
*/
|
||||
virtual bool Unload(char *error, size_t maxlen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @brief Called on plugin pause.
|
||||
*
|
||||
* @param error Error message buffer
|
||||
* @param maxlen Size of error message buffer
|
||||
* @return True on success, return false to request no pause.
|
||||
*/
|
||||
virtual bool Pause(char *error, size_t maxlen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @brief Called on plugin unpause.
|
||||
*
|
||||
* @param error Error message buffer
|
||||
* @param maxlen Size of error message buffer
|
||||
* @return True on success, return false to request no unpause.
|
||||
*/
|
||||
virtual bool Unpause(char *error, size_t maxlen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
/** @brief Return author as string */
|
||||
virtual const char *GetAuthor() =0;
|
||||
|
||||
/** @brief Return plugin name as string */
|
||||
virtual const char *GetName() =0;
|
||||
|
||||
/** @brief Return a description as string */
|
||||
virtual const char *GetDescription() =0;
|
||||
|
||||
/** @brief Return a URL as string */
|
||||
virtual const char *GetURL() =0;
|
||||
|
||||
/** @brief Return quick license code as string */
|
||||
virtual const char *GetLicense() =0;
|
||||
|
||||
/** @brief Return version as string */
|
||||
virtual const char *GetVersion() =0;
|
||||
|
||||
/** @brief Return author as string */
|
||||
virtual const char *GetDate() =0;
|
||||
|
||||
/** @brief Return author as string */
|
||||
virtual const char *GetLogTag() =0;
|
||||
public:
|
||||
/**
|
||||
* @brief Called when all plugins have been loaded.
|
||||
*
|
||||
* This is called after DLLInit(), and thus the mod has been mostly initialized.
|
||||
* It is also safe to assume that all other (automatically loaded) plugins are now
|
||||
* ready to start interacting, because they are all loaded.
|
||||
*/
|
||||
virtual void AllPluginsLoaded()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Added in 1.1 so plugins could listen to specific events
|
||||
*/
|
||||
class IMetamodListener
|
||||
{
|
||||
public:
|
||||
virtual ~IMetamodListener()
|
||||
{
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Called when a plugin is loaded.
|
||||
*
|
||||
* @param id Id of the plugin.
|
||||
*/
|
||||
virtual void OnPluginLoad(PluginId id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when a plugin is unloaded.
|
||||
*
|
||||
* @param id Id of the plugin.
|
||||
*/
|
||||
virtual void OnPluginUnload(PluginId id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when a plugin is paused.
|
||||
*
|
||||
* @param id Id of the plugin.
|
||||
*/
|
||||
virtual void OnPluginPause(PluginId id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when a plugin is unpaused.
|
||||
*
|
||||
* @param id Id of the plugin.
|
||||
*/
|
||||
virtual void OnPluginUnpause(PluginId id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when the level is loaded (after GameInit, before ServerActivate).
|
||||
*
|
||||
* To override this, hook IServerGameDLL::LevelInit().
|
||||
*
|
||||
* @param pMapName Name of the map.
|
||||
* @param pMapEntities Lump string of the map entities, in KeyValue format.
|
||||
* @param pOldLevel Unknown.
|
||||
* @param pLandmarkName Unknown.
|
||||
* @param loadGame Unknown.
|
||||
* @param background Unknown.
|
||||
*/
|
||||
virtual void OnLevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) { }
|
||||
|
||||
/**
|
||||
* @brief Called when the level is shut down. May be called more than once.
|
||||
*/
|
||||
virtual void OnLevelShutdown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when engineFactory() is used through Metamod:Source's wrapper.
|
||||
* This can be used to provide interfaces to other plugins or the GameDLL.
|
||||
*
|
||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
||||
*
|
||||
* @param iface Interface string.
|
||||
* @param ret Optional pointer to store return code.
|
||||
* @return Generic pointer to the interface, or NULL if not found.
|
||||
*/
|
||||
virtual void *OnEngineQuery(const char *iface, int *ret)
|
||||
{
|
||||
if (ret)
|
||||
{
|
||||
*ret = IFACE_FAILED;
|
||||
public:
|
||||
/**
|
||||
* @brief Called to request the plugin's API version.
|
||||
*
|
||||
* This is the first callback invoked, and always remains at the top
|
||||
* of the virtual table.
|
||||
*
|
||||
* @return Plugin API version.
|
||||
*/
|
||||
virtual int GetApiVersion()
|
||||
{
|
||||
return METAMOD_PLAPI_VERSION;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when the physics factory is used through Metamod:Source's wrapper.
|
||||
* This can be used to provide interfaces to other plugins.
|
||||
*
|
||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
||||
*
|
||||
* @param iface Interface string.
|
||||
* @param ret Optional pointer to store return code.
|
||||
* @return Generic pointer to the interface, or NULL if not found.
|
||||
*/
|
||||
virtual void *OnPhysicsQuery(const char *iface, int *ret)
|
||||
{
|
||||
if (ret)
|
||||
/**
|
||||
* @brief Virtual destructor so GCC doesn't complain.
|
||||
*/
|
||||
virtual ~ISmmPlugin()
|
||||
{
|
||||
*ret = IFACE_FAILED;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Called on plugin load.
|
||||
*
|
||||
* This is called as DLLInit() executes - after the parameters are
|
||||
* known, but before the original GameDLL function is called.
|
||||
* Therefore, you cannot hook it, but you don't need to - Load() is
|
||||
* basically your hook. You can override factories before the engine
|
||||
* and gamedll exchange them. However, take care to note that if your
|
||||
* plugin is unloaded, and the gamedll/engine have cached an interface
|
||||
* you've passed, something will definitely crash. Be careful.
|
||||
*
|
||||
* @param id Internal id of plugin. Saved globally by PLUGIN_SAVEVARS()
|
||||
* @param ismm External API for SourceMM. Saved globally by PLUGIN_SAVEVARS()
|
||||
* @param error Error message buffer
|
||||
* @param maxlength Size of error message buffer
|
||||
* @param late Set to true if your plugin was loaded late (not at server load).
|
||||
* @return True if successful, return false to reject the load.
|
||||
*/
|
||||
virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late) =0;
|
||||
|
||||
/**
|
||||
* @brief Called when the filesystem factory is used through Metamod:Source's wrapper.
|
||||
* This can be used to provide interfaces to other plugins.
|
||||
*
|
||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
||||
*
|
||||
* @param iface Interface string.
|
||||
* @param ret Optional pointer to store return code.
|
||||
* @return Generic pointer to the interface, or NULL if not found.
|
||||
*/
|
||||
virtual void *OnFileSystemQuery(const char *iface, int *ret)
|
||||
{
|
||||
if (ret)
|
||||
/**
|
||||
* @brief Called when all plugins have been loaded.
|
||||
*
|
||||
* This is called after DLLInit(), and thus the mod has been mostly initialized.
|
||||
* It is also safe to assume that all other (automatically loaded) plugins are now
|
||||
* ready to start interacting, because they are all loaded.
|
||||
*/
|
||||
virtual void AllPluginsLoaded()
|
||||
{
|
||||
*ret = IFACE_FAILED;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when the server DLL's factory is used through Metamod:Source's wrapper.
|
||||
* This can be used to provide interfaces to other plugins.
|
||||
*
|
||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
||||
*
|
||||
* @param iface Interface string.
|
||||
* @param ret Optional pointer to store return code.
|
||||
* @return Generic pointer to the interface, or NULL if not found.
|
||||
*/
|
||||
virtual void *OnGameDLLQuery(const char *iface, int *ret)
|
||||
{
|
||||
if (ret)
|
||||
{
|
||||
*ret = IFACE_FAILED;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when Metamod's own factory is invoked.
|
||||
* This can be used to provide interfaces to other plugins.
|
||||
*
|
||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
||||
*
|
||||
* @param iface Interface string.
|
||||
* @param ret Optional pointer to store return code.
|
||||
* @return Generic pointer to the interface, or NULL if not found.
|
||||
*/
|
||||
virtual void *OnMetamodQuery(const char *iface, int *ret)
|
||||
{
|
||||
if (ret)
|
||||
/**
|
||||
* @brief Called when your plugin is "queried".
|
||||
*
|
||||
* This is useful for rejecting a loaded state. For example, if your
|
||||
* plugin wants to stop operating, it can simply return false and copy
|
||||
* an error message. This will notify other plugins or MM:S of
|
||||
* something bad that happened. MM:S will not cache the return state,
|
||||
* so if you return false, your plugin will not actually be paused or
|
||||
* unloaded. This callback will be called when:
|
||||
* - Another plugin requests it
|
||||
* - Someone types "meta list", it will show up as "REFUSED"
|
||||
* - When Metamod need to re-check the plugin's status
|
||||
* - If the plugin does something like overload a factory, Metamod
|
||||
* will make sure the Query() returns true before calling it.
|
||||
* Also note that this query will only override Metamod when the
|
||||
* plugin is running and not paused.
|
||||
*
|
||||
* @param error Buffer for error message, or NULL if none.
|
||||
* @param maxlen Maximum length of error buffer.
|
||||
* @return Status code - true for okay, false for badness.
|
||||
*/
|
||||
virtual bool QueryRunning(char *error, size_t maxlen)
|
||||
{
|
||||
*ret = IFACE_FAILED;
|
||||
return true;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/**
|
||||
* @brief Called on plugin unload. You can return false if you know
|
||||
* your plugin is not capable of restoring critical states it modifies.
|
||||
*
|
||||
* @param error Error message buffer
|
||||
* @param maxlen Size of error message buffer
|
||||
* @return True on success, return false to request no unload.
|
||||
*/
|
||||
virtual bool Unload(char *error, size_t maxlen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called on plugin pause.
|
||||
*
|
||||
* @param error Error message buffer
|
||||
* @param maxlen Size of error message buffer
|
||||
* @return True on success, return false to request no pause.
|
||||
*/
|
||||
virtual bool Pause(char *error, size_t maxlen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called on plugin unpause.
|
||||
*
|
||||
* @param error Error message buffer
|
||||
* @param maxlen Size of error message buffer
|
||||
* @return True on success, return false to request no unpause.
|
||||
*/
|
||||
virtual bool Unpause(char *error, size_t maxlen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
/** @brief Return author as string */
|
||||
virtual const char *GetAuthor() =0;
|
||||
|
||||
/** @brief Return plugin name as string */
|
||||
virtual const char *GetName() =0;
|
||||
|
||||
/** @brief Return a description as string */
|
||||
virtual const char *GetDescription() =0;
|
||||
|
||||
/** @brief Return a URL as string */
|
||||
virtual const char *GetURL() =0;
|
||||
|
||||
/** @brief Return quick license code as string */
|
||||
virtual const char *GetLicense() =0;
|
||||
|
||||
/** @brief Return version as string */
|
||||
virtual const char *GetVersion() =0;
|
||||
|
||||
/** @brief Return author as string */
|
||||
virtual const char *GetDate() =0;
|
||||
|
||||
/** @brief Return author as string */
|
||||
virtual const char *GetLogTag() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Called when Metamod:Source acquires a valid IServerPluginCallbacks
|
||||
* pointer to be used for hooking by plugins.
|
||||
*
|
||||
* This will only be called after a call to ISmmAPI::EnableVSPListener().
|
||||
* If called before GameInit, this callback will occur before LevelInit.
|
||||
* Otherwise, it will be called on the first call after that.
|
||||
*
|
||||
* This callback is provided to all plugins regardless of which (or how many)
|
||||
* called EnableVSPListener(), but only if at least one did in fact enable it.
|
||||
*
|
||||
* This callback is only available for plugins using API v1:5 (Metamod:Source 1.4+).
|
||||
* If a plugin loads lately, it may still call EnableVSPListener().
|
||||
*
|
||||
* @param iface Interface pointer. If NULL, then the VSP listening construct
|
||||
* failed to initialize and is not available.
|
||||
* @brief Various events that Metamod can fire.
|
||||
*/
|
||||
virtual void OnVSPListening(IServerPluginCallbacks *iface) { }
|
||||
|
||||
/**
|
||||
* @brief Called when Metamod:Source is about to remove a concommand or convar.
|
||||
* This can also be called if ISmmAPI::UnregisterConCmdBase is used by a plugin.
|
||||
*
|
||||
* @param id Id of the plugin that created the concommand or convar.
|
||||
* @param pCommand Pointer to concommand or convar that is being removed.
|
||||
*/
|
||||
virtual void OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
|
||||
class IMetamodListener
|
||||
{
|
||||
}
|
||||
};
|
||||
public:
|
||||
/**
|
||||
* @brief Called when a plugin is loaded.
|
||||
*
|
||||
* @param id Id of the plugin.
|
||||
*/
|
||||
virtual void OnPluginLoad(PluginId id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when a plugin is unloaded.
|
||||
*
|
||||
* @param id Id of the plugin.
|
||||
*/
|
||||
virtual void OnPluginUnload(PluginId id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when a plugin is paused.
|
||||
*
|
||||
* @param id Id of the plugin.
|
||||
*/
|
||||
virtual void OnPluginPause(PluginId id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when a plugin is unpaused.
|
||||
*
|
||||
* @param id Id of the plugin.
|
||||
*/
|
||||
virtual void OnPluginUnpause(PluginId id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when the level is loaded (after GameInit, before
|
||||
* ServerActivate).
|
||||
*
|
||||
* To override this, hook IServerGameDLL::LevelInit().
|
||||
*
|
||||
* @param pMapName Name of the map.
|
||||
* @param pMapEntities Lump string of the map entities, in KeyValues
|
||||
* format.
|
||||
* @param pOldLevel Unknown.
|
||||
* @param pLandmarkName Unknown.
|
||||
* @param loadGame Unknown.
|
||||
* @param background Unknown.
|
||||
*/
|
||||
virtual void OnLevelInit(char const *pMapName,
|
||||
char const *pMapEntities,
|
||||
char const *pOldLevel,
|
||||
char const *pLandmarkName,
|
||||
bool loadGame,
|
||||
bool background)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when the level is shut down. May be called more than
|
||||
* once.
|
||||
*/
|
||||
virtual void OnLevelShutdown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when engineFactory() is used through Metamod:Source's
|
||||
* wrapper. This can be used to provide interfaces to other plugins or
|
||||
* the GameDLL.
|
||||
*
|
||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
||||
*
|
||||
* @param iface Interface string.
|
||||
* @param ret Optional pointer to store return code.
|
||||
* @return Generic pointer to the interface, or NULL if
|
||||
* not found.
|
||||
*/
|
||||
virtual void *OnEngineQuery(const char *iface, int *ret)
|
||||
{
|
||||
if (ret)
|
||||
{
|
||||
*ret = IFACE_FAILED;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when the physics factory is used through
|
||||
* Metamod:Source's wrapper. This can be used to provide interfaces to
|
||||
* other plugins.
|
||||
*
|
||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
||||
*
|
||||
* @param iface Interface string.
|
||||
* @param ret Optional pointer to store return code.
|
||||
* @return Generic pointer to the interface, or NULL if
|
||||
* not found.
|
||||
*/
|
||||
virtual void *OnPhysicsQuery(const char *iface, int *ret)
|
||||
{
|
||||
if (ret)
|
||||
{
|
||||
*ret = IFACE_FAILED;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when the filesystem factory is used through
|
||||
* Metamod:Source's wrapper. This can be used to provide interfaces to
|
||||
* other plugins.
|
||||
*
|
||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
||||
*
|
||||
* @param iface Interface string.
|
||||
* @param ret Optional pointer to store return code.
|
||||
* @return Generic pointer to the interface, or NULL if not
|
||||
* found.
|
||||
*/
|
||||
virtual void *OnFileSystemQuery(const char *iface, int *ret)
|
||||
{
|
||||
if (ret)
|
||||
{
|
||||
*ret = IFACE_FAILED;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when the server DLL's factory is used through
|
||||
* Metamod:Source's wrapper. This can be used to provide interfaces to
|
||||
* other plugins.
|
||||
*
|
||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
||||
*
|
||||
* @param iface Interface string.
|
||||
* @param ret Optional pointer to store return code.
|
||||
* @return Generic pointer to the interface, or NULL if not
|
||||
* found.
|
||||
*/
|
||||
virtual void *OnGameDLLQuery(const char *iface, int *ret)
|
||||
{
|
||||
if (ret)
|
||||
{
|
||||
*ret = IFACE_FAILED;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when Metamod's own factory is invoked.
|
||||
* This can be used to provide interfaces to other plugins.
|
||||
*
|
||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
||||
*
|
||||
* @param iface Interface string.
|
||||
* @param ret Optional pointer to store return code.
|
||||
* @return Generic pointer to the interface, or NULL if not
|
||||
* found.
|
||||
*/
|
||||
virtual void *OnMetamodQuery(const char *iface, int *ret)
|
||||
{
|
||||
if (ret)
|
||||
{
|
||||
*ret = IFACE_FAILED;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when Metamod:Source acquires a valid
|
||||
* IServerPluginCallbacks pointer to be used for hooking by plugins.
|
||||
*
|
||||
* This will only be called after a call to ISmmAPI::EnableVSPListener().
|
||||
* If called before GameInit, this callback will occur before LevelInit.
|
||||
* Otherwise, it will be called on the first call after that.
|
||||
*
|
||||
* This callback is provided to all plugins regardless of which (or how
|
||||
* many) called EnableVSPListener(), but only if at least one did in
|
||||
* fact enable it, and only once for all plugins. That is, a late
|
||||
* loading plugin should use ISmmAPI::GetVSPInfo() before relying on
|
||||
* this callback.
|
||||
*
|
||||
* @param iface Interface pointer. If NULL, then the VSP
|
||||
* listening construct failed to initialize and
|
||||
* is not available.
|
||||
*/
|
||||
virtual void OnVSPListening(IServerPluginCallbacks *iface)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when Metamod:Source is about to remove a concommand or
|
||||
* convar. This can also be called if ISmmAPI::UnregisterConCmdBase is
|
||||
* used by a plugin.
|
||||
*
|
||||
* @param id Id of the plugin that created the concommand or
|
||||
* convar.
|
||||
* @param pCommand Pointer to concommand or convar that is being
|
||||
* removed.
|
||||
*/
|
||||
virtual void OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#if !defined METAMOD_NO_AUTO_NAMESPACE
|
||||
using namespace SourceMM;
|
||||
#endif
|
||||
|
||||
|
||||
#define PL_EXPOSURE CreateInterface
|
||||
#define PL_EXPOSURE_C "CreateInterface"
|
||||
@ -370,7 +425,7 @@ public:
|
||||
PluginId g_PLID = (PluginId)0; \
|
||||
SourceHook::ISourceHook *g_SHPtr = NULL; \
|
||||
SMM_API void *PL_EXPOSURE(const char *name, int *code) { \
|
||||
if (name && !strcmp(name, PLAPI_NAME)) { \
|
||||
if (name && !strcmp(name, METAMOD_PLAPI_NAME)) { \
|
||||
return static_cast<void *>(&var); \
|
||||
} \
|
||||
return NULL; \
|
||||
|
||||
@ -191,7 +191,7 @@ void InitMainStates()
|
||||
SMM_API void *CreateInterface(const char *iface, int *ret)
|
||||
{
|
||||
/* Prevent loading of self as a SourceMM plugin or Valve server plugin :x */
|
||||
if (strcmp(iface, PLAPI_NAME) == 0)
|
||||
if (strcmp(iface, METAMOD_PLAPI_NAME) == 0)
|
||||
{
|
||||
provider->DisplayWarning("Do not try loading Metamod:Source as a plugin.\n");
|
||||
|
||||
@ -878,7 +878,7 @@ void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plm
|
||||
{
|
||||
major = SM_VERS_API_MAJOR;
|
||||
minor = SM_VERS_API_MINOR;
|
||||
plvers = PLAPI_VERSION;
|
||||
plvers = METAMOD_PLAPI_VERSION;
|
||||
plmin = PLAPI_MIN_VERSION;
|
||||
}
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
#include <eiface.h>
|
||||
#include <sourcehook/sourcehook_impl.h>
|
||||
#include <sourcehook/sourcehook.h>
|
||||
#include "ISmmAPI.h"
|
||||
#include <ISmmPlugin.h>
|
||||
#include "metamod_provider.h"
|
||||
#include "svn_version.h"
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ bool Command_Meta(IMetamodSourceCommandInfo *info)
|
||||
{
|
||||
CONMSG("Metamod:Source version %s\n", SOURCEMM_VERSION);
|
||||
CONMSG("Compiled on: %s\n", SOURCEMM_DATE);
|
||||
CONMSG("Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION);
|
||||
CONMSG("Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION);
|
||||
CONMSG("SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
|
||||
CONMSG("http://www.sourcemm.net/\n");
|
||||
|
||||
@ -679,7 +679,7 @@ bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info)
|
||||
{
|
||||
CLIENT_CONMSG(client, "Metamod:Source version %s\n", SOURCEMM_VERSION);
|
||||
CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE);
|
||||
CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION);
|
||||
CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION);
|
||||
CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
|
||||
CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
|
||||
|
||||
|
||||
@ -95,12 +95,12 @@ const char *CPluginManager::LookupAlias(const char *alias)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SourceHook::List<SourceMM::CNameAlias *>::iterator CPluginManager::_alias_begin()
|
||||
SourceHook::List<CNameAlias *>::iterator CPluginManager::_alias_begin()
|
||||
{
|
||||
return m_Aliases.begin();
|
||||
}
|
||||
|
||||
SourceHook::List<SourceMM::CNameAlias *>::iterator CPluginManager::_alias_end()
|
||||
SourceHook::List<CNameAlias *>::iterator CPluginManager::_alias_end()
|
||||
{
|
||||
return m_Aliases.end();
|
||||
}
|
||||
@ -426,7 +426,7 @@ CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source
|
||||
}
|
||||
else
|
||||
{
|
||||
pl->m_API = static_cast<ISmmPlugin *>((pfn)(PLAPI_NAME, NULL));
|
||||
pl->m_API = static_cast<ISmmPlugin *>((pfn)(METAMOD_PLAPI_NAME, NULL));
|
||||
if (!pl->m_API)
|
||||
{
|
||||
if (error)
|
||||
@ -446,11 +446,11 @@ CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source
|
||||
}
|
||||
pl->m_Status = Pl_Error;
|
||||
}
|
||||
else if (api > PLAPI_VERSION)
|
||||
else if (api > METAMOD_PLAPI_VERSION)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
UTIL_Format(error, maxlen, "Plugin API %d is newer than internal version (%d)", api, PLAPI_VERSION);
|
||||
UTIL_Format(error, maxlen, "Plugin API %d is newer than internal version (%d)", api, METAMOD_PLAPI_VERSION);
|
||||
}
|
||||
pl->m_Status = Pl_Error;
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
|
||||
#include <interface.h>
|
||||
#include <eiface.h>
|
||||
#include <convar.h>
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include "IPluginManager.h"
|
||||
@ -62,108 +63,105 @@
|
||||
|
||||
#define PLAPI_MIN_VERSION 13
|
||||
|
||||
namespace SourceMM
|
||||
struct CNameAlias
|
||||
{
|
||||
struct CNameAlias
|
||||
{
|
||||
SourceHook::String alias;
|
||||
SourceHook::String value;
|
||||
};
|
||||
SourceHook::String alias;
|
||||
SourceHook::String value;
|
||||
};
|
||||
/**
|
||||
* @brief Implements Plugin Manager API
|
||||
*/
|
||||
class CPluginManager : public ISmmPluginManager
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Implements Plugin Manager API
|
||||
* @brief Internal structure for holding plugin data
|
||||
*/
|
||||
class CPluginManager : public ISmmPluginManager
|
||||
{
|
||||
class CPlugin
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Internal structure for holding plugin data
|
||||
*/
|
||||
class CPlugin
|
||||
{
|
||||
public:
|
||||
CPlugin();
|
||||
public:
|
||||
PluginId m_Id;
|
||||
SourceHook::String m_File;
|
||||
Pl_Status m_Status;
|
||||
PluginId m_Source;
|
||||
ISmmPlugin *m_API;
|
||||
HINSTANCE m_Lib;
|
||||
SourceHook::List<ConCommandBase *> m_Cvars;
|
||||
SourceHook::List<ConCommandBase *> m_Cmds;
|
||||
SourceHook::List<IMetamodListener *> m_Events;
|
||||
};
|
||||
CPlugin();
|
||||
public:
|
||||
CPluginManager();
|
||||
~CPluginManager();
|
||||
void SetAllLoaded();
|
||||
public:
|
||||
PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
|
||||
bool Unload(PluginId id, bool force, char *error, size_t maxlen);
|
||||
bool Pause(PluginId id, char *error, size_t maxlen);
|
||||
bool Unpause(PluginId id, char *error, size_t maxlen);
|
||||
bool UnloadAll();
|
||||
void SetAlias(const char *alias, const char *value);
|
||||
public:
|
||||
bool Query(PluginId id, const char *&file, Pl_Status &status, PluginId &source);
|
||||
bool QueryRunning(PluginId id, char *error, size_t maxlength);
|
||||
bool QueryHandle(PluginId id, void *&handle);
|
||||
|
||||
void AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
|
||||
void AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
|
||||
void RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
|
||||
void RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
|
||||
|
||||
/**
|
||||
* @brief Finds a plugin by Id
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @return CPlugin on success, NULL otherwise
|
||||
*/
|
||||
CPlugin *FindById(PluginId id);
|
||||
|
||||
CPlugin *FindByAPI(ISmmPlugin *api);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
int GetPluginCount();
|
||||
const char *GetStatusText(CPlugin *pl);
|
||||
|
||||
//get alias info
|
||||
const char *LookupAlias(const char *alias);
|
||||
SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_begin();
|
||||
SourceHook::List<SourceMM::CNameAlias *>::iterator _alias_end();
|
||||
|
||||
//Internal iterators
|
||||
SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _begin();
|
||||
SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _end();
|
||||
private:
|
||||
//These are identical internal functions for the wrappers above.
|
||||
CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
|
||||
bool _Unload(CPlugin *pl, bool force, char *error, size_t maxlen);
|
||||
bool _Pause(CPlugin *pl, char *error, size_t maxlen);
|
||||
bool _Unpause(CPlugin *pl, char *error, size_t maxlen);
|
||||
void UnregAllConCmds(CPlugin *pl);
|
||||
private:
|
||||
PluginId m_LastId;
|
||||
SourceHook::List<CPlugin *> m_Plugins;
|
||||
SourceHook::List<CNameAlias *> m_Aliases;
|
||||
bool m_AllLoaded;
|
||||
PluginId m_Id;
|
||||
SourceHook::String m_File;
|
||||
Pl_Status m_Status;
|
||||
PluginId m_Source;
|
||||
ISmmPlugin *m_API;
|
||||
HINSTANCE m_Lib;
|
||||
SourceHook::List<ConCommandBase *> m_Cvars;
|
||||
SourceHook::List<ConCommandBase *> m_Cmds;
|
||||
SourceHook::List<IMetamodListener *> m_Events;
|
||||
};
|
||||
public:
|
||||
CPluginManager();
|
||||
~CPluginManager();
|
||||
void SetAllLoaded();
|
||||
public:
|
||||
PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
|
||||
bool Unload(PluginId id, bool force, char *error, size_t maxlen);
|
||||
bool Pause(PluginId id, char *error, size_t maxlen);
|
||||
bool Unpause(PluginId id, char *error, size_t maxlen);
|
||||
bool UnloadAll();
|
||||
void SetAlias(const char *alias, const char *value);
|
||||
public:
|
||||
bool Query(PluginId id, const char *&file, Pl_Status &status, PluginId &source);
|
||||
bool QueryRunning(PluginId id, char *error, size_t maxlength);
|
||||
bool QueryHandle(PluginId id, void *&handle);
|
||||
|
||||
void AddPluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
|
||||
void AddPluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
|
||||
void RemovePluginCvar(ISmmPlugin *api, ConCommandBase *pCvar);
|
||||
void RemovePluginCmd(ISmmPlugin *api, ConCommandBase *pCmd);
|
||||
|
||||
/**
|
||||
* @brief Finds a plugin by Id
|
||||
*
|
||||
* @param id Id of plugin
|
||||
* @return CPlugin on success, NULL otherwise
|
||||
*/
|
||||
CPlugin *FindById(PluginId id);
|
||||
|
||||
CPlugin *FindByAPI(ISmmPlugin *api);
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
int GetPluginCount();
|
||||
const char *GetStatusText(CPlugin *pl);
|
||||
|
||||
//get alias info
|
||||
const char *LookupAlias(const char *alias);
|
||||
SourceHook::List<CNameAlias *>::iterator _alias_begin();
|
||||
SourceHook::List<CNameAlias *>::iterator _alias_end();
|
||||
|
||||
//Internal iterators
|
||||
SourceHook::List<CPluginManager::CPlugin *>::iterator _begin();
|
||||
SourceHook::List<CPluginManager::CPlugin *>::iterator _end();
|
||||
private:
|
||||
//These are identical internal functions for the wrappers above.
|
||||
CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
|
||||
bool _Unload(CPlugin *pl, bool force, char *error, size_t maxlen);
|
||||
bool _Pause(CPlugin *pl, char *error, size_t maxlen);
|
||||
bool _Unpause(CPlugin *pl, char *error, size_t maxlen);
|
||||
void UnregAllConCmds(CPlugin *pl);
|
||||
private:
|
||||
PluginId m_LastId;
|
||||
SourceHook::List<CPlugin *> m_Plugins;
|
||||
SourceHook::List<CNameAlias *> m_Aliases;
|
||||
bool m_AllLoaded;
|
||||
};
|
||||
|
||||
typedef SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator PluginIter;
|
||||
typedef SourceHook::List<CPluginManager::CPlugin *>::iterator PluginIter;
|
||||
|
||||
/** @brief Singleton for plugin manager */
|
||||
extern SourceMM::CPluginManager g_PluginMngr;
|
||||
extern CPluginManager g_PluginMngr;
|
||||
|
||||
#endif //_INCLUDE_CPLUGIN_H
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user