core/HalfLife2.h
author Kyle Sanderson <kyle.leet@gmail.com>
Mon Aug 12 00:54:21 2013 +0100 (2013-08-12)
changeset 3997 59bcfc51eb79
parent 3853 3c8f57923db5
child 4069 336e32fe098f
permissions -rw-r--r--
Add support for nested datatables. (bug 5446, r=asherkin)
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>
skamonkey@3461
    47
#include <tier0/icommandline.h>
skamonkey@3515
    48
#if SOURCE_ENGINE >= SE_PORTAL2
skamonkey@3515
    49
#include <string_t.h>
skamonkey@3515
    50
#endif
skamonkey@3460
    51
dvander@1544
    52
class CCommand;
dvander@1544
    53
dvander@592
    54
using namespace SourceHook;
dvander@965
    55
using namespace SourceMod;
dvander@592
    56
dvander@895
    57
#define HUD_PRINTTALK		3
dvander@895
    58
#define HUD_PRINTCENTER		4
dvander@895
    59
dvander@592
    60
struct DataTableInfo
dvander@592
    61
{
dvander@592
    62
	ServerClass *sc;
dvander@1847
    63
	KTrie<sm_sendprop_info_t> lookup;
dvander@592
    64
};
dvander@592
    65
faluco@682
    66
struct DataMapTrie
faluco@682
    67
{
faluco@682
    68
	DataMapTrie() : trie(NULL) {}
kyle@3997
    69
	KTrie<sm_datatable_info_t> *trie;
faluco@682
    70
};
faluco@682
    71
dvander@1338
    72
struct DelayedFakeCliCmd
dvander@1338
    73
{
dvander@1338
    74
	String cmd;
dvander@1338
    75
	int client;
dvander@1338
    76
	int userid;
dvander@1338
    77
};
dvander@1338
    78
dvander@1544
    79
struct CachedCommandInfo
dvander@1544
    80
{
dvander@1544
    81
	const CCommand *args;
ds@2583
    82
#if SOURCE_ENGINE <= SE_DARKMESSIAH
dvander@1544
    83
	char cmd[300];
dvander@1544
    84
#endif
dvander@1544
    85
};
dvander@1544
    86
dvander@2162
    87
struct DelayedKickInfo
dvander@2162
    88
{
dvander@2162
    89
	int userid;
dvander@2162
    90
	int client;
dvander@2162
    91
	char buffer[384];
dvander@2162
    92
};
dvander@2162
    93
skamonkey@3515
    94
// copy from game/shared/entitylist_base.h
pred@2746
    95
class CEntInfo
pred@2746
    96
{
pred@2746
    97
public:
pred@2746
    98
	IHandleEntity	*m_pEntity;
pred@2746
    99
	int				m_SerialNumber;
pred@2746
   100
	CEntInfo		*m_pPrev;
pred@2746
   101
	CEntInfo		*m_pNext;
skamonkey@3853
   102
#if (SOURCE_ENGINE >= SE_PORTAL2) && (SOURCE_ENGINE != SE_DOTA)
skamonkey@3515
   103
	string_t		m_iName;
skamonkey@3515
   104
	string_t		m_iClassName;
skamonkey@3515
   105
#endif
pred@2746
   106
};
pred@2746
   107
dvander@965
   108
class CHalfLife2 : 
dvander@965
   109
	public SMGlobalClass,
dvander@965
   110
	public IGameHelpers
dvander@592
   111
{
dvander@592
   112
public:
dvander@592
   113
	CHalfLife2();
dvander@592
   114
	~CHalfLife2();
dvander@592
   115
public:
dvander@677
   116
	void OnSourceModStartup(bool late);
ds@873
   117
	void OnSourceModAllInitialized();
pred@2746
   118
	void OnSourceModAllInitialized_Post();
dvander@677
   119
	/*void OnSourceModAllShutdown();*/
dvander@965
   120
public: //IGameHelpers
dvander@592
   121
	SendProp *FindInSendTable(const char *classname, const char *offset);
dvander@1847
   122
	bool FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info);
dvander@965
   123
	datamap_t *GetDataMap(CBaseEntity *pEntity);
dvander@592
   124
	ServerClass *FindServerClass(const char *classname);
faluco@682
   125
	typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
