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