core/HalfLife2.h
author Kyle Sanderson <kyle.leet@gmail.com>
Tue Aug 28 16:20:15 2012 -0400 (2012-08-28)
changeset 3638 13ea64fe5237
parent 3515 c14c14e06cc1
child 3789 42e367aa4a00
permissions -rw-r--r--
Fixed crash in EntProp natives (bug 5297, r=psychonic).
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) {}
faluco@682
    69
	Trie *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@3515
   102
#if SOURCE_ENGINE >= SE_PORTAL2
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);
dvander@685
   126
	void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
dvander@1132
   127
	bool TextMsg(int client, int dest, const char *msg);
teame06@1264
   128
	bool HintTextMsg(int client, const char *msg);
pred@2801
   129
	bool HintTextMsg(cell_t *players, int count, const char *msg);
faluco@1218
   130
	bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
dvander@1423
   131
	bool IsLANServer();
ds@1944
   132
	bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL);
pred@2596
   133
	edict_t *EdictOfIndex(int index);
pred@2596
   134
	int IndexOfEdict(edict_t *pEnt);
pred@2596
   135
	edict_t *GetHandleEntity(CBaseHandle &hndl);
pred@2596
   136
	void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt);
dvander@2628
   137
	const char *GetCurrentMap();
dvander@2628
   138
	void ServerCommand(const char *buffer);
pred@2746
   139
	CBaseEntity *ReferenceToEntity(cell_t entRef);
pred@2746
   140
	cell_t EntityToReference(CBaseEntity *pEntity);
pred@2746
   141
	cell_t IndexToReference(int entIndex);
pred@2746
   142
	int ReferenceToIndex(cell_t entRef);
pred@2746
   143
	cell_t ReferenceToBCompatRef(cell_t entRef);
pred@2746
   144
	CEntInfo *LookupEntity(int entIndex);
pred@2746
   145
	cell_t EntityToBCompatRef(CBaseEntity *pEntity);
pred@2746
   146
	void *GetGlobalEntityList();
dvander@3010
   147
	int GetSendPropOffset(SendProp *prop);
skamonkey@3460
   148
	ICommandLine *GetValveCommandLine();
kyle@3638
   149
	const char *GetEntityClassname(edict_t *pEdict);
kyle@3638
   150
	const char *GetEntityClassname(CBaseEntity *pEntity);
dvander@1338
   151
public:
dvander@1338
   152
	void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
dvander@1338
   153
	void ProcessFakeCliCmdQueue();
dvander@1544
   154
public:
dvander@1544
   155
	void PushCommandStack(const CCommand *cmd);
dvander@1544
   156
	void PopCommandStack();
dvander@1544
   157
	const CCommand *PeekCommandStack();
dvander@1544
   158
	const char *CurrentCommandName();
dvander@2162
   159
	void AddDelayedKick(int client, int userid, const char *msg);
dvander@2162
   160
	void ProcessDelayedKicks();
dvander@2846
   161
#if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
dvander@1581
   162
	bool IsOriginalEngine();
dvander@1581
   163
#endif
dvander@592
   164
private:
dvander@592
   165
	DataTableInfo *_FindServerClass(const char *classname);
dvander@592
   166
private:
skamonkey@3460
   167
	void InitLogicalEntData();
skamonkey@3460
   168
	void InitCommandLine();
skamonkey@3460
   169
private:
dvander@592
   170
	Trie *m_pClasses;
dvander@592
   171
	List<DataTableInfo *> m_Tables;
faluco@682
   172
	THash<datamap_t *, DataMapTrie> m_Maps;
ds@873
   173
	int m_MsgTextMsg;
faluco@1218
   174
	int m_HinTextMsg;
ds@2583
   175
	int m_SayTextMsg;
faluco@1218
   176
	int m_VGUIMenu;
dvander@1338
   177
	Queue<DelayedFakeCliCmd *> m_CmdQueue;
dvander@1338
   178
	CStack<DelayedFakeCliCmd *> m_FreeCmds;
dvander@1544
   179
	CStack<CachedCommandInfo> m_CommandStack;
dvander@2162
   180
	Queue<DelayedKickInfo> m_DelayedKicks;
skamonkey@3462
   181
	void *m_pGetCommandLine;
dvander@592
   182
};
dvander@592
   183
dvander@592
   184
extern CHalfLife2 g_HL2;
dvander@592
   185
fyrenmoo@2879
   186
bool IndexToAThings(cell_t, CBaseEntity **pEntData, edict_t **pEdictData);
pred@2596
   187
dvander@592
   188
#endif //_INCLUDE_SOURCEMOD_CHALFLIFE2_H_