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