From 7a5b8caa16a06c3efafc5bc445fc39342985e7e6 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Thu, 21 Feb 2008 01:03:35 +0000 Subject: [PATCH] Added amb1460 - BfGetNumBytesLeft --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401878 --- core/smn_bitbuffer.cpp | 20 ++++++++++++++++++++ plugins/include/bitbuffer.inc | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/core/smn_bitbuffer.cpp b/core/smn_bitbuffer.cpp index 7db96957..949717e2 100644 --- a/core/smn_bitbuffer.cpp +++ b/core/smn_bitbuffer.cpp @@ -651,6 +651,25 @@ static cell_t smn_BfReadAngles(IPluginContext *pCtx, const cell_t *params) return 1; } +static cell_t smn_BfGetNumBytesLeft(IPluginContext *pCtx, const cell_t *params) +{ + Handle_t hndl = static_cast(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->GetNumBitsLeft() >> 3; +} + REGISTER_NATIVES(bitbufnatives) { {"BfWriteBool", smn_BfWriteBool}, @@ -681,5 +700,6 @@ REGISTER_NATIVES(bitbufnatives) {"BfReadVecCoord", smn_BfReadVecCoord}, {"BfReadVecNormal", smn_BfReadVecNormal}, {"BfReadAngles", smn_BfReadAngles}, + {"BfGetNumBytesLeft", smn_BfGetNumBytesLeft}, {NULL, NULL} }; diff --git a/plugins/include/bitbuffer.inc b/plugins/include/bitbuffer.inc index ddf0790d..87de566c 100644 --- a/plugins/include/bitbuffer.inc +++ b/plugins/include/bitbuffer.inc @@ -314,3 +314,12 @@ native BfReadVecNormal(Handle:bf, Float:vec[3]); * @error Invalid or incorrect Handle. */ native BfReadAngles(Handle:bf, Float:angles[3]); + +/** + * Returns the number of bytes left in a readable bitbuffer (bf_read). + * + * @param bf bf_read handle to read from. + * @return Number of bytes left unread. + * @error Invalid or incorrect Handle. + */ +native BfGetNumBytesLeft(Handle:bf);