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