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);