More consistency of some sort...
Oh god, what has possessed me to do this?
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
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
15 #include "sourcemod.h"
16 #include "HandleSys.h"
20 static cell_t smn_BfWriteBool(IPluginContext *pCtx, const cell_t *params)
22 Handle_t hndl = static_cast<Handle_t>(params[1]);
28 sec.pIdentity = g_pCoreIdent;
30 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
33 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
36 pBitBuf->WriteOneBit(params[2]);
41 static cell_t smn_BfWriteByte(IPluginContext *pCtx, const cell_t *params)
43 Handle_t hndl = static_cast<Handle_t>(params[1]);
49 sec.pIdentity = g_pCoreIdent;
51 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
54 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
57 pBitBuf->WriteByte(params[2]);
62 static cell_t smn_BfWriteChar(IPluginContext *pCtx, const cell_t *params)
64 Handle_t hndl = static_cast<Handle_t>(params[1]);
70 sec.pIdentity = g_pCoreIdent;
72 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
75 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
78 pBitBuf->WriteChar(params[2]);
83 static cell_t smn_BfWriteShort(IPluginContext *pCtx, const cell_t *params)
85 Handle_t hndl = static_cast<Handle_t>(params[1]);
91 sec.pIdentity = g_pCoreIdent;
93 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
96 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
99 pBitBuf->WriteShort(params[2]);
104 static cell_t smn_BfWriteWord(IPluginContext *pCtx, const cell_t *params)
106 Handle_t hndl = static_cast<Handle_t>(params[1]);
112 sec.pIdentity = g_pCoreIdent;
114 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
117 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
120 pBitBuf->WriteWord(params[2]);
125 static cell_t smn_BfWriteNum(IPluginContext *pCtx, const cell_t *params)
127 Handle_t hndl = static_cast<Handle_t>(params[1]);
133 sec.pIdentity = g_pCoreIdent;
135 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
138 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
141 pBitBuf->WriteLong(static_cast<long>(params[2]));
146 static cell_t smn_BfWriteFloat(IPluginContext *pCtx, const cell_t *params)
148 Handle_t hndl = static_cast<Handle_t>(params[1]);
154 sec.pIdentity = g_pCoreIdent;
156 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
159 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
162 pBitBuf->WriteFloat(sp_ctof(params[2]));
167 static cell_t smn_BfWriteString(IPluginContext *pCtx, const cell_t *params)
169 Handle_t hndl = static_cast<Handle_t>(params[1]);
176 sec.pIdentity = g_pCoreIdent;
178 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
181 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
185 if ((err=pCtx->LocalToString(params[2], &str)) != SP_ERROR_NONE)
187 pCtx->ThrowNativeErrorEx(err, NULL);
191 pBitBuf->WriteString(str);
196 static cell_t smn_BfWriteEntity(IPluginContext *pCtx, const cell_t *params)
198 Handle_t hndl = static_cast<Handle_t>(params[1]);
204 sec.pIdentity = g_pCoreIdent;
206 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
209 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
212 pBitBuf->WriteShort(params[2]);
217 static cell_t smn_BfWriteAngle(IPluginContext *pCtx, const cell_t *params)
219 Handle_t hndl = static_cast<Handle_t>(params[1]);
225 sec.pIdentity = g_pCoreIdent;
227 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
230 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
233 pBitBuf->WriteBitAngle(sp_ctof(params[2]), params[3]);
238 static cell_t smn_BfWriteCoord(IPluginContext *pCtx, const cell_t *params)
240 Handle_t hndl = static_cast<Handle_t>(params[1]);
246 sec.pIdentity = g_pCoreIdent;
248 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
251 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
254 pBitBuf->WriteBitCoord(sp_ctof(params[2]));
259 static cell_t smn_BfWriteVecCoord(IPluginContext *pCtx, const cell_t *params)
261 Handle_t hndl = static_cast<Handle_t>(params[1]);
267 sec.pIdentity = g_pCoreIdent;
269 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
272 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
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);
283 static cell_t smn_BfWriteVecNormal(IPluginContext *pCtx, const cell_t *params)
285 Handle_t hndl = static_cast<Handle_t>(params[1]);
291 sec.pIdentity = g_pCoreIdent;
293 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
296 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
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);
307 static cell_t smn_BfWriteAngles(IPluginContext *pCtx, const cell_t *params)
309 Handle_t hndl = static_cast<Handle_t>(params[1]);
315 sec.pIdentity = g_pCoreIdent;
317 if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf))
320 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
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);
331 static cell_t smn_BfReadBool(IPluginContext *pCtx, const cell_t *params)
333 Handle_t hndl = static_cast<Handle_t>(params[1]);
339 sec.pIdentity = g_pCoreIdent;
341 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
344 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
347 return pBitBuf->ReadOneBit() ? 1 : 0;
350 static cell_t smn_BfReadByte(IPluginContext *pCtx, const cell_t *params)
352 Handle_t hndl = static_cast<Handle_t>(params[1]);
358 sec.pIdentity = g_pCoreIdent;
360 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
363 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
366 return pBitBuf->ReadByte();
369 static cell_t smn_BfReadChar(IPluginContext *pCtx, const cell_t *params)
371 Handle_t hndl = static_cast<Handle_t>(params[1]);
377 sec.pIdentity = g_pCoreIdent;
379 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
382 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
385 return pBitBuf->ReadChar();
388 static cell_t smn_BfReadShort(IPluginContext *pCtx, const cell_t *params)
390 Handle_t hndl = static_cast<Handle_t>(params[1]);
396 sec.pIdentity = g_pCoreIdent;
398 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
401 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
404 return pBitBuf->ReadShort();
407 static cell_t smn_BfReadWord(IPluginContext *pCtx, const cell_t *params)
409 Handle_t hndl = static_cast<Handle_t>(params[1]);
415 sec.pIdentity = g_pCoreIdent;
417 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
420 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
423 return pBitBuf->ReadWord();
426 static cell_t smn_BfReadNum(IPluginContext *pCtx, const cell_t *params)
428 Handle_t hndl = static_cast<Handle_t>(params[1]);
434 sec.pIdentity = g_pCoreIdent;
436 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
439 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
442 return static_cast<cell_t>(pBitBuf->ReadLong());
445 static cell_t smn_BfReadFloat(IPluginContext *pCtx, const cell_t *params)
447 Handle_t hndl = static_cast<Handle_t>(params[1]);
453 sec.pIdentity = g_pCoreIdent;
455 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
458 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
461 return sp_ftoc(pBitBuf->ReadFloat());
464 static cell_t smn_BfReadString(IPluginContext *pCtx, const cell_t *params)
466 Handle_t hndl = static_cast<Handle_t>(params[1]);
473 sec.pIdentity = g_pCoreIdent;
475 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
478 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
481 pCtx->LocalToPhysAddr(params[2], (cell_t **)&buf);
482 if (!pBitBuf->ReadString(buf, params[3], params[4] ? true : false))
484 return pCtx->ThrowNativeError("Destination string buffer is too short, try increasing its size");
490 static cell_t smn_BfReadEntity(IPluginContext *pCtx, const cell_t *params)
492 Handle_t hndl = static_cast<Handle_t>(params[1]);
498 sec.pIdentity = g_pCoreIdent;
500 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
503 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
506 return pBitBuf->ReadShort();
509 static cell_t smn_BfReadAngle(IPluginContext *pCtx, const cell_t *params)
511 Handle_t hndl = static_cast<Handle_t>(params[1]);
517 sec.pIdentity = g_pCoreIdent;
519 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
522 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
525 return sp_ftoc(pBitBuf->ReadBitAngle(params[2]));
528 static cell_t smn_BfReadCoord(IPluginContext *pCtx, const cell_t *params)
530 Handle_t hndl = static_cast<Handle_t>(params[1]);
536 sec.pIdentity = g_pCoreIdent;
538 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
541 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
544 return sp_ftoc(pBitBuf->ReadBitCoord());
547 static cell_t smn_BfReadVecCoord(IPluginContext *pCtx, const cell_t *params)
549 Handle_t hndl = static_cast<Handle_t>(params[1]);
555 sec.pIdentity = g_pCoreIdent;
557 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
560 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
564 pCtx->LocalToPhysAddr(params[2], &pVec);
567 pBitBuf->ReadBitVec3Coord(vec);
569 pVec[0] = sp_ftoc(vec.x);
570 pVec[1] = sp_ftoc(vec.y);
571 pVec[2] = sp_ftoc(vec.z);
576 static cell_t smn_BfReadVecNormal(IPluginContext *pCtx, const cell_t *params)
578 Handle_t hndl = static_cast<Handle_t>(params[1]);
584 sec.pIdentity = g_pCoreIdent;
586 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
589 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
593 pCtx->LocalToPhysAddr(params[2], &pVec);
596 pBitBuf->ReadBitVec3Normal(vec);
598 pVec[0] = sp_ftoc(vec.x);
599 pVec[1] = sp_ftoc(vec.y);
600 pVec[2] = sp_ftoc(vec.z);
605 static cell_t smn_BfReadAngles(IPluginContext *pCtx, const cell_t *params)
607 Handle_t hndl = static_cast<Handle_t>(params[1]);
613 sec.pIdentity = g_pCoreIdent;
615 if ((herr=g_HandleSys.ReadHandle(hndl, g_RdBitBufType, &sec, (void **)&pBitBuf))
618 return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr);
622 pCtx->LocalToPhysAddr(params[2], &pAng);
625 pBitBuf->ReadBitAngles(ang);
627 pAng[0] = sp_ftoc(ang.x);
628 pAng[1] = sp_ftoc(ang.y);
629 pAng[2] = sp_ftoc(ang.z);
634 REGISTER_NATIVES(bitbufnatives)
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},