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