mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2025-12-07 18:38: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$
|
* Version: $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _INCLUDE_PLUGINMANAGER_H
|
#ifndef _INCLUDE_METAMOD_IPLUGINMANAGER_H
|
||||||
#define _INCLUDE_PLUGINMANAGER_H
|
#define _INCLUDE_METAMOD_IPLUGINMANAGER_H
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Plugin Manager interface
|
* @brief Plugin Manager interface
|
||||||
* @file IPluginManager.h
|
* @file IPluginManager.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef int PluginId;
|
namespace SourceMM
|
||||||
|
|
||||||
#include "ISmmPlugin.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Load sources
|
|
||||||
*/
|
|
||||||
enum
|
|
||||||
{
|
{
|
||||||
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(),
|
* @brief Used to uniquel identify plugins.
|
||||||
* 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;
|
typedef int PluginId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unloads a plugin
|
* @brief Load sources
|
||||||
*
|
|
||||||
* @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;
|
enum
|
||||||
|
{
|
||||||
|
Pl_BadLoad=0,
|
||||||
|
Pl_Console=-1,
|
||||||
|
Pl_File=-2,
|
||||||
|
Pl_MinId=1,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Pauses a plugin
|
* @brief Status of a plugin at runtime
|
||||||
*
|
|
||||||
* @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;
|
enum Pl_Status
|
||||||
|
{
|
||||||
|
Pl_NotFound=-4,
|
||||||
|
Pl_Error=-3,
|
||||||
|
Pl_Refused=-2,
|
||||||
|
Pl_Paused=-1,
|
||||||
|
Pl_Running=0,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
class ISmmPluginManager
|
||||||
* @brief Unpauses a plugin
|
{
|
||||||
*
|
public:
|
||||||
* @param id Id of plugin
|
/**
|
||||||
* @param force If true, forces the plugin to unload
|
* @brief Loads a plugin and returns its id. If this is called before DLLInit(),
|
||||||
* @param error String buffer for error messages
|
* then the plugin is considered to be "hot" - it might refuse its own load later!
|
||||||
* @param maxlen Maximum length of buffer
|
* Also, a hot plugin might not have an error message.
|
||||||
* @return True on success, false otherwise
|
*
|
||||||
*/
|
* @param file String containing file name
|
||||||
virtual bool Unpause(PluginId id, char *error, size_t maxlen) =0;
|
* @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
|
* @brief Unloads a plugin
|
||||||
*
|
*
|
||||||
* @return True on success, false otherwise
|
* @param id Id of plugin
|
||||||
*/
|
* @param error String buffer for error messages
|
||||||
virtual bool UnloadAll() =0;
|
* @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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
#if !defined METAMOD_NO_AUTO_NAMESPACE
|
||||||
* @brief Returns information about a plugin
|
using namespace SourceMM;
|
||||||
*
|
#endif
|
||||||
* @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;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //_INCLUDE_PLUGINMANAGER_H
|
#endif //_INCLUDE_PLUGINMANAGER_H
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,8 @@
|
|||||||
#include <interface.h>
|
#include <interface.h>
|
||||||
#include <eiface.h>
|
#include <eiface.h>
|
||||||
#include <sourcehook.h>
|
#include <sourcehook.h>
|
||||||
#include "IPluginManager.h"
|
#include <IPluginManager.h>
|
||||||
|
#include <ISmmPlugin.h>
|
||||||
|
|
||||||
#if defined __GNUC__
|
#if defined __GNUC__
|
||||||
#if ((__GNUC__ == 3) && (__GNUC_MINOR__ < 4)) || (__GNUC__ < 3)
|
#if ((__GNUC__ == 3) && (__GNUC_MINOR__ < 4)) || (__GNUC__ < 3)
|
||||||
@ -45,10 +46,6 @@
|
|||||||
#endif //version check
|
#endif //version check
|
||||||
#endif //__GNUC__
|
#endif //__GNUC__
|
||||||
|
|
||||||
class IMetamodListener;
|
|
||||||
class ISmmPluginManager;
|
|
||||||
class ISmmPlugin;
|
|
||||||
|
|
||||||
#define MMIFACE_SOURCEHOOK "ISourceHook" /**< ISourceHook Pointer */
|
#define MMIFACE_SOURCEHOOK "ISourceHook" /**< ISourceHook Pointer */
|
||||||
#define MMIFACE_PLMANAGER "IPluginManager" /**< SourceMM Plugin Functions */
|
#define MMIFACE_PLMANAGER "IPluginManager" /**< SourceMM Plugin Functions */
|
||||||
#define IFACE_MAXNUM 999 /**< Maximum interface version */
|
#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_EPISODEONE 2 /**< Episode 1 Source Engine (second major SDK) */
|
||||||
#define SOURCE_ENGINE_ORANGEBOX 3 /**< Orange Box Source Engine (third major SDK) */
|
#define SOURCE_ENGINE_ORANGEBOX 3 /**< Orange Box Source Engine (third major SDK) */
|
||||||
|
|
||||||
class ISmmAPI
|
namespace SourceMM
|
||||||
{
|
{
|
||||||
public:
|
class ISmmPlugin;
|
||||||
/**
|
class IMetamodListener;
|
||||||
* @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 ISmmAPI
|
||||||
* @brief Returns an interface factory for the HL2 engine.
|
{
|
||||||
*
|
public:
|
||||||
* @param syn If syn is true, the synthetic wrapper is returned.
|
/**
|
||||||
* If syn is false, the true function is returned.
|
* @brief Logs a message through the HL2 log system.
|
||||||
* @return CreateInterfaceFn function pointer.
|
* Note: Newlines are appended automatically.
|
||||||
*/
|
*
|
||||||
virtual CreateInterfaceFn GetEngineFactory(bool syn=true) =0;
|
* @param pl Plugin API pointer (used for tagging message)
|
||||||
|
* @param msg Formatted string.
|
||||||
/**
|
*/
|
||||||
* @brief Returns an interface factory for the HL2 physics engine.
|
virtual void LogMsg(ISmmPlugin *pl, const char *msg, ...) =0;
|
||||||
*
|
|
||||||
* @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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints an unformatted string to the remote server console.
|
* @brief Returns an interface factory for the HL2 engine.
|
||||||
*
|
*
|
||||||
* Note: Newlines are not added automatically.
|
* @param syn If syn is true, the synthetic wrapper is returned.
|
||||||
*
|
* If syn is false, the true function is returned.
|
||||||
* @param str Message string.
|
* @return CreateInterfaceFn function pointer.
|
||||||
*/
|
*/
|
||||||
virtual void ConPrint(const char *str) =0;
|
virtual CreateInterfaceFn GetEngineFactory(bool syn=true) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints a formatted message to the remote server console.
|
* @brief Returns an interface factory for the HL2 physics engine.
|
||||||
*
|
*
|
||||||
* Note: Newlines are not added automatically.
|
* @param syn If syn is true, the synthetic wrapper is returned.
|
||||||
*
|
* If syn is false, the true function is returned.
|
||||||
* @param fmt Formatted message.
|
* @return CreateInterfaceFn function pointer.
|
||||||
*/
|
*/
|
||||||
virtual void ConPrintf(const char *fmt, ...) =0;
|
virtual CreateInterfaceFn GetPhysicsFactory(bool syn=true) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the Metamod Version numbers as major version and minor (API) version.
|
* @brief Returns an interface factory for the HL2 file system.
|
||||||
* Changes to minor version are guaranteed to be backwards compatible.
|
*
|
||||||
* Changes to major version are not.
|
* @param syn If syn is true, the synthetic wrapper is returned.
|
||||||
*
|
* If syn is false, the true function is returned.
|
||||||
* @param major Filled with the major API version number.
|
* @return CreateInterfaceFn function pointer.
|
||||||
* @param minor Filled with the minor API version number.
|
*/
|
||||||
* @param plvers Filled with the current plugin API version number.
|
virtual CreateInterfaceFn GetFileSystemFactory(bool syn=true) =0;
|
||||||
* @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 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.
|
* @brief Prints an unformatted string to the remote server console.
|
||||||
*
|
*
|
||||||
* @param shvers Filled with the SourceHook API version number.
|
* Note: Newlines are not added automatically.
|
||||||
* @param shimpl Filled with the SourceHook implementation number.
|
*
|
||||||
*/
|
* @param str Message string.
|
||||||
virtual void GetShVersions(int &shvers, int &shimpl) =0;
|
*/
|
||||||
|
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.
|
* @brief Returns sourcehook API version and implementation version.
|
||||||
*
|
*
|
||||||
* @param plugin Plugin interface pointer.
|
* @param shvers Filled with the SourceHook API version number.
|
||||||
* @param pListener Listener interface pointer to add.
|
* @param shimpl Filled with the SourceHook implementation number.
|
||||||
*/
|
*/
|
||||||
virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) =0;
|
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
|
* @brief Queries the metamod factory
|
||||||
*
|
*
|
||||||
* @param iface String containing interface name
|
* @param iface String containing interface name
|
||||||
* @param ret Optional pointer to store return status
|
* @param ret Optional pointer to store return status
|
||||||
* @param id Optional pointer to store id of plugin that overrode interface, 0 if none
|
* @param id Optional pointer to store id of plugin that
|
||||||
* @return Returned pointer
|
* overrode interface, 0 if none
|
||||||
*/
|
* @return Returned pointer
|
||||||
virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
|
*/
|
||||||
|
virtual void *MetaFactory(const char *iface, int *ret, PluginId *id) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Given a base interface name, such as ServerGameDLL or ServerGameDLL003,
|
* @brief Given a base interface name, such as ServerGameDLL or
|
||||||
* reformats the string to increase the number, then returns the new number.
|
* ServerGameDLL003, reformats the string to increase the number, then
|
||||||
* This is the base function to InterfaceSearch() and VInterfaceMatch().
|
* 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.
|
* @param iface Input/output interface name. Must be writable.
|
||||||
* @return The newly incremented iface version number.
|
* @param maxlength Maximum length of iface buffer. Must be at least
|
||||||
*/
|
* strlen(iface)+4 chars.
|
||||||
virtual int FormatIface(char iface[], unsigned int maxlength) =0;
|
* @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().
|
* @brief Searches for an interface, eliminating the need to loop
|
||||||
*
|
* through FormatIface().
|
||||||
* @param fn InterfaceFactory function.
|
*
|
||||||
* @param iface Interface string name.
|
* @param fn InterfaceFactory function.
|
||||||
* @param max Maximum version to look up.
|
* @param iface Interface string name.
|
||||||
* @param ret Last return code from interface factory function.
|
* @param max Maximum version to look up.
|
||||||
* @return Interface pointer, or NULL if not found.
|
* @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;
|
*/
|
||||||
|
virtual void *InterfaceSearch(CreateInterfaceFn fn,
|
||||||
|
const char *iface,
|
||||||
|
int max,
|
||||||
|
int *ret) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the base directory of the game/server, equivalent to
|
* @brief Returns the base directory of the game/server, equivalent to
|
||||||
* IVEngineServer::GetGameDir(), except the path is absolute.
|
* IVEngineServer::GetGameDir(), except the path is absolute.
|
||||||
*
|
*
|
||||||
* @return Static pointer to game's absolute basedir.
|
* @return Static pointer to game's absolute basedir.
|
||||||
*/
|
*/
|
||||||
virtual const char *GetBaseDir() =0;
|
virtual const char *GetBaseDir() =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Formats a file path to the local OS.
|
* @brief Formats a file path to the local OS.
|
||||||
*
|
*
|
||||||
* Does not include any base directories. Note that all slashes and black
|
* Does not include any base directories. Note that all slashes and
|
||||||
* slashes are reverted to the local OS's expectancy.
|
* black slashes are reverted to the local OS's expectancy.
|
||||||
*
|
*
|
||||||
* @param buffer Destination buffer to store path.
|
* @param buffer Destination buffer to store path.
|
||||||
* @param len Maximum length of buffer, including null terminator.
|
* @param len Maximum length of buffer, including null
|
||||||
* @param fmt Formatted string.
|
* terminator.
|
||||||
*/
|
* @param fmt Formatted string.
|
||||||
virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
|
*/
|
||||||
|
virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints text in the specified client's console. Same as
|
* @brief Prints text in the specified client's console. Same as
|
||||||
* IVEngineServer::ClientPrintf except that it allows for string formatting.
|
* IVEngineServer::ClientPrintf except that it allows for string
|
||||||
*
|
* formatting.
|
||||||
* @param client Client edict pointer.
|
*
|
||||||
* @param fmt Formatted string to print to the client.
|
* @param client Client edict pointer.
|
||||||
*/
|
* @param fmt Formatted string to print to the client.
|
||||||
virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
|
*/
|
||||||
|
virtual void ClientConPrintf(edict_t *client, const char *fmt, ...) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Wrapper around InterfaceSearch(). Assumes no maximum.
|
* @brief Wrapper around InterfaceSearch(). Assumes no maximum.
|
||||||
* This is designed to replace the fact that searches only went upwards.
|
* 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.
|
* The "V" is intended to convey that this is for Valve formatted
|
||||||
*
|
* interface strings.
|
||||||
* @param fn Interface factory function.
|
*
|
||||||
* @param iface Interface string.
|
* @param fn Interface factory function.
|
||||||
* @param min Minimum value to search from. If zero, searching
|
* @param iface Interface string.
|
||||||
* begins from the first available version regardless
|
* @param min Minimum value to search from. If zero, searching
|
||||||
* of the interface. Note that this can return
|
* begins from the first available version regardless
|
||||||
* interfaces EARLIER than the version specified. A
|
* of the interface. Note that this can return
|
||||||
* value of -1 (default) specifies the string version
|
* interfaces EARLIER than the version specified. A
|
||||||
* as the minimum. Any other value specifices the
|
* value of -1 (default) specifies the string version
|
||||||
* minimum value to search from.
|
* as the minimum. Any other value specifices the
|
||||||
* @return Interface pointer, or NULL if not found.
|
* 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;
|
*/
|
||||||
|
virtual void *VInterfaceMatch(CreateInterfaceFn fn,
|
||||||
|
const char *iface,
|
||||||
|
int min=-1) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Tells SourceMM to add VSP hooking capability to plugins.
|
* @brief Tells SourceMM to add VSP hooking capability to plugins.
|
||||||
*
|
*
|
||||||
* Since this potentially uses more resources than it would otherwise,
|
* Since this potentially uses more resources than it would otherwise,
|
||||||
* plugins have to explicitly enable the feature. Whether requested or
|
* plugins have to explicitly enable the feature. Whether requested or
|
||||||
* not, if it is enabled, all plugins will get a pointer to the VSP
|
* not, if it is enabled, all plugins will get a pointer to the VSP
|
||||||
* listener through IMetamodListener. This will not be called more than
|
* listener through IMetamodListener. This will not be called more than
|
||||||
* once for a given plugin; if it is requested more than once, each
|
* 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
|
* successive call will only give the pointer to plugins which have not
|
||||||
* yet received it.
|
* yet received it.
|
||||||
*/
|
*/
|
||||||
virtual void EnableVSPListener() =0;
|
virtual void EnableVSPListener() =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the interface version of the GameDLL's IServerGameDLL
|
* @brief Returns the interface version of the GameDLL's IServerGameDLL
|
||||||
* implementation.
|
* implementation.
|
||||||
*
|
*
|
||||||
* @return Interface version of the loaded IServerGameDLL.
|
* @return Interface version of the loaded IServerGameDLL.
|
||||||
*/
|
*/
|
||||||
virtual int GetGameDLLVersion() =0;
|
virtual int GetGameDLLVersion() =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the number of user messages in the GameDLL.
|
* @brief Returns the number of user messages in the GameDLL.
|
||||||
*
|
*
|
||||||
* @return Number of user messages, or -1 if SourceMM has
|
* @return Number of user messages, or -1 if SourceMM has
|
||||||
* failed to get user message list.
|
* failed to get user message list.
|
||||||
*/
|
*/
|
||||||
virtual int GetUserMessageCount() =0;
|
virtual int GetUserMessageCount() =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the index of the specified user message.
|
* @brief Returns the index of the specified user message.
|
||||||
*
|
*
|
||||||
* @param name User message name.
|
* @param name User message name.
|
||||||
* @param size Optional pointer to store size of user message.
|
* @param size Optional pointer to store size of user message.
|
||||||
* @return Message index, or -1 on failure.
|
* @return Message index, or -1 on failure.
|
||||||
*/
|
*/
|
||||||
virtual int FindUserMessage(const char *name, int *size=NULL) =0;
|
virtual int FindUserMessage(const char *name, int *size=NULL) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the name of the specified user message.
|
* @brief Returns the name of the specified user message.
|
||||||
*
|
*
|
||||||
* @param index User message index.
|
* @param index User message index.
|
||||||
* @param size Optional pointer to store size of user message.
|
* @param size Optional pointer to store size of user message.
|
||||||
* @return Message name, or NULL on failure.
|
* @return Message name, or NULL on failure.
|
||||||
*/
|
*/
|
||||||
virtual const char *GetUserMessage(int index, int *size=NULL) =0;
|
virtual const char *GetUserMessage(int index, int *size=NULL) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the highest interface version of IServerPluginCallbacks
|
* @brief Returns the highest interface version of IServerPluginCallbacks
|
||||||
* that the engine supports. This is useful for games that run on older
|
* that the engine supports. This is useful for games that run on older
|
||||||
* versions of the Source engine, such as The Ship.
|
* versions of the Source engine, such as The Ship.
|
||||||
*
|
*
|
||||||
* @return Highest interface version of IServerPluginCallbacks.
|
* @return Highest interface version of IServerPluginCallbacks.
|
||||||
* Returns 0 if SourceMM's VSP listener isn't currently
|
* Returns 0 if SourceMM's VSP listener isn't
|
||||||
* enabled.
|
* currently enabled.
|
||||||
*/
|
*/
|
||||||
virtual int GetVSPVersion() =0;
|
virtual int GetVSPVersion() =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the engine interface that MM:S is using as a backend.
|
* @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
|
* The values will be one of the SOURCE_ENGINE_* constants from the top
|
||||||
* of this file.
|
* of this file.
|
||||||
*
|
*
|
||||||
* @return A SOURCE_ENGINE_* constant value.
|
* @return A SOURCE_ENGINE_* constant value.
|
||||||
*/
|
*/
|
||||||
virtual int GetSourceEngineBuild() =0;
|
virtual int GetSourceEngineBuild() =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the VSP listener loaded.
|
* @brief Returns the VSP listener loaded.
|
||||||
*
|
*
|
||||||
* This is useful for late-loading plugins which need to decide whether
|
* 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).
|
* to add a listener or not (or need to get the pointer at all).
|
||||||
*
|
*
|
||||||
* @param Optional pointer to store the VSP version.
|
* @param Optional pointer to store the VSP version.
|
||||||
* @return IServerPluginCallbacks pointer, or NULL if an
|
* @return IServerPluginCallbacks pointer, or NULL if an
|
||||||
* IMetamodListener event has yet to occur for
|
* IMetamodListener event has yet to occur for
|
||||||
* EnableVSPListener().
|
* EnableVSPListener().
|
||||||
*/
|
*/
|
||||||
virtual IServerPluginCallbacks *GetVSPInfo(int *pVersion) =0;
|
virtual IServerPluginCallbacks *GetVSPInfo(int *pVersion) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Formats a string. This is a platform safe wrapper around
|
* @brief Formats a string. This is a platform safe wrapper around
|
||||||
* snprintf/_snprintf.
|
* snprintf/_snprintf.
|
||||||
*
|
*
|
||||||
* @param buffer Buffer to write to.
|
* @param buffer Buffer to write to.
|
||||||
* @param maxlength Maximum length of the buffer.
|
* @param maxlength Maximum length of the buffer.
|
||||||
* @param format Format specifiers.
|
* @param format Format specifiers.
|
||||||
* @param ... Format arguments.
|
* @param ... Format arguments.
|
||||||
* @return Number of bytes actually written, not including the
|
* @return Number of bytes actually written, not including
|
||||||
* null terminator.
|
* the null terminator.
|
||||||
*/
|
*/
|
||||||
virtual size_t Format(char *buffer,
|
virtual size_t Format(char *buffer,
|
||||||
size_t maxlength,
|
size_t maxlength,
|
||||||
const char *format,
|
const char *format,
|
||||||
...) =0;
|
...) =0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Formats a string. This is a platform safe wrapper around
|
* @brief Formats a string. This is a platform safe wrapper around
|
||||||
@ -364,11 +378,15 @@ public:
|
|||||||
* null terminator.
|
* null terminator.
|
||||||
*/
|
*/
|
||||||
virtual size_t FormatArgs(char *buffer,
|
virtual size_t FormatArgs(char *buffer,
|
||||||
size_t maxlength,
|
size_t maxlength,
|
||||||
const char *format,
|
const char *format,
|
||||||
va_list ap) =0;
|
va_list ap) =0;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined METAMOD_NO_AUTO_NAMESPACE
|
||||||
|
using namespace SourceMM;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Version History
|
* Version History
|
||||||
|
|||||||
@ -35,331 +35,386 @@
|
|||||||
|
|
||||||
#include <interface.h>
|
#include <interface.h>
|
||||||
#include <sourcehook.h>
|
#include <sourcehook.h>
|
||||||
#include "ISmmAPI.h"
|
#include <IPluginManager.h>
|
||||||
|
#include <ISmmAPI.h>
|
||||||
|
|
||||||
#define PLAPI_VERSION 13
|
#define METAMOD_PLAPI_VERSION 13 /**< Version of this header file */
|
||||||
#define PLAPI_NAME "ISmmPlugin"
|
#define METAMOD_PLAPI_NAME "ISmmPlugin" /**< Name of the plugin interface */
|
||||||
|
|
||||||
class ISmmAPI;
|
namespace SourceMM
|
||||||
|
|
||||||
class ISmmPlugin
|
|
||||||
{
|
{
|
||||||
public:
|
class ISmmAPI;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Called when your plugin is "queried".
|
* @brief Callbacks that a plugin must expose.
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
virtual bool QueryRunning(char *error, size_t maxlen)
|
class ISmmPlugin
|
||||||
{
|
{
|
||||||
return true;
|
public:
|
||||||
}
|
/**
|
||||||
|
* @brief Called to request the plugin's API version.
|
||||||
/**
|
*
|
||||||
* @brief Called on plugin unload. You can return false if you know your plugin
|
* This is the first callback invoked, and always remains at the top
|
||||||
* is not capable of restoring critical states it modifies.
|
* of the virtual table.
|
||||||
*
|
*
|
||||||
* @param error Error message buffer
|
* @return Plugin API version.
|
||||||
* @param maxlen Size of error message buffer
|
*/
|
||||||
* @return True on success, return false to request no unload.
|
virtual int GetApiVersion()
|
||||||
*/
|
{
|
||||||
virtual bool Unload(char *error, size_t maxlen)
|
return METAMOD_PLAPI_VERSION;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
/**
|
||||||
}
|
* @brief Virtual destructor so GCC doesn't complain.
|
||||||
|
*/
|
||||||
/**
|
virtual ~ISmmPlugin()
|
||||||
* @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;
|
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.
|
* @brief Called when all plugins have been loaded.
|
||||||
* This can be used to provide interfaces to other plugins.
|
*
|
||||||
*
|
* This is called after DLLInit(), and thus the mod has been mostly initialized.
|
||||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
* It is also safe to assume that all other (automatically loaded) plugins are now
|
||||||
*
|
* ready to start interacting, because they are all loaded.
|
||||||
* @param iface Interface string.
|
*/
|
||||||
* @param ret Optional pointer to store return code.
|
virtual void AllPluginsLoaded()
|
||||||
* @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 your plugin is "queried".
|
||||||
|
*
|
||||||
/**
|
* This is useful for rejecting a loaded state. For example, if your
|
||||||
* @brief Called when Metamod's own factory is invoked.
|
* plugin wants to stop operating, it can simply return false and copy
|
||||||
* This can be used to provide interfaces to other plugins.
|
* an error message. This will notify other plugins or MM:S of
|
||||||
*
|
* something bad that happened. MM:S will not cache the return state,
|
||||||
* If ret is passed, you should fill it with IFACE_OK or IFACE_FAILED.
|
* so if you return false, your plugin will not actually be paused or
|
||||||
*
|
* unloaded. This callback will be called when:
|
||||||
* @param iface Interface string.
|
* - Another plugin requests it
|
||||||
* @param ret Optional pointer to store return code.
|
* - Someone types "meta list", it will show up as "REFUSED"
|
||||||
* @return Generic pointer to the interface, or NULL if not found.
|
* - When Metamod need to re-check the plugin's status
|
||||||
*/
|
* - If the plugin does something like overload a factory, Metamod
|
||||||
virtual void *OnMetamodQuery(const char *iface, int *ret)
|
* will make sure the Query() returns true before calling it.
|
||||||
{
|
* Also note that this query will only override Metamod when the
|
||||||
if (ret)
|
* 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
|
* @brief Various events that Metamod can fire.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
virtual void OnVSPListening(IServerPluginCallbacks *iface) { }
|
class IMetamodListener
|
||||||
|
|
||||||
/**
|
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
}
|
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 CreateInterface
|
||||||
#define PL_EXPOSURE_C "CreateInterface"
|
#define PL_EXPOSURE_C "CreateInterface"
|
||||||
@ -370,7 +425,7 @@ public:
|
|||||||
PluginId g_PLID = (PluginId)0; \
|
PluginId g_PLID = (PluginId)0; \
|
||||||
SourceHook::ISourceHook *g_SHPtr = NULL; \
|
SourceHook::ISourceHook *g_SHPtr = NULL; \
|
||||||
SMM_API void *PL_EXPOSURE(const char *name, int *code) { \
|
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 static_cast<void *>(&var); \
|
||||||
} \
|
} \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
|
|||||||
@ -191,7 +191,7 @@ void InitMainStates()
|
|||||||
SMM_API void *CreateInterface(const char *iface, int *ret)
|
SMM_API void *CreateInterface(const char *iface, int *ret)
|
||||||
{
|
{
|
||||||
/* Prevent loading of self as a SourceMM plugin or Valve server plugin :x */
|
/* 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");
|
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;
|
major = SM_VERS_API_MAJOR;
|
||||||
minor = SM_VERS_API_MINOR;
|
minor = SM_VERS_API_MINOR;
|
||||||
plvers = PLAPI_VERSION;
|
plvers = METAMOD_PLAPI_VERSION;
|
||||||
plmin = PLAPI_MIN_VERSION;
|
plmin = PLAPI_MIN_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@
|
|||||||
#include <eiface.h>
|
#include <eiface.h>
|
||||||
#include <sourcehook/sourcehook_impl.h>
|
#include <sourcehook/sourcehook_impl.h>
|
||||||
#include <sourcehook/sourcehook.h>
|
#include <sourcehook/sourcehook.h>
|
||||||
#include "ISmmAPI.h"
|
#include <ISmmPlugin.h>
|
||||||
#include "metamod_provider.h"
|
#include "metamod_provider.h"
|
||||||
#include "svn_version.h"
|
#include "svn_version.h"
|
||||||
|
|
||||||
|
|||||||
@ -72,7 +72,7 @@ bool Command_Meta(IMetamodSourceCommandInfo *info)
|
|||||||
{
|
{
|
||||||
CONMSG("Metamod:Source version %s\n", SOURCEMM_VERSION);
|
CONMSG("Metamod:Source version %s\n", SOURCEMM_VERSION);
|
||||||
CONMSG("Compiled on: %s\n", SOURCEMM_DATE);
|
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("SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
|
||||||
CONMSG("http://www.sourcemm.net/\n");
|
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, "Metamod:Source version %s\n", SOURCEMM_VERSION);
|
||||||
CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE);
|
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, "SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
|
||||||
CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
|
CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
|
||||||
|
|
||||||
|
|||||||
@ -95,12 +95,12 @@ const char *CPluginManager::LookupAlias(const char *alias)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceHook::List<SourceMM::CNameAlias *>::iterator CPluginManager::_alias_begin()
|
SourceHook::List<CNameAlias *>::iterator CPluginManager::_alias_begin()
|
||||||
{
|
{
|
||||||
return m_Aliases.begin();
|
return m_Aliases.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceHook::List<SourceMM::CNameAlias *>::iterator CPluginManager::_alias_end()
|
SourceHook::List<CNameAlias *>::iterator CPluginManager::_alias_end()
|
||||||
{
|
{
|
||||||
return m_Aliases.end();
|
return m_Aliases.end();
|
||||||
}
|
}
|
||||||
@ -426,7 +426,7 @@ CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source
|
|||||||
}
|
}
|
||||||
else
|
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 (!pl->m_API)
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
@ -446,11 +446,11 @@ CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source
|
|||||||
}
|
}
|
||||||
pl->m_Status = Pl_Error;
|
pl->m_Status = Pl_Error;
|
||||||
}
|
}
|
||||||
else if (api > PLAPI_VERSION)
|
else if (api > METAMOD_PLAPI_VERSION)
|
||||||
{
|
{
|
||||||
if (error)
|
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;
|
pl->m_Status = Pl_Error;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include <interface.h>
|
#include <interface.h>
|
||||||
#include <eiface.h>
|
#include <eiface.h>
|
||||||
|
#include <convar.h>
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sh_string.h>
|
#include <sh_string.h>
|
||||||
#include "IPluginManager.h"
|
#include "IPluginManager.h"
|
||||||
@ -62,108 +63,105 @@
|
|||||||
|
|
||||||
#define PLAPI_MIN_VERSION 13
|
#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:
|
public:
|
||||||
/**
|
CPlugin();
|
||||||
* @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;
|
|
||||||
};
|
|
||||||
public:
|
public:
|
||||||
CPluginManager();
|
PluginId m_Id;
|
||||||
~CPluginManager();
|
SourceHook::String m_File;
|
||||||
void SetAllLoaded();
|
Pl_Status m_Status;
|
||||||
public:
|
PluginId m_Source;
|
||||||
PluginId Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen);
|
ISmmPlugin *m_API;
|
||||||
bool Unload(PluginId id, bool force, char *error, size_t maxlen);
|
HINSTANCE m_Lib;
|
||||||
bool Pause(PluginId id, char *error, size_t maxlen);
|
SourceHook::List<ConCommandBase *> m_Cvars;
|
||||||
bool Unpause(PluginId id, char *error, size_t maxlen);
|
SourceHook::List<ConCommandBase *> m_Cmds;
|
||||||
bool UnloadAll();
|
SourceHook::List<IMetamodListener *> m_Events;
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
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 */
|
/** @brief Singleton for plugin manager */
|
||||||
extern SourceMM::CPluginManager g_PluginMngr;
|
extern CPluginManager g_PluginMngr;
|
||||||
|
|
||||||
#endif //_INCLUDE_CPLUGIN_H
|
#endif //_INCLUDE_CPLUGIN_H
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user