core/HalfLife2.h
author David Anderson <dvander@alliedmods.net>
Sun Aug 26 17:41:02 2007 +0000 (2007-08-26)
changeset 1369 bd9ccced1b1a
parent 1338 1ba17552b7b1
child 1423 e73b3563f254
permissions -rw-r--r--
fixed amb834 - command callbacks could potentially occur on invalid clients in very rare cases
dvander@592
     1
/**
dvander@592
     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@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@592
    38
#include "sm_trie.h"
dvander@592
    39
#include "sm_globals.h"
dvander@1338
    40
#include "sm_queue.h"
dvander@965
    41
#include <IGameHelpers.h>
faluco@1218
    42
#include <KeyValues.h>
dvander@592
    43
dvander@592
    44
using namespace SourceHook;
dvander@965
    45
using namespace SourceMod;
dvander@592
    46
dvander@895
    47
#define HUD_PRINTTALK		3
dvander@895
    48
#define HUD_PRINTCENTER		4
dvander@895
    49
dvander@592
    50
struct DataTableInfo
dvander@592
    51
{
dvander@592
    52
	ServerClass *sc;
dvander@592
    53
	Trie *lookup;
dvander@592
    54
};
dvander@592
    55
faluco@682
    56
struct DataMapTrie
faluco@682
    57
{
faluco@682
    58
	DataMapTrie() : trie(NULL) {}
faluco@682
    59
	Trie *trie;
faluco@682
    60
};
faluco@682
    61
dvander@1338
    62
struct DelayedFakeCliCmd
dvander@1338
    63
{
dvander@1338
    64
	String cmd;
dvander@1338
    65
	int client;
dvander@1338
    66
	int userid;
dvander@1338
    67
};
dvander@1338
    68
dvander@965
    69
class CHalfLife2 : 
dvander@965
    70
	public SMGlobalClass,
dvander@965
    71
	public IGameHelpers
dvander@592
    72
{
dvander@592
    73
public:
dvander@592
    74
	CHalfLife2();
dvander@592
    75
	~CHalfLife2();
dvander@592
    76
public:
dvander@677
    77
	void OnSourceModStartup(bool late);
ds@873
    78
	void OnSourceModAllInitialized();
dvander@677
    79
	/*void OnSourceModAllShutdown();*/
dvander@965
    80
public: //IGameHelpers
dvander@592
    81
	SendProp *FindInSendTable(const char *classname, const char *offset);
dvander@965
    82
	datamap_t *GetDataMap(CBaseEntity *pEntity);
dvander@592
    83
	ServerClass *FindServerClass(const char *classname);
faluco@682
    84
	typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
dvander@685
    85
	void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
dvander@1132
    86
	bool TextMsg(int client, int dest, const char *msg);
teame06@1264
    87
	bool HintTextMsg(int client, const char *msg);
faluco@1218
    88
	bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
dvander@1338
    89
public:
dvander@1338
    90
	void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
dvander@1338
    91
	void ProcessFakeCliCmdQueue();
dvander@592
    92
private:
dvander@592
    93
	DataTableInfo *_FindServerClass(const char *classname);
dvander@592
    94
private:
dvander@592
    95
	Trie *m_pClasses;
dvander@592
    96
	List<DataTableInfo *> m_Tables;
faluco@682
    97
	THash<datamap_t *, DataMapTrie> m_Maps;
ds@873
    98
	int m_MsgTextMsg;
faluco@1218
    99
	int m_HinTextMsg;
faluco@1218
   100
	int m_VGUIMenu;
dvander@1338
   101
	Queue<DelayedFakeCliCmd *> m_CmdQueue;
dvander@1338
   102
	CStack<DelayedFakeCliCmd *> m_FreeCmds;
dvander@592
   103
};
dvander@592
   104
dvander@592
   105
extern CHalfLife2 g_HL2;
dvander@685
   106
extern bool g_IsOriginalEngine;
dvander@592
   107
dvander@592
   108
#endif //_INCLUDE_SOURCEMOD_CHALFLIFE2_H_