core/HalfLife2.h
author Asher Baker <asherkin@gmail.com>
Sat Sep 08 21:02:46 2012 +0100 (2012-09-08)
changeset 3652 e0a6517dcd89
parent 3638 13ea64fe5237
child 3789 42e367aa4a00
permissions -rw-r--r--
Include the auto-version file in the build, so 3rd party plugins compiled aginst the includes get useful versioning info (bug 5453, r=dvander).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_CHALFLIFE2_H_
    33 #define _INCLUDE_SOURCEMOD_CHALFLIFE2_H_
    34 
    35 #include <sh_list.h>
    36 #include <sh_string.h>
    37 #include <sh_tinyhash.h>
    38 #include <sm_trie_tpl.h>
    39 #include "sm_trie.h"
    40 #include "sm_globals.h"
    41 #include "sm_queue.h"
    42 #include <IGameHelpers.h>
    43 #include <KeyValues.h>
    44 #include <server_class.h>
    45 #include <datamap.h>
    46 #include <ihandleentity.h>
    47 #include <tier0/icommandline.h>
    48 #if SOURCE_ENGINE >= SE_PORTAL2
    49 #include <string_t.h>
    50 #endif
    51 
    52 class CCommand;
    53 
    54 using namespace SourceHook;
    55 using namespace SourceMod;
    56 
    57 #define HUD_PRINTTALK		3
    58 #define HUD_PRINTCENTER		4
    59 
    60 struct DataTableInfo
    61 {
    62 	ServerClass *sc;
    63 	KTrie<sm_sendprop_info_t> lookup;
    64 };
    65 
    66 struct DataMapTrie
    67 {
    68 	DataMapTrie() : trie(NULL) {}
    69 	Trie *trie;
    70 };
    71 
    72 struct DelayedFakeCliCmd
    73 {
    74 	String cmd;
    75 	int client;
    76 	int userid;
    77 };
    78 
    79 struct CachedCommandInfo
    80 {
    81 	const CCommand *args;
    82 #if SOURCE_ENGINE <= SE_DARKMESSIAH
    83 	char cmd[300];
    84 #endif
    85 };
    86 
    87 struct DelayedKickInfo
    88 {
    89 	int userid;
    90 	int client;
    91 	char buffer[384];
    92 };
    93 
    94 // copy from game/shared/entitylist_base.h
    95 class CEntInfo
    96 {
    97 public:
    98 	IHandleEntity	*m_pEntity;
    99 	int				m_SerialNumber;
   100 	CEntInfo		*m_pPrev;
   101 	CEntInfo		*m_pNext;
   102 #if SOURCE_ENGINE >= SE_PORTAL2
   103 	string_t		m_iName;
   104 	string_t		m_iClassName;
   105 #endif
   106 };
   107 
   108 class CHalfLife2 : 
   109 	public SMGlobalClass,
   110 	public IGameHelpers
   111 {
   112 public:
   113 	CHalfLife2();
   114 	~CHalfLife2();
   115 public:
   116 	void OnSourceModStartup(bool late);
   117 	void OnSourceModAllInitialized();
   118 	void OnSourceModAllInitialized_Post();
   119 	/*void OnSourceModAllShutdown();*/
   120 public: //IGameHelpers
   121 	SendProp *FindInSendTable(const char *classname, const char *offset);
   122 	bool FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info);
   123 	datamap_t *GetDataMap(CBaseEntity *pEntity);
   124 	ServerClass *FindServerClass(const char *classname);
   125 	typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
   126 	void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
   127 	bool TextMsg(int client, int dest, const char *msg);
   128 	bool HintTextMsg(int client, const char *msg);
   129 	bool HintTextMsg(cell_t *players, int count, const char *msg);
   130 	bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
   131 	bool IsLANServer();
   132 	bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL);
   133 	edict_t *EdictOfIndex(int index);
   134 	int IndexOfEdict(edict_t *pEnt);
   135 	edict_t *GetHandleEntity(CBaseHandle &hndl);
   136 	void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt);
   137 	const char *GetCurrentMap();
   138 	void ServerCommand(const char *buffer);
   139 	CBaseEntity *ReferenceToEntity(cell_t entRef);
   140 	cell_t EntityToReference(CBaseEntity *pEntity);
   141 	cell_t IndexToReference(int entIndex);
   142 	int ReferenceToIndex(cell_t entRef);
   143 	cell_t ReferenceToBCompatRef(cell_t entRef);
   144 	CEntInfo *LookupEntity(int entIndex);
   145 	cell_t EntityToBCompatRef(CBaseEntity *pEntity);
   146 	void *GetGlobalEntityList();
   147 	int GetSendPropOffset(SendProp *prop);
   148 	ICommandLine *GetValveCommandLine();
   149 	const char *GetEntityClassname(edict_t *pEdict);
   150 	const char *GetEntityClassname(CBaseEntity *pEntity);
   151 public:
   152 	void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
   153 	void ProcessFakeCliCmdQueue();
   154 public:
   155 	void PushCommandStack(const CCommand *cmd);
   156 	void PopCommandStack();
   157 	const CCommand *PeekCommandStack();
   158 	const char *CurrentCommandName();
   159 	void AddDelayedKick(int client, int userid, const char *msg);
   160 	void ProcessDelayedKicks();
   161 #if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
   162 	bool IsOriginalEngine();
   163 #endif
   164 private:
   165 	DataTableInfo *_FindServerClass(const char *classname);
   166 private:
   167 	void InitLogicalEntData();
   168 	void InitCommandLine();
   169 private:
   170 	Trie *m_pClasses;
   171 	List<DataTableInfo *> m_Tables;
   172 	THash<datamap_t *, DataMapTrie> m_Maps;
   173 	int m_MsgTextMsg;
   174 	int m_HinTextMsg;
   175 	int m_SayTextMsg;
   176 	int m_VGUIMenu;
   177 	Queue<DelayedFakeCliCmd *> m_CmdQueue;
   178 	CStack<DelayedFakeCliCmd *> m_FreeCmds;
   179 	CStack<CachedCommandInfo> m_CommandStack;
   180 	Queue<DelayedKickInfo> m_DelayedKicks;
   181 	void *m_pGetCommandLine;
   182 };
   183 
   184 extern CHalfLife2 g_HL2;
   185 
   186 bool IndexToAThings(cell_t, CBaseEntity **pEntData, edict_t **pEdictData);
   187 
   188 #endif //_INCLUDE_SOURCEMOD_CHALFLIFE2_H_