core/sourcemod.h
author Phong Dang <teame06@gmail.com>
Wed Aug 01 07:29:40 2007 +0000 (2007-08-01)
changeset 1241 2e8046793bc9
parent 1231 17badaf66ce4
child 1330 ab94316bb52b
permissions -rw-r--r--
Added check to make sure player are alive to perform sm_slap, sm_burn, sm_slay.
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
dvander@1231
     3
 * ================================================================
dvander@1231
     4
 * SourceMod
dvander@1231
     5
 * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
dvander@1231
     6
 * ================================================================
dvander@370
     7
 *
dvander@1231
     8
 * This program is free software; you can redistribute it and/or 
dvander@1231
     9
 * modify it under the terms of the GNU General Public License, 
dvander@1231
    10
 * version 3.0, as published by the Free Software Foundation.
dvander@1231
    11
 * 
dvander@1231
    12
 * This program is distributed in the hope that it will be useful,
dvander@1231
    13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dvander@1231
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dvander@1231
    15
 * GNU General Public License for more details.
dvander@1231
    16
 *
dvander@1231
    17
 * You should have received a copy of the GNU General Public License
dvander@1231
    18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
dvander@1231
    20
 * As a special exception, AlliedModders LLC gives you permission to 
dvander@1231
    21
 * link the code of this program (as well as its derivative works) to 
dvander@1231
    22
 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
dvander@1231
    23
 * Game MODs that run on software by the Valve Corporation.  You must 
dvander@1231
    24
 * obey the GNU General Public License in all respects for all other 
dvander@1231
    25
 * code used. Additionally, AlliedModders LLC grants this exception 
dvander@1231
    26
 * to all derivative works. AlliedModders LLC defines further 
dvander@1231
    27
 * exceptions, found in LICENSE.txt (as of this writing, version 
dvander@1231
    28
 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
dvander@370
    29
 *
dvander@370
    30
 * Version: $Id$
dvander@370
    31
 */
dvander@370
    32
dvander@159
    33
#ifndef _INCLUDE_SOURCEMOD_GLOBALHEADER_H_
dvander@159
    34
#define _INCLUDE_SOURCEMOD_GLOBALHEADER_H_
dvander@159
    35
dvander@160
    36
#include "sm_globals.h"
dvander@317
    37
#include <ISourceMod.h>
faluco@484
    38
#include <sh_stack.h>
faluco@484
    39
#include "CDataPack.h"
faluco@484
    40
faluco@484
    41
using namespace SourceHook;
dvander@159
    42
dvander@162
    43
/**
dvander@162
    44
 * @brief Implements SourceMod's global overall management, API, and logic
dvander@162
    45
 */
dvander@162
    46
ds@661
    47
class SourceModBase : 
ds@661
    48
	public ISourceMod,
ds@661
    49
	public SMGlobalClass
dvander@160
    50
{
dvander@160
    51
public:
dvander@209
    52
	SourceModBase();
dvander@209
    53
public:
dvander@160
    54
	/**
dvander@160
    55
	 * @brief Initializes SourceMod, or returns an error on failure.
dvander@160
    56
	 */
ds@755
    57
	bool InitializeSourceMod(char *error, size_t maxlength, bool late);
dvander@209
    58
dvander@209
    59
	/** 
dvander@209
    60
	 * @brief Starts everything SourceMod needs to run
dvander@209
    61
	 */
dvander@209
    62
	void StartSourceMod(bool late);
dvander@209
    63
faluco@289
    64
	/** 
dvander@448
    65
	 * @brief Shuts down all SourceMod components
dvander@448
    66
	 */
faluco@289
    67
	void CloseSourceMod();
faluco@289
    68
dvander@209
    69
	/**
dvander@209
    70
	 * @brief Map change hook
dvander@209
    71
	 */
dvander@209
    72
	bool LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
dvander@209
    73
faluco@333
    74
	/**
dvander@448
    75
	 * @brief Level shutdown hook
dvander@448
    76
	 */
faluco@333
    77
	void LevelShutdown();
faluco@333
    78
dvander@209
    79
	/** 
faluco@484
    80
	 * @brief Returns whether or not a map load is in progress
dvander@209
    81
	 */
faluco@484
    82
	bool IsMapLoading() const;
dvander@209
    83
faluco@422
    84
	/** 
dvander@448
    85
	 * @brief Stores the global target index.
dvander@448
    86
	 */
faluco@422
    87
	void SetGlobalTarget(unsigned int index);
faluco@422
    88
faluco@422
    89
	/** 
dvander@448
    90
	 * @brief Returns the global target index.
dvander@448
    91
	 */
faluco@422
    92
	unsigned int GetGlobalTarget() const;
faluco@484
    93
	
faluco@484
    94
	/** 
ds@675
    95
	 * @brief Sets whether if SoureMod needs to check player auths.
ds@675
    96
	 */
faluco@484
    97
	void SetAuthChecking(bool set);
ds@661
    98
public: // SMGlobalClass
dvander@663
    99
	ConfigResult OnSourceModConfigChanged(const char *key, 
dvander@663
   100
										  const char *value, 
dvander@663
   101
										  ConfigSource source, 
dvander@663
   102
										  char *error, 
dvander@663
   103
										  size_t maxlength);
ds@661
   104
public: // ISourceMod
ds@729
   105
	const char *GetGamePath() const;
faluco@484
   106
	const char *GetSourceModPath() const;
dvander@317
   107
	size_t BuildPath(PathType type, char *buffer, size_t maxlength, char *format, ...);
dvander@317
   108
	void LogMessage(IExtension *pExt, const char *format, ...);
dvander@317
   109
	void LogError(IExtension *pExt, const char *format, ...);
dvander@347
   110
	size_t FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param);
faluco@484
   111
	IDataPack *CreateDataPack();
faluco@484
   112
	void FreeDataPack(IDataPack *pack);
faluco@484
   113
	HandleType_t GetDataPackHandleType(bool readonly=false);
faluco@682
   114
	KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false);
