core/HalfLife2.h
author Nicholas Hastings <skamonkey@gmail.com>
Fri Nov 04 10:01:33 2011 -0400 (2011-11-04)
changeset 3438 07a1b8a8a2ba
parent 3010 8ea042c00c80
child 3460 ccd11f0c5372
permissions -rw-r--r--
Updated TF2_OnIsHolidayActive ret behavior to match doc (bug 5155, r=fyren).
dvander@592
     1
/**
dvander@592
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
ds@1947
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@592
     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@592
    28
 *
dvander@592
    29
 * Version: $Id$
dvander@592
    30
 */
dvander@592
    31
dvander@592
    32
#ifndef _INCLUDE_SOURCEMOD_CHALFLIFE2_H_
dvander@592
    33
#define _INCLUDE_SOURCEMOD_CHALFLIFE2_H_
dvander@592
    34
dvander@592
    35
#include <sh_list.h>
dvander@1338
    36
#include <sh_string.h>
faluco@682
    37
#include <sh_tinyhash.h>
dvander@1847
    38
#include <sm_trie_tpl.h>
dvander@592
    39
#include "sm_trie.h"
dvander@592
    40
#include "sm_globals.h"
dvander@1338
    41
#include "sm_queue.h"
dvander@965
    42
#include <IGameHelpers.h>
faluco@1218
    43
#include <KeyValues.h>
ds@2051
    44
#include <server_class.h>
ds@2051
    45
#include <datamap.h>
pred@2746
    46
#include <ihandleentity.h>
dvander@592
    47
dvander@1544
    48
class CCommand;
dvander@1544
    49
dvander@592
    50
using namespace SourceHook;
dvander@965
    51
using namespace SourceMod;
dvander@592
    52
dvander@895
    53
#define HUD_PRINTTALK		3
dvander@895
    54
#define HUD_PRINTCENTER		4
dvander@895
    55
dvander@592
    56
struct DataTableInfo
dvander@592
    57
{
dvander@592
    58
	ServerClass *sc;
dvander@1847
    59
	KTrie<sm_sendprop_info_t> lookup;
dvander@592
    60
};
dvander@592
    61
faluco@682
    62
struct DataMapTrie
faluco@682
    63
{
faluco@682
    64
	DataMapTrie() : trie(NULL) {}
faluco@682
    65
	Trie *trie;
faluco@682
    66
};
faluco@682
    67
dvander@1338
    68
struct DelayedFakeCliCmd
dvander@1338
    69
{
dvander@1338
    70
	String cmd;
dvander@1338
    71
	int client;
dvander@1338
    72
	int userid;
dvander@1338
    73
};
dvander@1338
    74
dvander@1544
    75
struct CachedCommandInfo
dvander@1544
    76
{
dvander@1544
    77
	const CCommand *args;
ds@2583
    78
#if SOURCE_ENGINE <= SE_DARKMESSIAH
dvander@1544
    79
	char cmd[300];
dvander@1544
    80
#endif
dvander@1544
    81
};
dvander@1544
    82
dvander@2162
    83
struct DelayedKickInfo
dvander@2162
    84
{
dvander@2162
    85
	int userid;
dvander@2162
    86
	int client;
dvander@2162
    87
	char buffer[384];
dvander@2162
    88
};
dvander@2162
    89
pred@2746
    90
class CEntInfo
pred@2746
    91
{
pred@2746
    92
public:
pred@2746
    93
	IHandleEntity	*m_pEntity;
pred@2746
    94
	int				m_SerialNumber;
pred@2746
    95
	CEntInfo		*m_pPrev;
pred@2746
    96
	CEntInfo		*m_pNext;
pred@2746
    97
};
pred@2746
    98
dvander@965
    99
class CHalfLife2 : 
dvander@965
   100
	public SMGlobalClass,
dvander@965
   101
	public IGameHelpers
