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