ds@729
   115
	const char *GetGameFolderName() const;
faluco@733
   116
	ISourcePawnEngine *GetScriptingEngine();
faluco@733
   117
	IVirtualMachine *GetScriptingVM();
dvander@893
   118
	void AllPluginsLoaded();
dvander@209
   119
private:
dvander@209
   120
	/**
dvander@209
   121
	 * @brief Loading plugins
dvander@209
   122
	 */
dvander@209
   123
	void DoGlobalPluginLoads();
ds@661
   124
ds@661
   125
	/**
ds@661
   126
	 * @brief GameFrame hook
ds@661
   127
	 */
dvander@448
   128
	void GameFrame(bool simulating);
dvander@209
   129
private:
faluco@484
   130
	CStack<CDataPack *> m_freepacks;
ds@652
   131
	char m_SMBaseDir[PLATFORM_MAX_PATH];
ds@652
   132
	char m_SMRelDir[PLATFORM_MAX_PATH];
ds@696
   133
	char m_ModDir[32];
dvander@209
   134
	bool m_IsMapLoading;
faluco@333
   135
	bool m_ExecPluginReload;
faluco@786
   136
	bool m_ExecOnMapEnd;
faluco@422
   137
	unsigned int m_target;
dvander@448
   138
	bool m_CheckingAuth;
ds@661
   139
	bool m_GotBasePath;
dvander@211
   140
};
dvander@211
   141
dvander@160
   142
extern SourceModBase g_SourceMod;
dvander@685
   143
extern HandleType_t g_WrBitBufType;		//:TODO: find a better place for this
dvander@685
   144
extern HandleType_t g_RdBitBufType;		//:TODO: find a better place for this
dvander@159
   145
dvander@159
   146
#endif //_INCLUDE_SOURCEMOD_GLOBALHEADER_H_