implemented the bf_read natives
message hooks now receive the bf_read handle --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40604
This commit is contained in:
+318
-1
@@ -328,7 +328,310 @@ static cell_t smn_BfWriteAngles(IPluginContext *pCtx, const cell_t *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(wrbitbufnatives)
|
||||
static cell_t smn_BfReadBool(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return pBitBuf->ReadOneBit() ? 1 : 0;
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadByte(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return pBitBuf->ReadByte();
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadChar(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return pBitBuf->ReadChar();
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadShort(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return pBitBuf->ReadShort();
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadWord(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return pBitBuf->ReadWord();
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadNum(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return static_cast<cell_t>(pBitBuf->ReadLong());
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadFloat(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return sp_ftoc(pBitBuf->ReadFloat());
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadString(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
char *buf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
pCtx->LocalToPhysAddr(params[2], (cell_t **)&buf);
|
||||
if (!pBitBuf->ReadString(buf, params[3], params[4] ? true : false))
|
||||
{
|
||||
return pCtx->ThrowNativeError("Destination string buffer is too short, try increasing its size");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadEntity(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return pBitBuf->ReadShort();
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadAngle(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return sp_ftoc(pBitBuf->ReadBitAngle(params[2]));
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadCoord(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
return sp_ftoc(pBitBuf->ReadBitCoord());
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadVecCoord(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
cell_t *pVec;
|
||||
pCtx->LocalToPhysAddr(params[2], &pVec);
|
||||
|
||||
Vector vec;
|
||||
pBitBuf->ReadBitVec3Coord(vec);
|
||||
|
||||
pVec[0] = sp_ftoc(vec.x);
|
||||
pVec[1] = sp_ftoc(vec.y);
|
||||
pVec[2] = sp_ftoc(vec.z);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadVecNormal(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
cell_t *pVec;
|
||||
pCtx->LocalToPhysAddr(params[2], &pVec);
|
||||
|
||||
Vector vec;
|
||||
pBitBuf->ReadBitVec3Normal(vec);
|
||||
|
||||
pVec[0] = sp_ftoc(vec.x);
|
||||
pVec[1] = sp_ftoc(vec.y);
|
||||
pVec[2] = sp_ftoc(vec.z);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t smn_BfReadAngles(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
bf_read *pBitBuf;
|
||||
|
||||
sec.pOwner = NULL;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
|
||||
}
|
||||
|
||||
cell_t *pAng;
|
||||
pCtx->LocalToPhysAddr(params[2], &pAng);
|
||||
|
||||
QAngle ang;
|
||||
pBitBuf->ReadBitAngles(ang);
|
||||
|
||||
pAng[0] = sp_ftoc(ang.x);
|
||||
pAng[1] = sp_ftoc(ang.y);
|
||||
pAng[2] = sp_ftoc(ang.z);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(bitbufnatives)
|
||||
{
|
||||
{"BfWriteBool", smn_BfWriteBool},
|
||||
{"BfWriteByte", smn_BfWriteByte},
|
||||
@@ -344,5 +647,19 @@ REGISTER_NATIVES(wrbitbufnatives)
|
||||
{"BfWriteVecCoord", smn_BfWriteVecCoord},
|
||||
{"BfWriteVecNormal", smn_BfWriteVecNormal},
|
||||
{"BfWriteAngles", smn_BfWriteAngles},
|
||||
{"BfReadBool", smn_BfReadBool},
|
||||
{"BfReadByte", smn_BfReadByte},
|
||||
{"BfReadChar", smn_BfReadChar},
|
||||
{"BfReadShort", smn_BfReadShort},
|
||||
{"BfReadWord", smn_BfReadWord},
|
||||
{"BfReadNum", smn_BfReadNum},
|
||||
{"BfReadFloat", smn_BfReadFloat},
|
||||
{"BfReadString", smn_BfReadString},
|
||||
{"BfReadEntity", smn_BfReadEntity},
|
||||
{"BfReadAngle", smn_BfReadAngle},
|
||||
{"BfReadCoord", smn_BfReadCoord},
|
||||
{"BfReadVecCoord", smn_BfReadVecCoord},
|
||||
{"BfReadVecNormal", smn_BfReadVecNormal},
|
||||
{"BfReadAngles", smn_BfReadAngles},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
+25
-2
@@ -18,7 +18,11 @@
|
||||
#include "smn_usermsgs.h"
|
||||
|
||||
HandleType_t g_WrBitBufType;
|
||||
HandleType_t g_RdBitBufType;
|
||||
Handle_t g_CurMsgHandle;
|
||||
Handle_t g_ReadBufHandle;
|
||||
bf_read g_ReadBitBuf;
|
||||
|
||||
int g_MsgPlayers[256];
|
||||
bool g_IsMsgInExec = false;
|
||||
|
||||
@@ -45,15 +49,30 @@ private:
|
||||
|
||||
void UsrMessageNatives::OnSourceModAllInitialized()
|
||||
{
|
||||
HandleAccess sec;
|
||||
sec.access[HandleAccess_Delete] |= HANDLE_RESTRICT_IDENTITY;
|
||||
|
||||
g_WrBitBufType = g_HandleSys.CreateType("BitBufWriter", this, 0, NULL, NULL, g_pCoreIdent, NULL);
|
||||
g_RdBitBufType = g_HandleSys.CreateType("BitBufReader", this, 0, NULL, &sec, g_pCoreIdent, NULL);
|
||||
|
||||
g_ReadBufHandle = g_HandleSys.CreateHandle(g_RdBitBufType, &g_ReadBitBuf, NULL, g_pCoreIdent, NULL);
|
||||
|
||||
g_PluginSys.AddPluginsListener(this);
|
||||
}
|
||||
|
||||
void UsrMessageNatives::OnSourceModShutdown()
|
||||
{
|
||||
HandleSecurity sec;
|
||||
sec.pIdentity = g_pCoreIdent;
|
||||
|
||||
g_HandleSys.FreeHandle(g_ReadBufHandle, &sec);
|
||||
|
||||
g_HandleSys.RemoveType(g_WrBitBufType, g_pCoreIdent);
|
||||
g_HandleSys.RemoveType(g_RdBitBufType, g_pCoreIdent);
|
||||
|
||||
g_PluginSys.RemovePluginsListener(this);
|
||||
g_WrBitBufType = 0;
|
||||
g_RdBitBufType = 0;
|
||||
}
|
||||
|
||||
void UsrMessageNatives::OnHandleDestroy(HandleType_t type, void *object)
|
||||
@@ -221,8 +240,10 @@ void MsgListenerWrapper::OnUserMessage(int msg_id, bf_write *bf, IRecipientFilte
|
||||
cell_t res;
|
||||
size_t size = _FillInPlayers(g_MsgPlayers, pFilter);
|
||||
|
||||
g_ReadBitBuf.StartReading(bf->GetBasePointer(), bf->GetNumBytesWritten());
|
||||
|
||||
m_Hook->PushCell(msg_id);
|
||||
m_Hook->PushCell(0); //:TODO: push handle!
|
||||
m_Hook->PushCell(g_ReadBufHandle);
|
||||
m_Hook->PushArray(g_MsgPlayers, size);
|
||||
m_Hook->PushCell(size);
|
||||
m_Hook->PushCell(pFilter->IsReliable());
|
||||
@@ -235,8 +256,10 @@ ResultType MsgListenerWrapper::InterceptUserMessage(int msg_id, bf_write *bf, IR
|
||||
cell_t res = static_cast<cell_t>(Pl_Continue);
|
||||
size_t size = _FillInPlayers(g_MsgPlayers, pFilter);
|
||||
|
||||
g_ReadBitBuf.StartReading(bf->GetBasePointer(), bf->GetNumBytesWritten());
|
||||
|
||||
m_Intercept->PushCell(msg_id);
|
||||
m_Intercept->PushCell(0); //:TODO: push handle!
|
||||
m_Intercept->PushCell(g_ReadBufHandle);
|
||||
m_Intercept->PushArray(g_MsgPlayers, size);
|
||||
m_Intercept->PushCell(size);
|
||||
m_Intercept->PushCell(pFilter->IsReliable());
|
||||
|
||||
@@ -102,5 +102,6 @@ private:
|
||||
|
||||
extern SourceModBase g_SourceMod;
|
||||
extern HandleType_t g_WrBitBufType;
|
||||
extern HandleType_t g_RdBitBufType;
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_GLOBALHEADER_H_
|
||||
|
||||
Reference in New Issue
Block a user