Added support for logical (non-networked) entities using entity references - See http://wiki.alliedmods.net/Entity_References_%28SourceMod%29 (bug 2459, r=dvander)
This commit is contained in:
parent
7ec656db09
commit
3e36382b58
@ -37,10 +37,14 @@
|
||||
#include "sm_stringutil.h"
|
||||
#include "GameConfigs.h"
|
||||
#include <compat_wrappers.h>
|
||||
#include <Logger.h>
|
||||
|
||||
CHalfLife2 g_HL2;
|
||||
ConVar *sv_lan = NULL;
|
||||
|
||||
static void *g_EntList = NULL;
|
||||
static int entInfoOffset = -1;
|
||||
|
||||
namespace SourceHook
|
||||
{
|
||||
template<>
|
||||
@ -123,6 +127,51 @@ void CHalfLife2::OnSourceModAllInitialized()
|
||||
g_ShareSys.AddInterface(NULL, this);
|
||||
}
|
||||
|
||||
void CHalfLife2::OnSourceModAllInitialized_Post()
|
||||
{
|
||||
char *addr = NULL;
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
int offset;
|
||||
|
||||
/* gEntList and/or g_pEntityList */
|
||||
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;
|
||||
}
|
||||
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);
|
||||
#elif defined PLATFORM_LINUX
|
||||
/* gEntList and/or g_pEntityList */
|
||||
if (!g_pGameConf->GetMemSig("gEntList", (void **)&addr))
|
||||
{
|
||||
g_Logger.LogError("Logical Entities not supported by this mod (gEntList) - Reverting to networkable entities only");
|
||||
return;
|
||||
}
|
||||
if (!addr)
|
||||
{
|
||||
g_Logger.LogError("Failed lookup of gEntList - Reverting to networkable entities only");
|
||||
return;
|
||||
}
|
||||
g_EntList = reinterpret_cast<void *>(addr);
|
||||
#endif
|
||||
|
||||
if (!g_pGameConf->GetOffset("EntInfo", &entInfoOffset))
|
||||
{
|
||||
g_Logger.LogError("Logical Entities not supported by this mod (EntInfo) - Reverting to networkable entities only");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined METAMOD_PLAPI_VERSION
|
||||
bool CHalfLife2::IsOriginalEngine()
|
||||
{
|
||||
@ -642,3 +691,173 @@ void CHalfLife2::ServerCommand(const char *buffer)
|
||||
{
|
||||
engine->ServerCommand(buffer);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
CEntInfo *pInfo = NULL;
|
||||
|
||||
if (entRef & (1<<31))
|
||||
{
|
||||
/* Proper ent reference */
|
||||
int hndlValue = entRef & ~(1<<31);
|
||||
CBaseHandle hndl(hndlValue);
|
||||
|
||||
pInfo = LookupEntity(hndl.GetEntryIndex());
|
||||
if (pInfo->m_SerialNumber != hndl.GetSerialNumber())
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (!g_EntList || entInfoOffset == -1)
|
||||
{
|
||||
/* Attempt to use engine interface instead */
|
||||
static CEntInfo tempInfo;
|
||||
tempInfo.m_pNext = NULL;
|
||||
tempInfo.m_pPrev = NULL;
|
||||
|
||||
edict_t *pEdict = engine->PEntityOfEntIndex(entIndex);
|
||||
|
||||
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)
|
||||
{
|
||||
if (entRef == INVALID_EHANDLE_INDEX)
|
||||
{
|
||||
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();
|
||||
|
||||
if (hndl.GetEntryIndex() >= MAX_EDICTS)
|
||||
{
|
||||
return (hndl.ToInt() | (1<<31));
|
||||
}
|
||||
else
|
||||
{
|
||||
return hndl.GetEntryIndex();
|
||||
}
|
||||
}
|
||||
|
||||
cell_t CHalfLife2::ReferenceToBCompatRef(cell_t entRef)
|
||||
{
|
||||
if (entRef == INVALID_EHANDLE_INDEX)
|
||||
{
|
||||
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;
|
||||
}
|
@ -43,6 +43,7 @@
|
||||
#include <KeyValues.h>
|
||||
#include <server_class.h>
|
||||
#include <datamap.h>
|
||||
#include <ihandleentity.h>
|
||||
|
||||
class CCommand;
|
||||
|
||||
@ -86,6 +87,15 @@ struct DelayedKickInfo
|
||||
char buffer[384];
|
||||
};
|
||||
|
||||
class CEntInfo
|
||||
{
|
||||
public:
|
||||
IHandleEntity *m_pEntity;
|
||||
int m_SerialNumber;
|
||||
CEntInfo *m_pPrev;
|
||||
CEntInfo *m_pNext;
|
||||
};
|
||||
|
||||
class CHalfLife2 :
|
||||
public SMGlobalClass,
|
||||
public IGameHelpers
|
||||
@ -96,6 +106,7 @@ public:
|
||||
public:
|
||||
void OnSourceModStartup(bool late);
|
||||
void OnSourceModAllInitialized();
|
||||
void OnSourceModAllInitialized_Post();
|
||||
/*void OnSourceModAllShutdown();*/
|
||||
public: //IGameHelpers
|
||||
SendProp *FindInSendTable(const char *classname, const char *offset);
|
||||
@ -115,6 +126,14 @@ public: //IGameHelpers
|
||||
void SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt);
|
||||
const char *GetCurrentMap();
|
||||
void ServerCommand(const char *buffer);
|
||||
CBaseEntity *ReferenceToEntity(cell_t entRef);
|
||||
cell_t EntityToReference(CBaseEntity *pEntity);
|
||||
cell_t IndexToReference(int entIndex);
|
||||
int ReferenceToIndex(cell_t entRef);
|
||||
cell_t ReferenceToBCompatRef(cell_t entRef);
|
||||
CEntInfo *LookupEntity(int entIndex);
|
||||
cell_t EntityToBCompatRef(CBaseEntity *pEntity);
|
||||
void *GetGlobalEntityList();
|
||||
public:
|
||||
void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
|
||||
void ProcessFakeCliCmdQueue();
|
||||
|
@ -248,7 +248,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
|
||||
char *ban_reason, *ban_cmd;
|
||||
int client, ban_flags, ban_source, ban_time;
|
||||
|
||||
client = params[1];
|
||||
client = g_HL2.ReferenceToIndex(params[1]);
|
||||
|
||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
|
||||
if (!pPlayer || !pPlayer->IsConnected())
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "HandleSys.h"
|
||||
#include <bitbuf.h>
|
||||
#include <vector.h>
|
||||
#include <HalfLife2.h>
|
||||
|
||||
static cell_t smn_BfWriteBool(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
@ -226,7 +227,14 @@ static cell_t smn_BfWriteEntity(IPluginContext *pCtx, const cell_t *params)
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
pBitBuf->WriteShort(params[2]);
|
||||
int index = g_HL2.ReferenceToIndex(params[2]);
|
||||
|
||||
if (index == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pBitBuf->WriteShort(index);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -523,7 +531,9 @@ static cell_t smn_BfReadEntity(IPluginContext *pCtx, const cell_t *params)
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return pBitBuf->ReadShort();
|
||||
int ref = g_HL2.IndexToReference(pBitBuf->ReadShort());
|
||||
|
||||
return g_HL2.ReferenceToBCompatRef(ref);
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadAngle(IPluginContext *pCtx, const cell_t *params)
|
||||
|
@ -54,45 +54,74 @@ enum PropFieldType
|
||||
PropField_String_T, /**< Valid for Data fields. Read only! */
|
||||
};
|
||||
|
||||
inline edict_t *BaseEntityToEdict(CBaseEntity *pEntity)
|
||||
{
|
||||
IServerUnknown *pUnk = (IServerUnknown *)pEntity;
|
||||
IServerNetworkable *pNet = pUnk->GetNetworkable();
|
||||
|
||||
if (!pNet)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pNet->GetEdict();
|
||||
}
|
||||
|
||||
inline edict_t *GetEdict(cell_t num)
|
||||
{
|
||||
edict_t *pEdict = PEntityOfEntIndex(num);
|
||||
CBaseEntity *pEntity = g_HL2.ReferenceToEntity(num);
|
||||
|
||||
if (!pEntity)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
edict_t *pEdict = ::BaseEntityToEdict(pEntity);
|
||||
if (!pEdict || pEdict->IsFree())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (num > 0 && num <= g_Players.GetMaxClients())
|
||||
|
||||
int index = g_HL2.ReferenceToIndex(num);
|
||||
if (index > 0 && index <= g_Players.GetMaxClients())
|
||||
{
|
||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(num);
|
||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
|
||||
if (!pPlayer || !pPlayer->IsConnected())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return pEdict;
|
||||
}
|
||||
|
||||
edict_t *GetEntity(cell_t num, CBaseEntity **pData)
|
||||
{
|
||||
edict_t *pEdict = PEntityOfEntIndex(num);
|
||||
if (!pEdict || pEdict->IsFree())
|
||||
CBaseEntity *pEntity = g_HL2.ReferenceToEntity(num);
|
||||
|
||||
if (!pEntity)
|
||||
{
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
if (num > 0 && num <= g_Players.GetMaxClients())
|
||||
|
||||
int index = g_HL2.ReferenceToIndex(num);
|
||||
if (index > 0 && index <= g_Players.GetMaxClients())
|
||||
{
|
||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(num);
|
||||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
|
||||
if (!pPlayer || !pPlayer->IsConnected())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
IServerUnknown *pUnk;
|
||||
if ((pUnk=pEdict->GetUnknown()) == NULL)
|
||||
|
||||
*pData = pEntity;
|
||||
|
||||
edict_t *pEdict = ::BaseEntityToEdict(pEntity);
|
||||
if (!pEdict || pEdict->IsFree())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
*pData = pUnk->GetBaseEntity();
|
||||
|
||||
return pEdict;
|
||||
}
|
||||
|
||||
@ -161,11 +190,11 @@ static cell_t CreateEdict(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
static cell_t RemoveEdict(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
edict_t *pEdict = PEntityOfEntIndex(params[1]);
|
||||
edict_t *pEdict = GetEdict(params[1]);
|
||||
|
||||
if (!pEdict)
|
||||
{
|
||||
return pContext->ThrowNativeError("Edict %d is not a valid edict", params[1]);
|
||||
return pContext->ThrowNativeError("Edict %d (%d) is not a valid edict", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
engine->RemoveEdict(pEdict);
|
||||
@ -188,20 +217,8 @@ static cell_t IsValidEdict(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
static cell_t IsValidEntity(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
edict_t *pEdict = GetEdict(params[1]);
|
||||
CBaseEntity *pEntity = g_HL2.ReferenceToEntity(params[1]);
|
||||
|
||||
if (!pEdict)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
IServerUnknown *pUnknown = pEdict->GetUnknown();
|
||||
if (!pUnknown)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBaseEntity *pEntity = pUnknown->GetBaseEntity();
|
||||
return (pEntity != NULL) ? 1 : 0;
|
||||
}
|
||||
|
||||
@ -228,7 +245,7 @@ static cell_t GetEdictFlags(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
if (!pEdict)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid edict (%d)", params[1]);
|
||||
return pContext->ThrowNativeError("Invalid edict (%d - %d)", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
return pEdict->m_fStateFlags;
|
||||
@ -240,7 +257,7 @@ static cell_t SetEdictFlags(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
if (!pEdict)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid edict (%d)", params[1]);
|
||||
return pContext->ThrowNativeError("Invalid edict (%d - %d)", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
pEdict->m_fStateFlags = params[2];
|
||||
@ -254,7 +271,7 @@ static cell_t GetEdictClassname(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
if (!pEdict)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid edict (%d)", params[1]);
|
||||
return pContext->ThrowNativeError("Invalid edict (%d - %d)", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
const char *cls = pEdict->GetClassName();
|
||||
@ -271,14 +288,16 @@ static cell_t GetEdictClassname(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
static cell_t GetEntityNetClass(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
edict_t *pEdict = GetEdict(params[1]);
|
||||
CBaseEntity *pEntity = g_HL2.ReferenceToEntity(params[1]);
|
||||
|
||||
if (!pEdict)
|
||||
IServerUnknown *pUnk = (IServerUnknown *)pEntity;
|
||||
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid edict (%d)", params[1]);
|
||||
return pContext->ThrowNativeError("Invalid entity (%d - %d)", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
IServerNetworkable *pNet = pEdict->GetNetworkable();
|
||||
IServerNetworkable *pNet = pUnk->GetNetworkable();
|
||||
if (!pNet)
|
||||
{
|
||||
return 0;
|
||||
@ -294,11 +313,11 @@ static cell_t GetEntityNetClass(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t GetEntData(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -325,9 +344,9 @@ static cell_t SetEntData(IPluginContext *pContext, const cell_t *params)
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -336,7 +355,7 @@ static cell_t SetEntData(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeError("Offset %d is invalid", offset);
|
||||
}
|
||||
|
||||
if (params[5])
|
||||
if (params[5] && (pEdict != NULL))
|
||||
{
|
||||
g_HL2.SetEdictStateChanged(pEdict, offset);
|
||||
}
|
||||
@ -368,11 +387,11 @@ static cell_t SetEntData(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t GetEntDataFloat(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -391,9 +410,9 @@ static cell_t SetEntDataFloat(IPluginContext *pContext, const cell_t *params)
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -404,7 +423,7 @@ static cell_t SetEntDataFloat(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
*(float *)((uint8_t *)pEntity + offset) = sp_ctof(params[3]);
|
||||
|
||||
if (params[4])
|
||||
if (params[4] && (pEdict != NULL))
|
||||
{
|
||||
g_HL2.SetEdictStateChanged(pEdict, offset);
|
||||
}
|
||||
@ -415,11 +434,11 @@ static cell_t SetEntDataFloat(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t GetEntDataVector(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -445,9 +464,9 @@ static cell_t SetEntDataVector(IPluginContext *pContext, const cell_t *params)
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -465,7 +484,7 @@ static cell_t SetEntDataVector(IPluginContext *pContext, const cell_t *params)
|
||||
v->y = sp_ctof(vec[1]);
|
||||
v->z = sp_ctof(vec[2]);
|
||||
|
||||
if (params[4])
|
||||
if (params[4] && (pEdict != NULL))
|
||||
{
|
||||
g_HL2.SetEdictStateChanged(pEdict, offset);
|
||||
}
|
||||
@ -477,11 +496,11 @@ static cell_t SetEntDataVector(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t GetEntDataEnt(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -497,7 +516,8 @@ static cell_t GetEntDataEnt(IPluginContext *pContext, const cell_t *params)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return hndl.GetEntryIndex();
|
||||
int ref = g_HL2.IndexToReference(hndl.GetEntryIndex());
|
||||
return g_HL2.ReferenceToBCompatRef(ref);
|
||||
}
|
||||
|
||||
int CheckBaseHandle(CBaseHandle &hndl)
|
||||
@ -537,11 +557,11 @@ int CheckBaseHandle(CBaseHandle &hndl)
|
||||
static cell_t GetEntDataEnt2(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
GetEntity(params[1], &pEntity);
|
||||
|
||||
if (pEdict == NULL || pEntity == NULL)
|
||||
if (pEntity == NULL)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -552,7 +572,8 @@ static cell_t GetEntDataEnt2(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset);
|
||||
|
||||
return CheckBaseHandle(hndl);
|
||||
int ref = g_HL2.IndexToReference(hndl.GetEntryIndex());
|
||||
return g_HL2.ReferenceToBCompatRef(ref);
|
||||
}
|
||||
|
||||
/* THIS GUY IS DEPRECATED. */
|
||||
@ -561,9 +582,9 @@ static cell_t SetEntDataEnt(IPluginContext *pContext, const cell_t *params)
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -574,20 +595,23 @@ static cell_t SetEntDataEnt(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset);
|
||||
|
||||
if (params[3] == 0)
|
||||
if (params[3] == 0 || params[3] == INVALID_EHANDLE_INDEX)
|
||||
{
|
||||
hndl.Set(NULL);
|
||||
} else {
|
||||
edict_t *pEdict = GetEdict(params[3]);
|
||||
if (!pEdict)
|
||||
CBaseEntity *pOther;
|
||||
GetEntity(params[3], &pOther);
|
||||
|
||||
if (!pOther)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[3]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[3]), params[3]);
|
||||
}
|
||||
IServerEntity *pEntOther = pEdict->GetIServerEntity();
|
||||
hndl.Set(pEntOther);
|
||||
|
||||
IHandleEntity *pHandleEnt = (IHandleEntity *)pOther;
|
||||
hndl.Set(pHandleEnt);
|
||||
}
|
||||
|
||||
if (params[4])
|
||||
if (params[4] && (pEdict != NULL))
|
||||
{
|
||||
g_HL2.SetEdictStateChanged(pEdict, offset);
|
||||
}
|
||||
@ -600,9 +624,9 @@ static cell_t SetEntDataEnt2(IPluginContext *pContext, const cell_t *params)
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -613,22 +637,25 @@ static cell_t SetEntDataEnt2(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset);
|
||||
|
||||
if (params[3] == -1)
|
||||
if (params[3] == INVALID_EHANDLE_INDEX)
|
||||
{
|
||||
hndl.Set(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
edict_t *pEdict = GetEdict(params[3]);
|
||||
if (!pEdict)
|
||||
CBaseEntity *pOther;
|
||||
GetEntity(params[3], &pOther);
|
||||
|
||||
if (!pOther)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[3]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[3]), params[3]);
|
||||
}
|
||||
IServerEntity *pEntOther = pEdict->GetIServerEntity();
|
||||
hndl.Set(pEntOther);
|
||||
|
||||
IHandleEntity *pHandleEnt = (IHandleEntity *)pOther;
|
||||
hndl.Set(pHandleEnt);
|
||||
}
|
||||
|
||||
if (params[4])
|
||||
if (params[4] && (pEdict != NULL))
|
||||
{
|
||||
g_HL2.SetEdictStateChanged(pEdict, offset);
|
||||
}
|
||||
@ -642,7 +669,7 @@ static cell_t ChangeEdictState(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
if (!pEdict)
|
||||
{
|
||||
return pContext->ThrowNativeError("Edict %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Edict %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
g_HL2.SetEdictStateChanged(pEdict, params[2]);
|
||||
@ -725,11 +752,11 @@ static cell_t FindDataMapOffs(IPluginContext *pContext, const cell_t *params)
|
||||
datamap_t *pMap;
|
||||
typedescription_t *td;
|
||||
char *offset;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if ((pMap=CBaseEntity_GetDataDescMap(pEntity)) == NULL)
|
||||
@ -830,11 +857,11 @@ static cell_t FindDataMapOffs(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t GetEntDataString(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -855,9 +882,9 @@ static cell_t SetEntDataString(IPluginContext *pContext, const cell_t *params)
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
int offset = params[2];
|
||||
@ -872,7 +899,7 @@ static cell_t SetEntDataString(IPluginContext *pContext, const cell_t *params)
|
||||
pContext->LocalToString(params[3], &src);
|
||||
size_t len = strncopy(dest, src, params[4]);
|
||||
|
||||
if (params[5])
|
||||
if (params[5] && (pEdict != NULL))
|
||||
{
|
||||
g_HL2.SetEdictStateChanged(pEdict, offset);
|
||||
}
|
||||
@ -895,10 +922,11 @@ static cell_t SetEntDataString(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
|
||||
#define FIND_PROP_SEND(pProp) \
|
||||
IServerNetworkable *pNet = pEdict->GetNetworkable(); \
|
||||
IServerUnknown *pUnk = (IServerUnknown *)pEntity; \
|
||||
IServerNetworkable *pNet = pUnk->GetNetworkable(); \
|
||||
if (!pNet) \
|
||||
{ \
|
||||
return pContext->ThrowNativeError("Edict %d is not networkable", params[1]); \
|
||||
return pContext->ThrowNativeError("Edict %d (%d) is not networkable", g_HL2.ReferenceToIndex(params[1]), params[1]); \
|
||||
} \
|
||||
if (!g_HL2.FindSendPropInfo(pNet->GetServerClass()->GetName(), prop, pProp)) \
|
||||
{ \
|
||||
@ -942,12 +970,13 @@ static cell_t GetEntProp(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if ((class_name = pEdict->GetClassName()) == NULL)
|
||||
/* TODO: Find a way to lookup classname without having an edict - Is this a guaranteed prop? */
|
||||
if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
|
||||
{
|
||||
class_name = "";
|
||||
}
|
||||
@ -1033,12 +1062,12 @@ static cell_t SetEntProp(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if ((class_name = pEdict->GetClassName()) == NULL)
|
||||
if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
|
||||
{
|
||||
class_name = "";
|
||||
}
|
||||
@ -1123,12 +1152,12 @@ static cell_t GetEntPropFloat(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if ((class_name = pEdict->GetClassName()) == NULL)
|
||||
if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
|
||||
{
|
||||
class_name = "";
|
||||
}
|
||||
@ -1194,12 +1223,12 @@ static cell_t SetEntPropFloat(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if ((class_name = pEdict->GetClassName()) == NULL)
|
||||
if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
|
||||
{
|
||||
class_name = "";
|
||||
}
|
||||
@ -1252,7 +1281,7 @@ static cell_t SetEntPropFloat(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
*(float *)((uint8_t *)pEntity + offset) = sp_ctof(params[4]);
|
||||
|
||||
if (params[2] == Prop_Send)
|
||||
if (params[2] == Prop_Send && (pEdict != NULL))
|
||||
{
|
||||
g_HL2.SetEdictStateChanged(pEdict, offset);
|
||||
}
|
||||
@ -1270,12 +1299,12 @@ static cell_t GetEntPropEnt(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if ((class_name = pEdict->GetClassName()) == NULL)
|
||||
if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
|
||||
{
|
||||
class_name = "";
|
||||
}
|
||||
@ -1326,7 +1355,8 @@ static cell_t GetEntPropEnt(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEntity + offset);
|
||||
|
||||
return CheckBaseHandle(hndl);
|
||||
int ref = g_HL2.IndexToReference(hndl.GetEntryIndex());
|
||||
return g_HL2.ReferenceToBCompatRef(ref);
|
||||
}
|
||||
|
||||
static cell_t SetEntPropEnt(IPluginContext *pContext, const cell_t *params)
|
||||
@ -1339,12 +1369,12 @@ static cell_t SetEntPropEnt(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if ((class_name = pEdict->GetClassName()) == NULL)
|
||||
if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
|
||||
{
|
||||
class_name = "";
|
||||
}
|
||||
@ -1401,18 +1431,19 @@ static cell_t SetEntPropEnt(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
else
|
||||
{
|
||||
edict_t *pOther;
|
||||
CBaseEntity *pOtherEnt;
|
||||
CBaseEntity *pOther;
|
||||
GetEntity(params[4], &pOther);
|
||||
|
||||
if ((pOther = GetEntity(params[4], &pOtherEnt)) == NULL)
|
||||
if (!pOther)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid entity %d", params[4]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[4]), params[4]);
|
||||
}
|
||||
|
||||
hndl.Set(pOther->GetIServerEntity());
|
||||
IHandleEntity *pHandleEnt = (IHandleEntity *)pOther;
|
||||
hndl.Set(pHandleEnt);
|
||||
}
|
||||
|
||||
if (params[2] == Prop_Send)
|
||||
if (params[2] == Prop_Send && (pEdict != NULL))
|
||||
{
|
||||
g_HL2.SetEdictStateChanged(pEdict, offset);
|
||||
}
|
||||
@ -1430,12 +1461,12 @@ static cell_t GetEntPropVector(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if ((class_name = pEdict->GetClassName()) == NULL)
|
||||
if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
|
||||
{
|
||||
class_name = "";
|
||||
}
|
||||
@ -1508,12 +1539,12 @@ static cell_t SetEntPropVector(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if ((class_name = pEdict->GetClassName()) == NULL)
|
||||
if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
|
||||
{
|
||||
class_name = "";
|
||||
}
|
||||
@ -1573,7 +1604,7 @@ static cell_t SetEntPropVector(IPluginContext *pContext, const cell_t *params)
|
||||
v->y = sp_ctof(vec[1]);
|
||||
v->z = sp_ctof(vec[2]);
|
||||
|
||||
if (params[2] == Prop_Send)
|
||||
if (params[2] == Prop_Send && (pEdict != NULL))
|
||||
{
|
||||
g_HL2.SetEdictStateChanged(pEdict, offset);
|
||||
}
|
||||
@ -1592,12 +1623,12 @@ static cell_t GetEntPropString(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if ((class_name = pEdict->GetClassName()) == NULL)
|
||||
if (!pEdict || (class_name = pEdict->GetClassName()) == NULL)
|
||||
{
|
||||
class_name = "";
|
||||
}
|
||||
@ -1682,9 +1713,9 @@ static cell_t SetEntPropString(IPluginContext *pContext, const cell_t *params)
|
||||
int maxlen;
|
||||
edict_t *pEdict = GetEntity(params[1], &pEntity);
|
||||
|
||||
if (!pEdict || !pEntity)
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
switch (params[2])
|
||||
@ -1713,7 +1744,8 @@ static cell_t SetEntPropString(IPluginContext *pContext, const cell_t *params)
|
||||
case Prop_Send:
|
||||
{
|
||||
char *prop;
|
||||
IServerNetworkable *pNet = pEdict->GetNetworkable();
|
||||
IServerUnknown *pUnk = (IServerUnknown *)pEntity;
|
||||
IServerNetworkable *pNet = pUnk->GetNetworkable();
|
||||
if (!pNet)
|
||||
{
|
||||
return pContext->ThrowNativeError("The edict is not networkable");
|
||||
@ -1744,7 +1776,7 @@ static cell_t SetEntPropString(IPluginContext *pContext, const cell_t *params)
|
||||
pContext->LocalToString(params[4], &src);
|
||||
size_t len = strncopy(dest, src, maxlen);
|
||||
|
||||
if (params[2] == Prop_Send)
|
||||
if (params[2] == Prop_Send && (pEdict != NULL))
|
||||
{
|
||||
g_HL2.SetEdictStateChanged(pEdict, offset);
|
||||
}
|
||||
|
@ -475,6 +475,26 @@ static cell_t GuessSDKVersion(IPluginContext *pContext, const cell_t *params)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static cell_t IndexToReference(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
if (params[1] >= NUM_ENT_ENTRIES || params[1] < 0)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid entity index %i", params[1]);
|
||||
}
|
||||
|
||||
return g_HL2.IndexToReference(params[1]);
|
||||
}
|
||||
|
||||
static cell_t ReferenceToIndex(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return g_HL2.ReferenceToIndex(params[1]);
|
||||
}
|
||||
|
||||
static cell_t ReferenceToBCompatRef(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return g_HL2.ReferenceToBCompatRef(params[1]);
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(halflifeNatives)
|
||||
{
|
||||
{"CreateFakeClient", CreateFakeClient},
|
||||
@ -505,5 +525,8 @@ REGISTER_NATIVES(halflifeNatives)
|
||||
{"ShowVGUIPanel", ShowVGUIPanel},
|
||||
{"IsPlayerAlive", smn_IsPlayerAlive},
|
||||
{"GuessSDKVersion", GuessSDKVersion},
|
||||
{"EntIndexToEntRef", IndexToReference},
|
||||
{"EntRefToEntIndex", ReferenceToIndex},
|
||||
{"MakeCompatEntRef", ReferenceToBCompatRef},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
@ -37,21 +37,11 @@
|
||||
ICallWrapper *g_pAcceptInput = NULL;
|
||||
unsigned char g_Variant_t[SIZEOF_VARIANT_T] = {0};
|
||||
|
||||
#define ENTINDEX_TO_CBASEENTITY(index, buffer) \
|
||||
pEdict = PEntityOfEntIndex(index); \
|
||||
if (!pEdict || pEdict->IsFree()) \
|
||||
{ \
|
||||
return pContext->ThrowNativeError("Entity %d is not valid or is freed", index); \
|
||||
} \
|
||||
pUnk = pEdict->GetUnknown(); \
|
||||
if (!pUnk) \
|
||||
{ \
|
||||
return pContext->ThrowNativeError("Entity %d is a not an IServerUnknown", index); \
|
||||
} \
|
||||
buffer = pUnk->GetBaseEntity(); \
|
||||
#define ENTINDEX_TO_CBASEENTITY(ref, buffer) \
|
||||
buffer = gamehelpers->ReferenceToEntity(ref); \
|
||||
if (!buffer) \
|
||||
{ \
|
||||
return pContext->ThrowNativeError("Entity %d is not a CBaseEntity", index); \
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is not a CBaseEntity", gamehelpers->ReferenceToIndex(ref), ref); \
|
||||
}
|
||||
|
||||
/* Hack to init the variant_t object for the first time */
|
||||
@ -109,8 +99,6 @@ static cell_t AcceptEntityInput(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
|
||||
CBaseEntity *pActivator, *pCaller, *pDest;
|
||||
edict_t *pEdict;
|
||||
IServerUnknown *pUnk;
|
||||
|
||||
char *inputname;
|
||||
unsigned char vstk[sizeof(void *) + sizeof(const char *) + sizeof(CBaseEntity *)*2 + SIZEOF_VARIANT_T + sizeof(int)];
|
||||
@ -257,8 +245,6 @@ static cell_t SetVariantColor(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t SetVariantEntity(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CBaseEntity *pEntity;
|
||||
edict_t *pEdict;
|
||||
IServerUnknown *pUnk;
|
||||
unsigned char *vptr = g_Variant_t;
|
||||
CBaseHandle bHandle;
|
||||
|
||||
|
@ -205,20 +205,12 @@ void EntityOutputManager::FireEventDetour(void *pOutput, CBaseEntity *pActivator
|
||||
// attempt to directly lookup a hook using the pOutput pointer
|
||||
OutputNameStruct *pOutputName = NULL;
|
||||
|
||||
edict_t *pEdict = gameents->BaseEntityToEdict(pCaller);
|
||||
|
||||
/* TODO: Add support for entities without an edict */
|
||||
if (pEdict == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool fastLookup = false;
|
||||
|
||||
// Fast lookup failed - check the slow way for hooks that havn't fired yet
|
||||
if ((fastLookup = EntityOutputs->Retrieve(sOutput, (void **)&pOutputName)) == false)
|
||||
{
|
||||
const char *classname = pEdict->GetClassName();
|
||||
const char *classname = GetEntityClassname(pCaller);
|
||||
const char *outputname = FindOutputName(pOutput, pCaller);
|
||||
|
||||
pOutputName = FindOutputPointer(classname, outputname, false);
|
||||
@ -249,37 +241,31 @@ void EntityOutputManager::FireEventDetour(void *pOutput, CBaseEntity *pActivator
|
||||
|
||||
hook->in_use = true;
|
||||
|
||||
int serial = pEdict->m_NetworkSerialNumber;
|
||||
cell_t ref = gamehelpers->EntityToReference(pCaller);
|
||||
|
||||
if (serial != hook->entity_filter && hook->entity_index == IndexOfEdict(pEdict))
|
||||
if (hook->entity_ref != -1
|
||||
&& gamehelpers->ReferenceToIndex(hook->entity_ref) == gamehelpers->ReferenceToIndex(ref)
|
||||
&& ref != hook->entity_ref)
|
||||
{
|
||||
// same entity index but different serial number. Entity has changed, kill the hook.
|
||||
// same entity index but different reference. Entity has changed, kill the hook.
|
||||
_iter = pOutputName->hooks.erase(_iter);
|
||||
CleanUpHook(hook);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hook->entity_filter == -1 || hook->entity_filter == serial) // Global classname hook
|
||||
if (hook->entity_ref == -1 || hook->entity_ref == ref) // Global classname hook
|
||||
{
|
||||
//fire the forward to hook->pf
|
||||
hook->pf->PushString(pOutputName->Name);
|
||||
hook->pf->PushCell(IndexOfEdict(pEdict));
|
||||
|
||||
edict_t *pEdictActivator = gameents->BaseEntityToEdict(pActivator);
|
||||
if (!pEdictActivator)
|
||||
{
|
||||
hook->pf->PushCell(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
hook->pf->PushCell(IndexOfEdict(pEdictActivator));
|
||||
}
|
||||
hook->pf->PushCell(gamehelpers->ReferenceToBCompatRef(ref));
|
||||
hook->pf->PushCell(gamehelpers->EntityToBCompatRef(pActivator));
|
||||
|
||||
//hook->pf->PushCell(handle);
|
||||
hook->pf->PushFloat(fDelay);
|
||||
hook->pf->Execute(NULL);
|
||||
|
||||
if ((hook->entity_filter != -1) && hook->only_once)
|
||||
if ((hook->entity_ref != -1) && hook->only_once)
|
||||
{
|
||||
_iter = pOutputName->hooks.erase(_iter);
|
||||
CleanUpHook(hook);
|
||||
@ -454,36 +440,15 @@ const char *EntityOutputManager::FindOutputName(void *pOutput, CBaseEntity *pCal
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Thanks SM core
|
||||
edict_t *EntityOutputManager::BaseHandleToEdict(CBaseHandle &hndl)
|
||||
const char *EntityOutputManager::GetEntityClassname(CBaseEntity *pEntity)
|
||||
{
|
||||
if (!hndl.IsValid())
|
||||
static int offset = -1;
|
||||
if (offset == -1)
|
||||
{
|
||||
return NULL;
|
||||
datamap_t *pMap = gamehelpers->GetDataMap(pEntity);
|
||||
typedescription_t *pDesc = gamehelpers->FindInDataMap(pMap, "m_iClassname");
|
||||
offset = pDesc->fieldOffset[TD_OFFSET_NORMAL];
|
||||
}
|
||||
|
||||
int index = hndl.GetEntryIndex();
|
||||
|
||||
edict_t *pStoredEdict;
|
||||
|
||||
pStoredEdict = PEntityOfEntIndex(index);
|
||||
|
||||
if (pStoredEdict == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IServerEntity *pSE = pStoredEdict->GetIServerEntity();
|
||||
|
||||
if (pSE == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pSE->GetRefEHandle() != hndl)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pStoredEdict;
|
||||
}
|
||||
return (const char *)(((unsigned char *)pEntity) + offset);
|
||||
}
|
@ -49,8 +49,7 @@ struct OutputNameStruct;
|
||||
*/
|
||||
struct omg_hooks
|
||||
{
|
||||
int entity_filter; // if not -1 is an entity signature
|
||||
int entity_index;
|
||||
cell_t entity_ref;
|
||||
bool only_once;
|
||||
IPluginFunction *pf;
|
||||
OutputNameStruct *m_parent;
|
||||
@ -110,6 +109,8 @@ public:
|
||||
void OnHookAdded();
|
||||
void OnHookRemoved();
|
||||
|
||||
const char *GetEntityClassname(CBaseEntity *pEntity);
|
||||
|
||||
private:
|
||||
bool enabled;
|
||||
|
||||
@ -123,7 +124,6 @@ private:
|
||||
void DeleteFireEventDetour();
|
||||
|
||||
const char *FindOutputName(void *pOutput, CBaseEntity *pCaller);
|
||||
edict_t *BaseHandleToEdict(CBaseHandle &hndl);
|
||||
|
||||
//Maps CEntityOutput * to a OutputNameStruct
|
||||
IBasicTrie *EntityOutputs;
|
||||
|
@ -40,12 +40,13 @@ cell_t HookSingleEntityOutput(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeError("Entity Outputs are disabled - See error logs for details");
|
||||
}
|
||||
|
||||
edict_t *pEdict = PEntityOfEntIndex(params[1]);
|
||||
if (!pEdict)
|
||||
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(params[1]);
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid Entity index %i", params[1]);
|
||||
return pContext->ThrowNativeError("Invalid Entity index %i (%i)", gamehelpers->ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
const char *classname = pEdict->GetClassName();
|
||||
|
||||
const char *classname = g_OutputManager.GetEntityClassname(pEntity);
|
||||
|
||||
char *outputname;
|
||||
pContext->LocalToString(params[2], &outputname);
|
||||
@ -63,7 +64,7 @@ cell_t HookSingleEntityOutput(IPluginContext *pContext, const cell_t *params)
|
||||
for (_iter=pOutputName->hooks.begin(); _iter!=pOutputName->hooks.end(); _iter++)
|
||||
{
|
||||
hook = (omg_hooks *)*_iter;
|
||||
if (hook->pf == pFunction && hook->entity_filter == pEdict->m_NetworkSerialNumber)
|
||||
if (hook->pf == pFunction && hook->entity_ref == gamehelpers->EntityToReference(pEntity))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -71,8 +72,7 @@ cell_t HookSingleEntityOutput(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
hook = g_OutputManager.NewHook();
|
||||
|
||||
hook->entity_filter = pEdict->m_NetworkSerialNumber;
|
||||
hook->entity_index = IndexOfEdict(pEdict);
|
||||
hook->entity_ref = gamehelpers->EntityToReference(pEntity);
|
||||
hook->only_once= !!params[4];
|
||||
hook->pf = pFunction;
|
||||
hook->m_parent = pOutputName;
|
||||
@ -125,7 +125,7 @@ cell_t HookEntityOutput(IPluginContext *pContext, const cell_t *params)
|
||||
for (_iter=pOutputName->hooks.begin(); _iter!=pOutputName->hooks.end(); _iter++)
|
||||
{
|
||||
hook = (omg_hooks *)*_iter;
|
||||
if (hook->pf == pFunction && hook->entity_filter == -1)
|
||||
if (hook->pf == pFunction && hook->entity_ref == -1)
|
||||
{
|
||||
//already hooked to this function...
|
||||
//throw an error or just let them get away with stupidity?
|
||||
@ -136,7 +136,7 @@ cell_t HookEntityOutput(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
hook = g_OutputManager.NewHook();
|
||||
|
||||
hook->entity_filter = -1;
|
||||
hook->entity_ref = -1;
|
||||
hook->pf = pFunction;
|
||||
hook->m_parent = pOutputName;
|
||||
hook->in_use = false;
|
||||
@ -192,7 +192,7 @@ cell_t UnHookEntityOutput(IPluginContext *pContext, const cell_t *params)
|
||||
for (_iter=pOutputName->hooks.begin(); _iter!=pOutputName->hooks.end(); _iter++)
|
||||
{
|
||||
hook = (omg_hooks *)*_iter;
|
||||
if (hook->pf == pFunction && hook->entity_filter == -1)
|
||||
if (hook->pf == pFunction && hook->entity_ref == -1)
|
||||
{
|
||||
// remove this hook.
|
||||
if (hook->in_use)
|
||||
@ -220,13 +220,13 @@ cell_t UnHookSingleEntityOutput(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
|
||||
// Find the classname of the entity and lookup the classname and output structures
|
||||
edict_t *pEdict = PEntityOfEntIndex(params[1]);
|
||||
if (!pEdict)
|
||||
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(params[1]);
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid Entity index %i", params[1]);
|
||||
return pContext->ThrowNativeError("Invalid Entity index %i (%i)", gamehelpers->ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
const char *classname = pEdict->GetClassName();
|
||||
const char *classname = g_OutputManager.GetEntityClassname(pEntity);
|
||||
|
||||
char *outputname;
|
||||
pContext->LocalToString(params[2], &outputname);
|
||||
@ -249,7 +249,8 @@ cell_t UnHookSingleEntityOutput(IPluginContext *pContext, const cell_t *params)
|
||||
for (_iter=pOutputName->hooks.begin(); _iter!=pOutputName->hooks.end(); _iter++)
|
||||
{
|
||||
hook = (omg_hooks *)*_iter;
|
||||
if (hook->pf == pFunction && hook->entity_index == IndexOfEdict(pEdict))
|
||||
/* We're not serial checking and just removing by index here - This was always allowed so is left for bcompat */
|
||||
if (hook->pf == pFunction && gamehelpers->ReferenceToIndex(hook->entity_ref) == gamehelpers->ReferenceToIndex(params[1]))
|
||||
{
|
||||
// remove this hook.
|
||||
if (hook->in_use)
|
||||
|
@ -38,8 +38,7 @@ public:
|
||||
bool ShouldHitEntity(IHandleEntity *pEntity, int contentsMask)
|
||||
{
|
||||
cell_t res = 1;
|
||||
edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(pEntity));
|
||||
m_pFunc->PushCell(IndexOfEdict(pEdict));
|
||||
m_pFunc->PushCell(gamehelpers->EntityToBCompatRef(reinterpret_cast<CBaseEntity *>(pEntity)));
|
||||
m_pFunc->PushCell(contentsMask);
|
||||
m_pFunc->PushCell(m_Data);
|
||||
m_pFunc->Execute(&res);
|
||||
@ -505,8 +504,7 @@ static cell_t smn_TRGetEntityIndex(IPluginContext *pContext, const cell_t *param
|
||||
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
|
||||
}
|
||||
|
||||
edict_t *pEdict = gameents->BaseEntityToEdict(tr->m_pEnt);
|
||||
return IndexOfEdict(pEdict);
|
||||
return gamehelpers->EntityToBCompatRef(tr->m_pEnt);
|
||||
}
|
||||
|
||||
static cell_t smn_TRGetPointContents(IPluginContext *pContext, const cell_t *params)
|
||||
@ -532,8 +530,7 @@ static cell_t smn_TRGetPointContents(IPluginContext *pContext, const cell_t *par
|
||||
#else
|
||||
mask = enginetrace->GetPointContents(pos, &hentity);
|
||||
#endif
|
||||
edict_t *pEdict = gameents->BaseEntityToEdict(reinterpret_cast<CBaseEntity *>(hentity));
|
||||
*ent = IndexOfEdict(pEdict);
|
||||
*ent = gamehelpers->EntityToBCompatRef(reinterpret_cast<CBaseEntity *>(hentity));
|
||||
}
|
||||
|
||||
return mask;
|
||||
@ -541,7 +538,8 @@ static cell_t smn_TRGetPointContents(IPluginContext *pContext, const cell_t *par
|
||||
|
||||
static cell_t smn_TRGetPointContentsEnt(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
edict_t *pEdict = PEntityOfEntIndex(params[1]);
|
||||
/* TODO: See if we can get the collidable with a prop and remove the reliance on edicts */
|
||||
edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[1]));
|
||||
if (!pEdict || pEdict->IsFree())
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is invalid", params[1]);
|
||||
|
@ -222,8 +222,7 @@ DataStatus EncodeValveParam(IPluginContext *pContext,
|
||||
CBaseEntity *pEntity = *(CBaseEntity **)buffer;
|
||||
if (pEntity)
|
||||
{
|
||||
edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
|
||||
*addr = IndexOfEdict(pEdict);
|
||||
*addr = gamehelpers->EntityToBCompatRef(pEntity);
|
||||
} else {
|
||||
*addr = -1;
|
||||
}
|
||||
@ -384,16 +383,21 @@ DataStatus DecodeValveParam(IPluginContext *pContext,
|
||||
}
|
||||
case Valve_CBasePlayer:
|
||||
{
|
||||
edict_t *pEdict;
|
||||
CBaseEntity *pEntity = NULL;
|
||||
if (data->decflags & VDECODE_FLAG_BYREF)
|
||||
{
|
||||
cell_t *addr;
|
||||
pContext->LocalToPhysAddr(param, &addr);
|
||||
param = *addr;
|
||||
}
|
||||
if (param >= 1 && param <= playerhelpers->GetMaxClients())
|
||||
int index = gamehelpers->ReferenceToIndex(param);
|
||||
if (index == INVALID_EHANDLE_INDEX && param != -1)
|
||||
{
|
||||
IGamePlayer *player = playerhelpers->GetGamePlayer(param);
|
||||
return Data_Fail;
|
||||
}
|
||||
if (index >= 1 && index <= playerhelpers->GetMaxClients())
|
||||
{
|
||||
IGamePlayer *player = playerhelpers->GetGamePlayer(index);
|
||||
if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME)
|
||||
&& !player->IsConnected())
|
||||
{
|
||||
@ -403,44 +407,20 @@ DataStatus DecodeValveParam(IPluginContext *pContext,
|
||||
pContext->ThrowNativeError("Client %d is not in game", param);
|
||||
return Data_Fail;
|
||||
}
|
||||
pEdict = player->GetEdict();
|
||||
pEntity = gamehelpers->ReferenceToEntity(param);
|
||||
} else if (param == -1) {
|
||||
if (data->decflags & VDECODE_FLAG_ALLOWNULL)
|
||||
{
|
||||
pEdict = NULL;
|
||||
pEntity = NULL;
|
||||
} else {
|
||||
pContext->ThrowNativeError("NULL not allowed");
|
||||
return Data_Fail;
|
||||
}
|
||||
} else if (param == 0) {
|
||||
if (data->decflags & VDECODE_FLAG_ALLOWWORLD)
|
||||
{
|
||||
pEdict = PEntityOfEntIndex(0);
|
||||
} else {
|
||||
pContext->ThrowNativeError("World not allowed");
|
||||
return Data_Fail;
|
||||
}
|
||||
} else {
|
||||
pContext->ThrowNativeError("Entity index %d is not a valid client", param);
|
||||
return Data_Fail;
|
||||
}
|
||||
CBaseEntity *pEntity = NULL;
|
||||
if (pEdict)
|
||||
{
|
||||
IServerUnknown *pUnknown = pEdict->GetUnknown();
|
||||
if (!pUnknown)
|
||||
{
|
||||
pContext->ThrowNativeError("Entity %d is a not an IServerUnknown", param);
|
||||
return Data_Fail;
|
||||
}
|
||||
pEntity = pUnknown->GetBaseEntity();
|
||||
if (!pEntity)
|
||||
{
|
||||
pContext->ThrowNativeError("Entity %d is not a CBaseEntity", param);
|
||||
return Data_Fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CBaseEntity **ebuf = (CBaseEntity **)buffer;
|
||||
*ebuf = pEntity;
|
||||
|
||||
@ -448,16 +428,21 @@ DataStatus DecodeValveParam(IPluginContext *pContext,
|
||||
}
|
||||
case Valve_CBaseEntity:
|
||||
{
|
||||
edict_t *pEdict;
|
||||
CBaseEntity *pEntity = NULL;
|
||||
if (data->decflags & VDECODE_FLAG_BYREF)
|
||||
{
|
||||
cell_t *addr;
|
||||
pContext->LocalToPhysAddr(param, &addr);
|
||||
param = *addr;
|
||||
}
|
||||
if (param >= 1 && param <= playerhelpers->GetMaxClients())
|
||||
int index = gamehelpers->ReferenceToIndex(param);
|
||||
if (index == INVALID_EHANDLE_INDEX && param != -1)
|
||||
{
|
||||
IGamePlayer *player = playerhelpers->GetGamePlayer(param);
|
||||
return Data_Fail;
|
||||
}
|
||||
if (index >= 1 && index <= playerhelpers->GetMaxClients())
|
||||
{
|
||||
IGamePlayer *player = playerhelpers->GetGamePlayer(index);
|
||||
if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME)
|
||||
&& !player->IsConnected())
|
||||
{
|
||||
@ -467,44 +452,28 @@ DataStatus DecodeValveParam(IPluginContext *pContext,
|
||||
pContext->ThrowNativeError("Client %d is not in game", param);
|
||||
return Data_Fail;
|
||||
}
|
||||
pEdict = player->GetEdict();
|
||||
pEntity = gamehelpers->ReferenceToEntity(param);
|
||||
} else if (param == -1) {
|
||||
if (data->decflags & VDECODE_FLAG_ALLOWNULL)
|
||||
{
|
||||
pEdict = NULL;
|
||||
pEntity = NULL;
|
||||
} else {
|
||||
pContext->ThrowNativeError("NULL not allowed");
|
||||
return Data_Fail;
|
||||
}
|
||||
} else if (param == 0) {
|
||||
} else if (index == 0) {
|
||||
if (data->decflags & VDECODE_FLAG_ALLOWWORLD)
|
||||
{
|
||||
pEdict = PEntityOfEntIndex(0);
|
||||
pEntity = gamehelpers->ReferenceToEntity(0);
|
||||
} else {
|
||||
pContext->ThrowNativeError("World not allowed");
|
||||
return Data_Fail;
|
||||
}
|
||||
} else {
|
||||
pEdict = PEntityOfEntIndex(param);
|
||||
if (!pEdict || pEdict->IsFree())
|
||||
{
|
||||
pContext->ThrowNativeError("Entity %d is not valid or is freed", param);
|
||||
return Data_Fail;
|
||||
}
|
||||
}
|
||||
CBaseEntity *pEntity = NULL;
|
||||
if (pEdict)
|
||||
{
|
||||
IServerUnknown *pUnknown = pEdict->GetUnknown();
|
||||
if (!pUnknown)
|
||||
{
|
||||
pContext->ThrowNativeError("Entity %d is a not an IServerUnknown", param);
|
||||
return Data_Fail;
|
||||
}
|
||||
pEntity = pUnknown->GetBaseEntity();
|
||||
pEntity = gamehelpers->ReferenceToEntity(param);
|
||||
if (!pEntity)
|
||||
{
|
||||
pContext->ThrowNativeError("Entity %d is not a CBaseEntity", param);
|
||||
pContext->ThrowNativeError("Entity %d is not valid", param);
|
||||
return Data_Fail;
|
||||
}
|
||||
}
|
||||
|
@ -34,54 +34,35 @@
|
||||
void **g_pGameRules = NULL;
|
||||
void *g_EntList = NULL;
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
|
||||
void InitializeValveGlobals()
|
||||
{
|
||||
char *addr = NULL;
|
||||
int offset;
|
||||
g_EntList = gamehelpers->GetGlobalEntityList();
|
||||
|
||||
/* gEntList and/or g_pEntityList */
|
||||
if (!g_pGameConf->GetMemSig("LevelShutdown", (void **)&addr) || !addr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!g_pGameConf->GetOffset("gEntList", &offset) || !offset)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_EntList = *reinterpret_cast<void **>(addr + offset);
|
||||
char *addr;
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
/* g_pGameRules */
|
||||
if (!g_pGameConf->GetMemSig("CreateGameRulesObject", (void **)&addr) || !addr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int offset;
|
||||
if (!g_pGameConf->GetOffset("g_pGameRules", &offset) || !offset)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_pGameRules = *reinterpret_cast<void ***>(addr + offset);
|
||||
}
|
||||
#elif defined PLATFORM_LINUX
|
||||
void InitializeValveGlobals()
|
||||
{
|
||||
char *addr = NULL;
|
||||
|
||||
/* gEntList and/or g_pEntityList */
|
||||
if (!g_pGameConf->GetMemSig("gEntList", (void **)&addr) || !addr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_EntList = reinterpret_cast<void *>(addr);
|
||||
|
||||
/* g_pGameRules */
|
||||
if (!g_pGameConf->GetMemSig("g_pGameRules", (void **)&addr) || !addr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_pGameRules = reinterpret_cast<void **>(addr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t UTIL_StringToSignature(const char *str, char buffer[], size_t maxlength)
|
||||
{
|
||||
|
@ -241,13 +241,8 @@ int GetClientAimTarget(edict_t *pEdict, bool only_players)
|
||||
return -1;
|
||||
}
|
||||
|
||||
edict_t *pTarget = gameents->BaseEntityToEdict(tr.m_pEnt);
|
||||
if (pTarget == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ent_index = IndexOfEdict(pTarget);
|
||||
int ent_ref = gamehelpers->EntityToBCompatRef(tr.m_pEnt);
|
||||
int ent_index = gamehelpers->ReferenceToIndex(ent_ref);
|
||||
|
||||
IGamePlayer *pTargetPlayer = playerhelpers->GetGamePlayer(ent_index);
|
||||
if (pTargetPlayer != NULL && !pTargetPlayer->IsInGame())
|
||||
@ -259,7 +254,7 @@ int GetClientAimTarget(edict_t *pEdict, bool only_players)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ent_index;
|
||||
return ent_ref;
|
||||
}
|
||||
|
||||
bool IsEyeAnglesSupported()
|
||||
|
@ -164,18 +164,7 @@ static cell_t GiveNamedItem(IPluginContext *pContext, const cell_t *params)
|
||||
DECODE_VALVE_PARAM(3, vparams, 1);
|
||||
FINISH_CALL_SIMPLE(&pEntity);
|
||||
|
||||
if (pEntity == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
|
||||
if (!pEdict)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return IndexOfEdict(pEdict);
|
||||
return gamehelpers->EntityToBCompatRef(pEntity);
|
||||
}
|
||||
|
||||
static cell_t GetPlayerWeaponSlot(IPluginContext *pContext, const cell_t *params)
|
||||
@ -200,18 +189,7 @@ static cell_t GetPlayerWeaponSlot(IPluginContext *pContext, const cell_t *params
|
||||
DECODE_VALVE_PARAM(2, vparams, 0);
|
||||
FINISH_CALL_SIMPLE(&pEntity);
|
||||
|
||||
if (pEntity == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
|
||||
if (!pEdict)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return IndexOfEdict(pEdict);
|
||||
return gamehelpers->EntityToBCompatRef(pEntity);
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||
@ -389,7 +367,7 @@ static cell_t SetClientViewEntity(IPluginContext *pContext, const cell_t *params
|
||||
return pContext->ThrowNativeError("Client %d is not in game", params[1]);
|
||||
}
|
||||
|
||||
edict_t *pEdict = PEntityOfEntIndex(params[2]);
|
||||
edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[1]));
|
||||
if (!pEdict || pEdict->IsFree())
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d is not valid", params[2]);
|
||||
@ -477,13 +455,12 @@ static cell_t SlapPlayer(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
|
||||
/* First check if the client is valid */
|
||||
int client = params[1];
|
||||
IGamePlayer *player = playerhelpers->GetGamePlayer(client);
|
||||
IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
|
||||
if (!player)
|
||||
{
|
||||
return pContext->ThrowNativeError("Client %d is not valid", client);
|
||||
return pContext->ThrowNativeError("Client %d is not valid", params[1]);
|
||||
} else if (!player->IsInGame()) {
|
||||
return pContext->ThrowNativeError("Client %d is not in game", client);
|
||||
return pContext->ThrowNativeError("Client %d is not in game", params[1]);
|
||||
}
|
||||
|
||||
edict_t *pEdict = player->GetEdict();
|
||||
@ -551,7 +528,7 @@ static cell_t SlapPlayer(IPluginContext *pContext, const cell_t *params)
|
||||
CellRecipientFilter rf;
|
||||
rf.SetToReliable(true);
|
||||
rf.Initialize(player_list, total_players);
|
||||
engsound->EmitSound(rf, client, CHAN_AUTO, sound_name, VOL_NORM, ATTN_NORM, 0, PITCH_NORM, &pos);
|
||||
engsound->EmitSound(rf, params[1], CHAN_AUTO, sound_name, VOL_NORM, ATTN_NORM, 0, PITCH_NORM, &pos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -619,16 +596,15 @@ static cell_t GetClientEyePosition(IPluginContext *pContext, const cell_t *param
|
||||
|
||||
static cell_t GetClientEyeAngles(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
int client = params[1];
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]);
|
||||
|
||||
if (!pPlayer)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid client index %d", client);
|
||||
return pContext->ThrowNativeError("Invalid client index %d", params[1]);
|
||||
}
|
||||
else if (!pPlayer->IsInGame())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client %d is not in game", client);
|
||||
return pContext->ThrowNativeError("Client %d is not in game", params[1]);
|
||||
}
|
||||
|
||||
edict_t *pEdict = pPlayer->GetEdict();
|
||||
@ -678,18 +654,7 @@ static cell_t FindEntityByClassname(IPluginContext *pContext, const cell_t *para
|
||||
DECODE_VALVE_PARAM(2, vparams, 1);
|
||||
FINISH_CALL_SIMPLE(&pEntity);
|
||||
|
||||
if (pEntity == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
|
||||
if (!pEdict)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return IndexOfEdict(pEdict);
|
||||
return gamehelpers->EntityToBCompatRef(pEntity);
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE == SE_LEFT4DEAD
|
||||
@ -718,18 +683,7 @@ static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
|
||||
*(bool *)(vptr + 8) = true;
|
||||
FINISH_CALL_SIMPLE(&pEntity);
|
||||
|
||||
if (pEntity == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
|
||||
if (!pEdict)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return IndexOfEdict(pEdict);
|
||||
return gamehelpers->EntityToBCompatRef(pEntity);
|
||||
}
|
||||
#else
|
||||
static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
|
||||
@ -755,18 +709,7 @@ static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
|
||||
DECODE_VALVE_PARAM(2, vparams, 1);
|
||||
FINISH_CALL_SIMPLE(&pEntity);
|
||||
|
||||
if (pEntity == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
|
||||
if (!pEdict)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return IndexOfEdict(pEdict);
|
||||
return gamehelpers->EntityToBCompatRef(pEntity);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -881,16 +824,15 @@ static cell_t DispatchKeyValueVector(IPluginContext *pContext, const cell_t *par
|
||||
|
||||
static cell_t sm_GetClientAimTarget(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
int client = params[1];
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
|
||||
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]);
|
||||
|
||||
if (!pPlayer)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid client index %d", client);
|
||||
return pContext->ThrowNativeError("Invalid client index %d", params[1]);
|
||||
}
|
||||
else if (!pPlayer->IsInGame())
|
||||
{
|
||||
return pContext->ThrowNativeError("Client %d is not in game", client);
|
||||
return pContext->ThrowNativeError("Client %d is not in game", params[1]);
|
||||
}
|
||||
|
||||
return GetClientAimTarget(pPlayer->GetEdict(), params[2] ? true : false);
|
||||
|
@ -383,7 +383,7 @@ static cell_t EmitAmbientSound(IPluginContext *pContext, const cell_t *params)
|
||||
float vol, delay;
|
||||
int pitch, flags, level;
|
||||
|
||||
entity = params[3];
|
||||
entity = gamehelpers->ReferenceToIndex(params[3]);
|
||||
|
||||
cell_t *addr;
|
||||
pContext->LocalToPhysAddr(params[2], &addr);
|
||||
@ -436,7 +436,7 @@ static cell_t FadeClientVolume(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
static cell_t StopSound(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
int entity = params[1];
|
||||
int entity = gamehelpers->ReferenceToIndex(params[1]);
|
||||
int channel = params[2];
|
||||
|
||||
char *name;
|
||||
@ -477,7 +477,7 @@ static cell_t EmitSound(IPluginContext *pContext, const cell_t *params)
|
||||
char *sample;
|
||||
pContext->LocalToString(params[3], &sample);
|
||||
|
||||
int entity = params[4];
|
||||
int entity = gamehelpers->ReferenceToIndex(params[4]);
|
||||
int channel = params[5];
|
||||
int level = params[6];
|
||||
int flags = params[7];
|
||||
@ -648,7 +648,7 @@ static cell_t EmitSentence(IPluginContext *pContext, const cell_t *params)
|
||||
crf.Initialize(addr, numClients);
|
||||
|
||||
int sentence = params[3];
|
||||
int entity = params[4];
|
||||
int entity = gamehelpers->ReferenceToIndex(params[4]);
|
||||
int channel = params[5];
|
||||
int level = params[6];
|
||||
int flags = params[7];
|
||||
|
46
gamedata/core.games/engine.darkm.txt
Normal file
46
gamedata/core.games/engine.darkm.txt
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Do not edit this file. Any changes will be overwritten by the gamedata
|
||||
* updater or by upgrading your SourceMod install.
|
||||
*
|
||||
* To override data in this file, create a subdirectory named "custom" and
|
||||
* place your own gamedata file(s) inside of it. Such files will be parsed
|
||||
* after SM's own.
|
||||
*
|
||||
* For more information, see http://wiki.alliedmods.net/Gamedata_Updating_(SourceMod)
|
||||
*/
|
||||
|
||||
"Games"
|
||||
{
|
||||
/* CGlobalEntityList */
|
||||
"#default"
|
||||
{
|
||||
"#supported"
|
||||
{
|
||||
"game" "!Might and Magic Multiplayer"
|
||||
}
|
||||
|
||||
"Offsets"
|
||||
{
|
||||
/* Offset into LevelShutdown */
|
||||
"gEntList"
|
||||
{
|
||||
"windows" "11"
|
||||
}
|
||||
|
||||
"EntInfo"
|
||||
{
|
||||
"windows" "4"
|
||||
"linux" "4"
|
||||
}
|
||||
}
|
||||
|
||||
"Signatures"
|
||||
{
|
||||
"LevelShutdown"
|
||||
{
|
||||
"library" "server"
|
||||
"windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
62
gamedata/core.games/engine.ep1.txt
Normal file
62
gamedata/core.games/engine.ep1.txt
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Do not edit this file. Any changes will be overwritten by the gamedata
|
||||
* updater or by upgrading your SourceMod install.
|
||||
*
|
||||
* To override data in this file, create a subdirectory named "custom" and
|
||||
* place your own gamedata file(s) inside of it. Such files will be parsed
|
||||
* after SM's own.
|
||||
*
|
||||
* For more information, see http://wiki.alliedmods.net/Gamedata_Updating_(SourceMod)
|
||||
*/
|
||||
|
||||
"Games"
|
||||
{
|
||||
/* CGlobalEntityList */
|
||||
"#default"
|
||||
{
|
||||
"#supported"
|
||||
{
|
||||
"game" "cstrike"
|
||||
"game" "garrysmod"
|
||||
"game" "hl2mp"
|
||||
"game" "ship"
|
||||
"game" "insurgency"
|
||||
"game" "pvkii"
|
||||
"game" "sourceforts"
|
||||
"game" "FortressForever"
|
||||
"game" "empires"
|
||||
"game" "synergy"
|
||||
"game" "hidden"
|
||||
"game" "zombie_master"
|
||||
}
|
||||
|
||||
"Offsets"
|
||||
{
|
||||
/* Offset into LevelShutdown */
|
||||
"gEntList"
|
||||
{
|
||||
"windows" "11"
|
||||
}
|
||||
|
||||
"EntInfo"
|
||||
{
|
||||
"windows" "4"
|
||||
"linux" "4"
|
||||
}
|
||||
}
|
||||
|
||||
"Signatures"
|
||||
{
|
||||
"LevelShutdown"
|
||||
{
|
||||
"library" "server"
|
||||
"windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8"
|
||||
}
|
||||
"gEntList"
|
||||
{
|
||||
"library" "server"
|
||||
"linux" "@gEntList"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
54
gamedata/core.games/engine.ep2.txt
Normal file
54
gamedata/core.games/engine.ep2.txt
Normal file
@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Do not edit this file. Any changes will be overwritten by the gamedata
|
||||
* updater or by upgrading your SourceMod install.
|
||||
*
|
||||
* To override data in this file, create a subdirectory named "custom" and
|
||||
* place your own gamedata file(s) inside of it. Such files will be parsed
|
||||
* after SM's own.
|
||||
*
|
||||
* For more information, see http://wiki.alliedmods.net/Gamedata_Updating_(SourceMod)
|
||||
*/
|
||||
|
||||
"Games"
|
||||
{
|
||||
/* CGlobalEntityList */
|
||||
"#default"
|
||||
{
|
||||
"#supported"
|
||||
{
|
||||
"game" "dod"
|
||||
"game" "tf"
|
||||
"game" "ageofchivalry"
|
||||
"game" "ZPS"
|
||||
}
|
||||
|
||||
"Offsets"
|
||||
{
|
||||
/* Offset into LevelShutdown */
|
||||
"gEntList"
|
||||
{
|
||||
"windows" "11"
|
||||
}
|
||||
|
||||
"EntInfo"
|
||||
{
|
||||
"windows" "4"
|
||||
"linux" "4"
|
||||
}
|
||||
}
|
||||
|
||||
"Signatures"
|
||||
{
|
||||
"LevelShutdown"
|
||||
{
|
||||
"library" "server"
|
||||
"windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8"
|
||||
}
|
||||
"gEntList"
|
||||
{
|
||||
"library" "server"
|
||||
"linux" "@gEntList"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
gamedata/core.games/engine.l4d.txt
Normal file
51
gamedata/core.games/engine.l4d.txt
Normal file
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Do not edit this file. Any changes will be overwritten by the gamedata
|
||||
* updater or by upgrading your SourceMod install.
|
||||
*
|
||||
* To override data in this file, create a subdirectory named "custom" and
|
||||
* place your own gamedata file(s) inside of it. Such files will be parsed
|
||||
* after SM's own.
|
||||
*
|
||||
* For more information, see http://wiki.alliedmods.net/Gamedata_Updating_(SourceMod)
|
||||
*/
|
||||
|
||||
"Games"
|
||||
{
|
||||
/* CGlobalEntityList */
|
||||
"#default"
|
||||
{
|
||||
"#supported"
|
||||
{
|
||||
"game" "left4dead"
|
||||
}
|
||||
|
||||
"Offsets"
|
||||
{
|
||||
/* Offset into LevelShutdown */
|
||||
"gEntList"
|
||||
{
|
||||
"windows" "11"
|
||||
}
|
||||
|
||||
"EntInfo"
|
||||
{
|
||||
"windows" "4"
|
||||
"linux" "4"
|
||||
}
|
||||
}
|
||||
|
||||
"Signatures"
|
||||
{
|
||||
"LevelShutdown"
|
||||
{
|
||||
"library" "server"
|
||||
"windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8"
|
||||
}
|
||||
"gEntList"
|
||||
{
|
||||
"library" "server"
|
||||
"linux" "@gEntList"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,4 +14,25 @@
|
||||
"common.games.txt"
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
"engine.l4d.txt"
|
||||
{
|
||||
"engine" "left4dead"
|
||||
}
|
||||
|
||||
"engine.ep2.txt"
|
||||
{
|
||||
"engine" "orangebox"
|
||||
}
|
||||
|
||||
"engine.ep1.txt"
|
||||
{
|
||||
"engine" "original"
|
||||
}
|
||||
|
||||
"engine.darkm.txt"
|
||||
{
|
||||
"engine" "darkmessiah"
|
||||
}
|
||||
|
||||
}
|
@ -105,24 +105,9 @@
|
||||
{
|
||||
"game" "!Might and Magic Multiplayer"
|
||||
}
|
||||
|
||||
"Offsets"
|
||||
{
|
||||
/* Offset into LevelShutdown */
|
||||
"gEntList"
|
||||
{
|
||||
"windows" "11"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
"Signatures"
|
||||
{
|
||||
"LevelShutdown"
|
||||
{
|
||||
"library" "server"
|
||||
"windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8"
|
||||
}
|
||||
|
||||
/* Functions in CGlobalEntityList */
|
||||
"FindEntityByClassname"
|
||||
{
|
||||
@ -239,7 +224,7 @@
|
||||
/**
|
||||
* CBaseClient::SetUserCVar(char const*,char const*);
|
||||
* Linux offset straight from VTable dump.
|
||||
* Windows offset is crazy. Found the windows 'SetName' function using string "(%d)%-0.*s"
|
||||
* Windows offset is crazy. Found the windows SetName function using string "(%d)%-0.*s"
|
||||
* Cross referenced back to the vtable and counted manually (SetUserCvar is 1 higher, offsets start from 1)
|
||||
*/
|
||||
"SetUserCvar"
|
||||
|
@ -139,28 +139,8 @@
|
||||
"game" "zombie_master"
|
||||
}
|
||||
|
||||
"Offsets"
|
||||
{
|
||||
/* Offset into LevelShutdown */
|
||||
"gEntList"
|
||||
{
|
||||
"windows" "11"
|
||||
}
|
||||
}
|
||||
|
||||
"Signatures"
|
||||
{
|
||||
"LevelShutdown"
|
||||
{
|
||||
"library" "server"
|
||||
"windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8"
|
||||
}
|
||||
"gEntList"
|
||||
{
|
||||
"library" "server"
|
||||
"linux" "@gEntList"
|
||||
}
|
||||
|
||||
{
|
||||
/* Functions in CGlobalEntityList */
|
||||
"FindEntityByClassname"
|
||||
{
|
||||
@ -288,7 +268,7 @@
|
||||
/**
|
||||
* CBaseClient::SetUserCVar(char const*,char const*);
|
||||
* Linux offset straight from VTable dump.
|
||||
* Windows offset is crazy. Found the windows 'SetName' function using string "(%d)%-0.*s"
|
||||
* Windows offset is crazy. Found the windows SetName function using string "(%d)%-0.*s"
|
||||
* Cross referenced back to the vtable and counted manually (SetUserCvar is 1 higher, offsets start from 1)
|
||||
*/
|
||||
"SetUserCvar"
|
||||
|
@ -100,28 +100,8 @@
|
||||
"game" "ZPS"
|
||||
}
|
||||
|
||||
"Offsets"
|
||||
{
|
||||
/* Offset into LevelShutdown */
|
||||
"gEntList"
|
||||
{
|
||||
"windows" "11"
|
||||
}
|
||||
}
|
||||
|
||||
"Signatures"
|
||||
{
|
||||
"LevelShutdown"
|
||||
{
|
||||
"library" "server"
|
||||
"windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8"
|
||||
}
|
||||
"gEntList"
|
||||
{
|
||||
"library" "server"
|
||||
"linux" "@gEntList"
|
||||
}
|
||||
|
||||
/* Functions in CGlobalEntityList */
|
||||
"FindEntityByClassname"
|
||||
{
|
||||
@ -261,7 +241,7 @@
|
||||
/**
|
||||
* CBaseClient::SetUserCVar(char const*,char const*);
|
||||
* Linux offset straight from VTable dump.
|
||||
* Windows offset is crazy. Found the windows 'SetName' function using string "(%d)%-0.*s"
|
||||
* Windows offset is crazy. Found the windows SetName function using string "(%d)%-0.*s"
|
||||
* Cross referenced back to the vtable and counted manually (SetUserCvar is 1 higher, offsets start from 1)
|
||||
*/
|
||||
"SetUserCvar"
|
||||
|
@ -101,29 +101,9 @@
|
||||
{
|
||||
"game" "left4dead"
|
||||
}
|
||||
|
||||
"Offsets"
|
||||
{
|
||||
/* Offset into LevelShutdown */
|
||||
"gEntList"
|
||||
{
|
||||
"windows" "11"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
"Signatures"
|
||||
{
|
||||
"LevelShutdown"
|
||||
{
|
||||
"library" "server"
|
||||
"windows" "\xE8\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xE8"
|
||||
}
|
||||
"gEntList"
|
||||
{
|
||||
"library" "server"
|
||||
"linux" "@gEntList"
|
||||
}
|
||||
|
||||
/* Functions in CGlobalEntityList */
|
||||
"FindEntityByClassname"
|
||||
{
|
||||
@ -258,7 +238,7 @@
|
||||
/**
|
||||
* CBaseClient::SetUserCVar(char const*,char const*);
|
||||
* Linux offset straight from VTable dump.
|
||||
* Windows offset is crazy. Found the windows 'SetName' function using string "(%d)%-0.*s"
|
||||
* Windows offset is crazy. Found the windows SetName function using string "(%d)%-0.*s"
|
||||
* Cross referenced back to the vtable and counted manually (SetUserCvar is 1 higher, offsets start from 1)
|
||||
*/
|
||||
"SetUserCvar"
|
||||
|
@ -56,6 +56,8 @@ enum DialogType
|
||||
DialogType_AskConnect /**< ask the client to connect to a specified IP */
|
||||
};
|
||||
|
||||
#define INVALID_ENT_REFERENCE 0xFFFFFFFF
|
||||
|
||||
/**
|
||||
* Logs a generic message to the HL2 logs.
|
||||
*
|
||||
@ -544,3 +546,28 @@ stock DisplayAskConnectBox(client, Float:time, const String:ip[])
|
||||
CreateDialog(client, Kv, DialogType_AskConnect);
|
||||
CloseHandle(Kv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an entity index into a serial encoded entity reference.
|
||||
*
|
||||
* @param entity Entity index.
|
||||
* @return Entity reference.
|
||||
*/
|
||||
native EntIndexToEntRef(entity);
|
||||
|
||||
/**
|
||||
* Retrieves the entity index from a reference.
|
||||
*
|
||||
* @param ref Entity reference.
|
||||
* @return Entity index.
|
||||
*/
|
||||
native EntRefToEntIndex(ref);
|
||||
|
||||
/**
|
||||
* Converts a reference into a backwards compatible version.
|
||||
*
|
||||
* @param ref Entity reference.
|
||||
* @return Bcompat reference.
|
||||
*/
|
||||
native MakeCompatEntRef(ref);
|
||||
|
||||
|
@ -193,6 +193,63 @@ namespace SourceMod
|
||||
* @param buffer Command buffer (does not auto \n terminate).
|
||||
*/
|
||||
virtual void ServerCommand(const char *buffer) =0;
|
||||
|
||||
/**
|
||||
* @brief Looks up a reference and returns the CBasseEntity* it points to.
|
||||
*
|
||||
* @note Supports 'old style' simple indexes and does a serial confirmation check on references.
|
||||
*
|
||||
* @param entRef Entity reference.
|
||||
* @return Entity pointer.
|
||||
*/
|
||||
virtual CBaseEntity *ReferenceToEntity(cell_t entRef) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the entity reference for an entity.
|
||||
*
|
||||
* @param pEntity Entity pointer.
|
||||
* @return Entity reference.
|
||||
*/
|
||||
virtual cell_t EntityToReference(CBaseEntity *pEntity) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the entity reference for logical entities, or the index for networked entities.
|
||||
*
|
||||
* @param pEntity Entity pointer.
|
||||
* @return Entity reference/index.
|
||||
*/
|
||||
virtual cell_t EntityToBCompatRef(CBaseEntity *pEntity) =0;
|
||||
|
||||
/**
|
||||
* @brief Converts an entity index into an entity reference.
|
||||
*
|
||||
* @param entIndex Entity index.
|
||||
* @return Entity reference.
|
||||
*/
|
||||
virtual cell_t IndexToReference(int entIndex) =0;
|
||||
|
||||
/**
|
||||
* @brief Retrieves the entity index from a reference.
|
||||
*
|
||||
* @param entRef Entity reference.
|
||||
* @return Entity index.
|
||||
*/
|
||||
virtual int ReferenceToIndex(cell_t entRef) =0;
|
||||
|
||||
/**
|
||||
* @brief Converts a reference into a bcompat version (index for networked entities).
|
||||
*
|
||||
* @param entRef Entity reference.
|
||||
* @return Entity reference/index.
|
||||
*/
|
||||
virtual cell_t ReferenceToBCompatRef(cell_t entRef) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the g_EntList pointer.
|
||||
*
|
||||
* @return g_EntList pointer.
|
||||
*/
|
||||
virtual void *GetGlobalEntityList() =0;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user