core/sourcemod.h
author Scott Ehlert <ds@alliedmods.net>
Fri Mar 21 04:26:53 2008 +0000 (2008-03-21)
changeset 1944 17984feecafd
parent 1904 baa051d23eef
child 1947 e73a1e51833b
permissions -rw-r--r--
Merged crash fix (amb1539) from 1.0.1 branch
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>
dvander@1904
    38
#include <sh_vector.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
	 */
dvander@1690
    87
	unsigned int 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;
ds@661
    93
public: // SMGlobalClass
dvander@663
    94
	ConfigResult OnSourceModConfigChanged(const char *key, 
dvander@663
    95
										  const char *value, 
dvander@663
    96
										  ConfigSource source, 
dvander@663
    97
										  char *error, 
dvander@663
    98
										  size_t maxlength);
ds@661
    99
public: // ISourceMod
ds@729
   100
	const char *GetGamePath() const;
faluco@484
   101
	const char *GetSourceModPath() const;
ds@1411
   102
	size_t BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...);
dvander@317
   103
	void LogMessage(IExtension *pExt, const char *format, ...);
dvander@317
   104
	void LogError(IExtension *pExt, const char *format, ...);
dvander@347
   105
	size_t FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param);
faluco@484
   106
	IDataPack *CreateDataPack();
faluco@484
   107
	void FreeDataPack(IDataPack *pack);
faluco@484
   108
	HandleType_t GetDataPackHandleType(bool readonly=false);
faluco@682
   109
	KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false);
ds@729
   110
	const char *GetGameFolderName() const;
faluco@733
   111
	ISourcePawnEngine *GetScriptingEngine();
faluco@733
   112
	IVirtualMachine *GetScriptingVM();
dvander@893
   113
	void AllPluginsLoaded();
dvander@1371
   114
	time_t GetAdjustedTime();
dvander@1630
   115
	void GlobalPause();
dvander@1630
   116
	void GlobalUnpause();
dvander@209
   117
	void DoGlobalPluginLoads();
dvander@1904
   118
	void AddGameFrameHook(GAME_FRAME_HOOK hook);
dvander@1904
   119
	void RemoveGameFrameHook(GAME_FRAME_HOOK hook);
dvander@1904
   120
	void ProcessGameFrameHooks(bool simulating);
dvander@209
   121
private:
faluco@484
   122
	CStack<CDataPack *> m_freepacks;
ds@652
   123
	char m_SMBaseDir[PLATFORM_MAX_PATH];
ds@652
   124
	char m_SMRelDir[PLATFORM_MAX_PATH];
ds@696
   125
	char m_ModDir[32];
dvander@209
   126
	bool m_IsMapLoading;
faluco@333
   127
	bool m_ExecPluginReload;
faluco@786
   128
	bool m_ExecOnMapEnd;
faluco@422
   129
	unsigned int m_target;
ds@661
   130
	bool m_GotBasePath;
dvander@1904
   131
	CVector<GAME_FRAME_HOOK> m_frame_hooks;
dvander@211
   132
};
dvander@211
   133
dvander@1581
   134
extern bool g_Loaded;
dvander@160
   135
extern SourceModBase g_SourceMod;
dvander@685
   136
extern HandleType_t g_WrBitBufType;		//:TODO: find a better place for this
dvander@685
   137
extern HandleType_t g_RdBitBufType;		//:TODO: find a better place for this
dvander@159
   138
dvander@159
   139
#endif //_INCLUDE_SOURCEMOD_GLOBALHEADER_H_