core/sourcemod.h
author David Anderson <dvander@alliedmods.net>
Sat Nov 17 05:33:47 2007 +0000 (2007-11-17)
changeset 1690 7cc4f79a0416
parent 1630 2f2fe925f377
child 1904 baa051d23eef
permissions -rw-r--r--
added GetGlobalTarget/SetGlobalTarget to g_pSM
const'd some things
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 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 "CDataPack.h"
    39 
    40 using namespace SourceHook;
    41 
    42 /**
    43  * @brief Implements SourceMod's global overall management, API, and logic
    44  */
    45 
    46 class SourceModBase : 
    47 	public ISourceMod,
    48 	public SMGlobalClass
    49 {
    50 public:
    51 	SourceModBase();
    52 public:
    53 	/**
    54 	 * @brief Initializes SourceMod, or returns an error on failure.
    55 	 */
    56 	bool InitializeSourceMod(char *error, size_t maxlength, bool late);
    57 
    58 	/** 
    59 	 * @brief Starts everything SourceMod needs to run
    60 	 */
    61 	void StartSourceMod(bool late);
    62 
    63 	/** 
    64 	 * @brief Shuts down all SourceMod components
    65 	 */
    66 	void CloseSourceMod();
    67 
    68 	/**
    69 	 * @brief Map change hook
    70 	 */
    71 	bool LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
    72 
    73 	/**
    74 	 * @brief Level shutdown hook
    75 	 */
    76 	void LevelShutdown();
    77 
    78 	/** 
    79 	 * @brief Returns whether or not a map load is in progress
    80 	 */
    81 	bool IsMapLoading() const;
    82 
    83 	/** 
    84 	 * @brief Stores the global target index.
    85 	 */
    86 	unsigned int SetGlobalTarget(unsigned int index);
    87 
    88 	/** 
    89 	 * @brief Returns the global target index.
    90 	 */
    91 	unsigned int GetGlobalTarget() const;
    92 public: // SMGlobalClass
    93 	ConfigResult OnSourceModConfigChanged(const char *key, 
    94 										  const char *value, 
    95 										  ConfigSource source, 
    96 										  char *error, 
    97 										  size_t maxlength);
    98 public: // ISourceMod
    99 	const char *GetGamePath() const;
   100 	const char *GetSourceModPath() const;
   101 	size_t BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...);
   102 	void LogMessage(IExtension *pExt, const char *format, ...);
   103 	void LogError(IExtension *pExt, const char *format, ...);
   104 	size_t FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param);
   105 	IDataPack *CreateDataPack();
   106 	void FreeDataPack(IDataPack *pack);
   107 	HandleType_t GetDataPackHandleType(bool readonly=false);
   108 	KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false);
   109 	const char *GetGameFolderName() const;
   110 	ISourcePawnEngine *GetScriptingEngine();
   111 	IVirtualMachine *GetScriptingVM();
   112 	void AllPluginsLoaded();
   113 	time_t GetAdjustedTime();
   114 	void GlobalPause();
   115 	void GlobalUnpause();
   116 	void DoGlobalPluginLoads();
   117 private:
   118 	CStack<CDataPack *> m_freepacks;
   119 	char m_SMBaseDir[PLATFORM_MAX_PATH];
   120 	char m_SMRelDir[PLATFORM_MAX_PATH];
   121 	char m_ModDir[32];
   122 	bool m_IsMapLoading;
   123 	bool m_ExecPluginReload;
   124 	bool m_ExecOnMapEnd;
   125 	unsigned int m_target;
   126 	bool m_GotBasePath;
   127 };
   128 
   129 extern bool g_Loaded;
   130 extern SourceModBase g_SourceMod;
   131 extern HandleType_t g_WrBitBufType;		//:TODO: find a better place for this
   132 extern HandleType_t g_RdBitBufType;		//:TODO: find a better place for this
   133 
   134 #endif //_INCLUDE_SOURCEMOD_GLOBALHEADER_H_