core/HalfLife2.h
author Peace-Maker <januk@freenet.de>
Sat May 10 05:42:33 2014 -0700 (2014-05-10)
changeset 4354 7011587e0021
parent 4069 336e32fe098f
permissions -rw-r--r--
Remove LogMessageEx definition from logging.inc (bug 5897, r=kyles).
dvander@592
     1
/**
dvander@4069
     2
 * vim: set ts=4 sw=4 tw=99 noet :
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@4069
    38
#include <am-utility.h>
dvander@4069
    39
#include <am-hashmap.h>
dvander@4069
    40
#include <sm_stringhashmap.h>
dvander@4069
    41
#include <sm_namehashset.h>
dvander@592
    42
#include "sm_globals.h"
dvander@1338
    43
#include "sm_queue.h"
dvander@965
    44
#include <IGameHelpers.h>
faluco@1218
    45
#include <KeyValues.h>
ds@2051
    46
#include <server_class.h>
ds@2051
    47
#include <datamap.h>
pred@2746
    48
#include <ihandleentity.h>
skamonkey@3461
    49
#include <tier0/icommandline.h>
skamonkey@3515
    50
#if SOURCE_ENGINE >= SE_PORTAL2
skamonkey@3515
    51
#include <string_t.h>
skamonkey@3515
    52
#endif
skamonkey@3460
    53
dvander@1544
    54
class CCommand;
dvander@1544
    55
dvander@592
    56
using namespace SourceHook;
dvander@965
    57
using namespace SourceMod;
dvander@592
    58
dvander@895
    59
#define HUD_PRINTTALK		3
dvander@895
    60
#define HUD_PRINTCENTER		4
dvander@895
    61
dvander@592
    62
struct DataTableInfo
dvander@592
    63
{
dvander@4069
    64
	struct SendPropPolicy
dvander@4069
    65
	{
dvander@4069
    66
		static inline bool matches(const char *name, const sm_sendprop_info_t &info)
dvander@4069
    67
		{
dvander@4069
    68
			return strcmp(name, info.prop->GetName()) == 0;
dvander@4069
    69
		}
dvander@4069
    70
	};
dvander@4069
    71
dvander@4069
    72
	static inline bool matches(const char *name, const DataTableInfo *info)
dvander@4069
    73
	{
dvander@4069
    74
		return strcmp(name, info->sc->GetName()) == 0;
dvander@4069
    75
	}
dvander@4069
    76
dvander@4069
    77
	DataTableInfo(ServerClass *sc)
dvander@4069
    78
		: sc(sc)
dvander@4069
    79
	{
dvander@4069
    80
	}
dvander@4069
    81
dvander@592
    82
	ServerClass *sc;
dvander@4069
    83
	NameHashSet<sm_sendprop_info_t, SendPropPolicy> lookup;
dvander@592
    84
};
dvander@592
    85
dvander@4069
    86
struct DataMapCachePolicy
faluco@682
    87
{
dvander@4069
    88
	static inline bool matches(const char *name, const sm_datatable_info_t &info)
dvander@4069
    89
	{
dvander@4069
    90
		return strcmp(name, info.prop->fieldName) == 0;
dvander@4069
    91
	}
faluco@682
    92
};
faluco@682
    93
dvander@4069
    94
typedef NameHashSet<sm_datatable_info_t, DataMapCachePolicy> DataMapCache;
dvander@4069
    95
dvander@1338
    96
struct DelayedFakeCliCmd
dvander@1338
    97
{
dvander@1338
    98
	String cmd;
dvander@1338
    99
	int client;
dvander@1338
   100
	int userid;
dvander@1338
   101
};
dvander@1338
   102
dvander@1544
   103
struct CachedCommandInfo
dvander@1544
   104
{
dvander@1544
   105
	const CCommand *args;
ds@2583
   106
#if SOURCE_ENGINE <= SE_DARKMESSIAH
dvander@1544
   107
	char cmd[300];
dvander@1544
   108
#endif
dvander@1544
   109
};
dvander@1544
   110
dvander@2162
   111
struct DelayedKickInfo
dvander@2162
   112
{
dvander@2162
   113
	int userid;
dvander@2162
   114
	int client;
dvander@2162
   115
	char buffer[384];
dvander@2162
   116
};
dvander@2162
   117
skamonkey@3515
   118
// copy from game/shared/entitylist_base.h
pred@2746
   119
class CEntInfo
pred@2746
   120
{
pred@2746
   121
public:
pred@2746
   122
	IHandleEntity	*m_pEntity;
pred@2746
   123
	int				m_SerialNumber;
pred@2746
   124
	CEntInfo		*m_pPrev;
pred@2746
   125
	CEntInfo		*m_pNext;
skamonkey@3853
   126
#if (SOURCE_ENGINE >= SE_PORTAL2) && (SOURCE_ENGINE != SE_DOTA)
skamonkey@3515
   127
	string_t		m_iName;
skamonkey@3515
   128
	string_t		m_iClassName;
skamonkey@3515
   129
#endif
pred@2746
   130
};
pred@2746
   131
dvander@965
   132
class CHalfLife2 : 
dvander@965
   133
	public SMGlobalClass,
dvander@965
   134
	public IGameHelpers
dvander@592
   135
{
dvander@592
   136
public:
dvander@592
   137
	CHalfLife2();
dvander@592
   138
	~CHalfLife2();
dvander@592
   139
public:
dvander@677
   140
	void OnSourceModStartup(bool late);
ds@873
   141
	void OnSourceModAllInitialized();
pred@2746
   142
	void OnSourceModAllInitialized_Post();
dvander@677
   143
	/*void OnSourceModAllShutdown();*/
