ds@757: /** ds@757: * vim: set ts=4 : ds@1330: * ============================================================================= ds@1330: * SourceMod Base Extension Code ds@1947: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. ds@1330: * ============================================================================= ds@757: * 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. ds@757: * 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 . ds@757: * ds@757: * Version: $Id$ ds@757: */ ds@757: ds@757: #ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ ds@757: #define _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_ ds@757: ds@757: /** ds@757: * @file smsdk_ext.h ds@757: * @brief Contains wrappers for making Extensions easier to write. ds@757: */ ds@757: ds@757: #include "smsdk_config.h" ds@757: #include ds@757: #include ds@757: #include ds@757: #include ds@757: #include dvander@943: #if defined SMEXT_ENABLE_FORWARDSYS ds@757: #include dvander@943: #endif //SMEXT_ENABLE_FORWARDSYS dvander@943: #if defined SMEXT_ENABLE_PLAYERHELPERS dvander@943: #include dvander@943: #endif //SMEXT_ENABLE_PlAYERHELPERS dvander@943: #if defined SMEXT_ENABLE_DBMANAGER dvander@943: #include dvander@943: #endif //SMEXT_ENABLE_DBMANAGER dvander@943: #if defined SMEXT_ENABLE_GAMECONF dvander@943: #include dvander@943: #endif dvander@1226: #if defined SMEXT_ENABLE_MEMUTILS dvander@1226: #include dvander@1226: #endif dvander@1226: #if defined SMEXT_ENABLE_GAMEHELPERS dvander@1226: #include dvander@1226: #endif dvander@1226: #if defined SMEXT_ENABLE_TIMERSYS dvander@1226: #include dvander@1226: #endif dvander@1226: #if defined SMEXT_ENABLE_ADTFACTORY dvander@1226: #include dvander@1226: #endif dvander@1226: #if defined SMEXT_ENABLE_THREADER dvander@1226: #include dvander@1226: #endif dvander@1226: #if defined SMEXT_ENABLE_LIBSYS dvander@1226: #include dvander@1226: #endif pred@2504: #if defined SMEXT_ENABLE_PLUGINSYS pred@2504: #include pred@2504: #endif pred@2504: #if defined SMEXT_ENABLE_MENUS pred@2504: #include pred@2504: #endif pred@2504: #if defined SMEXT_ENABLE_ADMINSYS pred@2504: #include pred@2504: #endif pred@2504: #if defined SMEXT_ENABLE_TEXTPARSERS pred@2504: #include pred@2504: #endif pred@2504: #if defined SMEXT_ENABLE_USERMSGS pred@2504: #include pred@2504: #endif pred@2504: #if defined SMEXT_ENABLE_TRANSLATOR pred@2504: #include pred@2504: #endif ds@757: ds@757: #if defined SMEXT_CONF_METAMOD ds@757: #include ds@757: #include ds@757: #endif ds@757: ds@757: using namespace SourceMod; ds@757: using namespace SourcePawn; ds@757: ds@757: class SDKExtension : ds@757: #if defined SMEXT_CONF_METAMOD ds@757: public ISmmPlugin, ds@757: #endif ds@757: public IExtensionInterface ds@757: { ds@757: public: ds@757: /** Constructor */ ds@757: SDKExtension(); ds@757: public: ds@757: /** ds@757: * @brief This is called after the initial loading sequence has been processed. ds@757: * ds@757: * @param error Error message buffer. ds@757: * @param maxlength Size of error message buffer. ds@757: * @param late Whether or not the module was loaded after map load. ds@757: * @return True to succeed loading, false to fail. ds@757: */ ds@757: virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late); ds@757: ds@757: /** ds@757: * @brief This is called right before the extension is unloaded. ds@757: */ ds@757: virtual void SDK_OnUnload(); ds@757: ds@757: /** ds@757: * @brief This is called once all known extensions have been loaded. ds@757: */ ds@757: virtual void SDK_OnAllLoaded(); ds@757: ds@757: /** ds@757: * @brief Called when the pause state is changed. ds@757: */ ds@757: virtual void SDK_OnPauseChange(bool paused); ds@757: ds@757: #if defined SMEXT_CONF_METAMOD ds@757: /** ds@757: * @brief Called when Metamod is attached, before the extension version is called. ds@757: * ds@757: * @param error Error buffer. ds@757: * @param maxlength Maximum size of error buffer. ds@757: * @param late Whether or not Metamod considers this a late load. ds@757: * @return True to succeed, false to fail. ds@757: */ ds@757: virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late); ds@757: ds@757: /** ds@757: * @brief Called when Metamod is detaching, after the extension version is called. ds@757: * NOTE: By default this is blocked unless sent from SourceMod. ds@757: * ds@757: * @param error Error buffer. ds@757: * @param maxlength Maximum size of error buffer. ds@757: * @return True to succeed, false to fail. ds@757: */ ds@757: virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength); ds@757: ds@757: /** ds@757: * @brief Called when Metamod's pause state is changing. ds@757: * NOTE: By default this is blocked unless sent from SourceMod. ds@757: * ds@757: * @param paused Pause state being set. ds@757: * @param error Error buffer. ds@757: * @param maxlength Maximum size of error buffer. ds@757: * @return True to succeed, false to fail. ds@757: */ ds@757: virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength); ds@757: #endif ds@757: dvander@943: public: //IExtensionInterface ds@757: virtual bool OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late); ds@757: virtual void OnExtensionUnload(); ds@757: virtual void OnExtensionsAllLoaded(); ds@757: ds@757: /** Returns whether or not this is a Metamod-based extension */ ds@757: virtual bool IsMetamodExtension(); ds@757: ds@757: /** ds@757: * @brief Called when the pause state changes. ds@757: * ds@757: * @param state True if being paused, false if being unpaused. ds@757: */ ds@757: virtual void OnExtensionPauseChange(bool state); ds@757: ds@757: /** Returns name */ ds@757: virtual const char *GetExtensionName(); ds@757: /** Returns URL */ ds@757: virtual const char *GetExtensionURL(); ds@757: /** Returns log tag */ ds@757: virtual const char *GetExtensionTag(); ds@757: /** Returns author */ ds@757: virtual const char *GetExtensionAuthor(); ds@757: /** Returns version string */ ds@757: virtual const char *GetExtensionVerString(); ds@757: /** Returns description string */ ds@757: virtual const char *GetExtensionDescription(); ds@757: /** Returns date string */ ds@757: virtual const char *GetExtensionDateString(); ds@757: #if defined SMEXT_CONF_METAMOD dvander@943: public: //ISmmPlugin ds@757: /** Called when the extension is attached to Metamod. */ dvander@943: virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late); ds@757: /** Returns the author to MM */ ds@757: virtual const char *GetAuthor(); ds@757: /** Returns the name to MM */ ds@757: virtual const char *GetName(); ds@757: /** Returns the description to MM */ ds@757: virtual const char *GetDescription(); ds@757: /** Returns the URL to MM */ ds@757: virtual const char *GetURL(); ds@757: /** Returns the license to MM */ ds@757: virtual const char *GetLicense(); ds@757: /** Returns the version string to MM */ ds@757: virtual const char *GetVersion(); ds@757: /** Returns the date string to MM */ ds@757: virtual const char *GetDate(); ds@757: /** Returns the logtag to MM */ ds@757: virtual const char *GetLogTag(); ds@757: /** Called on unload */ dvander@943: virtual bool Unload(char *error, size_t maxlength); ds@757: /** Called on pause */ dvander@943: virtual bool Pause(char *error, size_t maxlength); ds@757: /** Called on unpause */ dvander@943: virtual bool Unpause(char *error, size_t maxlength); ds@757: private: ds@757: bool m_SourceMMLoaded; ds@757: bool m_WeAreUnloaded; ds@757: bool m_WeGotPauseChange; ds@757: #endif ds@757: }; ds@757: ds@757: extern SDKExtension *g_pExtensionIface; dvander@943: extern IExtension *myself; ds@757: ds@757: extern IShareSys *g_pShareSys; dvander@943: extern IShareSys *sharesys; /* Note: Newer name */ dvander@943: extern ISourceMod *g_pSM; dvander@943: extern ISourceMod *smutils; /* Note: Newer name */ dvander@943: dvander@943: /* Optional interfaces are below */ dvander@943: #if defined SMEXT_ENABLE_FORWARDSYS dvander@943: extern IForwardManager *g_pForwards; dvander@943: extern IForwardManager *forwards; /* Note: Newer name */ dvander@943: #endif //SMEXT_ENABLE_FORWARDSYS dvander@943: #if defined SMEXT_ENABLE_HANDLESYS ds@757: extern IHandleSys *g_pHandleSys; dvander@943: extern IHandleSys *handlesys; /* Note: Newer name */ dvander@943: #endif //SMEXT_ENABLE_HANDLESYS dvander@943: #if defined SMEXT_ENABLE_PLAYERHELPERS dvander@943: extern IPlayerManager *playerhelpers; dvander@943: #endif //SMEXT_ENABLE_PLAYERHELPERS dvander@943: #if defined SMEXT_ENABLE_DBMANAGER dvander@943: extern IDBManager *dbi; dvander@943: #endif //SMEXT_ENABLE_DBMANAGER dvander@943: #if defined SMEXT_ENABLE_GAMECONF dvander@943: extern IGameConfigManager *gameconfs; dvander@943: #endif //SMEXT_ENABLE_DBMANAGER dvander@1226: #if defined SMEXT_ENABLE_MEMUTILS dvander@1226: extern IMemoryUtils *memutils; dvander@1226: #endif dvander@1226: #if defined SMEXT_ENABLE_GAMEHELPERS dvander@1226: extern IGameHelpers *gamehelpers; dvander@1226: #endif dvander@1226: #if defined SMEXT_ENABLE_TIMERSYS dvander@1226: extern ITimerSystem *timersys; dvander@1226: #endif dvander@1226: #if defined SMEXT_ENABLE_ADTFACTORY dvander@1226: extern IADTFactory *adtfactory; dvander@1226: #endif dvander@1226: #if defined SMEXT_ENABLE_THREADER dvander@1226: extern IThreader *threader; dvander@1226: #endif dvander@1226: #if defined SMEXT_ENABLE_LIBSYS dvander@1226: extern ILibrarySys *libsys; dvander@1226: #endif pred@2504: #if defined SMEXT_ENABLE_PLUGINSYS pred@2504: extern SourceMod::IPluginManager *plsys; pred@2504: #endif pred@2504: #if defined SMEXT_ENABLE_MENUS pred@2504: extern IMenuManager *menus; pred@2504: #endif pred@2504: #if defined SMEXT_ENABLE_ADMINSYS pred@2504: extern IAdminSystem *adminsys; pred@2504: #endif pred@2504: #if defined SMEXT_ENABLE_USERMSGS pred@2504: extern IUserMessages *usermsgs; pred@2504: #endif pred@2504: #if defined SMEXT_ENABLE_TRANSLATOR pred@2504: extern ITranslator *translator; pred@2504: #endif ds@757: ds@757: #if defined SMEXT_CONF_METAMOD ds@757: PLUGIN_GLOBALVARS(); ds@757: extern IVEngineServer *engine; ds@757: extern IServerGameDLL *gamedll; ds@757: #endif ds@757: ds@757: /** Creates a SourceMod interface macro pair */ ds@757: #define SM_MKIFACE(name) SMINTERFACE_##name##_NAME, SMINTERFACE_##name##_VERSION ds@757: /** Automates retrieving SourceMod interfaces */ ds@757: #define SM_GET_IFACE(prefix, addr) \ ds@757: if (!g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr)) \ ds@757: { \ dvander@1650: if (error != NULL && maxlength) \ ds@757: { \ dvander@1650: size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ dvander@1650: if (len >= maxlength) \ dvander@1650: { \ dvander@1650: error[maxlength - 1] = '\0'; \ dvander@1650: } \ ds@757: } \ dvander@1650: return false; \ ds@757: } ds@757: /** Automates retrieving SourceMod interfaces when needed outside of SDK_OnLoad() */ ds@757: #define SM_GET_LATE_IFACE(prefix, addr) \ ds@757: g_pShareSys->RequestInterface(SM_MKIFACE(prefix), myself, (SMInterface **)&addr) ds@757: /** Validates a SourceMod interface pointer */ ds@757: #define SM_CHECK_IFACE(prefix, addr) \ ds@757: if (!addr) \ ds@757: { \ dvander@1650: if (error != NULL && maxlength) \ ds@757: { \ dvander@1650: size_t len = snprintf(error, maxlength, "Could not find interface: %s", SMINTERFACE_##prefix##_NAME); \ dvander@1650: if (len >= maxlength) \ dvander@1650: { \ dvander@1650: error[maxlength - 1] = '\0'; \ dvander@1650: } \ ds@757: } \ dvander@1650: return false; \ ds@757: } ds@757: ds@757: #endif // _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_