dvander@592
   102
{
dvander@592
   103
public:
dvander@592
   104
	CHalfLife2();
dvander@592
   105
	~CHalfLife2();
dvander@592
   106
public:
dvander@677
   107
	void OnSourceModStartup(bool late);
ds@873
   108
	void OnSourceModAllInitialized();
pred@2746
   109
	void OnSourceModAllInitialized_Post();
dvander@677
   110
	/*void OnSourceModAllShutdown();*/
dvander@965
   111
public: //IGameHelpers
dvander@592
   112
	SendProp *FindInSendTable(const char *classname, const char *offset);
dvander@1847
   113
	bool FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info);
dvander@965
   114
	datamap_t *GetDataMap(CBaseEntity *pEntity);
dvander@592
   115
	ServerClass *FindServerClass(const char *classname);
faluco@682
   116
	typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
dvander@685
   117
	void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
dvander@1132
   118
	bool TextMsg(int client, int dest, const char *msg);
teame06@1264
   119
	bool HintTextMsg(int client, const char *msg);
pred@2801
   120
	bool HintTextMsg(cell_t *players, int count, const char *msg);
faluco@1218
   121
	bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
dvander@1423
   122
	bool IsLANServer();
ds@1944
   123
	bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL);
pred@2596
   124
	edict_t *EdictOfIndex(int index);
pred@2596
   125
	int IndexOfEdict(edict_t *pEnt);
pred@2596
   126
	edict_t *GetHandleEntity(CBaseHandle &hndl);
pred@2596
   127
	void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt);
dvander@2628
   128
	const char *GetCurrentMap();
dvander@2628
   129
	void ServerCommand(const char *buffer);
pred@2746
   130
	CBaseEntity *ReferenceToEntity(cell_t entRef);
pred@2746
   131
	cell_t EntityToReference(CBaseEntity *pEntity);
pred@2746
   132
	cell_t IndexToReference(int entIndex);
pred@2746
   133
	int ReferenceToIndex(cell_t entRef);
pred@2746
   134
	cell_t ReferenceToBCompatRef(cell_t entRef);
pred@2746
   135
	CEntInfo *LookupEntity(int entIndex);
pred@2746
   136
	cell_t EntityToBCompatRef(CBaseEntity *pEntity);
pred@2746
   137
	void *GetGlobalEntityList();
dvander@3010
   138
	int GetSendPropOffset(SendProp *prop);
dvander@1338
   139
public:
dvander@1338
   140
	void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
dvander@1338
   141
	void ProcessFakeCliCmdQueue();
dvander@1544
   142
public:
dvander@1544
   143
	void PushCommandStack(const CCommand *cmd);
dvander@1544
   144
	void PopCommandStack();
dvander@1544
   145
	const CCommand *PeekCommandStack();
dvander@1544
   146
	const char *CurrentCommandName();
dvander@2162
   147
	void AddDelayedKick(int client, int userid, const char *msg);
dvander@2162
   148
	void ProcessDelayedKicks();
dvander@2846
   149
#if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
dvander@1581
   150
	bool IsOriginalEngine();
dvander@1581
   151
#endif
dvander@592
   152
private:
dvander@592
   153
	DataTableInfo *_FindServerClass(const char *classname);
dvander@592
   154
private:
dvander@592
   155
	Trie *m_pClasses;
dvander@592
   156
	List<DataTableInfo *> m_Tables;
faluco@682
   157
	THash<datamap_t *, DataMapTrie> m_Maps;
ds@873
   158
	int m_MsgTextMsg;
faluco@1218
   159
	int m_HinTextMsg;
ds@2583
   160
	int m_SayTextMsg;
faluco@1218
   161
	int m_VGUIMenu;
dvander@1338
   162
	Queue<DelayedFakeCliCmd *> m_CmdQueue;
dvander@1338
   163
	CStack<DelayedFakeCliCmd *> m_FreeCmds;
dvander@1544
   164
	CStack<CachedCommandInfo> m_CommandStack;
dvander@2162
   165
	Queue<DelayedKickInfo> m_DelayedKicks;
dvander@592
   166
};
dvander@592
   167
dvander@592
   168
extern CHalfLife2 g_HL2;
dvander@592
   169
fyrenmoo@2879
   170
bool IndexToAThings(cell_t, CBaseEntity **pEntData, edict_t **pEdictData);
pred@2596
   171
dvander@592
   172
#endif //_INCLUDE_SOURCEMOD_CHALFLIFE2_H_