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 REGISTER_NATIVES(wrbitbufnatives)
333 {"BfWriteBool", smn_BfWriteBool},
334 {"BfWriteByte", smn_BfWriteByte},
335 {"BfWriteChar", smn_BfWriteChar},
336 {"BfWriteShort", smn_BfWriteShort},
337 {"BfWriteWord", smn_BfWriteWord},
338 {"BfWriteNum", smn_BfWriteNum},
339 {"BfWriteFloat", smn_BfWriteFloat},
340 {"BfWriteString", smn_BfWriteString},
341 {"BfWriteEntity", smn_BfWriteEntity},
342 {"BfWriteAngle", smn_BfWriteAngle},
343 {"BfWriteCoord", smn_BfWriteCoord},
344 {"BfWriteVecCoord", smn_BfWriteVecCoord},
345 {"BfWriteVecNormal", smn_BfWriteVecNormal},
346 {"BfWriteAngles", smn_BfWriteAngles},