kyle@3997
   126
	bool FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatable_info_t *pDataTable);
dvander@685
   127
	void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
dvander@1132
   128
	bool TextMsg(int client, int dest, const char *msg);
teame06@1264
   129
	bool HintTextMsg(int client, const char *msg);
pred@2801
   130
	bool HintTextMsg(cell_t *players, int count, const char *msg);
faluco@1218
   131
	bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
dvander@1423
   132
	bool IsLANServer();
ds@1944
   133
	bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL);
pred@2596
   134
	edict_t *EdictOfIndex(int index);
pred@2596
   135
	int IndexOfEdict(edict_t *pEnt);
pred@2596
   136
	edict_t *GetHandleEntity(CBaseHandle &hndl);
pred@2596
   137
	void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt);
dvander@2628
   138
	const char *GetCurrentMap();
dvander@2628
   139
	void ServerCommand(const char *buffer);
pred@2746
   140
	CBaseEntity *ReferenceToEntity(cell_t entRef);
pred@2746
   141
	cell_t EntityToReference(CBaseEntity *pEntity);
pred@2746
   142
	cell_t IndexToReference(int entIndex);
pred@2746
   143
	int ReferenceToIndex(cell_t entRef);
pred@2746
   144
	cell_t ReferenceToBCompatRef(cell_t entRef);
pred@2746
   145
	CEntInfo *LookupEntity(int entIndex);
pred@2746
   146
	cell_t EntityToBCompatRef(CBaseEntity *pEntity);
pred@2746
   147
	void *GetGlobalEntityList();
dvander@3010
   148
	int GetSendPropOffset(SendProp *prop);
skamonkey@3460
   149
	ICommandLine *GetValveCommandLine();
kyle@3638
   150
	const char *GetEntityClassname(edict_t *pEdict);
kyle@3638
   151
	const char *GetEntityClassname(CBaseEntity *pEntity);
skamonkey@3789
   152
	bool IsMapValid(const char *map);
dvander@1338
   153
public:
dvander@1338
   154
	void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
dvander@1338
   155
	void ProcessFakeCliCmdQueue();
dvander@1544
   156
public:
dvander@1544
   157
	void PushCommandStack(const CCommand *cmd);
dvander@1544
   158
	void PopCommandStack();
dvander@1544
   159
	const CCommand *PeekCommandStack();
dvander@1544
   160
	const char *CurrentCommandName();
dvander@2162
   161
	void AddDelayedKick(int client, int userid, const char *msg);
dvander@2162
   162
	void ProcessDelayedKicks();
dvander@2846
   163
#if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
dvander@1581
   164
	bool IsOriginalEngine();
dvander@1581
   165
#endif
dvander@592
   166
private:
dvander@592
   167
	DataTableInfo *_FindServerClass(const char *classname);
dvander@592
   168
private:
skamonkey@3460
   169
	void InitLogicalEntData();
skamonkey@3460
   170
	void InitCommandLine();
skamonkey@3460
   171
private:
dvander@592
   172
	Trie *m_pClasses;
dvander@592
   173
	List<DataTableInfo *> m_Tables;
faluco@682
   174
	THash<datamap_t *, DataMapTrie> m_Maps;
ds@873
   175
	int m_MsgTextMsg;
faluco@1218
   176
	int m_HinTextMsg;
ds@2583
   177
	int m_SayTextMsg;
faluco@1218
   178
	int m_VGUIMenu;
dvander@1338
   179
	Queue<DelayedFakeCliCmd *> m_CmdQueue;
dvander@1338
   180
	CStack<DelayedFakeCliCmd *> m_FreeCmds;
dvander@1544
   181
	CStack<CachedCommandInfo> m_CommandStack;
dvander@2162
   182
	Queue<DelayedKickInfo> m_DelayedKicks;
skamonkey@3462
   183
	void *m_pGetCommandLine;
dvander@592
   184
};
dvander@592
   185
dvander@592
   186
extern CHalfLife2 g_HL2;
dvander@592
   187
fyrenmoo@2879
   188
bool IndexToAThings(cell_t, CBaseEntity **pEntData, edict_t **pEdictData);
pred@2596
   189
dvander@592
   190
#endif //_INCLUDE_SOURCEMOD_CHALFLIFE2_H_