core/smn_bitbuffer.cpp
author David Anderson <dvander@alliedmods.net>
Fri Jun 01 02:30:29 2007 +0000 (2007-06-01)
changeset 868 bdbf922e246f
parent 600 f6d811158ad3
child 1231 17badaf66ce4
permissions -rw-r--r--
-initial import of database natives + config
-initial import of completed database layer
-CreateIdentity now requires a non-optional second pointer. This breaks backwards compatibility for CreateIdentity(), however, this is not a function extension authors are supposed to be calling
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #include "sourcemod.h"
    16 #include "HandleSys.h"
    17 #include <bitbuf.h>
    18 #include <vector.h>
    19 
    20 static cell_t smn_BfWriteBool(IPluginContext *pCtx, const cell_t *params)
    21 {
    22 	Handle_t hndl = static_cast<Handle_t>(params[1]);
    23 	HandleError herr;
    24 	HandleSecurity sec;
    25 	bf_write *pBitBuf;
    26 
    27 	sec.pOwner = NULL;
    28 	sec.pIdentity = g_pCoreIdent;
    29 
    30 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
    31 		!= HandleError_None)
    32 	{
    33 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
    34 	}
    35 
    36 	pBitBuf->WriteOneBit(params[2]);
    37 
    38 	return 1;
    39 }
    40 
    41 static cell_t smn_BfWriteByte(IPluginContext *pCtx, const cell_t *params)
    42 {
    43 	Handle_t hndl = static_cast<Handle_t>(params[1]);
    44 	HandleError herr;
    45 	HandleSecurity sec;
    46 	bf_write *pBitBuf;
    47 
    48 	sec.pOwner = NULL;
    49 	sec.pIdentity = g_pCoreIdent;
    50 
    51 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
    52 		!= HandleError_None)
    53 	{
    54 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
    55 	}
    56 
    57 	pBitBuf->WriteByte(params[2]);
    58 
    59 	return 1;
    60 }
    61 
    62 static cell_t smn_BfWriteChar(IPluginContext *pCtx, const cell_t *params)
    63 {
    64 	Handle_t hndl = static_cast<Handle_t>(params[1]);
    65 	HandleError herr;
    66 	HandleSecurity sec;
    67 	bf_write *pBitBuf;
    68 
    69 	sec.pOwner = NULL;
    70 	sec.pIdentity = g_pCoreIdent;
    71 
    72 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
    73 		!= HandleError_None)
    74 	{
    75 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
    76 	}
    77 
    78 	pBitBuf->WriteChar(params[2]);
    79 
    80 	return 1;
    81 }
    82 
    83 static cell_t smn_BfWriteShort(IPluginContext *pCtx, const cell_t *params)
    84 {
    85 	Handle_t hndl = static_cast<Handle_t>(params[1]);
    86 	HandleError herr;
    87 	HandleSecurity sec;
    88 	bf_write *pBitBuf;
    89 
    90 	sec.pOwner = NULL;
    91 	sec.pIdentity = g_pCoreIdent;
    92 
    93 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
    94 		!= HandleError_None)
    95 	{
    96 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
    97 	}
    98 
    99 	pBitBuf->WriteShort(params[2]);
   100 
   101 	return 1;
   102 }
   103 
   104 static cell_t smn_BfWriteWord(IPluginContext *pCtx, const cell_t *params)
   105 {
   106 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   107 	HandleError herr;
   108 	HandleSecurity sec;
   109 	bf_write *pBitBuf;
   110 
   111 	sec.pOwner = NULL;
   112 	sec.pIdentity = g_pCoreIdent;
   113 
   114 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
   115 		!= HandleError_None)
   116 	{
   117 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   118 	}
   119 
   120 	pBitBuf->WriteWord(params[2]);
   121 
   122 	return 1;
   123 }
   124 
   125 static cell_t smn_BfWriteNum(IPluginContext *pCtx, const cell_t *params)
   126 {
   127 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   128 	HandleError herr;
   129 	HandleSecurity sec;
   130 	bf_write *pBitBuf;
   131 
   132 	sec.pOwner = NULL;
   133 	sec.pIdentity = g_pCoreIdent;
   134 
   135 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
   136 		!= HandleError_None)
   137 	{
   138 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   139 	}
   140 
   141 	pBitBuf->WriteLong(static_cast<long>(params[2]));
   142 
   143 	return 1;
   144 }
   145 
   146 static cell_t smn_BfWriteFloat(IPluginContext *pCtx, const cell_t *params)
   147 {
   148 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   149 	HandleError herr;
   150 	HandleSecurity sec;
   151 	bf_write *pBitBuf;
   152 
   153 	sec.pOwner = NULL;
   154 	sec.pIdentity = g_pCoreIdent;
   155 
   156 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
   157 		!= HandleError_None)
   158 	{
   159 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   160 	}
   161 
   162 	pBitBuf->WriteFloat(sp_ctof(params[2]));
   163 
   164 	return 1;
   165 }
   166 
   167 static cell_t smn_BfWriteString(IPluginContext *pCtx, const cell_t *params)
   168 {
   169 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   170 	HandleError herr;
   171 	HandleSecurity sec;
   172 	bf_write *pBitBuf;
   173 	int err;
   174 
   175 	sec.pOwner = NULL;
   176 	sec.pIdentity = g_pCoreIdent;
   177 
   178 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
   179 		!= HandleError_None)
   180 	{
   181 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   182 	}
   183 
   184 	char *str;
   185 	if ((err=pCtx->LocalToString(params[2], &str)) != SP_ERROR_NONE)
   186 	{
   187 		pCtx->ThrowNativeErrorEx(err, NULL);
   188 		return 0;
   189 	}
   190 
   191 	pBitBuf->WriteString(str);
   192 
   193 	return 1;
   194 }
   195 
   196 static cell_t smn_BfWriteEntity(IPluginContext *pCtx, const cell_t *params)
   197 {
   198 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   199 	HandleError herr;
   200 	HandleSecurity sec;
   201 	bf_write *pBitBuf;
   202 
   203 	sec.pOwner = NULL;
   204 	sec.pIdentity = g_pCoreIdent;
   205 
   206 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
   207 		!= HandleError_None)
   208 	{
   209 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   210 	}
   211 
   212 	pBitBuf->WriteShort(params[2]);
   213 
   214 	return 1;
   215 }
   216 
   217 static cell_t smn_BfWriteAngle(IPluginContext *pCtx, const cell_t *params)
   218 {
   219 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   220 	HandleError herr;
   221 	HandleSecurity sec;
   222 	bf_write *pBitBuf;
   223 
   224 	sec.pOwner = NULL;
   225 	sec.pIdentity = g_pCoreIdent;
   226 
   227 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
   228 		!= HandleError_None)
   229 	{
   230 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   231 	}
   232 
   233 	pBitBuf->WriteBitAngle(sp_ctof(params[2]), params[3]);
   234 
   235 	return 1;
   236 }
   237 
   238 static cell_t smn_BfWriteCoord(IPluginContext *pCtx, const cell_t *params)
   239 {
   240 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   241 	HandleError herr;
   242 	HandleSecurity sec;
   243 	bf_write *pBitBuf;
   244 
   245 	sec.pOwner = NULL;
   246 	sec.pIdentity = g_pCoreIdent;
   247 
   248 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
   249 		!= HandleError_None)
   250 	{
   251 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   252 	}
   253 
   254 	pBitBuf->WriteBitCoord(sp_ctof(params[2]));
   255 
   256 	return 1;
   257 }
   258 
   259 static cell_t smn_BfWriteVecCoord(IPluginContext *pCtx, const cell_t *params)
   260 {
   261 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   262 	HandleError herr;
   263 	HandleSecurity sec;
   264 	bf_write *pBitBuf;
   265 
   266 	sec.pOwner = NULL;
   267 	sec.pIdentity = g_pCoreIdent;
   268 
   269 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
   270 		!= HandleError_None)
   271 	{
   272 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   273 	}
   274 
   275 	cell_t *pVec;
   276 	pCtx->LocalToPhysAddr(params[2], &pVec);
   277 	Vector vec(sp_ctof(pVec[0]), sp_ctof(pVec[1]), sp_ctof(pVec[2]));
   278 	pBitBuf->WriteBitVec3Coord(vec);
   279 
   280 	return 1;
   281 }
   282 
   283 static cell_t smn_BfWriteVecNormal(IPluginContext *pCtx, const cell_t *params)
   284 {
   285 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   286 	HandleError herr;
   287 	HandleSecurity sec;
   288 	bf_write *pBitBuf;
   289 
   290 	sec.pOwner = NULL;
   291 	sec.pIdentity = g_pCoreIdent;
   292 
   293 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
   294 		!= HandleError_None)
   295 	{
   296 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   297 	}
   298 
   299 	cell_t *pVec;
   300 	pCtx->LocalToPhysAddr(params[2], &pVec);
   301 	Vector vec(sp_ctof(pVec[0]), sp_ctof(pVec[1]), sp_ctof(pVec[2]));
   302 	pBitBuf->WriteBitVec3Normal(vec);
   303 
   304 	return 1;
   305 }
   306 
   307 static cell_t smn_BfWriteAngles(IPluginContext *pCtx, const cell_t *params)
   308 {
   309 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   310 	HandleError herr;
   311 	HandleSecurity sec;
   312 	bf_write *pBitBuf;
   313 
   314 	sec.pOwner = NULL;
   315 	sec.pIdentity = g_pCoreIdent;
   316 
   317 	if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
   318 		!= HandleError_None)
   319 	{
   320 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   321 	}
   322 
   323 	cell_t *pAng;
   324 	pCtx->LocalToPhysAddr(params[2], &pAng);
   325 	QAngle ang(sp_ctof(pAng[0]), sp_ctof(pAng[1]), sp_ctof(pAng[2]));
   326 	pBitBuf->WriteBitAngles(ang);
   327 
   328 	return 1;
   329 }
   330 
   331 static cell_t smn_BfReadBool(IPluginContext *pCtx, const cell_t *params)
   332 {
   333 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   334 	HandleError herr;
   335 	HandleSecurity sec;
   336 	bf_read *pBitBuf;
   337 
   338 	sec.pOwner = NULL;
   339 	sec.pIdentity = g_pCoreIdent;
   340 
   341 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   342 		!= HandleError_None)
   343 	{
   344 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   345 	}
   346 
   347 	return pBitBuf->ReadOneBit() ? 1 : 0;
   348 }
   349 
   350 static cell_t smn_BfReadByte(IPluginContext *pCtx, const cell_t *params)
   351 {
   352 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   353 	HandleError herr;
   354 	HandleSecurity sec;
   355 	bf_read *pBitBuf;
   356 
   357 	sec.pOwner = NULL;
   358 	sec.pIdentity = g_pCoreIdent;
   359 
   360 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   361 		!= HandleError_None)
   362 	{
   363 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   364 	}
   365 
   366 	return pBitBuf->ReadByte();
   367 }
   368 
   369 static cell_t smn_BfReadChar(IPluginContext *pCtx, const cell_t *params)
   370 {
   371 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   372 	HandleError herr;
   373 	HandleSecurity sec;
   374 	bf_read *pBitBuf;
   375 
   376 	sec.pOwner = NULL;
   377 	sec.pIdentity = g_pCoreIdent;
   378 
   379 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   380 		!= HandleError_None)
   381 	{
   382 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   383 	}
   384 
   385 	return pBitBuf->ReadChar();
   386 }
   387 
   388 static cell_t smn_BfReadShort(IPluginContext *pCtx, const cell_t *params)
   389 {
   390 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   391 	HandleError herr;
   392 	HandleSecurity sec;
   393 	bf_read *pBitBuf;
   394 
   395 	sec.pOwner = NULL;
   396 	sec.pIdentity = g_pCoreIdent;
   397 
   398 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   399 		!= HandleError_None)
   400 	{
   401 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   402 	}
   403 
   404 	return pBitBuf->ReadShort();
   405 }
   406 
   407 static cell_t smn_BfReadWord(IPluginContext *pCtx, const cell_t *params)
   408 {
   409 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   410 	HandleError herr;
   411 	HandleSecurity sec;
   412 	bf_read *pBitBuf;
   413 
   414 	sec.pOwner = NULL;
   415 	sec.pIdentity = g_pCoreIdent;
   416 
   417 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   418 		!= HandleError_None)
   419 	{
   420 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   421 	}
   422 
   423 	return pBitBuf->ReadWord();
   424 }
   425 
   426 static cell_t smn_BfReadNum(IPluginContext *pCtx, const cell_t *params)
   427 {
   428 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   429 	HandleError herr;
   430 	HandleSecurity sec;
   431 	bf_read *pBitBuf;
   432 
   433 	sec.pOwner = NULL;
   434 	sec.pIdentity = g_pCoreIdent;
   435 
   436 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   437 		!= HandleError_None)
   438 	{
   439 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   440 	}
   441 
   442 	return static_cast<cell_t>(pBitBuf->ReadLong());
   443 }
   444 
   445 static cell_t smn_BfReadFloat(IPluginContext *pCtx, const cell_t *params)
   446 {
   447 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   448 	HandleError herr;
   449 	HandleSecurity sec;
   450 	bf_read *pBitBuf;
   451 
   452 	sec.pOwner = NULL;
   453 	sec.pIdentity = g_pCoreIdent;
   454 
   455 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   456 		!= HandleError_None)
   457 	{
   458 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   459 	}
   460 
   461 	return sp_ftoc(pBitBuf->ReadFloat());
   462 }
   463 
   464 static cell_t smn_BfReadString(IPluginContext *pCtx, const cell_t *params)
   465 {
   466 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   467 	HandleError herr;
   468 	HandleSecurity sec;
   469 	bf_read *pBitBuf;
   470 	char *buf;
   471 
   472 	sec.pOwner = NULL;
   473 	sec.pIdentity = g_pCoreIdent;
   474 
   475 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   476 		!= HandleError_None)
   477 	{
   478 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   479 	}
   480 
   481 	pCtx->LocalToPhysAddr(params[2], (cell_t **)&buf);
   482 	if (!pBitBuf->ReadString(buf, params[3], params[4] ? true : false))
   483 	{
   484 		return pCtx->ThrowNativeError("Destination string buffer is too short, try increasing its size");
   485 	}
   486 
   487 	return 1;
   488 }
   489 
   490 static cell_t smn_BfReadEntity(IPluginContext *pCtx, const cell_t *params)
   491 {
   492 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   493 	HandleError herr;
   494 	HandleSecurity sec;
   495 	bf_read *pBitBuf;
   496 
   497 	sec.pOwner = NULL;
   498 	sec.pIdentity = g_pCoreIdent;
   499 
   500 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   501 		!= HandleError_None)
   502 	{
   503 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   504 	}
   505 
   506 	return pBitBuf->ReadShort();
   507 }
   508 
   509 static cell_t smn_BfReadAngle(IPluginContext *pCtx, const cell_t *params)
   510 {
   511 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   512 	HandleError herr;
   513 	HandleSecurity sec;
   514 	bf_read *pBitBuf;
   515 
   516 	sec.pOwner = NULL;
   517 	sec.pIdentity = g_pCoreIdent;
   518 
   519 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   520 		!= HandleError_None)
   521 	{
   522 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   523 	}
   524 
   525 	return sp_ftoc(pBitBuf->ReadBitAngle(params[2]));
   526 }
   527 
   528 static cell_t smn_BfReadCoord(IPluginContext *pCtx, const cell_t *params)
   529 {
   530 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   531 	HandleError herr;
   532 	HandleSecurity sec;
   533 	bf_read *pBitBuf;
   534 
   535 	sec.pOwner = NULL;
   536 	sec.pIdentity = g_pCoreIdent;
   537 
   538 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   539 		!= HandleError_None)
   540 	{
   541 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   542 	}
   543 
   544 	return sp_ftoc(pBitBuf->ReadBitCoord());
   545 }
   546 
   547 static cell_t smn_BfReadVecCoord(IPluginContext *pCtx, const cell_t *params)
   548 {
   549 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   550 	HandleError herr;
   551 	HandleSecurity sec;
   552 	bf_read *pBitBuf;
   553 
   554 	sec.pOwner = NULL;
   555 	sec.pIdentity = g_pCoreIdent;
   556 
   557 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   558 		!= HandleError_None)
   559 	{
   560 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   561 	}
   562 
   563 	cell_t *pVec;
   564 	pCtx->LocalToPhysAddr(params[2], &pVec);
   565 
   566 	Vector vec;
   567 	pBitBuf->ReadBitVec3Coord(vec);
   568 
   569 	pVec[0] = sp_ftoc(vec.x);
   570 	pVec[1] = sp_ftoc(vec.y);
   571 	pVec[2] = sp_ftoc(vec.z);
   572 
   573 	return 1;
   574 }
   575 
   576 static cell_t smn_BfReadVecNormal(IPluginContext *pCtx, const cell_t *params)
   577 {
   578 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   579 	HandleError herr;
   580 	HandleSecurity sec;
   581 	bf_read *pBitBuf;
   582 
   583 	sec.pOwner = NULL;
   584 	sec.pIdentity = g_pCoreIdent;
   585 
   586 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   587 		!= HandleError_None)
   588 	{
   589 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   590 	}
   591 
   592 	cell_t *pVec;
   593 	pCtx->LocalToPhysAddr(params[2], &pVec);
   594 
   595 	Vector vec;
   596 	pBitBuf->ReadBitVec3Normal(vec);
   597 
   598 	pVec[0] = sp_ftoc(vec.x);
   599 	pVec[1] = sp_ftoc(vec.y);
   600 	pVec[2] = sp_ftoc(vec.z);
   601 
   602 	return 1;
   603 }
   604 
   605 static cell_t smn_BfReadAngles(IPluginContext *pCtx, const cell_t *params)
   606 {
   607 	Handle_t hndl = static_cast<Handle_t>(params[1]);
   608 	HandleError herr;
   609 	HandleSecurity sec;
   610 	bf_read *pBitBuf;
   611 
   612 	sec.pOwner = NULL;
   613 	sec.pIdentity = g_pCoreIdent;
   614 
   615 	if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
   616 		!= HandleError_None)
   617 	{
   618 		return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
   619 	}
   620 
   621 	cell_t *pAng;
   622 	pCtx->LocalToPhysAddr(params[2], &pAng);
   623 
   624 	QAngle ang;
   625 	pBitBuf->ReadBitAngles(ang);
   626 
   627 	pAng[0] = sp_ftoc(ang.x);
   628 	pAng[1] = sp_ftoc(ang.y);
   629 	pAng[2] = sp_ftoc(ang.z);
   630 
   631 	return 1;
   632 }
   633 
   634 REGISTER_NATIVES(bitbufnatives)
   635 {
   636 	{"BfWriteBool",				smn_BfWriteBool},
   637 	{"BfWriteByte",				smn_BfWriteByte},
   638 	{"BfWriteChar",				smn_BfWriteChar},
   639 	{"BfWriteShort",			smn_BfWriteShort},
   640 	{"BfWriteWord",				smn_BfWriteWord},
   641 	{"BfWriteNum",				smn_BfWriteNum},
   642 	{"BfWriteFloat",			smn_BfWriteFloat},
   643 	{"BfWriteString",			smn_BfWriteString},
   644 	{"BfWriteEntity",			smn_BfWriteEntity},
   645 	{"BfWriteAngle",			smn_BfWriteAngle},
   646 	{"BfWriteCoord",			smn_BfWriteCoord},
   647 	{"BfWriteVecCoord",			smn_BfWriteVecCoord},
   648 	{"BfWriteVecNormal",		smn_BfWriteVecNormal},
   649 	{"BfWriteAngles",			smn_BfWriteAngles},
   650 	{"BfReadBool",				smn_BfReadBool},
   651 	{"BfReadByte",				smn_BfReadByte},
   652 	{"BfReadChar",				smn_BfReadChar},
   653 	{"BfReadShort",				smn_BfReadShort},
   654 	{"BfReadWord",				smn_BfReadWord},
   655 	{"BfReadNum",				smn_BfReadNum},
   656 	{"BfReadFloat",				smn_BfReadFloat},
   657 	{"BfReadString",			smn_BfReadString},
   658 	{"BfReadEntity",			smn_BfReadEntity},
   659 	{"BfReadAngle",				smn_BfReadAngle},
   660 	{"BfReadCoord",				smn_BfReadCoord},
   661 	{"BfReadVecCoord",			smn_BfReadVecCoord},
   662 	{"BfReadVecNormal",			smn_BfReadVecNormal},
   663 	{"BfReadAngles",			smn_BfReadAngles},
   664 	{NULL,						NULL}
   665 };