dvander@965
   144
public: //IGameHelpers
dvander@592
   145
	SendProp *FindInSendTable(const char *classname, const char *offset);
dvander@1847
   146
	bool FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info);
dvander@965
   147
	datamap_t *GetDataMap(CBaseEntity *pEntity);
dvander@592
   148
	ServerClass *FindServerClass(const char *classname);
faluco@682
   149
	typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
kyle@3997
   150
	bool FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatable_info_t *pDataTable);
dvander@685
   151
	void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
dvander@1132
   152
	bool TextMsg(int client, int dest, const char *msg);
teame06@1264
   153
	bool HintTextMsg(int client, const char *msg);
pred@2801
   154
	bool HintTextMsg(cell_t *players, int count, const char *msg);
faluco@1218
   155
	bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
dvander@1423
   156
	bool IsLANServer();
ds@1944
   157
	bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL);
pred@2596
   158
	edict_t *EdictOfIndex(int index);
pred@2596
   159
	int IndexOfEdict(edict_t *pEnt);
pred@2596
   160
	edict_t *GetHandleEntity(CBaseHandle &hndl);
pred@2596
   161
	void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt);
dvander@2628
   162
	const char *GetCurrentMap();
dvander@2628
   163
	void ServerCommand(const char *buffer);
pred@2746
   164
	CBaseEntity *ReferenceToEntity(cell_t entRef);
pred@2746
   165
	cell_t EntityToReference(CBaseEntity *pEntity);
pred@2746
   166
	cell_t IndexToReference(int entIndex);
pred@2746
   167
	int ReferenceToIndex(cell_t entRef);
pred@2746
   168
	cell_t ReferenceToBCompatRef(cell_t entRef);
pred@2746
   169
	CEntInfo *LookupEntity(int entIndex);
pred@2746
   170
	cell_t EntityToBCompatRef(CBaseEntity *pEntity);
pred@2746
   171
	void *GetGlobalEntityList();
dvander@3010
   172
	int GetSendPropOffset(SendProp *prop);
skamonkey@3460
   173
	ICommandLine *GetValveCommandLine();
kyle@3638
   174
	const char *GetEntityClassname(edict_t *pEdict);
kyle@3638
   175
	const char *GetEntityClassname(CBaseEntity *pEntity);
skamonkey@3789
   176
	bool IsMapValid(const char *map);
dvander@1338
   177
public:
dvander@1338
   178
	void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
dvander@1338
   179
	void ProcessFakeCliCmdQueue();
dvander@1544
   180
public:
dvander@1544
   181
	void PushCommandStack(const CCommand *cmd);
dvander@1544
   182
	void PopCommandStack();
dvander@1544
   183
	const CCommand *PeekCommandStack();
dvander@1544
   184
	const char *CurrentCommandName();
dvander@2162
   185
	void AddDelayedKick(int client, int userid, const char *msg);
dvander@2162
   186
	void ProcessDelayedKicks();
dvander@2846
   187
#if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
dvander@1581
   188
	bool IsOriginalEngine();
dvander@1581
   189
#endif
dvander@592
   190
private:
dvander@592
   191
	DataTableInfo *_FindServerClass(const char *classname);
dvander@592
   192
private:
skamonkey@3460
   193
	void InitLogicalEntData();
skamonkey@3460
   194
	void InitCommandLine();
skamonkey@3460
   195
private:
dvander@4069
   196
	typedef ke::HashMap<datamap_t *, DataMapCache *, ke::PointerPolicy<datamap_t> > DataTableMap;
dvander@4069
   197
dvander@4069
   198
	NameHashSet<DataTableInfo *> m_Classes;
dvander@4069
   199
	DataTableMap m_Maps;
ds@873
   200
	int m_MsgTextMsg;
faluco@1218
   201
	int m_HinTextMsg;
ds@2583
   202
	int m_SayTextMsg;
faluco@1218
   203
	int m_VGUIMenu;
dvander@1338
   204
	Queue<DelayedFakeCliCmd *> m_CmdQueue;
dvander@1338
   205
	CStack<DelayedFakeCliCmd *> m_FreeCmds;
dvander@1544
   206
	CStack<CachedCommandInfo> m_CommandStack;
dvander@2162
   207
	Queue<DelayedKickInfo> m_DelayedKicks;
skamonkey@3462
   208
	void *m_pGetCommandLine;
dvander@592
   209
};
dvander@592
   210
dvander@592
   211
extern CHalfLife2 g_HL2;
dvander@592
   212
fyrenmoo@2879
   213
bool IndexToAThings(cell_t, CBaseEntity **pEntData, edict_t **pEdictData);
pred@2596
   214
dvander@592
   215
#endif //_INCLUDE_SOURCEMOD_CHALFLIFE2_H_