Updated license headers on virtually all files with extremely minor changes in the name of some sort of strange consistency.
All plugin and include file headers also have been changed to say about GPL3 instead of GPL2.
(This day shall henceforth be known as the Eighty Column Massacre of '07)
3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
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.
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
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/>.
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>.
32 #include "sourcemod.h"
33 #include "HandleSys.h"
37 static cell_t smn_BfWriteBool(IPluginContext *pCtx, const cell_t *params)
39 Handle_t hndl = static_cast<Handle_t>(params[1]);
45 sec.pIdentity = g_pCoreIdent;
47 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
50 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
53 pBitBuf->WriteOneBit(params[2]);
58 static cell_t smn_BfWriteByte(IPluginContext *pCtx, const cell_t *params)
60 Handle_t hndl = static_cast<Handle_t>(params[1]);
66 sec.pIdentity = g_pCoreIdent;
68 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
71 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
74 pBitBuf->WriteByte(params[2]);
79 static cell_t smn_BfWriteChar(IPluginContext *pCtx, const cell_t *params)
81 Handle_t hndl = static_cast<Handle_t>(params[1]);
87 sec.pIdentity = g_pCoreIdent;
89 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
92 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
95 pBitBuf->WriteChar(params[2]);
100 static cell_t smn_BfWriteShort(IPluginContext *pCtx, const cell_t *params)
102 Handle_t hndl = static_cast<Handle_t>(params[1]);
108 sec.pIdentity = g_pCoreIdent;
110 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
113 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
116 pBitBuf->WriteShort(params[2]);
121 static cell_t smn_BfWriteWord(IPluginContext *pCtx, const cell_t *params)
123 Handle_t hndl = static_cast<Handle_t>(params[1]);
129 sec.pIdentity = g_pCoreIdent;
131 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
134 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
137 pBitBuf->WriteWord(params[2]);
142 static cell_t smn_BfWriteNum(IPluginContext *pCtx, const cell_t *params)
144 Handle_t hndl = static_cast<Handle_t>(params[1]);
150 sec.pIdentity = g_pCoreIdent;
152 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
155 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
158 pBitBuf->WriteLong(static_cast<long>(params[2]));
163 static cell_t smn_BfWriteFloat(IPluginContext *pCtx, const cell_t *params)
165 Handle_t hndl = static_cast<Handle_t>(params[1]);
171 sec.pIdentity = g_pCoreIdent;
173 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
176 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
179 pBitBuf->WriteFloat(sp_ctof(params[2]));
184 static cell_t smn_BfWriteString(IPluginContext *pCtx, const cell_t *params)
186 Handle_t hndl = static_cast<Handle_t>(params[1]);
193 sec.pIdentity = g_pCoreIdent;
195 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
198 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
202 if ((err=pCtx->LocalToString(params[2], &str)) != SP_ERROR_NONE)
204 pCtx->ThrowNativeErrorEx(err, NULL);
208 pBitBuf->WriteString(str);
213 static cell_t smn_BfWriteEntity(IPluginContext *pCtx, const cell_t *params)
215 Handle_t hndl = static_cast<Handle_t>(params[1]);
221 sec.pIdentity = g_pCoreIdent;
223 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
226 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
229 pBitBuf->WriteShort(params[2]);
234 static cell_t smn_BfWriteAngle(IPluginContext *pCtx, const cell_t *params)
236 Handle_t hndl = static_cast<Handle_t>(params[1]);
242 sec.pIdentity = g_pCoreIdent;
244 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
247 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
250 pBitBuf->WriteBitAngle(sp_ctof(params[2]), params[3]);
255 static cell_t smn_BfWriteCoord(IPluginContext *pCtx, const cell_t *params)
257 Handle_t hndl = static_cast<Handle_t>(params[1]);
263 sec.pIdentity = g_pCoreIdent;
265 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
268 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
271 pBitBuf->WriteBitCoord(sp_ctof(params[2]));
276 static cell_t smn_BfWriteVecCoord(IPluginContext *pCtx, const cell_t *params)
278 Handle_t hndl = static_cast<Handle_t>(params[1]);
284 sec.pIdentity = g_pCoreIdent;
286 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
289 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
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);
300 static cell_t smn_BfWriteVecNormal(IPluginContext *pCtx, const cell_t *params)
302 Handle_t hndl = static_cast<Handle_t>(params[1]);
308 sec.pIdentity = g_pCoreIdent;
310 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
313 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
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);
324 static cell_t smn_BfWriteAngles(IPluginContext *pCtx, const cell_t *params)
326 Handle_t hndl = static_cast<Handle_t>(params[1]);
332 sec.pIdentity = g_pCoreIdent;
334 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
337 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
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);
348 static cell_t smn_BfReadBool(IPluginContext *pCtx, const cell_t *params)
350 Handle_t hndl = static_cast<Handle_t>(params[1]);
356 sec.pIdentity = g_pCoreIdent;
358 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
361 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
364 return pBitBuf->ReadOneBit() ? 1 : 0;
367 static cell_t smn_BfReadByte(IPluginContext *pCtx, const cell_t *params)
369 Handle_t hndl = static_cast<Handle_t>(params[1]);
375 sec.pIdentity = g_pCoreIdent;
377 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
380 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
383 return pBitBuf->ReadByte();
386 static cell_t smn_BfReadChar(IPluginContext *pCtx, const cell_t *params)
388 Handle_t hndl = static_cast<Handle_t>(params[1]);
394 sec.pIdentity = g_pCoreIdent;
396 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
399 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
402 return pBitBuf->ReadChar();
405 static cell_t smn_BfReadShort(IPluginContext *pCtx, const cell_t *params)
407 Handle_t hndl = static_cast<Handle_t>(params[1]);
413 sec.pIdentity = g_pCoreIdent;
415 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
418 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
421 return pBitBuf->ReadShort();
424 static cell_t smn_BfReadWord(IPluginContext *pCtx, const cell_t *params)
426 Handle_t hndl = static_cast<Handle_t>(params[1]);
432 sec.pIdentity = g_pCoreIdent;
434 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
437 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
440 return pBitBuf->ReadWord();
443 static cell_t smn_BfReadNum(IPluginContext *pCtx, const cell_t *params)
445 Handle_t hndl = static_cast<Handle_t>(params[1]);
451 sec.pIdentity = g_pCoreIdent;
453 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
456 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
459 return static_cast<cell_t>(pBitBuf->ReadLong());
462 static cell_t smn_BfReadFloat(IPluginContext *pCtx, const cell_t *params)
464 Handle_t hndl = static_cast<Handle_t>(params[1]);
470 sec.pIdentity = g_pCoreIdent;
472 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
475 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
478 return sp_ftoc(pBitBuf->ReadFloat());
481 static cell_t smn_BfReadString(IPluginContext *pCtx, const cell_t *params)
483 Handle_t hndl = static_cast<Handle_t>(params[1]);
490 sec.pIdentity = g_pCoreIdent;
492 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
495 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
498 pCtx->LocalToPhysAddr(params[2], (cell_t **)&buf);
499 if (!pBitBuf->ReadString(buf, params[3], params[4] ? true : false))
501 return pCtx->ThrowNativeError("Destination string buffer is too short, try increasing its size");
507 static cell_t smn_BfReadEntity(IPluginContext *pCtx, const cell_t *params)
509 Handle_t hndl = static_cast<Handle_t>(params[1]);
515 sec.pIdentity = g_pCoreIdent;
517 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
520 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
523 return pBitBuf->ReadShort();
526 static cell_t smn_BfReadAngle(IPluginContext *pCtx, const cell_t *params)
528 Handle_t hndl = static_cast<Handle_t>(params[1]);
534 sec.pIdentity = g_pCoreIdent;
536 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
539 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
542 return sp_ftoc(pBitBuf->ReadBitAngle(params[2]));
545 static cell_t smn_BfReadCoord(IPluginContext *pCtx, const cell_t *params)
547 Handle_t hndl = static_cast<Handle_t>(params[1]);
553 sec.pIdentity = g_pCoreIdent;
555 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
558 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
561 return sp_ftoc(pBitBuf->ReadBitCoord());
564 static cell_t smn_BfReadVecCoord(IPluginContext *pCtx, const cell_t *params)
566 Handle_t hndl = static_cast<Handle_t>(params[1]);
572 sec.pIdentity = g_pCoreIdent;
574 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
577 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
581 pCtx->LocalToPhysAddr(params[2], &pVec);
584 pBitBuf->ReadBitVec3Coord(vec);
586 pVec[0] = sp_ftoc(vec.x);
587 pVec[1] = sp_ftoc(vec.y);
588 pVec[2] = sp_ftoc(vec.z);
593 static cell_t smn_BfReadVecNormal(IPluginContext *pCtx, const cell_t *params)
595 Handle_t hndl = static_cast<Handle_t>(params[1]);
601 sec.pIdentity = g_pCoreIdent;
603 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
606 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
610 pCtx->LocalToPhysAddr(params[2], &pVec);
613 pBitBuf->ReadBitVec3Normal(vec);
615 pVec[0] = sp_ftoc(vec.x);
616 pVec[1] = sp_ftoc(vec.y);
617 pVec[2] = sp_ftoc(vec.z);
622 static cell_t smn_BfReadAngles(IPluginContext *pCtx, const cell_t *params)
624 Handle_t hndl = static_cast<Handle_t>(params[1]);
630 sec.pIdentity = g_pCoreIdent;
632 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
635 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
639 pCtx->LocalToPhysAddr(params[2], &pAng);
642 pBitBuf->ReadBitAngles(ang);
644 pAng[0] = sp_ftoc(ang.x);
645 pAng[1] = sp_ftoc(ang.y);
646 pAng[2] = sp_ftoc(ang.z);
651 REGISTER_NATIVES(bitbufnatives)
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},