core/sourcemod.h
author Matt Woodrow <pred@alliedmods.net>
Fri Aug 08 00:17:37 2008 +0000 (2008-08-08)
changeset 2224 676c3b826f13
parent 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Initial Import of beta structs extension.
     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 /**
    44  * @brief Implements SourceMod's global overall management, API, and logic
    45  */
    46 
    47 class SourceModBase : 
    48 	public ISourceMod,
    49 	public SMGlobalClass
    50 {
    51 public:
    52 	SourceModBase();
    53 public:
    54 	/**
    55 	 * @brief Initializes SourceMod, or returns an error on failure.
    56 	 */
    57 	bool InitializeSourceMod(char *error, size_t maxlength, bool late);
    58 
    59 	/** 
    60 	 * @brief Starts everything SourceMod needs to run
    61 	 */
    62 	void StartSourceMod(bool late);
    63 
    64 	/** 
    65 	 * @brief Shuts down all SourceMod components
    66 	 */
    67 	void CloseSourceMod();
    68 
    69 	/**
    70 	 * @brief Map change hook
    71 	 */
    72 	bool LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
    73 
    74 	/**
    75 	 * @brief Level shutdown hook
    76 	 */
    77 	void LevelShutdown();
    78 
    79 	/** 
    80 	 * @brief Returns whether or not a map load is in progress
    81 	 */
    82 	bool IsMapLoading() const;
    83 
    84 	/** 
    85 	 * @brief Stores the global target index.
    86 	 */
    87 	unsigned int SetGlobalTarget(unsigned int index);
    88 
    89 	/** 
    90 	 * @brief Returns the global target index.
    91 	 */
    92 	unsigned int GetGlobalTarget() const;
    93 public: // SMGlobalClass
    94 	ConfigResult OnSourceModConfigChanged(const char *key, 
    95 										  const char *value, 
    96 										  ConfigSource source, 
    97 										  char *error, 
    98 										  size_t maxlength);
    99 public: // ISourceMod
   100 	const char *GetGamePath() const;
   101 	const char *GetSourceModPath() const;
   102 	size_t BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...);
   103 	void LogMessage(IExtension *pExt, const char *format, ...);
   104 	void LogError(IExtension *pExt, const char *format, ...);
   105 	size_t FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param);
   106 	IDataPack *CreateDataPack();
   107 	void FreeDataPack(IDataPack *pack);
   108 	HandleType_t GetDataPackHandleType(bool readonly=false);
   109 	KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false);
   110 	const char *GetGameFolderName() const;
   111 	ISourcePawnEngine *GetScriptingEngine();
   112 	IVirtualMachine *GetScriptingVM();
   113 	void AllPluginsLoaded();
   114 	time_t GetAdjustedTime();
   115 	void GlobalPause();
   116 	void GlobalUnpause();
   117 	void DoGlobalPluginLoads();
   118 	void AddGameFrameHook(GAME_FRAME_HOOK hook);
   119 	void RemoveGameFrameHook(GAME_FRAME_HOOK hook);
   120 	void ProcessGameFrameHooks(bool simulating);
   121 private:
   122 	CStack<CDataPack *> m_freepacks;
   123 	char m_SMBaseDir[PLATFORM_MAX_PATH];
   124 	char m_SMRelDir[PLATFORM_MAX_PATH];
   125 	char m_ModDir[32];
   126 	bool m_IsMapLoading;
   127 	bool m_ExecPluginReload;
   128 	bool m_ExecOnMapEnd;
   129 	unsigned int m_target;
   130 	bool m_GotBasePath;
   131 	CVector<GAME_FRAME_HOOK> m_frame_hooks;
   132 };
   133 
   134 extern bool g_Loaded;
   135 extern SourceModBase g_SourceMod;
   136 extern HandleType_t g_WrBitBufType;		//:TODO: find a better place for this
   137 extern HandleType_t g_RdBitBufType;		//:TODO: find a better place for this
   138 
   139 #endif //_INCLUDE_SOURCEMOD_GLOBALHEADER_H_