core/sourcemod.h
author David Anderson <dvander@alliedmods.net>
Thu Mar 05 02:06:59 2009 -0500 (2009-03-05)
changeset 2653 0ae7d8ab1de7
parent 2628 541e48653064
child 3104 b15fb3b476f1
permissions -rw-r--r--
Removed -dev tag for release.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_GLOBALHEADER_H_
    33 #define _INCLUDE_SOURCEMOD_GLOBALHEADER_H_
    34 
    35 #include "sm_globals.h"
    36 #include <ISourceMod.h>
    37 #include <sh_stack.h>
    38 #include <sh_vector.h>
    39 #include "CDataPack.h"
    40 
    41 using namespace SourceHook;
    42 
    43 #if defined _DEBUG
    44 # define IF_DEBUG_SPEW
    45 # define ENDIF_DEBUG_SPEW
    46 #else
    47 # define IF_DEBUG_SPEW			\
    48 	if (sm_show_debug_spew)		\
    49 	{
    50 # define ENDIF_DEBUG_SPEW		\
    51 	}
    52 #endif
    53 
    54 /**
    55  * @brief Implements SourceMod's global overall management, API, and logic
    56  */
    57 
    58 class SourceModBase : 
    59 	public ISourceMod,
    60 	public SMGlobalClass
    61 {
    62 public:
    63 	SourceModBase();
    64 public:
    65 	/**
    66 	 * @brief Initializes SourceMod, or returns an error on failure.
    67 	 */
    68 	bool InitializeSourceMod(char *error, size_t maxlength, bool late);
    69 
    70 	/** 
    71 	 * @brief Starts everything SourceMod needs to run
    72 	 */
    73 	void StartSourceMod(bool late);
    74 
    75 	/** 
    76 	 * @brief Shuts down all SourceMod components
    77 	 */
    78 	void CloseSourceMod();
    79 
    80 	/**
    81 	 * @brief Map change hook
    82 	 */
    83 	bool LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
    84 
    85 	/**
    86 	 * @brief Level shutdown hook
    87 	 */
    88 	void LevelShutdown();
    89 
    90 	/** 
    91 	 * @brief Returns whether or not a map load is in progress
    92 	 */
    93 	bool IsMapLoading() const;
    94 
    95 	/** 
    96 	 * @brief Stores the global target index.
    97 	 */
    98 	unsigned int SetGlobalTarget(unsigned int index);
    99 
   100 	/** 
   101 	 * @brief Returns the global target index.
   102 	 */
   103 	unsigned int GetGlobalTarget() const;
   104 public: // SMGlobalClass
   105 	ConfigResult OnSourceModConfigChanged(const char *key, 
   106 										  const char *value, 
   107 										  ConfigSource source, 
   108 										  char *error, 
   109 										  size_t maxlength);
   110 public: // ISourceMod
   111 	const char *GetGamePath() const;
   112 	const char *GetSourceModPath() const;
   113 	size_t BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...);
   114 	void LogMessage(IExtension *pExt, const char *format, ...);
   115 	void LogError(IExtension *pExt, const char *format, ...);
   116 	size_t FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param);
   117 	IDataPack *CreateDataPack();
   118 	void FreeDataPack(IDataPack *pack);
   119 	HandleType_t GetDataPackHandleType(bool readonly=false);
   120 	KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false);
   121 	const char *GetGameFolderName() const;
   122 	ISourcePawnEngine *GetScriptingEngine();
   123 	IVirtualMachine *GetScriptingVM();
   124 	void AllPluginsLoaded();
   125 	time_t GetAdjustedTime();
   126 	void GlobalPause();
   127 	void GlobalUnpause();
   128 	void DoGlobalPluginLoads();
   129 	void AddGameFrameHook(GAME_FRAME_HOOK hook);
   130 	void RemoveGameFrameHook(GAME_FRAME_HOOK hook);
   131 	void ProcessGameFrameHooks(bool simulating);
   132 	size_t Format(char *buffer, size_t maxlength, const char *fmt, ...);
   133 	size_t FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap);
   134 	void AddFrameAction(FRAMEACTION fn, void *data);
   135 	const char *GetCoreConfigValue(const char *key);
   136 	int GetPluginId();
   137 private:
   138 	CStack<CDataPack *> m_freepacks;
   139 	char m_SMBaseDir[PLATFORM_MAX_PATH];
   140 	char m_SMRelDir[PLATFORM_MAX_PATH];
   141 	char m_ModDir[32];
   142 	bool m_IsMapLoading;
   143 	bool m_ExecPluginReload;
   144 	bool m_ExecOnMapEnd;
   145 	unsigned int m_target;
   146 	bool m_GotBasePath;
   147 	CVector<GAME_FRAME_HOOK> m_frame_hooks;
   148 };
   149 
   150 extern bool g_Loaded;
   151 extern bool sm_show_debug_spew;
   152 extern SourceModBase g_SourceMod;
   153 extern HandleType_t g_WrBitBufType;		//:TODO: find a better place for this
   154 extern HandleType_t g_RdBitBufType;		//:TODO: find a better place for this
   155 
   156 #endif //_INCLUDE_SOURCEMOD_GLOBALHEADER_H_