From 8c1deffee3fa031ac05dc21b3bc86ea9b662f04d Mon Sep 17 00:00:00 2001 From: urShadow Date: Sun, 6 May 2018 15:19:48 +0300 Subject: [PATCH] Add native BS_GetNumberOfBitsAllocated --- src/Natives.h | 28 ++++++++++++++++++++++++++++ src/Pawn.RakNet.inc | 1 + 2 files changed, 29 insertions(+) diff --git a/src/Natives.h b/src/Natives.h index e70e3e4..18ee841 100644 --- a/src/Natives.h +++ b/src/Natives.h @@ -338,6 +338,33 @@ namespace Natives { return 1; } + // native BS_GetNumberOfBitsAllocated(BitStream:bs, &number); + cell AMX_NATIVE_CALL n_BS_GetNumberOfBitsAllocated(AMX *amx, cell *params) { + if (!Utils::check_params(__FUNCTION__, 2, params)) { + return 0; + } + + const auto bs = reinterpret_cast(params[1]); + + if (!bs) { + Logger::instance()->Write("[%s] %s: invalid BitStream handle", Settings::kPluginName, __FUNCTION__); + + return 0; + } + + cell *cptr{}; + + if (amx_GetAddr(amx, params[2], &cptr) != AMX_ERR_NONE) { + Logger::instance()->Write("[%s] %s: invalid param reference", Settings::kPluginName, __FUNCTION__); + + return 0; + } + + *cptr = static_cast(bs->GetNumberOfBitsAllocated()); + + return 1; + } + // native BS_WriteValue(BitStream:bs, {Float,_}:...); cell AMX_NATIVE_CALL n_BS_WriteValue(AMX *amx, cell *params) { if (params[0] < (sizeof(cell) * 3)) { @@ -697,6 +724,7 @@ namespace Natives { { "BS_GetNumberOfBitsUsed", n_BS_GetNumberOfBitsUsed }, { "BS_GetNumberOfBytesUsed", n_BS_GetNumberOfBytesUsed }, { "BS_GetNumberOfUnreadBits", n_BS_GetNumberOfUnreadBits }, + { "BS_GetNumberOfBitsAllocated", n_BS_GetNumberOfBitsAllocated }, { "BS_WriteValue", n_BS_WriteValue }, { "BS_ReadValue", n_BS_ReadValue }, diff --git a/src/Pawn.RakNet.inc b/src/Pawn.RakNet.inc index 78dc61a..98d3788 100755 --- a/src/Pawn.RakNet.inc +++ b/src/Pawn.RakNet.inc @@ -249,6 +249,7 @@ native BS_GetNumberOfBitsUsed(BitStream:bs, &number); native BS_GetNumberOfBytesUsed(BitStream:bs, &number); native BS_GetNumberOfUnreadBits(BitStream:bs, &number); + native BS_GetNumberOfBitsAllocated(BitStream:bs, &number); native BS_WriteValue(BitStream:bs, {PR_ValueType, Float, _}:...); native BS_ReadValue(BitStream:bs, {PR_ValueType, Float, _}:...);