2008-03-30 09:00:22 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
|
|
|
* SourceMod
|
|
|
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "HalfLife2.h"
|
|
|
|
#include "sourcemod.h"
|
|
|
|
#include "sourcemm_api.h"
|
|
|
|
#include "UserMessages.h"
|
|
|
|
#include "PlayerManager.h"
|
|
|
|
#include "sm_stringutil.h"
|
2010-05-15 08:35:42 +02:00
|
|
|
#include <IGameConfigs.h>
|
2008-03-30 09:00:22 +02:00
|
|
|
#include <compat_wrappers.h>
|
2009-07-24 02:34:31 +02:00
|
|
|
#include <Logger.h>
|
2012-02-25 21:09:56 +01:00
|
|
|
#include "LibrarySys.h"
|
2010-05-15 08:35:42 +02:00
|
|
|
#include "logic_bridge.h"
|
2012-10-26 22:28:05 +02:00
|
|
|
#include <tier0/mem.h>
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
|
|
|
#include <cstrike15_usermessages.pb.h>
|
|
|
|
#endif
|
|
|
|
|
2012-02-25 22:41:00 +01:00
|
|
|
|
|
|
|
typedef ICommandLine *(*FakeGetCommandLine)();
|
|
|
|
|
2012-02-25 21:09:56 +01:00
|
|
|
#if defined _WIN32
|
|
|
|
#define TIER0_NAME "tier0.dll"
|
|
|
|
#define VSTDLIB_NAME "vstdlib.dll"
|
|
|
|
#elif defined __APPLE__
|
|
|
|
#define TIER0_NAME "libtier0.dylib"
|
|
|
|
#define VSTDLIB_NAME "libvstdlib.dylib"
|
2012-02-25 22:41:00 +01:00
|
|
|
#elif defined __linux__
|
2013-02-05 22:45:11 +01:00
|
|
|
#if SOURCE_ENGINE == SE_ORANGEBOXVALVE || SOURCE_ENGINE == SE_CSS
|
2012-10-26 22:28:05 +02:00
|
|
|
#define TIER0_NAME "libtier0_srv.so"
|
|
|
|
#define VSTDLIB_NAME "libvstdlib_srv.so"
|
2013-02-05 22:45:11 +01:00
|
|
|
#elif SOURCE_ENGINE >= SE_LEFT4DEAD
|
2012-04-28 19:49:25 +02:00
|
|
|
#define TIER0_NAME "libtier0.so"
|
2012-02-25 22:41:00 +01:00
|
|
|
#define VSTDLIB_NAME "libvstdlib.so"
|
2012-04-28 19:49:25 +02:00
|
|
|
#else
|
|
|
|
#define TIER0_NAME "tier0_i486.so"
|
|
|
|
#define VSTDLIB_NAME "vstdlib_i486.so"
|
2012-02-25 22:41:00 +01:00
|
|
|
#endif
|
2012-02-25 21:09:56 +01:00
|
|
|
#endif
|
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
CHalfLife2 g_HL2;
|
|
|
|
ConVar *sv_lan = NULL;
|
|
|
|
|
2009-07-24 02:34:31 +02:00
|
|
|
static void *g_EntList = NULL;
|
|
|
|
static int entInfoOffset = -1;
|
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
namespace SourceHook
|
|
|
|
{
|
|
|
|
template<>
|
|
|
|
int HashFunction<datamap_t *>(datamap_t * const &k)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<int>(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
int Compare<datamap_t *>(datamap_t * const &k1, datamap_t * const &k2)
|
|
|
|
{
|
|
|
|
return (k1-k2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CHalfLife2::CHalfLife2()
|
|
|
|
{
|
|
|
|
m_pClasses = sm_trie_create();
|
|
|
|
}
|
|
|
|
|
|
|
|
CHalfLife2::~CHalfLife2()
|
|
|
|
{
|
|
|
|
sm_trie_destroy(m_pClasses);
|
|
|
|
|
|
|
|
List<DataTableInfo *>::iterator iter;
|
|
|
|
DataTableInfo *pInfo;
|
|
|
|
for (iter=m_Tables.begin(); iter!=m_Tables.end(); iter++)
|
|
|
|
{
|
|
|
|
pInfo = (*iter);
|
|
|
|
delete pInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Tables.clear();
|
|
|
|
|
|
|
|
THash<datamap_t *, DataMapTrie>::iterator h_iter;
|
|
|
|
for (h_iter=m_Maps.begin(); h_iter!=m_Maps.end(); h_iter++)
|
|
|
|
{
|
|
|
|
if (h_iter->val.trie)
|
|
|
|
{
|
|
|
|
sm_trie_destroy(h_iter->val.trie);
|
|
|
|
h_iter->val.trie = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Maps.clear();
|
|
|
|
}
|
|
|
|
|
2009-02-18 09:19:22 +01:00
|
|
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
2008-03-30 09:00:22 +02:00
|
|
|
CSharedEdictChangeInfo *g_pSharedChangeInfo = NULL;
|
2009-02-18 09:19:22 +01:00
|
|
|
#endif
|
|
|
|
|
2009-10-29 09:33:57 +01:00
|
|
|
#if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
|
2008-03-30 09:00:22 +02:00
|
|
|
bool is_original_engine = false;
|
2009-10-29 09:33:57 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
void CHalfLife2::OnSourceModStartup(bool late)
|
|
|
|
{
|
2009-02-18 09:19:22 +01:00
|
|
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
/* The Ship currently is the only known game to use an older version of the engine */
|
2009-10-29 09:33:57 +01:00
|
|
|
#if defined METAMOD_PLAPI_VERSION || PLAPI_VERSION >= 11
|
2008-03-30 09:00:22 +02:00
|
|
|
if (g_SMAPI->GetSourceEngineBuild() == SOURCE_ENGINE_ORIGINAL)
|
|
|
|
#else
|
|
|
|
if (strcasecmp(g_SourceMod.GetGameFolderName(), "ship") == 0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
is_original_engine = true;
|
|
|
|
}
|
|
|
|
else if (g_pSharedChangeInfo == NULL)
|
|
|
|
{
|
|
|
|
g_pSharedChangeInfo = engine->GetSharedEdictChangeInfo();
|
|
|
|
}
|
2009-02-18 09:19:22 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHalfLife2::OnSourceModAllInitialized()
|
|
|
|
{
|
|
|
|
m_MsgTextMsg = g_UserMsgs.GetMessageIndex("TextMsg");
|
|
|
|
m_HinTextMsg = g_UserMsgs.GetMessageIndex("HintText");
|
2009-02-18 09:19:22 +01:00
|
|
|
m_SayTextMsg = g_UserMsgs.GetMessageIndex("SayText");
|
2008-03-30 09:00:22 +02:00
|
|
|
m_VGUIMenu = g_UserMsgs.GetMessageIndex("VGUIMenu");
|
|
|
|
g_ShareSys.AddInterface(NULL, this);
|
|
|
|
}
|
|
|
|
|
2009-07-24 02:34:31 +02:00
|
|
|
void CHalfLife2::OnSourceModAllInitialized_Post()
|
2012-02-25 21:09:56 +01:00
|
|
|
{
|
|
|
|
InitLogicalEntData();
|
|
|
|
InitCommandLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHalfLife2::InitLogicalEntData()
|
2009-07-24 02:34:31 +02:00
|
|
|
{
|
|
|
|
char *addr = NULL;
|
|
|
|
|
2011-04-04 19:44:19 +02:00
|
|
|
/*
|
|
|
|
* gEntList and/or g_pEntityList
|
|
|
|
*
|
|
|
|
* First try to lookup pointer directly for platforms with symbols.
|
|
|
|
* If symbols aren't present (Windows or stripped Linux/Mac),
|
|
|
|
* attempt find via LevelShutdown + offset
|
|
|
|
*/
|
|
|
|
if (g_pGameConf->GetMemSig("gEntList", (void **)&addr))
|
2009-07-24 02:34:31 +02:00
|
|
|
{
|
2011-04-12 04:30:03 +02:00
|
|
|
#if !defined PLATFORM_WINDOWS
|
2011-04-04 19:44:19 +02:00
|
|
|
if (!addr)
|
|
|
|
{
|
|
|
|
// Key exists so notify if lookup fails, but try other method.
|
|
|
|
g_Logger.LogError("Failed lookup of gEntList directly - Reverting to lookup via LevelShutdown");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-12 04:30:03 +02:00
|
|
|
#endif
|
2011-04-04 19:44:19 +02:00
|
|
|
g_EntList = reinterpret_cast<void *>(addr);
|
2011-04-12 04:30:03 +02:00
|
|
|
#if !defined PLATFORM_WINDOWS
|
2011-04-04 19:44:19 +02:00
|
|
|
}
|
2011-04-12 04:30:03 +02:00
|
|
|
#endif
|
2009-07-24 02:34:31 +02:00
|
|
|
}
|
2011-04-04 19:44:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (!g_EntList)
|
2009-07-24 02:34:31 +02:00
|
|
|
{
|
2011-04-04 19:44:19 +02:00
|
|
|
if (!g_pGameConf->GetMemSig("LevelShutdown", (void **)&addr))
|
|
|
|
{
|
|
|
|
g_Logger.LogError("Logical Entities not supported by this mod (LevelShutdown) - Reverting to networkable entities only");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!addr)
|
|
|
|
{
|
|
|
|
g_Logger.LogError("Failed lookup of LevelShutdown - Reverting to networkable entities only");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int offset;
|
|
|
|
if (!g_pGameConf->GetOffset("gEntList", &offset))
|
|
|
|
{
|
|
|
|
g_Logger.LogError("Logical Entities not supported by this mod (gEntList) - Reverting to networkable entities only");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_EntList = *reinterpret_cast<void **>(addr + offset);
|
2009-07-24 02:34:31 +02:00
|
|
|
}
|
2011-04-04 19:44:19 +02:00
|
|
|
|
|
|
|
if (!g_EntList)
|
2009-07-24 02:34:31 +02:00
|
|
|
{
|
|
|
|
g_Logger.LogError("Failed lookup of gEntList - Reverting to networkable entities only");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_pGameConf->GetOffset("EntInfo", &entInfoOffset))
|
|
|
|
{
|
|
|
|
g_Logger.LogError("Logical Entities not supported by this mod (EntInfo) - Reverting to networkable entities only");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-25 21:09:56 +01:00
|
|
|
void CHalfLife2::InitCommandLine()
|
|
|
|
{
|
|
|
|
char path[PLATFORM_MAX_PATH];
|
|
|
|
char error[256];
|
|
|
|
|
|
|
|
g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "../bin/" TIER0_NAME);
|
|
|
|
|
|
|
|
if (!g_LibSys.IsPathFile(path))
|
|
|
|
{
|
|
|
|
g_Logger.LogError("Could not find path for: " TIER0_NAME);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ILibrary *lib = g_LibSys.OpenLibrary(path, error, sizeof(error));
|
2012-02-25 22:41:00 +01:00
|
|
|
m_pGetCommandLine = lib->GetSymbolAddress("CommandLine_Tier0");
|
2012-02-25 21:09:56 +01:00
|
|
|
|
|
|
|
/* '_Tier0' dropped on Alien Swarm version */
|
|
|
|
if (m_pGetCommandLine == NULL)
|
|
|
|
{
|
2012-02-25 22:41:00 +01:00
|
|
|
m_pGetCommandLine = lib->GetSymbolAddress("CommandLine");
|
2012-02-25 21:09:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_pGetCommandLine == NULL)
|
|
|
|
{
|
|
|
|
/* We probably have a Ship engine. */
|
|
|
|
lib->CloseLibrary();
|
|
|
|
g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "../bin/" VSTDLIB_NAME);
|
|
|
|
if (!g_LibSys.IsPathFile(path))
|
|
|
|
{
|
|
|
|
g_Logger.LogError("Could not find path for: " VSTDLIB_NAME);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((lib = g_LibSys.OpenLibrary(path, error, sizeof(error))) == NULL)
|
|
|
|
{
|
|
|
|
g_Logger.LogError("Could not load %s: %s", path, error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-25 22:41:00 +01:00
|
|
|
m_pGetCommandLine = lib->GetSymbolAddress("CommandLine");
|
2012-02-25 21:09:56 +01:00
|
|
|
|
|
|
|
if (m_pGetCommandLine == NULL)
|
|
|
|
{
|
|
|
|
g_Logger.LogError("Could not locate any command line functionality");
|
|
|
|
}
|
|
|
|
|
|
|
|
lib->CloseLibrary();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ICommandLine *CHalfLife2::GetValveCommandLine()
|
|
|
|
{
|
|
|
|
if (!m_pGetCommandLine)
|
|
|
|
return NULL;
|
|
|
|
|
2012-02-25 22:41:00 +01:00
|
|
|
return ((FakeGetCommandLine)((FakeGetCommandLine *)m_pGetCommandLine))();
|
2012-02-25 21:09:56 +01:00
|
|
|
}
|
|
|
|
|
2009-10-29 09:33:57 +01:00
|
|
|
#if !defined METAMOD_PLAPI_VERSION || PLAPI_VERSION < 11
|
2008-03-30 09:00:22 +02:00
|
|
|
bool CHalfLife2::IsOriginalEngine()
|
|
|
|
{
|
|
|
|
return is_original_engine;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-18 09:19:22 +01:00
|
|
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
2008-03-30 09:00:22 +02:00
|
|
|
IChangeInfoAccessor *CBaseEdict::GetChangeAccessor()
|
|
|
|
{
|
|
|
|
return engine->GetChangeAccessor( (const edict_t *)this );
|
|
|
|
}
|
2009-02-18 09:19:22 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
bool UTIL_FindInSendTable(SendTable *pTable,
|
|
|
|
const char *name,
|
|
|
|
sm_sendprop_info_t *info,
|
|
|
|
unsigned int offset)
|
|
|
|
{
|
|
|
|
const char *pname;
|
|
|
|
int props = pTable->GetNumProps();
|
|
|
|
SendProp *prop;
|
|
|
|
|
|
|
|
for (int i=0; i<props; i++)
|
|
|
|
{
|
|
|
|
prop = pTable->GetProp(i);
|
|
|
|
pname = prop->GetName();
|
|
|
|
if (pname && strcmp(name, pname) == 0)
|
|
|
|
{
|
|
|
|
info->prop = prop;
|
|
|
|
info->actual_offset = offset + info->prop->GetOffset();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (prop->GetDataTable())
|
|
|
|
{
|
|
|
|
if (UTIL_FindInSendTable(prop->GetDataTable(),
|
|
|
|
name,
|
|
|
|
info,
|
|
|
|
offset + prop->GetOffset())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedescription_t *UTIL_FindInDataMap(datamap_t *pMap, const char *name)
|
|
|
|
{
|
|
|
|
while (pMap)
|
|
|
|
{
|
|
|
|
for (int i=0; i<pMap->dataNumFields; i++)
|
|
|
|
{
|
|
|
|
if (pMap->dataDesc[i].fieldName == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(name, pMap->dataDesc[i].fieldName) == 0)
|
|
|
|
{
|
|
|
|
return &(pMap->dataDesc[i]);
|
|
|
|
}
|
|
|
|
if (pMap->dataDesc[i].td)
|
|
|
|
{
|
|
|
|
typedescription_t *_td;
|
|
|
|
if ((_td=UTIL_FindInDataMap(pMap->dataDesc[i].td, name)) != NULL)
|
|
|
|
{
|
|
|
|
return _td;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pMap = pMap->baseMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerClass *CHalfLife2::FindServerClass(const char *classname)
|
|
|
|
{
|
|
|
|
DataTableInfo *pInfo = _FindServerClass(classname);
|
|
|
|
|
|
|
|
if (!pInfo)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pInfo->sc;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataTableInfo *CHalfLife2::_FindServerClass(const char *classname)
|
|
|
|
{
|
|
|
|
DataTableInfo *pInfo = NULL;
|
|
|
|
|
|
|
|
if (!sm_trie_retrieve(m_pClasses, classname, (void **)&pInfo))
|
|
|
|
{
|
|
|
|
ServerClass *sc = gamedll->GetAllServerClasses();
|
|
|
|
while (sc)
|
|
|
|
{
|
|
|
|
if (strcmp(classname, sc->GetName()) == 0)
|
|
|
|
{
|
|
|
|
pInfo = new DataTableInfo;
|
|
|
|
pInfo->sc = sc;
|
|
|
|
sm_trie_insert(m_pClasses, classname, pInfo);
|
|
|
|
m_Tables.push_back(pInfo);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc = sc->m_pNext;
|
|
|
|
}
|
|
|
|
if (!pInfo)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info)
|
|
|
|
{
|
|
|
|
DataTableInfo *pInfo;
|
|
|
|
sm_sendprop_info_t *prop;
|
|
|
|
|
|
|
|
if ((pInfo = _FindServerClass(classname)) == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((prop = pInfo->lookup.retrieve(offset)) == NULL)
|
|
|
|
{
|
|
|
|
sm_sendprop_info_t temp_info;
|
|
|
|
|
|
|
|
if (!UTIL_FindInSendTable(pInfo->sc->m_pTable, offset, &temp_info, 0))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pInfo->lookup.insert(offset, temp_info);
|
|
|
|
*info = temp_info;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*info = *prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendProp *CHalfLife2::FindInSendTable(const char *classname, const char *offset)
|
|
|
|
{
|
|
|
|
sm_sendprop_info_t info;
|
|
|
|
|
|
|
|
if (!FindSendPropInfo(classname, offset, &info))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return info.prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedescription_t *CHalfLife2::FindInDataMap(datamap_t *pMap, const char *offset)
|
|
|
|
{
|
|
|
|
typedescription_t *td = NULL;
|
|
|
|
DataMapTrie &val = m_Maps[pMap];
|
|
|
|
|
|
|
|
if (!val.trie)
|
|
|
|
{
|
|
|
|
val.trie = sm_trie_create();
|
|
|
|
}
|
|
|
|
if (!sm_trie_retrieve(val.trie, offset, (void **)&td))
|
|
|
|
{
|
|
|
|
if ((td = UTIL_FindInDataMap(pMap, offset)) != NULL)
|
|
|
|
{
|
|
|
|
sm_trie_insert(val.trie, offset, td);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return td;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)
|
|
|
|
{
|
2009-02-18 09:19:22 +01:00
|
|
|
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
2008-03-30 09:00:22 +02:00
|
|
|
if (g_pSharedChangeInfo != NULL)
|
|
|
|
{
|
|
|
|
if (offset)
|
|
|
|
{
|
|
|
|
pEdict->StateChanged(offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pEdict->StateChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-02-18 09:19:22 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
pEdict->m_fStateFlags |= FL_EDICT_CHANGED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CHalfLife2::TextMsg(int client, int dest, const char *msg)
|
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
#if SOURCE_ENGINE != SE_CSGO
|
2008-03-30 09:00:22 +02:00
|
|
|
bf_write *pBitBuf = NULL;
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
cell_t players[] = {client};
|
|
|
|
|
2009-02-18 09:19:22 +01:00
|
|
|
if (dest == HUD_PRINTTALK)
|
|
|
|
{
|
|
|
|
const char *chat_saytext = g_pGameConf->GetKeyValue("ChatSayText");
|
|
|
|
|
|
|
|
/* Use SayText user message instead */
|
|
|
|
if (chat_saytext != NULL && strcmp(chat_saytext, "yes") == 0)
|
|
|
|
{
|
|
|
|
char buffer[192];
|
|
|
|
UTIL_Format(buffer, sizeof(buffer), "%s\1\n", msg);
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
|
|
|
CCSUsrMsg_SayText *pMsg;
|
|
|
|
if ((pMsg = (CCSUsrMsg_SayText *)g_UserMsgs.StartProtobufMessage(m_SayTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pMsg->set_ent_idx(0);
|
|
|
|
pMsg->set_text(buffer);
|
|
|
|
pMsg->set_chat(false);
|
|
|
|
#else
|
|
|
|
if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_SayTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
2009-02-18 09:19:22 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pBitBuf->WriteByte(0);
|
|
|
|
pBitBuf->WriteString(buffer);
|
|
|
|
pBitBuf->WriteByte(1);
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2009-02-18 09:19:22 +01:00
|
|
|
|
|
|
|
g_UserMsgs.EndMessage();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
|
|
|
CCSUsrMsg_TextMsg *pMsg;
|
|
|
|
if ((pMsg = (CCSUsrMsg_TextMsg *)g_UserMsgs.StartProtobufMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client tries to read all 5 'params' and will crash if less
|
|
|
|
pMsg->set_msg_dst(dest);
|
|
|
|
pMsg->add_params(msg);
|
|
|
|
pMsg->add_params("");
|
|
|
|
pMsg->add_params("");
|
|
|
|
pMsg->add_params("");
|
|
|
|
pMsg->add_params("");
|
|
|
|
#else
|
|
|
|
if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pBitBuf->WriteByte(dest);
|
|
|
|
pBitBuf->WriteString(msg);
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2009-02-18 09:19:22 +01:00
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
g_UserMsgs.EndMessage();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CHalfLife2::HintTextMsg(int client, const char *msg)
|
|
|
|
{
|
|
|
|
cell_t players[] = {client};
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
|
|
|
CCSUsrMsg_HintText *pMsg;
|
|
|
|
if ((pMsg = (CCSUsrMsg_HintText *)g_UserMsgs.StartProtobufMessage(m_HinTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pMsg->set_text(msg);
|
|
|
|
#else
|
|
|
|
bf_write *pBitBuf = NULL;
|
|
|
|
|
|
|
|
if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_HinTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *pre_byte = g_pGameConf->GetKeyValue("HintTextPreByte");
|
|
|
|
if (pre_byte != NULL && strcmp(pre_byte, "yes") == 0)
|
|
|
|
{
|
|
|
|
pBitBuf->WriteByte(1);
|
|
|
|
}
|
|
|
|
pBitBuf->WriteString(msg);
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
g_UserMsgs.EndMessage();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-17 08:54:40 +02:00
|
|
|
bool CHalfLife2::HintTextMsg(cell_t *players, int count, const char *msg)
|
|
|
|
{
|
2013-01-23 03:43:12 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
|
|
|
CCSUsrMsg_HintText *pMsg;
|
|
|
|
if ((pMsg = (CCSUsrMsg_HintText *)g_UserMsgs.StartProtobufMessage(m_HinTextMsg, players, count, USERMSG_RELIABLE)) == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pMsg->set_text(msg);
|
|
|
|
#else
|
2009-09-17 08:54:40 +02:00
|
|
|
bf_write *pBitBuf = NULL;
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_HinTextMsg, players, count, USERMSG_RELIABLE)) == NULL)
|
2009-09-17 08:54:40 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *pre_byte = g_pGameConf->GetKeyValue("HintTextPreByte");
|
|
|
|
if (pre_byte != NULL && strcmp(pre_byte, "yes") == 0)
|
|
|
|
{
|
|
|
|
pBitBuf->WriteByte(1);
|
|
|
|
}
|
|
|
|
pBitBuf->WriteString(msg);
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
|
|
|
|
2009-09-17 08:54:40 +02:00
|
|
|
g_UserMsgs.EndMessage();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
bool CHalfLife2::ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show)
|
|
|
|
{
|
|
|
|
KeyValues *SubKey = NULL;
|
|
|
|
int count = 0;
|
|
|
|
cell_t players[] = {client};
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
|
|
|
CCSUsrMsg_VGUIMenu *pMsg;
|
|
|
|
if ((pMsg = (CCSUsrMsg_VGUIMenu *)g_UserMsgs.StartProtobufMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-23 03:43:12 +01:00
|
|
|
#else
|
|
|
|
bf_write *pBitBuf = NULL;
|
|
|
|
if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
SubKey = data->GetFirstSubKey();
|
|
|
|
while (SubKey)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
SubKey = SubKey->GetNextKey();
|
|
|
|
}
|
|
|
|
SubKey = data->GetFirstSubKey();
|
|
|
|
}
|
|
|
|
|
2013-01-23 03:43:12 +01:00
|
|
|
#if SOURCE_ENGINE == SE_CSGO
|
|
|
|
pMsg->set_name(name);
|
|
|
|
pMsg->set_show(show);
|
|
|
|
|
|
|
|
while (SubKey)
|
|
|
|
{
|
|
|
|
CCSUsrMsg_VGUIMenu_Subkey *key = pMsg->add_subkeys();
|
|
|
|
key->set_name(SubKey->GetName());
|
|
|
|
key->set_str(SubKey->GetString());
|
|
|
|
SubKey = SubKey->GetNextKey();
|
|
|
|
}
|
|
|
|
#else
|
2008-03-30 09:00:22 +02:00
|
|
|
pBitBuf->WriteString(name);
|
|
|
|
pBitBuf->WriteByte((show) ? 1 : 0);
|
|
|
|
pBitBuf->WriteByte(count);
|
|
|
|
while (SubKey)
|
|
|
|
{
|
|
|
|
pBitBuf->WriteString(SubKey->GetName());
|
|
|
|
pBitBuf->WriteString(SubKey->GetString());
|
|
|
|
SubKey = SubKey->GetNextKey();
|
|
|
|
}
|
2013-01-23 03:43:12 +01:00
|
|
|
#endif
|
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
g_UserMsgs.EndMessage();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHalfLife2::AddToFakeCliCmdQueue(int client, int userid, const char *cmd)
|
|
|
|
{
|
|
|
|
DelayedFakeCliCmd *pFake;
|
|
|
|
|
|
|
|
if (m_FreeCmds.empty())
|
|
|
|
{
|
|
|
|
pFake = new DelayedFakeCliCmd;
|
|
|
|
} else {
|
|
|
|
pFake = m_FreeCmds.front();
|
|
|
|
m_FreeCmds.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
pFake->client = client;
|
|
|
|
pFake->userid = userid;
|
|
|
|
pFake->cmd.assign(cmd);
|
|
|
|
|
|
|
|
m_CmdQueue.push(pFake);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHalfLife2::ProcessFakeCliCmdQueue()
|
|
|
|
{
|
|
|
|
while (!m_CmdQueue.empty())
|
|
|
|
{
|
|
|
|
DelayedFakeCliCmd *pFake = m_CmdQueue.first();
|
|
|
|
|
|
|
|
if (g_Players.GetClientOfUserId(pFake->userid) == pFake->client)
|
|
|
|
{
|
|
|
|
CPlayer *pPlayer = g_Players.GetPlayerByIndex(pFake->client);
|
|
|
|
serverpluginhelpers->ClientCommand(pPlayer->GetEdict(), pFake->cmd.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_CmdQueue.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CHalfLife2::IsLANServer()
|
|
|
|
{
|
|
|
|
sv_lan = icvar->FindVar("sv_lan");
|
|
|
|
|
|
|
|
if (!sv_lan)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (sv_lan->GetInt() != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CHalfLife2::KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID)
|
|
|
|
{
|
2009-10-29 09:33:57 +01:00
|
|
|
#if defined METAMOD_PLAPI_VERSION || PLAPI_VERSION >= 11
|
2008-03-30 09:00:22 +02:00
|
|
|
if (g_SMAPI->GetSourceEngineBuild() == SOURCE_ENGINE_ORIGINAL)
|
|
|
|
#else
|
|
|
|
if (strcasecmp(g_SourceMod.GetGameFolderName(), "ship") == 0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
Assert(filesystem);
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
Assert(_heapchk() == _HEAPOK);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FileHandle_t f = filesystem->Open(resourceName, "rb", pathID);
|
|
|
|
if (!f)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// load file into a null-terminated buffer
|
|
|
|
int fileSize = filesystem->Size(f);
|
|
|
|
char *buffer = (char *)MemAllocScratch(fileSize + 1);
|
|
|
|
|
|
|
|
Assert(buffer);
|
|
|
|
|
|
|
|
filesystem->Read(buffer, fileSize, f); // read into local buffer
|
|
|
|
|
|
|
|
buffer[fileSize] = 0; // null terminate file as EOF
|
|
|
|
|
|
|
|
filesystem->Close( f ); // close file after reading
|
|
|
|
|
|
|
|
bool retOK = kv->LoadFromBuffer( resourceName, buffer, filesystem );
|
|
|
|
|
|
|
|
MemFreeScratch();
|
|
|
|
|
|
|
|
return retOK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return kv->LoadFromFile(filesystem, resourceName, pathID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHalfLife2::PushCommandStack(const CCommand *cmd)
|
|
|
|
{
|
|
|
|
CachedCommandInfo info;
|
|
|
|
|
|
|
|
info.args = cmd;
|
2009-02-18 09:19:22 +01:00
|
|
|
#if SOURCE_ENGINE <= SE_DARKMESSIAH
|
2008-03-30 09:00:22 +02:00
|
|
|
strncopy(info.cmd, cmd->Arg(0), sizeof(info.cmd));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_CommandStack.push(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
const CCommand *CHalfLife2::PeekCommandStack()
|
|
|
|
{
|
|
|
|
if (m_CommandStack.empty())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_CommandStack.front().args;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHalfLife2::PopCommandStack()
|
|
|
|
{
|
|
|
|
m_CommandStack.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *CHalfLife2::CurrentCommandName()
|
|
|
|
{
|
2008-11-14 16:18:30 +01:00
|
|
|
#if SOURCE_ENGINE >= SE_ORANGEBOX
|
2008-03-30 09:00:22 +02:00
|
|
|
return m_CommandStack.front().args->Arg(0);
|
|
|
|
#else
|
|
|
|
return m_CommandStack.front().cmd;
|
|
|
|
#endif
|
|
|
|
}
|
2008-07-06 02:45:26 +02:00
|
|
|
|
|
|
|
void CHalfLife2::AddDelayedKick(int client, int userid, const char *msg)
|
|
|
|
{
|
|
|
|
DelayedKickInfo kick;
|
|
|
|
|
|
|
|
kick.client = client;
|
|
|
|
kick.userid = userid;
|
|
|
|
UTIL_Format(kick.buffer, sizeof(kick.buffer), "%s", msg);
|
|
|
|
|
|
|
|
m_DelayedKicks.push(kick);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHalfLife2::ProcessDelayedKicks()
|
|
|
|
{
|
|
|
|
while (!m_DelayedKicks.empty())
|
|
|
|
{
|
|
|
|
DelayedKickInfo info = m_DelayedKicks.first();
|
|
|
|
m_DelayedKicks.pop();
|
|
|
|
|
|
|
|
CPlayer *player = g_Players.GetPlayerByIndex(info.client);
|
|
|
|
if (player == NULL || player->GetUserId() != info.userid)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
player->Kick(info.buffer);
|
|
|
|
}
|
|
|
|
}
|
2009-02-22 02:38:05 +01:00
|
|
|
|
|
|
|
edict_t *CHalfLife2::EdictOfIndex(int index)
|
|
|
|
{
|
|
|
|
return ::PEntityOfEntIndex(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHalfLife2::IndexOfEdict(edict_t *pEnt)
|
|
|
|
{
|
|
|
|
return ::IndexOfEdict(pEnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
edict_t *CHalfLife2::GetHandleEntity(CBaseHandle &hndl)
|
|
|
|
{
|
|
|
|
if (!hndl.IsValid())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = hndl.GetEntryIndex();
|
|
|
|
|
|
|
|
edict_t *pStoredEdict;
|
|
|
|
CBaseEntity *pStoredEntity;
|
|
|
|
|
2009-12-16 08:14:53 +01:00
|
|
|
if (!IndexToAThings(index, &pStoredEntity, &pStoredEdict))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-02-22 02:38:05 +01:00
|
|
|
|
|
|
|
if (pStoredEdict == NULL || pStoredEntity == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IServerEntity *pSE = pStoredEdict->GetIServerEntity();
|
|
|
|
|
|
|
|
if (pSE == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pSE->GetRefEHandle() != hndl)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pStoredEdict;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHalfLife2::SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt)
|
|
|
|
{
|
|
|
|
IServerEntity *pEntOther = pEnt->GetIServerEntity();
|
|
|
|
|
|
|
|
if (pEntOther == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hndl.Set(pEntOther);
|
|
|
|
}
|
2009-03-01 05:14:16 +01:00
|
|
|
|
|
|
|
const char *CHalfLife2::GetCurrentMap()
|
|
|
|
{
|
|
|
|
return STRING(gpGlobals->mapname);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHalfLife2::ServerCommand(const char *buffer)
|
|
|
|
{
|
|
|
|
engine->ServerCommand(buffer);
|
|
|
|
}
|
2009-07-24 02:34:31 +02:00
|
|
|
|
|
|
|
cell_t CHalfLife2::EntityToReference(CBaseEntity *pEntity)
|
|
|
|
{
|
|
|
|
IServerUnknown *pUnknown = (IServerUnknown *)pEntity;
|
|
|
|
CBaseHandle hndl = pUnknown->GetRefEHandle();
|
|
|
|
return (hndl.ToInt() | (1<<31));
|
|
|
|
}
|
|
|
|
|
|
|
|
CBaseEntity *CHalfLife2::ReferenceToEntity(cell_t entRef)
|
|
|
|
{
|
2012-05-31 13:43:11 +02:00
|
|
|
if ((unsigned)entRef == INVALID_EHANDLE_INDEX)
|
2012-05-31 13:32:07 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-24 02:34:31 +02:00
|
|
|
CEntInfo *pInfo = NULL;
|
|
|
|
|
|
|
|
if (entRef & (1<<31))
|
|
|
|
{
|
|
|
|
/* Proper ent reference */
|
|
|
|
int hndlValue = entRef & ~(1<<31);
|
|
|
|
CBaseHandle hndl(hndlValue);
|
|
|
|
|
|
|
|
pInfo = LookupEntity(hndl.GetEntryIndex());
|
2012-05-31 13:32:07 +02:00
|
|
|
if (!pInfo || pInfo->m_SerialNumber != hndl.GetSerialNumber())
|
2009-07-24 02:34:31 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Old style index only */
|
|
|
|
pInfo = LookupEntity(entRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pInfo)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IServerUnknown *pUnk = static_cast<IServerUnknown *>(pInfo->m_pEntity);
|
|
|
|
if (pUnk)
|
|
|
|
{
|
|
|
|
return pUnk->GetBaseEntity();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the CEntInfo pointer from g_EntList for a given entity index
|
|
|
|
*/
|
|
|
|
CEntInfo *CHalfLife2::LookupEntity(int entIndex)
|
|
|
|
{
|
2011-09-09 21:29:17 +02:00
|
|
|
// Make sure that our index is within the bounds of the global ent array
|
|
|
|
if (entIndex < 0 || entIndex >= NUM_ENT_ENTRIES)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-24 02:34:31 +02:00
|
|
|
if (!g_EntList || entInfoOffset == -1)
|
|
|
|
{
|
|
|
|
/* Attempt to use engine interface instead */
|
|
|
|
static CEntInfo tempInfo;
|
|
|
|
tempInfo.m_pNext = NULL;
|
|
|
|
tempInfo.m_pPrev = NULL;
|
|
|
|
|
2009-07-24 02:54:08 +02:00
|
|
|
edict_t *pEdict = PEntityOfEntIndex(entIndex);
|
2009-07-24 02:34:31 +02:00
|
|
|
|
|
|
|
if (!pEdict)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IServerUnknown *pUnk = pEdict->GetUnknown();
|
|
|
|
|
|
|
|
if (!pUnk)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tempInfo.m_pEntity = pUnk;
|
|
|
|
tempInfo.m_SerialNumber = pUnk->GetRefEHandle().GetSerialNumber();
|
|
|
|
|
|
|
|
return &tempInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEntInfo *pArray = (CEntInfo *)(((unsigned char *)g_EntList) + entInfoOffset);
|
|
|
|
return &pArray[entIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
SERIAL_MASK = 0x7fff (15 bits)
|
|
|
|
|
|
|
|
#define MAX_EDICT_BITS 11
|
|
|
|
#define NUM_ENT_ENTRY_BITS (MAX_EDICT_BITS + 1)
|
|
|
|
m_Index = iEntry | (iSerialNumber << NUM_ENT_ENTRY_BITS);
|
|
|
|
|
|
|
|
Top 5 bits of a handle are unused.
|
|
|
|
Bit 31 - Our 'reference' flag indicator
|
|
|
|
*/
|
|
|
|
|
|
|
|
cell_t CHalfLife2::IndexToReference(int entIndex)
|
|
|
|
{
|
|
|
|
CBaseEntity *pEnt = ReferenceToEntity(entIndex);
|
|
|
|
if (!pEnt)
|
|
|
|
{
|
|
|
|
return INVALID_EHANDLE_INDEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EntityToReference(pEnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHalfLife2::ReferenceToIndex(cell_t entRef)
|
|
|
|
{
|
2009-07-24 02:54:08 +02:00
|
|
|
if ((unsigned)entRef == INVALID_EHANDLE_INDEX)
|
2009-07-24 02:34:31 +02:00
|
|
|
{
|
|
|
|
return INVALID_EHANDLE_INDEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entRef & (1<<31))
|
|
|
|
{
|
|
|
|
/* Proper ent reference */
|
|
|
|
int hndlValue = entRef & ~(1<<31);
|
|
|
|
CBaseHandle hndl(hndlValue);
|
|
|
|
|
|
|
|
CEntInfo *pInfo = LookupEntity(hndl.GetEntryIndex());
|
|
|
|
|
|
|
|
if (pInfo->m_SerialNumber != hndl.GetSerialNumber())
|
|
|
|
{
|
|
|
|
return INVALID_EHANDLE_INDEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hndl.GetEntryIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
return entRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell_t CHalfLife2::EntityToBCompatRef(CBaseEntity *pEntity)
|
|
|
|
{
|
|
|
|
if (pEntity == NULL)
|
|
|
|
{
|
|
|
|
return INVALID_EHANDLE_INDEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
IServerUnknown *pUnknown = (IServerUnknown *)pEntity;
|
|
|
|
CBaseHandle hndl = pUnknown->GetRefEHandle();
|
|
|
|
|
2012-12-01 19:41:00 +01:00
|
|
|
if (hndl == INVALID_EHANDLE_INDEX)
|
|
|
|
{
|
|
|
|
return INVALID_EHANDLE_INDEX;
|
|
|
|
}
|
|
|
|
|
2009-07-24 02:34:31 +02:00
|
|
|
if (hndl.GetEntryIndex() >= MAX_EDICTS)
|
|
|
|
{
|
|
|
|
return (hndl.ToInt() | (1<<31));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return hndl.GetEntryIndex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cell_t CHalfLife2::ReferenceToBCompatRef(cell_t entRef)
|
|
|
|
{
|
2009-07-24 02:54:08 +02:00
|
|
|
if ((unsigned)entRef == INVALID_EHANDLE_INDEX)
|
2009-07-24 02:34:31 +02:00
|
|
|
{
|
|
|
|
return INVALID_EHANDLE_INDEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hndlValue = entRef & ~(1<<31);
|
|
|
|
CBaseHandle hndl(hndlValue);
|
|
|
|
|
|
|
|
if (hndl.GetEntryIndex() < MAX_EDICTS)
|
|
|
|
{
|
|
|
|
return hndl.GetEntryIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
return entRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *CHalfLife2::GetGlobalEntityList()
|
|
|
|
{
|
|
|
|
return g_EntList;
|
2009-07-24 02:54:08 +02:00
|
|
|
}
|
2010-05-15 08:35:42 +02:00
|
|
|
|
|
|
|
int CHalfLife2::GetSendPropOffset(SendProp *prop)
|
|
|
|
{
|
|
|
|
return prop->GetOffset();
|
|
|
|
}
|
|
|
|
|
2012-08-28 22:20:15 +02:00
|
|
|
const char *CHalfLife2::GetEntityClassname(edict_t * pEdict)
|
|
|
|
{
|
|
|
|
if (pEdict == NULL || pEdict->IsFree())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IServerUnknown *pUnk = pEdict->GetUnknown();
|
|
|
|
if (pUnk == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBaseEntity * pEntity = pUnk->GetBaseEntity();
|
|
|
|
|
|
|
|
if (pEntity == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetEntityClassname(pEntity);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *CHalfLife2::GetEntityClassname(CBaseEntity *pEntity)
|
|
|
|
{
|
|
|
|
static int offset = -1;
|
|
|
|
if (offset == -1)
|
|
|
|
{
|
|
|
|
datamap_t *pMap = GetDataMap(pEntity);
|
|
|
|
typedescription_t *pDesc = FindInDataMap(pMap, "m_iClassname");
|
|
|
|
offset = GetTypeDescOffs(pDesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *(const char **)(((unsigned char *)pEntity) + offset);
|
|
|
|
}
|