ds@1952: /**
ds@1952: * vim: set ts=4 :
ds@1952: * =============================================================================
ds@1952: * SourceMod
ds@1952: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
ds@1952: * =============================================================================
ds@1952: *
ds@1952: * This program is free software; you can redistribute it and/or modify it under
ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952: * Free Software Foundation.
ds@1952: *
ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1952: * details.
ds@1952: *
ds@1952: * You should have received a copy of the GNU General Public License along with
ds@1952: * this program. If not, see .
ds@1952: *
ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1952: * this exception to all derivative works. AlliedModders LLC defines further
ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952: * or .
ds@1952: *
ds@1952: * Version: $Id$
ds@1952: */
ds@1952:
ds@1952: #include "sourcemod.h"
ds@1952: #include "HandleSys.h"
ds@1952: #include
ds@1952: #include
ds@1952:
ds@1952: static cell_t smn_BfWriteBool(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteOneBit(params[2]);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteByte(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteByte(params[2]);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteChar(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteChar(params[2]);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteShort(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteShort(params[2]);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteWord(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteWord(params[2]);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteNum(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteLong(static_cast(params[2]));
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteFloat(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteFloat(sp_ctof(params[2]));
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteString(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952: int err;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: char *str;
ds@1952: if ((err=pCtx->LocalToString(params[2], &str)) != SP_ERROR_NONE)
ds@1952: {
ds@1952: pCtx->ThrowNativeErrorEx(err, NULL);
ds@1952: return 0;
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteString(str);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteEntity(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteShort(params[2]);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteAngle(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteBitAngle(sp_ctof(params[2]), params[3]);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteCoord(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pBitBuf->WriteBitCoord(sp_ctof(params[2]));
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteVecCoord(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: cell_t *pVec;
ds@1952: pCtx->LocalToPhysAddr(params[2], &pVec);
ds@1952: Vector vec(sp_ctof(pVec[0]), sp_ctof(pVec[1]), sp_ctof(pVec[2]));
ds@1952: pBitBuf->WriteBitVec3Coord(vec);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteVecNormal(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: cell_t *pVec;
ds@1952: pCtx->LocalToPhysAddr(params[2], &pVec);
ds@1952: Vector vec(sp_ctof(pVec[0]), sp_ctof(pVec[1]), sp_ctof(pVec[2]));
ds@1952: pBitBuf->WriteBitVec3Normal(vec);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfWriteAngles(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_write *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: cell_t *pAng;
ds@1952: pCtx->LocalToPhysAddr(params[2], &pAng);
ds@1952: QAngle ang(sp_ctof(pAng[0]), sp_ctof(pAng[1]), sp_ctof(pAng[2]));
ds@1952: pBitBuf->WriteBitAngles(ang);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadBool(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return pBitBuf->ReadOneBit() ? 1 : 0;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadByte(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return pBitBuf->ReadByte();
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadChar(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return pBitBuf->ReadChar();
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadShort(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return pBitBuf->ReadShort();
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadWord(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return pBitBuf->ReadWord();
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadNum(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return static_cast(pBitBuf->ReadLong());
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadFloat(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return sp_ftoc(pBitBuf->ReadFloat());
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadString(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952: int numChars = 0;
ds@1952: char *buf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: pCtx->LocalToPhysAddr(params[2], (cell_t **)&buf);
ds@1952: pBitBuf->ReadString(buf, params[3], params[4] ? true : false, &numChars);
ds@1952:
ds@1952: if (pBitBuf->IsOverflowed())
ds@1952: {
ds@1952: return -numChars - 1;
ds@1952: }
ds@1952:
ds@1952: return numChars;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadEntity(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return pBitBuf->ReadShort();
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadAngle(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return sp_ftoc(pBitBuf->ReadBitAngle(params[2]));
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadCoord(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return sp_ftoc(pBitBuf->ReadBitCoord());
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadVecCoord(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: cell_t *pVec;
ds@1952: pCtx->LocalToPhysAddr(params[2], &pVec);
ds@1952:
ds@1952: Vector vec;
ds@1952: pBitBuf->ReadBitVec3Coord(vec);
ds@1952:
ds@1952: pVec[0] = sp_ftoc(vec.x);
ds@1952: pVec[1] = sp_ftoc(vec.y);
ds@1952: pVec[2] = sp_ftoc(vec.z);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadVecNormal(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: cell_t *pVec;
ds@1952: pCtx->LocalToPhysAddr(params[2], &pVec);
ds@1952:
ds@1952: Vector vec;
ds@1952: pBitBuf->ReadBitVec3Normal(vec);
ds@1952:
ds@1952: pVec[0] = sp_ftoc(vec.x);
ds@1952: pVec[1] = sp_ftoc(vec.y);
ds@1952: pVec[2] = sp_ftoc(vec.z);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfReadAngles(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: cell_t *pAng;
ds@1952: pCtx->LocalToPhysAddr(params[2], &pAng);
ds@1952:
ds@1952: QAngle ang;
ds@1952: pBitBuf->ReadBitAngles(ang);
ds@1952:
ds@1952: pAng[0] = sp_ftoc(ang.x);
ds@1952: pAng[1] = sp_ftoc(ang.y);
ds@1952: pAng[2] = sp_ftoc(ang.z);
ds@1952:
ds@1952: return 1;
ds@1952: }
ds@1952:
ds@1952: static cell_t smn_BfGetNumBytesLeft(IPluginContext *pCtx, const cell_t *params)
ds@1952: {
ds@1952: Handle_t hndl = static_cast(params[1]);
ds@1952: HandleError herr;
ds@1952: HandleSecurity sec;
ds@1952: bf_read *pBitBuf;
ds@1952:
ds@1952: sec.pOwner = NULL;
ds@1952: sec.pIdentity = g_pCoreIdent;
ds@1952:
ds@1952: if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
ds@1952: != HandleError_None)
ds@1952: {
ds@1952: return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
ds@1952: }
ds@1952:
ds@1952: return pBitBuf->GetNumBitsLeft() >> 3;
ds@1952: }
ds@1952:
ds@1952: REGISTER_NATIVES(bitbufnatives)
ds@1952: {
ds@1952: {"BfWriteBool", smn_BfWriteBool},
ds@1952: {"BfWriteByte", smn_BfWriteByte},
ds@1952: {"BfWriteChar", smn_BfWriteChar},
ds@1952: {"BfWriteShort", smn_BfWriteShort},
ds@1952: {"BfWriteWord", smn_BfWriteWord},
ds@1952: {"BfWriteNum", smn_BfWriteNum},
ds@1952: {"BfWriteFloat", smn_BfWriteFloat},
ds@1952: {"BfWriteString", smn_BfWriteString},
ds@1952: {"BfWriteEntity", smn_BfWriteEntity},
ds@1952: {"BfWriteAngle", smn_BfWriteAngle},
ds@1952: {"BfWriteCoord", smn_BfWriteCoord},
ds@1952: {"BfWriteVecCoord", smn_BfWriteVecCoord},
ds@1952: {"BfWriteVecNormal", smn_BfWriteVecNormal},
ds@1952: {"BfWriteAngles", smn_BfWriteAngles},
ds@1952: {"BfReadBool", smn_BfReadBool},
ds@1952: {"BfReadByte", smn_BfReadByte},
ds@1952: {"BfReadChar", smn_BfReadChar},
ds@1952: {"BfReadShort", smn_BfReadShort},
ds@1952: {"BfReadWord", smn_BfReadWord},
ds@1952: {"BfReadNum", smn_BfReadNum},
ds@1952: {"BfReadFloat", smn_BfReadFloat},
ds@1952: {"BfReadString", smn_BfReadString},
ds@1952: {"BfReadEntity", smn_BfReadEntity},
ds@1952: {"BfReadAngle", smn_BfReadAngle},
ds@1952: {"BfReadCoord", smn_BfReadCoord},
ds@1952: {"BfReadVecCoord", smn_BfReadVecCoord},
ds@1952: {"BfReadVecNormal", smn_BfReadVecNormal},
ds@1952: {"BfReadAngles", smn_BfReadAngles},
ds@1952: {"BfGetNumBytesLeft", smn_BfGetNumBytesLeft},
ds@1952: {NULL, NULL}
ds@1952: };