dvander@372: /**
ds@653: * vim: set ts=4 :
ds@1330: * =============================================================================
dvander@1226: * SourceMod
dvander@1226: * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
ds@1330: * =============================================================================
dvander@372: *
ds@1330: * This program is free software; you can redistribute it and/or modify it under
ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330: * Free Software Foundation.
dvander@379: *
ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1330: * details.
dvander@1226: *
ds@1330: * You should have received a copy of the GNU General Public License along with
ds@1330: * this program. If not, see .
dvander@1226: *
ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1330: * this exception to all derivative works. AlliedModders LLC defines further
ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330: * or .
dvander@372: *
dvander@372: * Version: $Id$
dvander@372: */
dvander@372:
dvander@324: #ifndef _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
dvander@324: #define _INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_
dvander@324:
dvander@372: /**
dvander@372: * @file ISourceMod.h
ds@729: * @brief Defines miscellaneous helper functions useful to extensions.
dvander@372: */
dvander@372:
faluco@682: #include
dvander@359: #include
faluco@484: #include
dvander@324:
dvander@324: #define SMINTERFACE_SOURCEMOD_NAME "ISourceMod"
dvander@735: #define SMINTERFACE_SOURCEMOD_VERSION 3
dvander@324:
faluco@682: /**
faluco@682: * @brief Forward declaration of the KeyValues class.
faluco@682: */
faluco@682: class KeyValues;
faluco@682:
dvander@324: namespace SourceMod
dvander@324: {
dvander@372: /**
dvander@372: * @brief Describes various ways of formatting a base path.
dvander@372: */
dvander@324: enum PathType
dvander@324: {
dvander@372: Path_None = 0, /**< No base path */
dvander@372: Path_Game, /**< Base path is absolute mod folder */
dvander@372: Path_SM, /**< Base path is absolute to SourceMod */
dvander@372: Path_SM_Rel, /**< Base path is relative to SourceMod */
dvander@324: };
dvander@324:
dvander@372: /**
faluco@484: * @brief Contains miscellaneous helper functions.
dvander@372: */
dvander@324: class ISourceMod : public SMInterface
dvander@324: {
dvander@324: public:
dvander@324: virtual const char *GetInterfaceName()
dvander@324: {
dvander@324: return SMINTERFACE_SOURCEMOD_NAME;
dvander@324: }
dvander@324: virtual unsigned int GetInterfaceVersion()
dvander@324: {
dvander@324: return SMINTERFACE_SOURCEMOD_VERSION;
dvander@324: }
dvander@324: public:
dvander@324: /**
ds@729: * @brief Returns the full path to the game directory.
dvander@324: *
ds@729: * @return A string containing the full game path.
dvander@324: */
ds@729: virtual const char *GetGamePath() const =0;
dvander@324:
dvander@324: /**
dvander@324: * @brief Returns the full path to the SourceMod directory.
dvander@324: *
dvander@324: * @return A string containing the full SourceMod path.
dvander@324: */
faluco@484: virtual const char *GetSourceModPath() const =0;
dvander@324:
dvander@324: /**
dvander@324: * @brief Builds a platform path for a specific target base path.
dvander@324: *
dvander@324: * @param type Type of path to use as a base.
dvander@324: * @param buffer Buffer to write to.
dvander@324: * @param maxlength Size of buffer.
dvander@324: * @param format Format string.
dvander@324: * @param ... Format arguments.
dvander@324: * @return Number of bytes written.
dvander@324: */
ds@1411: virtual size_t BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...) =0;
dvander@324:
dvander@324: /**
dvander@324: * @brief Logs a message to the SourceMod logs.
dvander@324: *
dvander@372: * @param pExt Extension calling this function.
dvander@324: * @param format Message format.
dvander@324: * @param ... Message format parameters.
dvander@324: */
dvander@324: virtual void LogMessage(IExtension *pExt, const char *format, ...) =0;
dvander@324:
dvander@324: /**
dvander@324: * @brief Logs a message to the SourceMod error logs.
dvander@324: *
dvander@372: * @param pExt Extension calling this function.
dvander@324: * @param format Message format.
dvander@324: * @param ... Message format parameters.
dvander@324: */
dvander@324: virtual void LogError(IExtension *pExt, const char *format, ...) =0;
dvander@347:
dvander@347: /**
dvander@347: * @brief Formats a string from a native.
dvander@347: *
dvander@347: * @param buffer Buffer to store message.
ds@729: * @param maxlength Maximum length of buffer (including null terminator).
dvander@347: * @param pContext Pointer to the plugin's context.
dvander@347: * @param params Parameter array that was passed to the native.
dvander@347: * @param param Parameter index where format string and variable arguments begin.
dvander@416: * Note: parameter indexes start at 1.
dvander@347: * @return Number of bytes written, not including the null terminator.
dvander@347: */
dvander@347: virtual size_t FormatString(char *buffer,
dvander@347: size_t maxlength,
dvander@359: SourcePawn::IPluginContext *pContext,
dvander@347: const cell_t *params,
dvander@347: unsigned int param) =0;
dvander@440:
dvander@440: /**
dvander@440: * @brief Creates a data pack object.
dvander@440: *
dvander@440: * @return A new IDataPack object.
dvander@440: */
dvander@440: virtual IDataPack *CreateDataPack() =0;
dvander@440:
dvander@440: /**
dvander@440: * @brief Releases a data pack's resources so it can be re-used.
dvander@440: *
dvander@440: * @param pack An IDataPack object to release.
dvander@440: */
dvander@440: virtual void FreeDataPack(IDataPack *pack) =0;
dvander@440:
ds@696: /**
dvander@1191: * @brief Not implemented, do not use.
ds@696: *
dvander@1191: * @param readonly Ignored
dvander@1191: * @return 0
ds@696: */
ds@696: virtual HandleType_t GetDataPackHandleType(bool readonly=false) =0;
faluco@682:
ds@696: /**
ds@696: * @brief Retrieves a KeyValues pointer from a handle.
ds@696: *
ds@696: * @param hndl Handle_t from which to retrieve contents.
ds@696: * @param err Optional address to store a possible handle error.
ds@696: * @param root If true it will return the root KeyValues pointer for the whole structure.
ds@696: *
ds@696: * @return The KeyValues pointer, or NULL for any error encountered.
ds@696: */
ds@696: virtual KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false) =0;
ds@696:
ds@696: /**
ds@729: * @brief Returns the name of the game directory.
ds@696: *
ds@729: * @return A string containing the name of the game directory.
ds@696: */
ds@729: virtual const char *GetGameFolderName() const =0;
faluco@733:
faluco@733: /**
faluco@733: * @brief Returns the scripting engine interface.
faluco@733: *
faluco@733: * @return A pointer to the scripting engine interface.
faluco@733: */
faluco@733: virtual SourcePawn::ISourcePawnEngine *GetScriptingEngine() =0;
faluco@733:
faluco@733: /**
faluco@733: * @brief Returns the JIT interface.
faluco@733: *
faluco@733: * @return A pointer to the JIT interface.
faluco@733: */
faluco@733: virtual SourcePawn::IVirtualMachine *GetScriptingVM() =0;
dvander@1371:
dvander@1371: /**
dvander@1371: * @brief Returns the adjusted server time.
dvander@1371: *
dvander@1371: * @return Adjusted server time.
dvander@1371: */
dvander@1371: virtual time_t GetAdjustedTime() =0;
dvander@324: };
ds@432: }
dvander@324:
dvander@324: #endif //_INCLUDE_SOURCEMOD_MAIN_HELPER_INTERFACE_H_