reorganized SourceMod for the public SDK

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40329
This commit is contained in:
David Anderson
2007-01-19 05:33:04 +00:00
parent f3eedff775
commit 8a46219d96
30 changed files with 1132 additions and 3 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef _INCLUDE_SOURCEMOD_TEXTPARSERS_H_
#define _INCLUDE_SOURCEMOD_TEXTPARSERS_H_
#include "interfaces/ITextParsers.h"
#include <ITextParsers.h>
using namespace SourceMod;
-217
View File
@@ -1,217 +0,0 @@
#ifndef _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
#define _INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
#include <IShareSys.h>
#include <ILibrarySys.h>
namespace SourceMod
{
class IExtensionInterface;
typedef void * ITERATOR;
/**
* @brief Encapsulates an IExtension.
*/
class IExtension
{
public:
/**
* @brief Returns whether or not the extension is properly loaded.
*/
virtual bool IsLoaded() =0;
/**
* @brief Returns the extension's API interface
*
* @return An IExtensionInterface pointer.
*/
virtual IExtensionInterface *GetAPI() =0;
/**
* @brief Returns the filename of the extension, relative to the
* extension folder.
*
* @return A string containing the extension file name.
*/
virtual const char *GetFilename() =0;
/**
* @brief Returns the extension's identity token.
*
* @return An IdentityToken_t pointer.
*/
virtual IdentityToken_t *GetIdentity() =0;
/**
* @brief Retrieves the extension dependency list for this extension.
*
* @param pOwner Optional pointer to store the first interface's owner.
* @param pInterface Optional pointer to store the first interface.
* @return An ITERATOR pointer for the results, or NULL if no results at all.
*/
virtual ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface) =0;
/**
* @brief Finds the next dependency in the dependency list.
*
* @param iter Pointer to iterator from FindFirstDependency.
* @param pOwner Optional pointer to store the interface's owner.
* @param pInterface Optional pointer to store the interface.
* @return True if there are more results after this, false otherwise.
*/
virtual bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface) =0;
/**
* @brief Frees an ITERATOR handle from FindFirstDependency.
*
* @param iter Pointer to iterator to free.
*/
virtual void FreeDependencyIterator(ITERATOR *iter) =0;
/**
* @brief Queries the extension to see its run state.
*
* @param error Error buffer (may be NULL).
* @param maxlength Maximum length of buffer.
* @return True if extension is okay, false if not okay.
*/
virtual bool IsRunning(char *error, size_t maxlength) =0;
};
#define SMINTERFACE_EXTENSIONAPI_VERSION 1
/**
* @brief The interface an extension must expose.
*/
class IExtensionInterface
{
public:
virtual unsigned int GetExtensionVersion()
{
return SMINTERFACE_EXTENSIONAPI_VERSION;
}
public:
/**
* @brief Called when the extension is loaded.
*
* @param me Pointer back to extension.
* @param sys Pointer to interface sharing system of SourceMod.
* @param error Error buffer to print back to, if any.
* @param err_max Maximum size of error buffer.
* @param late If this extension was loaded "late" (i.e. manually).
* @return True if load should continue, false otherwise.
*/
virtual bool OnExtensionLoad(IExtension *me,
IShareSys *sys,
char *error,
size_t err_max,
bool late) =0;
/**
* @brief Called when the extension is about to be unloaded.
*/
virtual void OnExtensionUnload() =0;
/**
* @brief Called when all extensions are loaded (loading cycle is done).
* If loaded late, this will be called right after OnExtensionLoad().
*/
virtual void OnExtensionsAllLoaded() =0;
/**
* @brief Called when your pause state is about to change.
*
* @param pause True if pausing, false if unpausing.
*/
virtual void OnExtensionPauseChange(bool pause) =0;
/**
* @brief Asks the extension whether it's safe to remove an external interface it's using.
* If it's not safe, return false, and the extension will be unloaded afterwards.
* NOTE: It is important to also hook NotifyInterfaceDrop() in order to clean up resources.
*
* @param pInterface Pointer to interface being dropped.
* @return True to continue, false to unload this extension afterwards.
*/
virtual bool QueryInterfaceDrop(SMInterface *pInterface)
{
return true;
}
/**
* @brief Notifies the extension that an external interface it uses is being removed.
*
* @param pInterface Pointer to interface being dropped.
*/
virtual void NotifyInterfaceDrop(SMInterface *pInterface)
{
}
/**
* @brief Return false to tell Core that your extension should be considered unsable.
*
* @param error Error buffer.
* @param maxlength Size of error buffer.
* @return True on success, false otherwise.
*/
virtual bool QueryRunning(char *error, size_t maxlength)
{
return true;
}
public:
virtual bool IsMetamodExtension() =0;
virtual const char *GetExtensionName() =0;
virtual const char *GetExtensionURL() =0;
virtual const char *GetExtensionTag() =0;
virtual const char *GetExtensionAuthor() =0;
virtual const char *GetExtensionVerString() =0;
virtual const char *GetExtensionDescription() =0;
virtual const char *GetExtensionDateString() =0;
};
#define SMINTERFACE_EXTENSIONMANAGER_NAME "IExtensionManager"
#define SMINTERFACE_EXTENSIONMANAGER_VERSION 1
enum ExtensionLifetime
{
ExtLifetime_Forever, //Extension will never be unloaded automatically
ExtLifetime_Map, //Extension will be unloaded at the end of the map
};
class IExtensionManager : public SMInterface
{
public:
virtual const char *GetInterfaceName()
{
return SMINTERFACE_EXTENSIONMANAGER_NAME;
}
virtual unsigned int GetInterfaceVersion()
{
return SMINTERFACE_EXTENSIONMANAGER_VERSION;
}
public:
/**
* @brief Loads a extension into the extension system.
*
* @param path Path to extension file, relative to the extensions folder.
* @param lifetime Lifetime of the extension.
* @param error Error buffer.
* @param err_max Maximum error buffer length.
* @return New IExtension on success, NULL on failure.
*/
virtual IExtension *LoadExtension(const char *path,
ExtensionLifetime lifetime,
char *error,
size_t err_max) =0;
/**
* @brief Attempts to unload a module.
*
* @param pExt IExtension pointer.
* @return True if successful, false otherwise.
*/
virtual bool UnloadExtension(IExtension *pExt) =0;
};
};
#endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_
-350
View File
@@ -1,350 +0,0 @@
#ifndef _INCLUDE_SOURCEMOD_FORWARDINTERFACE_H_
#define _INCLUDE_SOURCEMOD_FORWARDINTERFACE_H_
#include <IForwardSys.h>
#include <IPluginSys.h>
#include <IPluginFunction.h>
#define SMINTERFACE_FORWARDMANAGER_NAME "IForwardManager"
#define SMINTERFACE_FORWARDMANAGER_VERSION 1
/**
* There is some very important documentation at the bottom of this file.
* Readers interested in knowing more about the forward system, scrolling down is a must!
*/
namespace SourceMod
{
enum ResultType
{
Pl_Continue = 0, /* No result */
Pl_Handled = 1, /* Result was handled, stop at the end */
Pl_Stop = 2, /* Result was handled, stop now */
};
enum ExecType
{
ET_Ignore = 0, /* Ignore all return values, return 0 */
ET_Single = 1, /* Only return the last exec, ignore all others */
ET_Event = 2, /* Acts as an event with the ResultTypes above, no mid-Stops allowed, returns highest */
ET_Hook = 3, /* Acts as a hook with the ResultTypes above, mid-Stops allowed, returns highest */
ET_Custom = 4, /* Ignored or handled by an IForwardFilter */
};
class IForward;
class IForwardFilter
{
public:
/**
* @brief Called when an error occurs executing a plugin.
*
* @param fwd IForward pointer.
* @param func IPluginFunction pointer to the failed function.
* @param err Error code.
* @return True to handle, false to pass to global error reporter.
*/
virtual bool OnErrorReport(IForward *fwd,
IPluginFunction *func,
int err)
{
return false;
}
/**
* @brief Called after each function return during execution.
* NOTE: Only used for ET_Custom.
*
* @param fwd IForward pointer.
* @param func IPluginFunction pointer to the executed function.
* @param retval Pointer to current return value (can be modified).
* @return ResultType denoting the next action to take.
*/
virtual ResultType OnFunctionReturn(IForward *fwd,
IPluginFunction *func,
cell_t *retval)
{
return Pl_Continue;
}
/**
* @brief Called when execution begins.
*/
virtual void OnExecuteBegin()
{
};
/**
* @brief Called when execution ends.
*
* @param final_ret Final return value (modifiable).
* @param success Number of successful execs.
* @param failed Number of failed execs.
*/
virtual void OnExecuteEnd(cell_t *final_ret, unsigned int success, unsigned int failed)
{
}
};
/**
* @brief Abstracts multiple function calling.
*
* NOTE: Parameters should be pushed in forward order, unlike
* the virtual machine/IPluginContext order.
* NOTE: Some functions are repeated in here because their
* documentation differs from their IPluginFunction equivalents.
* Missing are the Push functions, whose only doc change is that
* they throw SP_ERROR_PARAM on type mismatches.
*/
class IForward : public ICallable
{
public:
virtual ~IForward()
{
}
public:
/**
* @brief Returns the name of the forward.
*
* @return Forward name.
*/
virtual const char *GetForwardName() =0;
/**
* @brief Returns the number of functions in this forward.
*
* @return Number of functions in forward.
*/
virtual unsigned int GetFunctionCount() =0;
/**
* @brief Returns the method of multi-calling this forward has.
*
* @return ExecType of the forward.
*/
virtual ExecType GetExecType() =0;
/**
* @brief Executes the forward.
*
* @param result Pointer to store result in.
* @param filter Optional pointer to an IForwardFilter.
* @return Error code, if any.
*/
virtual int Execute(cell_t *result, IForwardFilter *filter=NULL) =0;
/**
* @brief Pushes an array of cells onto the current call. Different rules than ICallable.
* NOTE: On Execute, the pointer passed will be modified according to the copyback rule.
*
* @param inarray Array to copy. Cannot be NULL, unlike ICallable's version.
* @param cells Number of cells to allocate and optionally read from the input array.
* @param phys_addr Unused. If a value is passed, it will be filled with NULL.
* @param flags Whether or not changes should be copied back to the input array.
* @return Error code, if any.
*/
virtual int PushArray(cell_t *inarray,
unsigned int cells,
cell_t **phys_addr,
int flags=0) =0;
};
class IChangeableForward : public IForward
{
public:
/**
* @brief Removes a function from the call list.
* NOTE: Only removes one instance.
*
* @param func Function to remove.
* @return Whether or not the function was removed.
*/
virtual bool RemoveFunction(IPluginFunction *func) =0;
/**
* @brief Removes all instances of a plugin from the call list.
*
* @param plugin Plugin to remove instances of.
* @return Number of functions removed therein.
*/
virtual unsigned int RemoveFunctionsOfPlugin(IPlugin *plugin) =0;
/**
* @brief Adds a function to the call list.
* NOTE: Cannot be used during an incompleted call.
* NOTE: If used during a call, function is temporarily queued until calls are over.
* NOTE: Adding mulitple copies of the same function is illegal.
*
* @param func Function to add.
* @return True on success, otherwise false.
*/
virtual bool AddFunction(IPluginFunction *func) =0;
/**
* @brief Adds a function to the call list.
* NOTE: Cannot be used during an incompleted call.
* NOTE: If used during a call, function is temporarily queued until calls are over.
*
* @param ctx Context to use as a look-up.
* @param funcid Function id to add.
* @return True on success, otherwise false.
*/
virtual bool AddFunction(sp_context_t *ctx, funcid_t index) =0;
};
#define SP_PARAMTYPE_ANY 0
#define SP_PARAMFLAG_BYREF (1<<0)
#define SP_PARAMTYPE_CELL (1<<1)
#define SP_PARAMTYPE_FLOAT (2<<1)
#define SP_PARAMTYPE_STRING (3<<1)|SP_PARAMFLAG_BYREF
#define SP_PARAMTYPE_ARRAY (4<<1)|SP_PARAMFLAG_BYREF
#define SP_PARAMTYPE_VARARG (5<<1)
enum ParamType
{
Param_Any = SP_PARAMTYPE_ANY,
Param_Cell = SP_PARAMTYPE_CELL,
Param_Float = SP_PARAMTYPE_FLOAT,
Param_String = SP_PARAMTYPE_STRING,
Param_Array = SP_PARAMTYPE_ARRAY,
Param_VarArgs = SP_PARAMTYPE_VARARG,
Param_CellByRef = SP_PARAMTYPE_CELL|SP_PARAMFLAG_BYREF,
Param_FloatByRef = SP_PARAMTYPE_FLOAT|SP_PARAMFLAG_BYREF,
};
class IForwardManager : public SMInterface
{
public:
virtual const char *GetInterfaceName()
{
return SMINTERFACE_FORWARDMANAGER_NAME;
}
virtual unsigned int GetInterfaceVersion()
{
return SMINTERFACE_FORWARDMANAGER_VERSION;
}
public:
/**
* @brief Creates a managed forward. This forward exists globally.
* The name used to create the forward is used as its public function in all target plugins.
* As new non-private plugins become loaded or unloaded, they will be automatically added
* or removed. This is ideal for global, static forwards that are never changed.
*
* @param name Name of public function to use in forward.
* @param et Execution type to be used.
* @param num_params Number of parameter this function will have.
* NOTE: For varargs, this should include the vararg parameter.
* @param types Array of type information about each parameter. If NULL, types
* are read off the vararg stream.
* @param ... If types is NULL, num_params ParamTypes should be pushed.
* @return A new IForward on success, NULL if type combination is impossible.
*/
virtual IForward *CreateForward(const char *name,
ExecType et,
unsigned int num_params,
ParamType *types,
...) =0;
/**
* @brief Creates an unmanaged forward. This forward exists privately.
* Unlike managed forwards, no functions are ever added by the Manager.
* However, functions will be removed automatically if their parent plugin is unloaded.
*
* @param name Name of forward (unused except for lookup, can be NULL for anonymous).
* @param et Execution type to be used.
* @param num_params Number of parameter this function will have.
* NOTE: For varargs, this should include the vararg parameter.
* @param types Array of type information about each parameter. If NULL, types
* are read off the vararg stream.
* @param ... If types is NULL, num_params ParamTypes should be pushed.
* @return A new IChangeableForward on success, NULL if type combination is impossible.
*/
virtual IChangeableForward *CreateForwardEx(const char *name,
ExecType et,
int num_params,
ParamType *types,
...) =0;
/**
* @brief Finds a forward by name. Does not return anonymous forwards (named NULL or "").
*
* @param name Name of forward.
* @param ifchng Optionally store either NULL or an IChangeableForward pointer
* depending on type of forward.
* @return IForward pointer, or NULL if none found matching the name.
*/
virtual IForward *FindForward(const char *name, IChangeableForward **ifchng) =0;
/**
* @brief Frees and destroys a forward object.
*
* @param forward An IForward created by CreateForward() or CreateForwardEx().
*/
virtual void ReleaseForward(IForward *forward) =0;
};
};
/**
* In the AMX Mod X model of forwarding, each forward contained a list of pairs, each pair containing
* a function ID and an AMX structure. The forward structure itself did very little but hold parameter types.
* An execution call worked like this:
* - executeForward() took in a function id and a list of parameters
* - for each contained plugin:
* - the list of parameters was preprocessed and pushed
* - the call was made
* - the list was freed and copybacks were made
* - return
*
* The advantages to this is that the system is very easy to implement, and it's fast. The disadvantage is
* varargs tend to be very unforgiving and inflexible, and thus weird problems arose with casting. You also
* lose flexibility, type checking, and the ability to reasonably use variable arguments lists in the VM.
*
* SourceMod replaces this forward system with a far more advanced, but a bit bulkier one. The idea is that
* each plugin has a table of functions, and each function is an ICallable object. As well as being an ICallable,
* each function is an IPluginFunction. An ICallable simply describes the process of adding parameters to a
* function call. An IPluginFunction describes the process of actually calling a function and performing allocation,
* copybacks, and deallocations.
*
* A very powerful forward system emerges: a Forward is just a collection of IPluginFunctions. Thus, the same
* API can be easily wrapped around a simple list, and it will look transparent to the user.
* Advantages:
* 1) "SP Forwards" from AMX Mod X are simply IPluginFunctions without a collection.
* 2) Forwards are function based, rather than plugin based, and are thus far more flexible at runtime..
* 3) [2] Individual functions can be paused and more than one function from the same plugin can be hooked.
* 4) [2] One hook type that used to map to many SP Forwards can now be centralized as one Forward.
* This helps alleviate messes like Fakemeta.
* 5) Parameter pushing is type-checked and allows for variable arguments.
*
* Note that while #2,3,4 could be added to AMX Mod X, the real binding property is #1, which makes the system
* object oriented, rather than AMX Mod X, which hides the objects behind static functions. It is entirely a design
* issue, rather than a usability one. The interesting part is when it gets to implementation, which has to cache
* parameter pushing until execution. Without this, multiple function calls can be started across one plugin, which
* will result in heap corruption given SourcePawn's implementation.
*
* Observe the new calling process:
* - Each parameter is pushed into a local cache using the ICallable interface.
* - For each function in the collection:
* - Each parameter is decoded and -pushed into the function.
* - The call is made.
* - Return
*
* Astute readers will note the (minor) problems:
* 1) More memory is used. Specifically, rather than N params of memory, you now have N params * M plugins.
* This is because, again, parameters are cached both per-function and per-forward.
* 2) There are slightly more calls going around: one extra call for each parameter, since each push is manual.
*
* HISTORICAL NOTES:
* There used to be a # about copy backs.
* Note that originally, the Forward implementation was a thin wrapper around IForwards. It did not cache pushes,
* and instead immediately fired them to each internal plugin. This was to allow users to know that pointers would
* be immediately resolved. Unfortunately, this became extremely burdensome on the API and exposed many problems,
* the major (and breaking) one was that two separate Function objects cannot be in a calling process on the same
* plugin at once. (:TODO: perhaps prevent that in the IPlugin object?) This is because heap functions lose their order
* and become impossible to re-arrange without some global heap tracking mechanis. It also made iterative copy backs
* for arrays/references overwhelmingly complex, since each plugin had to have its memory back-patched for each copy.
* Therefore, this was scrapped for cached parameters (current implementation), which is the implementation AMX Mod X
* uses. It is both faster and works better.
*/
#endif //_INCLUDE_SOURCEMOD_FORWARDINTERFACE_H_
-252
View File
@@ -1,252 +0,0 @@
#ifndef _INCLUDE_SOURCEMOD_HANDLESYSTEM_INTERFACE_H_
#define _INCLUDE_SOURCEMOD_HANDLESYSTEM_INTERFACE_H_
#include <IShareSys.h>
#include <sp_vm_types.h>
#define SMINTERFACE_HANDLESYSTEM_NAME "IHandleSys"
#define SMINTERFACE_HANDLESYSTEM_VERSION 1
#define DEFAULT_IDENTITY NULL
namespace SourceMod
{
/**
* Both of these types have invalid values of '0' for error checking.
*/
typedef unsigned int HandleType_t;
typedef unsigned int Handle_t;
class SourcePawn::IPluginContext;
/**
* About type checking:
* Types can be inherited - a Parent type ("Supertype") can have child types.
* When accessing handles, type checking is done. This table shows how this is resolved:
*
* HANDLE CHECK -> RESULT
* ------ ----- ------
* Parent Parent Success
* Parent Child Fail
* Child Parent Success
* Child Child Success
*/
enum HandleError
{
HandleError_None = 0, /* No error */
HandleError_Changed, /* The handle has been freed and reassigned */
HandleError_Type, /* The handle has a different type registered */
HandleError_Freed, /* The handle has been freed */
HandleError_Index, /* generic internal indexing error */
HandleError_Access, /* No access permitted to free this handle */
HandleError_Limit, /* The limited number of handles has been reached */
HandleError_Identity, /* The identity token was not usable */
HandleError_Owner, /* Owners do not match for this operation */
HandleError_Version, /* Unrecognized security structure version */
HandleError_Parameter, /* An invalid parameter was passed */
HandleError_NoInherit, /* This type cannot be inherited */
};
/**
* Access rights specific to a type
*/
enum HTypeAccessRight
{
HTypeAccess_Create = 0, /* Handles of this type can be created (DEFAULT=false) */
HTypeAccess_Inherit, /* Sub-types can inherit this type (DEFAULT=false) */
/* -------------- */
HTypeAccess_TOTAL, /* Total number of type access rights */
};
/**
* Access rights specific to a Handle. These rights are exclusive.
* For example, you do not need "read" access to delete or clone.
*/
enum HandleAccessRight
{
HandleAccess_Read, /* Can be read (DEFAULT=ident only) */
HandleAccess_Delete, /* Can be deleted (DEFAULT=owner only) */
HandleAccess_Clone, /* Can be cloned (DEFAULT=any) */
/* ------------- */
HandleAccess_TOTAL, /* Total number of access rights */
};
#define HANDLE_RESTRICT_IDENTITY (1<<0) /* Access is restricted to the identity */
#define HANDLE_RESTRICT_OWNER (1<<1) /* Access is restricted to the owner */
/**
* This is used to define per-type access rights.
*/
struct TypeAccess
{
TypeAccess()
{
hsVersion = SMINTERFACE_HANDLESYSTEM_VERSION;
}
unsigned int hsVersion;
IdentityToken_t *ident;
bool access[HTypeAccess_TOTAL];
};
/**
* This is used to define per-Handle access rights.
*/
struct HandleAccess
{
HandleAccess()
{
hsVersion = SMINTERFACE_HANDLESYSTEM_VERSION;
}
unsigned int hsVersion;
unsigned int access[HandleAccess_TOTAL];
};
/**
* This pair of tokens is used for identification.
*/
struct HandleSecurity
{
IdentityToken_t *pOwner; /* Owner of the Handle */
IdentityToken_t *pIdentity; /* Owner of the Type */
};
class IHandleTypeDispatch
{
public:
virtual unsigned int GetDispatchVersion()
{
return SMINTERFACE_HANDLESYSTEM_VERSION;
}
public:
/**
* @brief Called when destroying a handle. Must be implemented.
*/
virtual void OnHandleDestroy(HandleType_t type, void *object) =0;
};
class IHandleSys : public SMInterface
{
public:
virtual unsigned int GetInterfaceVersion()
{
return SMINTERFACE_HANDLESYSTEM_VERSION;
}
virtual const char *GetInterfaceName()
{
return SMINTERFACE_HANDLESYSTEM_NAME;
}
public:
/**
* @brief Creates a new Handle type.
* NOTE: Currently, a child type may not have its own children.
* NOTE: Handle names must be unique if not private.
*
* @param name Name of handle type (NULL or "" to be anonymous)
* @param dispatch Pointer to a valid IHandleTypeDispatch object.
* @param parent Parent handle to inherit from, 0 for none.
* @param typeAccess Pointer to a TypeAccess object, NULL to use default
* or inherited permissions. Pointer can be temporary.
* @param hndlAccess Pointer to a HandleAccess object to define default
* default permissions on each Handle. NULL to use default
* permissions.
* @param ident Security token for any permissions. If typeAccess is NULL, this
* becomes the owning identity.
* @param err Optional pointer to store an error code.
* @return A new HandleType_t unique ID, or 0 on failure.
*/
virtual HandleType_t CreateType(const char *name,
IHandleTypeDispatch *dispatch,
HandleType_t parent,
const TypeAccess *typeAccess,
const HandleAccess *hndlAccess,
IdentityToken_t *ident,
HandleError *err) =0;
/**
* @brief Removes a handle type.
* NOTE: This removes all child types.
*
* @param type Type chain to remove.
* @param ident Identity token. Removal fails if the token does not match.
* @return True on success, false on failure.
*/
virtual bool RemoveType(HandleType_t type, IdentityToken_t *ident) =0;
/**
* @brief Finds a handle type by name.
*
* @param name Name of handle type to find (anonymous not allowed).
* @param type Address to store found handle in (if not found, undefined).
* @return True if found, false otherwise.
*/
virtual bool FindHandleType(const char *name, HandleType_t *type) =0;
/**
* @brief Creates a new handle.
*
* @param type Type to use on the handle.
* @param object Object to bind to the handle.
* @param owner Owner of the new Handle (may be NULL).
* @param ident Identity for type access if needed (may be NULL).
* @param err Optional pointer to store an error code.
* @return A new Handle_t, or 0 on failure.
*/
virtual Handle_t CreateHandle(HandleType_t type,
void *object,
IdentityToken_t *owner,
IdentityToken_t *ident,
HandleError *err) =0;
/**
* @brief Frees the memory associated with a handle and calls any destructors.
* NOTE: This function will decrement the internal reference counter. It will
* only perform any further action if the counter hits 0.
*
* @param type Handle_t identifier to destroy.
* @param pSecurity Security information struct (may be NULL).
* @return A HandleError error code.
*/
virtual HandleError FreeHandle(Handle_t handle, const HandleSecurity *pSecurity) =0;
/**
* @brief Clones a handle by adding to its internal reference count. Its data,
* type, and security permissions remain the same.
*
* @param handle Handle to duplicate. Any non-free handle target is valid.
* @param newhandle Stores the duplicated handle in the pointer (must not be NULL).
* @param newOwner New owner of cloned handle.
* @param pSecurity Security information struct (may be NULL).
* @return A HandleError error code.
*/
virtual HandleError CloneHandle(Handle_t handle,
Handle_t *newhandle,
IdentityToken_t *newOwner,
const HandleSecurity *pSecurity) =0;
/**
* @brief Retrieves the contents of a handle.
*
* @param handle Handle_t from which to retrieve contents.
* @param type Expected type to read as. 0 ignores typing rules.
* @param pSecurity Security information struct (may be NULL).
* @param object Optional address to store object in.
* @return HandleError error code.
*/
virtual HandleError ReadHandle(Handle_t handle,
HandleType_t type,
const HandleSecurity *pSecurity,
void **object) =0;
/**
* @brief Sets access permissions on one or more structures.
*
* @param pTypeAccess Optional TypeAccess buffer to initialize with the default values.
* @param pHandleAccess Optional HandleAccess buffer to initialize with the default values.
* @return True on success, false if version is unsupported.
*/
virtual bool InitAccessDefaults(TypeAccess *pTypeAccess, HandleAccess *pHandleAccess) =0;
};
};
#endif //_INCLUDE_SOURCEMOD_HANDLESYSTEM_INTERFACE_H_
-155
View File
@@ -1,155 +0,0 @@
#ifndef _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
#define _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
#include <IShareSys.h>
namespace SourceMod
{
#define SMINTERFACE_LIBRARYSYS_NAME "ILibrarySys"
#define SMINTERFACE_LIBRARYSYS_VERSION 1
class ILibrary
{
public:
virtual ~ILibrary()
{
/* Calling delete will call CloseLibrary! */
};
public:
/**
* @brief Closes dynamic library and invalidates pointer.
*/
virtual void CloseLibrary() =0;
/**
* @brief Retrieves a symbol pointer from the dynamic library.
*
* @param symname Symbol name.
* @return Symbol pointer, NULL if not found.
*/
virtual void *GetSymbolAddress(const char *symname) =0;
};
/**
* @brief Directory browsing abstraction.
*/
class IDirectory
{
public:
virtual ~IDirectory()
{
}
public:
/**
* @brief Returns true if there are more files to read, false otherwise.
*/
virtual bool MoreFiles() =0;
/**
* @brief Advances to the next entry in the stream.
*/
virtual void NextEntry() =0;
/**
* @brief Returns the name of the current entry.
*/
virtual const char *GetEntryName() =0;
/**
* @brief Returns whether the current entry is a directory.
*/
virtual bool IsEntryDirectory() =0;
/**
* @brief Returns whether the current entry is a file.
*/
virtual bool IsEntryFile() =0;
/**
* @brief Returns true if the current entry is valid
* (Used similarly to MoreFiles).
*/
virtual bool IsEntryValid() =0;
};
/**
* @brief Contains various operating system specific code.
*/
class ILibrarySys : public SMInterface
{
public:
virtual const char *GetInterfaceName()
{
return SMINTERFACE_LIBRARYSYS_NAME;
}
virtual unsigned int GetInterfaceVersion()
{
return SMINTERFACE_LIBRARYSYS_VERSION;
}
public:
/**
* @brief Opens a dynamic library file.
*
* @param path Path to library file (.dll/.so).
* @param error Buffer for any error message (may be NULL).
* @param err_max Maximum length of error buffer.
* @return Pointer to an ILibrary, NULL if failed.
*/
virtual ILibrary *OpenLibrary(const char *path, char *error, size_t err_max) =0;
/**
* @brief Opens a directory for reading.
*
* @param path Path to directory.
* @return Pointer to an IDirectory, NULL if failed.
*/
virtual IDirectory *OpenDirectory(const char *path) =0;
/**
* @brief Closes a directory and frees its handle.
*
* @param dir Pointer to IDirectory.
*/
virtual void CloseDirectory(IDirectory *dir) =0;
/**
* @brief Returns true if a path exists.
*/
virtual bool PathExists(const char *path) =0;
/**
* @brief Returns true if the path is a normal file.
*/
virtual bool IsPathFile(const char *path) =0;
/**
* @brief Returns true if the path is a normal directory.
*/
virtual bool IsPathDirectory(const char *path) =0;
/**
* @brief Gets a platform-specific error message.
* This should only be called when an ILibrary function fails.
* Win32 equivalent: GetLastError() + FormatMessage()
* POSIX equivalent: errno + strerror()
*
* @param error Error message buffer.
* @param err_max Maximum length of error buffer.
*/
virtual void GetPlatformError(char *error, size_t err_max) =0;
/**
* @brief Formats a string similar to snprintf(), except
* corrects all non-platform compatible path separators to be
* the correct platform character.
*
* @param buffer Output buffer pointer.
* @param maxlength Output buffer size.
* @param pathfmt Format string of path.
* @param ... Format string arguments.
*/
virtual size_t PathFormat(char *buffer, size_t maxlength, const char *pathfmt, ...) =0;
};
};
#endif //_INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
-153
View File
@@ -1,153 +0,0 @@
#ifndef _INCLUDE_SOURCEMOD_PLUGINFUNCTION_INTERFACE_H_
#define _INCLUDE_SOURCEMOD_PLUGINFUNCTION_INTERFACE_H_
#include <IPluginSys.h>
namespace SourceMod
{
#define SM_PARAM_COPYBACK (1<<0) /* Copy an array/reference back after call */
#define SM_PARAM_STRING_UTF8 (1<<0) /* String should be UTF-8 handled */
#define SM_PARAM_STRING_COPY (1<<1) /* String should be copied into the plugin */
/**
* @brief Represents what a function needs to implement in order to be callable.
*/
class ICallable
{
public:
/**
* @brief Pushes a cell onto the current call.
*
* @param cell Parameter value to push.
* @return Error code, if any.
*/
virtual int PushCell(cell_t cell) =0;
/**
* @brief Pushes a cell by reference onto the current call.
* NOTE: On Execute, the pointer passed will be modified if copyback is enabled.
* NOTE: By reference parameters are cached and thus are not read until execution.
* This means you cannot push a pointer, change it, and push it again and expect
* two different values to come out.
*
* @param cell Address containing parameter value to push.
* @param flags Copy-back flags.
* @return Error code, if any.
*/
virtual int PushCellByRef(cell_t *cell, int flags) =0;
/**
* @brief Pushes a float onto the current call.
*
* @param float Parameter value to push.
* @return Error code, if any.
*/
virtual int PushFloat(float number) =0;
/**
* @brief Pushes a float onto the current call by reference.
* NOTE: On Execute, the pointer passed will be modified if copyback is enabled.
* NOTE: By reference parameters are cached and thus are not read until execution.
* This means you cannot push a pointer, change it, and push it again and expect
* two different values to come out.
*
* @param float Parameter value to push.
& @param flags Copy-back flags.
* @return Error code, if any.
*/
virtual int PushFloatByRef(float *number, int flags) =0;
/**
* @brief Pushes an array of cells onto the current call.
* NOTE: On Execute, the pointer passed will be modified if non-NULL and copy-back
* is enabled.
* NOTE: By reference parameters are cached and thus are not read until execution.
* This means you cannot push a pointer, change it, and push it again and expect
* two different values to come out.
*
* @param inarray Array to copy, NULL if no initial array should be copied.
* @param cells Number of cells to allocate and optionally read from the input array.
* @param phys_addr Optional return address for physical array, if one was made.
* @param flags Whether or not changes should be copied back to the input array.
* @return Error code, if any.
*/
virtual int PushArray(cell_t *inarray,
unsigned int cells,
cell_t **phys_addr,
int flags=0) =0;
/**
* @brief Pushes a string onto the current call.
*
* @param string String to push.
* @return Error code, if any.
*/
virtual int PushString(const char *string) =0;
/**
* @brief Pushes a string or string buffer.
* NOTE: On Execute, the pointer passed will be modified if copy-back is enabled.
*
* @param buffer Pointer to string buffer.
* @param length Length of buffer.
* @param sz_flags String flags.
* @param cp_flags Copy-back flags.
* @return Error code, if any.
*/
virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags) =0;
/**
* @brief Cancels a function call that is being pushed but not yet executed.
* This can be used be reset for CallFunction() use.
*/
virtual void Cancel() =0;
};
/**
* @brief Encapsulates a function call in a plugin.
* NOTE: Function calls must be atomic to one execution context.
* NOTE: This object should not be deleted. It lives for the lifetime of the plugin.
*/
class IPluginFunction : public ICallable
{
public:
/**
* @brief Executes the forward, resets the pushed parameter list, and performs any copybacks.
*
* @param result Pointer to store return value in.
* @return Error code, if any.
*/
virtual int Execute(cell_t *result) =0;
/**
* @brief Executes the function with the given parameter array.
* Parameters are read in forward order (i.e. index 0 is parameter #1)
* NOTE: You will get an error if you attempt to use CallFunction() with
* previously pushed parameters.
*
* @param param Array of cell parameters.
* @param num_params Number of parameters to push.
* @param result Pointer to store result of function on return.
* @return SourcePawn error code (if any).
*/
virtual int CallFunction(const cell_t *params, unsigned int num_params, cell_t *result) =0;
/**
* @brief Returns which plugin this function belongs to.
*
* @return IPlugin pointer to parent plugin.
*/
virtual IPlugin *GetParentPlugin() =0;
/**
* @brief Returns the physical address of a by-reference parameter.
*
* @param Parameter index to read (beginning at 0).
* @return Address, or NULL if invalid parameter specified.
*/
virtual cell_t *GetAddressOfPushedParam(unsigned int param) =0;
};
};
#endif //_INCLUDE_SOURCEMOD_PLUGINFUNCTION_INTERFACE_H_
-302
View File
@@ -1,302 +0,0 @@
#ifndef _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
#define _INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
#include <IShareSys.h>
#include <sp_vm_api.h>
#define SMINTERFACE_PLUGINSYSTEM_NAME "IPluginManager"
#define SMINTERFACE_PLUGINSYSTEM_VERSION 1
#define SM_CONTEXTVAR_USER 3
namespace SourceMod
{
class IPlugin;
/**
* @brief Encapsulates plugin public information.
*/
typedef struct sm_plugininfo_s
{
const char *name;
const char *author;
const char *description;
const char *version;
const char *url;
} sm_plugininfo_t;
/**
* @brief Describes the usability status of a plugin.
* Note: The status "Loaded" and "Created" are only reachable
* during map load.
*/
enum PluginStatus
{
Plugin_Running=0, /* Plugin is running */
/* All states below are unexecutable */
Plugin_Paused, /* Plugin is loaded but paused */
Plugin_Error, /* Plugin is loaded but errored/locked */
/* All states below do not have all natives */
Plugin_Loaded, /* Plugin has passed loading and can be finalized */
Plugin_Failed, /* Plugin has a fatal failure */
Plugin_Created, /* Plugin is created but not initialized */
Plugin_Uncompiled, /* Plugin is not yet compiled by the JIT */
Plugin_BadLoad, /* Plugin failed to load */
};
/**
* @brief Describes the object lifetime of a plugin.
*/
enum PluginType
{
PluginType_Private, /* Plugin is privately managed and receives no forwards */
PluginType_MapUpdated, /* Plugin will never be unloaded unless for updates on mapchange */
PluginType_MapOnly, /* Plugin will be removed at mapchange */
PluginType_Global, /* Plugin will never be unloaded or updated */
};
class IPluginFunction;
/**
* @brief Encapsulates a run-time plugin as maintained by SourceMod.
*/
class IPlugin
{
public:
virtual ~IPlugin()
{
}
/**
* @brief Returns the lifetime of a plugin.
*/
virtual PluginType GetType() const =0;
/**
* @brief Returns the current API context being used in the plugin.
*
* @return Pointer to an IPluginContext, or NULL if not loaded.
*/
virtual SourcePawn::IPluginContext *GetBaseContext() const =0;
/**
* @brief Returns the context structure being used in the plugin.
*
* @return Pointer to an sp_context_t, or NULL if not loaded.
*/
virtual sp_context_t *GetContext() const =0;
/**
* @brief Returns the plugin file structure.
*
* @return Pointer to an sp_plugin_t, or NULL if not loaded.
*/
virtual const sp_plugin_t *GetPluginStructure() const =0;
/**
* @brief Returns information about the plugin by reference.
*
* @return Pointer to a sm_plugininfo_t object, NULL if plugin is not loaded.
*/
virtual const sm_plugininfo_t *GetPublicInfo() const =0;
/**
* @brief Returns the plugin filename (relative to plugins dir).
*/
virtual const char *GetFilename() const =0;
/**
* @brief Returns true if a plugin is in debug mode, false otherwise.
*/
virtual bool IsDebugging() const =0;
/**
* @brief Returns the plugin status.
*/
virtual PluginStatus GetStatus() const =0;
/**
* @brief Sets whether the plugin is paused or not.
*
* @return True on successful state change, false otherwise.
*/
virtual bool SetPauseState(bool paused) =0;
/**
* @brief Returns the unique serial number of a plugin.
*/
virtual unsigned int GetSerial() const =0;
/**
* @brief Returns a function by name.
*
* @param public_name Name of the function.
* @return A new IPluginFunction pointer, NULL if not found.
*/
virtual IPluginFunction *GetFunctionByName(const char *public_name) =0;
/**
* @brief Returns a function by its id.
*
* @param func_id Function ID.
* @return A new IPluginFunction pointer, NULL if not found.
*/
virtual IPluginFunction *GetFunctionById(funcid_t func_id) =0;
/**
* @brief Returns a plugin's identity token.
*/
virtual IdentityToken_t *GetIdentity() const =0;
};
/**
* @brief Iterates over a list of plugins.
*/
class IPluginIterator
{
public:
virtual ~IPluginIterator()
{
};
public:
/**
* @brief Returns true if there are more plugins in the iterator.
*/
virtual bool MorePlugins() =0;
/**
* @brief Returns the plugin at the current iterator position.
*/
virtual IPlugin *GetPlugin() =0;
/**
* @brief Advances to the next plugin in the iterator.
*/
virtual void NextPlugin() =0;
/**
* @brief Destroys the iterator object.
* Note: You may use 'delete' in lieu of this function.
*/
virtual void Release() =0;
};
/**
* @brief Listens for plugin-oriented events.
*/
class IPluginsListener
{
public:
/**
* @brief Called when a plugin is created/mapped into memory.
*/
virtual void OnPluginCreated(IPlugin *plugin)
{
}
/**
* @brief Called when a plugin is fully loaded successfully.
*/
virtual void OnPluginLoaded(IPlugin *plugin)
{
}
/**
* @brief Called when a plugin is unloaded (only if fully loaded).
*/
virtual void OnPluginUnloaded(IPlugin *plugin)
{
}
/**
* @brief Called when a plugin is destroyed.
* NOTE: Always called if Created, even if load failed.
*/
virtual void OnPluginDestroyed(IPlugin *plugin)
{
}
};
/**
* @brief Manages the runtime loading and unloading of plugins.
*/
class IPluginManager : public SMInterface
{
public:
virtual const char *GetInterfaceName()
{
return SMINTERFACE_PLUGINSYSTEM_NAME;
}
virtual unsigned int GetInterfaceVersion()
{
return SMINTERFACE_PLUGINSYSTEM_VERSION;
}
public:
/**
* @brief Attempts to load a plugin.
*
* @param path Path and filename of plugin, relative to plugins folder.
* @param debug Whether or not to default the plugin into debug mode.
* @param type Lifetime of the plugin.
* @param error Buffer to hold any error message.
* @param err_max Maximum length of error message buffer.
* @return A new plugin pointer on success, false otherwise.
*/
virtual IPlugin *LoadPlugin(const char *path,
bool debug,
PluginType type,
char error[],
size_t err_max) =0;
/**
* @brief Attempts to unload a plugin.
*
* @param plugin Pointer to the plugin handle.
* @return True on success, false otherwise.
*/
virtual bool UnloadPlugin(IPlugin *plugin) =0;
/**
* @brief Finds a plugin by its context.
* Note: This function should be considered O(1).
*
* @param ctx Pointer to an sp_context_t.
* @return Pointer to a matching IPlugin, or NULL if none found.
*/
virtual IPlugin *FindPluginByContext(const sp_context_t *ctx) =0;
/**
* @brief Returns the number of plugins (both failed and loaded).
*
* @return The number of internally cached plugins.
*/
virtual unsigned int GetPluginCount() =0;
/**
* @brief Returns a pointer that can be used to iterate through plugins.
* Note: This pointer must be freed using EITHER delete OR IPluginIterator::Release().
*/
virtual IPluginIterator *GetPluginIterator() =0;
/**
* @brief Adds a plugin manager listener.
*
* @param listener Pointer to a listener.
*/
virtual void AddPluginsListener(IPluginsListener *listener) =0;
/**
* @brief Removes a plugin listener.
*
* @param listener Pointer to a listener.
*/
virtual void RemovePluginsListener(IPluginsListener *listener) =0;
};
};
#endif //_INCLUDE_SOURCEMOD_PLUGINMNGR_INTERFACE_H_
-90
View File
@@ -1,90 +0,0 @@
#ifndef _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_H_
#define _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_H_
/**
* @brief Note: This interface is not exposed.
* The reason should be obvious: we do not want users touching the "root" console menu.
* If we exposed this, every little plugin would be dropping down a silly set of user commands,
* whereas this menu is explicitly provided for stuff that only Core itself is capable of managing.
*/
namespace SourceMod
{
/**
* @brief Handles a root console menu action.
*/
class IRootConsoleCommand
{
public:
virtual void OnRootConsoleCommand(const char *command, unsigned int argcount) =0;
};
/**
* @brief Manages the root console menu - the "sm" command for servers.
*/
class IRootConsole
{
public:
/**
* @brief Adds a root console command handler. The command must be unique.
*
* @param cmd String containing the console command.
* @param text Description text.
* @param pHandler An IRootConsoleCommand pointer to handle the command.
* @return True on success, false on too many commands or duplicate command.
*/
virtual bool AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler) =0;
/**
* @brief Removes a root console command handler.
*
* @param cmd String containing the console command.
* @param pHandler An IRootConsoleCommand pointer for verification.
* @return True on success, false otherwise.
*/
virtual bool RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler) =0;
/**
* @brief Prints text back to the console.
*
* @param fmt Format of string.
* @param ... Format arguments.
*/
virtual void ConsolePrint(const char *fmt, ...) =0;
/**
* @brief Returns the string of an argument.
*
* @param argno The index of the argument.
* @return A string containing the argument, or nothing if invalid.
*/
virtual const char *GetArgument(unsigned int argno) =0;
/**
* @brief Returns the number of arguments.
*
* @return Number of arguments.
*/
virtual unsigned int GetArgumentCount() =0;
/**
* @brief Returns the entire argument string.
*
* @return String containing all arguments.
*/
virtual const char *GetArguments() =0;
/**
* @brief Draws a generic command/description pair.
* NOTE: The pair is currently four spaces indented and 16-N spaces of separation,
* N being the length of the command name. This is subject to change in case we
* account for Valve's font choices.
*
* @param option String containing the command option.
* @param description String containing the command description.
*/
virtual void DrawGenericOption(const char *cmd, const char *text) =0;
};
};
#endif //_INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_H_
-149
View File
@@ -1,149 +0,0 @@
#ifndef _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
#define _INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
#include <sp_vm_types.h>
#define NO_IDENTITY 0
namespace SourceMod
{
class IExtension;
struct IdentityToken_t;
typedef unsigned int HandleType_t;
typedef HandleType_t IdentityType_t;
/**
* @brief Defines the base functionality required by a shared interface.
*/
class SMInterface
{
public:
/**
* @brief Must return an integer defining the interface's version.
*/
virtual unsigned int GetInterfaceVersion() =0;
/**
* @brief Must return a string defining the interface's unique name.
*/
virtual const char *GetInterfaceName() =0;
/**
* @brief Must return whether the requested version number is backwards comaptible.
* Note: This can be overridden for breaking changes or custom versioning.
*
* @param version Version number to compare against.
* @return True if compatible, false otherwise.
*/
virtual bool IsVersionCompatible(unsigned int version)
{
if (version > GetInterfaceVersion())
{
return false;
}
return true;
}
};
/**
* @brief Tracks dependencies and fires dependency listeners.
*/
class IShareSys
{
public:
/**
* @brief Adds an interface to the global interface system.
*
* @param myself Object adding this interface, in order to track dependencies.
* @param iface Interface pointer (must be unique).
* @return True on success, false otherwise.
*/
virtual bool AddInterface(IExtension *myself, SMInterface *iface) =0;
/**
* @brief Requests an interface from the global interface system.
* If found, the interface's internal reference count will be increased.
*
* @param iface_name Interface name.
* @param iface_vers Interface version to attempt to match.
* @param myself Object requesting this interface, in order to track dependencies.
* @param pIface Pointer to store the return value in.
*/
virtual bool RequestInterface(const char *iface_name,
unsigned int iface_vers,
IExtension *myself,
SMInterface **pIface) =0;
/**
* @brief Adds a list of natives to the global native pool, to be bound on plugin load.
* NOTE: Adding natives currently does not bind them to any loaded plugins.
* You must manually bind late natives.
*
* @param token Identity token of parent object.
* @param natives Array of natives to add. The last entry must have NULL members.
*/
virtual void AddNatives(IExtension *myself, const sp_nativeinfo_t *natives) =0;
/**
* @brief Creates a new identity type.
* NOTE: Module authors should never need to use this. Due to the current implementation,
* there is a hardcoded limit of 15 types. Core uses up a few, so think carefully!
*
* @param name String containing type name. Must not be empty or NULL.
* @return A new HandleType_t identifier, or 0 on failure.
*/
virtual IdentityType_t CreateIdentType(const char *name) =0;
/**
* @brief Finds an identity type by name.
* DEFAULT IDENTITY TYPES:
* "PLUGIN" - An IPlugin object.
* "MODULE" - An IModule object.
* "CORE" - An SMGlobalClass or other singleton.
*
* @param name String containing type name to search for.
* @return A HandleType_t identifier if found, 0 otherwise.
*/
virtual IdentityType_t FindIdentType(const char *name) =0;
/**
* @brief Creates a new identity token. This token is guaranteed to be unique
* amongst all other open identities.
*
* @param type Identity type.
* @return A new IdentityToken_t identifier.
*/
virtual IdentityToken_t *CreateIdentity(IdentityType_t type) =0;
/**
* @brief Destroys an identity type. Note that this will delete any identities
* that are under this type.
*
* @param type Identity type.
*/
virtual void DestroyIdentType(IdentityType_t type) =0;
/**
* @brief Destroys an identity token. Any handles being owned by this token, or
* any handles being
*
* @param identity Identity to remove.
*/
virtual void DestroyIdentity(IdentityToken_t *identity) =0;
/**
* @brief Requires an extension. This tells SourceMod that without this extension,
* your extension should not be loaded. The name should not include the ".dll" or
* the ".so" part of the file name.
*
* @param myself IExtension pointer to yourself.
* @param filename File of extension to require.
* @param require Whether or not this extension is a required dependency.
* @param autoload Whether or not to autoload this extension.
*/
virtual void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload) =0;
};
};
#endif //_INCLUDE_SOURCEMOD_IFACE_SHARE_SYS_H_
-74
View File
@@ -1,74 +0,0 @@
#ifndef _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
#define _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
#include <IShareSys.h>
#define SMINTERFACE_SOURCEMOD_NAME "ISourceMod"
#define SMINTERFACE_SOURCEMOD_VERSION 1
namespace SourceMod
{
enum PathType
{
Path_None = 0,
Path_Game,
Path_SM,
};
class ISourceMod : public SMInterface
{
public:
virtual const char *GetInterfaceName()
{
return SMINTERFACE_SOURCEMOD_NAME;
}
virtual unsigned int GetInterfaceVersion()
{
return SMINTERFACE_SOURCEMOD_VERSION;
}
public:
/**
* @brief Returns the full path to the mod directory.
*
* @return A string containing the full mod path.
*/
virtual const char *GetModPath() =0;
/**
* @brief Returns the full path to the SourceMod directory.
*
* @return A string containing the full SourceMod path.
*/
virtual const char *GetSourceModPath() =0;
/**
* @brief Builds a platform path for a specific target base path.
*
* @param type Type of path to use as a base.
* @param buffer Buffer to write to.
* @param maxlength Size of buffer.
* @param format Format string.
* @param ... Format arguments.
* @return Number of bytes written.
*/
virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, char *format, ...) =0;
/**
* @brief Logs a message to the SourceMod logs.
*
* @param format Message format.
* @param ... Message format parameters.
*/
virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
/**
* @brief Logs a message to the SourceMod error logs.
*
* @param format Message format.
* @param ... Message format parameters.
*/
virtual void LogError(IExtension *pExt, const char *format, ...) =0;
};
};
#endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
-316
View File
@@ -1,316 +0,0 @@
#ifndef _INCLUDE_SOURCEMOD_TEXTPARSERS_INTERFACE_H_
#define _INCLUDE_SOURCEMOD_TEXTPARSERS_INTERFACE_H_
#include <IShareSys.h>
namespace SourceMod
{
/**
* The INI file format is defined as:
* WHITESPACE: 0x20, \n, \t, \r
* IDENTIFIER: A-Z a-z 0-9 _ - , + . $ ? /
* STRING: Any set of symbols
*
* Basic syntax is comprised of SECTIONs.
* A SECTION is defined as:
* [SECTIONNAME]
* OPTION
* OPTION
* OPTION...
*
* SECTIONNAME is an IDENTIFIER.
* OPTION can be repeated any number of times, once per line.
* OPTION is defined as one of:
* KEY = "VALUE"
* KEY = VALUE
* KEY
* Where KEY is an IDENTIFIER and VALUE is a STRING.
*
* WHITESPACE should always be omitted.
* COMMENTS should be stripped, and are defined as text occuring in:
* ;<TEXT>
*
* Example file below. Note that
* The second line is technically invalid. The event handler
* must decide whether this should be allowed.
* --FILE BELOW--
* [gaben]
* hi = clams
* bye = "NO CLAMS"
*
* [valve]
* cannot
* maintain
* products
*/
class ITextListener_INI
{
public:
/**
* @brief Called when a new section is encountered in an INI file.
*
* @param section Name of section in between the [ and ] characters.
* @param invalid_tokens True if invalid tokens were detected in the name.
* @param close_bracket True if a closing bracket was detected, false otherwise.
* @param extra_tokens True if extra tokens were detected on the line.
* @param curtok Contains current token in the line where the section name starts.
* You can add to this offset when failing to point to a token.
* @return True to keep parsing, false otherwise.
*/
virtual bool ReadINI_NewSection(const char *section,
bool invalid_tokens,
bool close_bracket,
bool extra_tokens,
unsigned int *curtok)
{
return true;
}
/**
* @brief Called when encountering a key/value pair in an INI file.
*
* @param key Name of key.
* @param value String containing value (with quotes stripped, if any).
* @param invalid_tokens Whether or not the key contained invalid tokens.
* @param equal_token There was an '=' sign present (in case the value is missing).
* @param quotes Whether value was enclosed in quotes.
* @param curtoken Contains the token index of the start of the value string.
* This can be changed when returning false.
* @return True to keep parsing, false otherwise.
*/
virtual bool ReadINI_KeyValue(const char *key,
const char *value,
bool invalid_tokens,
bool equal_token,
bool quotes,
unsigned int *curtok)
{
return true;
}
/**
* @brief Called after a line has been preprocessed, if it has text.
*
* @param line Contents of line.
* @param curtok Pointer to optionally store failed position in string.
* @return True to keep parsing, false otherwise.
*/
virtual bool ReadINI_RawLine(const char *line, unsigned int *cutok)
{
return true;
}
};
/**
* :TODO: write this in CFG (context free grammar) format so it makes sense
*
* The SMC file format is defined as:
* WHITESPACE: 0x20, \n, \t, \r
* IDENTIFIER: Any ASCII character EXCLUDING ", {, }, ;, //, /*, or WHITESPACE.
* STRING: Any set of symbols enclosed in quotes.
* Note: if a STRING does not have quotes, it is parsed as an IDENTIFIER.
*
* Basic syntax is comprised of SECTIONBLOCKs.
* A SECTIONBLOCK defined as:
*
* SECTIONNAME
* {
* OPTION
* }
*
* OPTION can be repeated any number of times inside a SECTIONBLOCK.
* A new line will terminate an OPTION, but there can be more than one OPTION per line.
* OPTION is defined any of:
* "KEY" "VALUE"
* SECTIONBLOCK
*
* SECTIONNAME, KEY, VALUE, and SINGLEKEY are strings
* SECTIONNAME cannot have trailing characters if quoted, but the quotes can be optionally removed.
* If SECTIONNAME is not enclosed in quotes, the entire sectionname string is used (minus surrounding whitespace).
* If KEY is not enclosed in quotes, the key is terminated at first whitespace.
* If VALUE is not properly enclosed in quotes, the entire value string is used (minus surrounding whitespace).
* The VALUE may have inner quotes, but the key string may not.
*
* For an example, see configs/permissions.cfg
*
* WHITESPACE should be ignored.
* Comments are text occuring inside the following tokens, and should be stripped
* unless they are inside literal strings:
* ;<TEXT>
* //<TEXT>
* /*<TEXT> */
enum SMCParseResult
{
SMCParse_Continue, //continue parsing
SMCParse_Halt, //stop parsing here
SMCParse_HaltFail //stop parsing and return failure
};
enum SMCParseError
{
SMCParse_Okay = 0, //no error
SMCParse_StreamOpen, //stream failed to open
SMCParse_StreamError, //the stream died... somehow
SMCParse_Custom, //a custom handler threw an error
SMCParse_InvalidSection1, //a section was declared without quotes, and had extra tokens
SMCParse_InvalidSection2, //a section was declared without any header
SMCParse_InvalidSection3, //a section ending was declared with too many unknown tokens
SMCParse_InvalidSection4, //a section ending has no matching beginning
SMCParse_InvalidSection5, //a section beginning has no matching ending
SMCParse_InvalidTokens, //there were too many unidentifiable strings on one line
SMCParse_TokenOverflow, //the token buffer overflowed
SMCParse_InvalidProperty1, //a property was declared outside of any section
};
class ITextListener_SMC
{
public:
/**
* @brief Called when starting parsing.
*/
virtual void ReadSMC_ParseStart()
{
};
/**
* @brief Called when ending parsing.
*
* @param halted True if abnormally halted, false otherwise.
* @param failed True if parsing failed, false otherwise.
*/
virtual void ReadSMC_ParseEnd(bool halted, bool failed)
{
}
/**
* @brief Called when a warning occurs.
* @param error By-reference variable containing the error message of the warning.
* @param tokens Pointer to the token stream causing the error.
* @return SMCParseResult directive.
*/
virtual SMCParseResult ReadSMC_OnWarning(SMCParseError &error, const char *tokens)
{
return SMCParse_HaltFail;
}
/**
* @brief Called when entering a new section
*
* @param name Name of section, with the colon omitted.
* @param opt_quotes Whether or not the option string was enclosed in quotes.
* @return SMCParseResult directive.
*/
virtual SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes)
{
return SMCParse_Continue;
}
/**
* @brief Called when encountering a key/value pair in a section.
*
* @param key Key string.
* @param value Value string. If no quotes were specified, this will be NULL,
and key will contain the entire string.
* @param key_quotes Whether or not the key was in quotation marks.
* @param value_quotes Whether or not the value was in quotation marks.
* @return SMCParseResult directive.
*/
virtual SMCParseResult ReadSMC_KeyValue(const char *key,
const char *value,
bool key_quotes,
bool value_quotes)
{
return SMCParse_Continue;
}
/**
* @brief Called when leaving the current section.
*
* @return SMCParseResult directive.
*/
virtual SMCParseResult ReadSMC_LeavingSection()
{
return SMCParse_Continue;
}
/**
* @brief Called after an input line has been preprocessed.
*
* @param line String containing line input.
* @param curline Number of line in file.
* @return SMCParseResult directive.
*/
virtual SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline)
{
return SMCParse_Continue;
}
};
#define SMINTERFACE_TEXTPARSERS_NAME "ITextParsers"
#define SMINTERFACE_TEXTPARSERS_VERSION 1
class ITextParsers : public SMInterface
{
public:
virtual const char *GetInterfaceName()
{
return SMINTERFACE_TEXTPARSERS_NAME;
}
virtual unsigned int GetInterfaceVersion()
{
return SMINTERFACE_TEXTPARSERS_VERSION;
}
public:
/**
* @brief Parses an INI-format file.
*
* @param file Path to file.
* @param ini_listener Event handler for reading file.
* @param line If non-NULL, will contain last line parsed (0 if file could not be opened).
* @param col If non-NULL, will contain last column parsed (undefined if file could not be opened).
* @return True if parsing succeded, false if file couldn't be opened or there was a syntax error.
*/
virtual bool ParseFile_INI(const char *file,
ITextListener_INI *ini_listener,
unsigned int *line,
unsigned int *col) =0;
/**
* @brief Parses an SMC-format text file.
* Note that the parser makes every effort to obey broken syntax.
* For example, if an open brace is missing, but the section name has a colon,
* it will let you know. It is up to the event handlers to decide whether to be strict or not.
*
* @param file Path to file.
* @param smc_listener Event handler for reading file.
* @param line If non-NULL, will contain last line parsed (0 if file could not be opened).
* @param col If non-NULL, will contain last column parsed (undefined if file could not be opened).
* @return An SMCParseError result code.
*/
virtual SMCParseError ParseFile_SMC(const char *file,
ITextListener_SMC *smc_listener,
unsigned int *line,
unsigned int *col) =0;
/**
* @brief Converts an SMCParseError to a stirng.
*
* @param err SMCParseError.
* @return String error message, or NULL if none.
*/
virtual const char *GetSMCErrorString(SMCParseError err) =0;
public:
/**
* @brief Returns the number of bytes that a multi-byte character contains in a UTF-8 stream.
* If the current character is not multi-byte, the function returns 1.
*
* @param stream Pointer to multi-byte ANSI character string.
* @return Number of bytes in current character.
*/
virtual unsigned int GetUTF8CharBytes(const char *stream) =0;
};
};
#endif //_INCLUDE_SOURCEMOD_TEXTPARSERS_INTERFACE_H_
+1 -1
View File
@@ -8,7 +8,7 @@
#include <sp_vm_types.h>
#include <sp_vm_api.h>
#include "sm_platform.h"
#include "interfaces/IShareSys.h"
#include <IShareSys.h>
using namespace SourcePawn;
using namespace SourceMod;
+1 -1
View File
@@ -50,7 +50,7 @@ void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap);
if (len >= sizeof(buffer))
if (len >= sizeof(buffer) - 1)
{
buffer[510] = '\n';
buffer[511] = '\0';
+6
View File
@@ -564,6 +564,12 @@ void CExtensionManager::MarkAllLoaded()
}
}
void CExtensionManager::AddDependency(IExtension *pSource, const char *file, bool required, bool autoload)
{
/* :TODO: implement */
return;
}
void CExtensionManager::OnRootConsoleCommand(const char *cmd, unsigned int argcount)
{
if (argcount >= 3)
+1
View File
@@ -80,6 +80,7 @@ public:
void AddNatives(IExtension *pOwner, const sp_nativeinfo_t *natives);
void BindAllNativesToPlugin(IPlugin *pPlugin);
void MarkAllLoaded();
void AddDependency(IExtension *pSource, const char *file, bool required, bool autoload);
private:
CExtension *FindByOrder(unsigned int num);
private:
+6
View File
@@ -194,3 +194,9 @@ void ShareSystem::RemoveInterfaces(IExtension *pExtension)
}
}
}
void ShareSystem::AddDependency(IExtension *myself, const char *filename, bool require, bool autoload)
{
g_Extensions.AddDependency(myself, filename, require, autoload);
}
+1
View File
@@ -42,6 +42,7 @@ public: //IShareSys
IdentityToken_t *CreateIdentity(IdentityType_t type);
void DestroyIdentType(IdentityType_t type);
void DestroyIdentity(IdentityToken_t *identity);
void AddDependency(IExtension *myself, const char *filename, bool require, bool autoload);
public: //SMGlobalClass
/* Pre-empt in case anything tries to register idents early */
void OnSourceModStartup(bool late);