Skip to content

Commit

Permalink
Add native BS_GetNumberOfBitsAllocated
Browse files Browse the repository at this point in the history
  • Loading branch information
katursis committed May 6, 2018
1 parent 46740f9 commit 8c1deff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Natives.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<RakNet::BitStream *>(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<cell>(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)) {
Expand Down Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions src/Pawn.RakNet.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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, _}:...);
Expand Down

0 comments on commit 8c1deff

Please sign in to comment.