|
faluco@505
|
1 |
/** |
|
faluco@505
|
2 |
* vim: set ts=4 : |
|
faluco@505
|
3 |
* =============================================================== |
|
faluco@505
|
4 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
faluco@505
|
5 |
* =============================================================== |
|
faluco@505
|
6 |
* |
|
faluco@505
|
7 |
* This file is not open source and may not be copied without explicit |
|
faluco@505
|
8 |
* written permission of AlliedModders LLC. This file may not be redistributed |
|
faluco@505
|
9 |
* in whole or significant part. |
|
faluco@505
|
10 |
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php |
|
faluco@505
|
11 |
* |
|
faluco@505
|
12 |
* Version: $Id$ |
|
faluco@505
|
13 |
*/ |
|
faluco@505
|
14 |
|
|
ds@511
|
15 |
#include "sourcemod.h" |
|
ds@511
|
16 |
#include "HandleSys.h" |
|
faluco@505
|
17 |
#include <bitbuf.h> |
|
faluco@505
|
18 |
#include <vector.h> |
|
faluco@505
|
19 |
|
|
faluco@505
|
20 |
static cell_t smn_BfWriteBool(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
21 |
{ |
|
faluco@505
|
22 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
23 |
HandleError herr; |
|
faluco@505
|
24 |
HandleSecurity sec; |
|
faluco@505
|
25 |
bf_write *pBitBuf; |
|
faluco@505
|
26 |
|
|
faluco@505
|
27 |
sec.pOwner = NULL; |
|
faluco@505
|
28 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
29 |
|
|
faluco@505
|
30 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
31 |
!= HandleError_None) |
|
faluco@505
|
32 |
{ |
|
faluco@505
|
33 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
34 |
} |
|
faluco@505
|
35 |
|
|
faluco@505
|
36 |
pBitBuf->WriteOneBit(params[2]); |
|
faluco@505
|
37 |
|
|
faluco@505
|
38 |
return 1; |
|
faluco@505
|
39 |
} |
|
faluco@505
|
40 |
|
|
faluco@505
|
41 |
static cell_t smn_BfWriteByte(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
42 |
{ |
|
faluco@505
|
43 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
44 |
HandleError herr; |
|
faluco@505
|
45 |
HandleSecurity sec; |
|
faluco@505
|
46 |
bf_write *pBitBuf; |
|
faluco@505
|
47 |
|
|
faluco@505
|
48 |
sec.pOwner = NULL; |
|
faluco@505
|
49 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
50 |
|
|
faluco@505
|
51 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
52 |
!= HandleError_None) |
|
faluco@505
|
53 |
{ |
|
faluco@505
|
54 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
55 |
} |
|
faluco@505
|
56 |
|
|
faluco@505
|
57 |
pBitBuf->WriteByte(params[2]); |
|
faluco@505
|
58 |
|
|
faluco@505
|
59 |
return 1; |
|
faluco@505
|
60 |
} |
|
faluco@505
|
61 |
|
|
faluco@505
|
62 |
static cell_t smn_BfWriteChar(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
63 |
{ |
|
faluco@505
|
64 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
65 |
HandleError herr; |
|
faluco@505
|
66 |
HandleSecurity sec; |
|
faluco@505
|
67 |
bf_write *pBitBuf; |
|
faluco@505
|
68 |
|
|
faluco@505
|
69 |
sec.pOwner = NULL; |
|
faluco@505
|
70 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
71 |
|
|
faluco@505
|
72 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
73 |
!= HandleError_None) |
|
faluco@505
|
74 |
{ |
|
faluco@505
|
75 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
76 |
} |
|
faluco@505
|
77 |
|
|
faluco@505
|
78 |
pBitBuf->WriteChar(params[2]); |
|
faluco@505
|
79 |
|
|
faluco@505
|
80 |
return 1; |
|
faluco@505
|
81 |
} |
|
faluco@505
|
82 |
|
|
faluco@505
|
83 |
static cell_t smn_BfWriteShort(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
84 |
{ |
|
faluco@505
|
85 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
86 |
HandleError herr; |
|
faluco@505
|
87 |
HandleSecurity sec; |
|
faluco@505
|
88 |
bf_write *pBitBuf; |
|
faluco@505
|
89 |
|
|
faluco@505
|
90 |
sec.pOwner = NULL; |
|
faluco@505
|
91 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
92 |
|
|
faluco@505
|
93 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
94 |
!= HandleError_None) |
|
faluco@505
|
95 |
{ |
|
faluco@505
|
96 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
97 |
} |
|
faluco@505
|
98 |
|
|
faluco@505
|
99 |
pBitBuf->WriteShort(params[2]); |
|
faluco@505
|
100 |
|
|
faluco@505
|
101 |
return 1; |
|
faluco@505
|
102 |
} |
|
faluco@505
|
103 |
|
|
faluco@505
|
104 |
static cell_t smn_BfWriteWord(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
105 |
{ |
|
faluco@505
|
106 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
107 |
HandleError herr; |
|
faluco@505
|
108 |
HandleSecurity sec; |
|
faluco@505
|
109 |
bf_write *pBitBuf; |
|
faluco@505
|
110 |
|
|
faluco@505
|
111 |
sec.pOwner = NULL; |
|
faluco@505
|
112 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
113 |
|
|
faluco@505
|
114 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
115 |
!= HandleError_None) |
|
faluco@505
|
116 |
{ |
|
faluco@505
|
117 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
118 |
} |
|
faluco@505
|
119 |
|
|
faluco@505
|
120 |
pBitBuf->WriteWord(params[2]); |
|
faluco@505
|
121 |
|
|
faluco@505
|
122 |
return 1; |
|
faluco@505
|
123 |
} |
|
faluco@505
|
124 |
|
|
faluco@505
|
125 |
static cell_t smn_BfWriteNum(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
126 |
{ |
|
faluco@505
|
127 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
128 |
HandleError herr; |
|
faluco@505
|
129 |
HandleSecurity sec; |
|
faluco@505
|
130 |
bf_write *pBitBuf; |
|
faluco@505
|
131 |
|
|
faluco@505
|
132 |
sec.pOwner = NULL; |
|
faluco@505
|
133 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
134 |
|
|
faluco@505
|
135 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
136 |
!= HandleError_None) |
|
faluco@505
|
137 |
{ |
|
faluco@505
|
138 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
139 |
} |
|
faluco@505
|
140 |
|
|
faluco@505
|
141 |
pBitBuf->WriteLong(static_cast<long>(params[2])); |
|
faluco@505
|
142 |
|
|
faluco@505
|
143 |
return 1; |
|
faluco@505
|
144 |
} |
|
faluco@505
|
145 |
|
|
faluco@505
|
146 |
static cell_t smn_BfWriteFloat(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
147 |
{ |
|
faluco@505
|
148 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
149 |
HandleError herr; |
|
faluco@505
|
150 |
HandleSecurity sec; |
|
faluco@505
|
151 |
bf_write *pBitBuf; |
|
faluco@505
|
152 |
|
|
faluco@505
|
153 |
sec.pOwner = NULL; |
|
faluco@505
|
154 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
155 |
|
|
faluco@505
|
156 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
157 |
!= HandleError_None) |
|
faluco@505
|
158 |
{ |
|
faluco@505
|
159 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
160 |
} |
|
faluco@505
|
161 |
|
|
faluco@505
|
162 |
pBitBuf->WriteFloat(sp_ctof(params[2])); |
|
faluco@505
|
163 |
|
|
faluco@505
|
164 |
return 1; |
|
faluco@505
|
165 |
} |
|
faluco@505
|
166 |
|
|
faluco@505
|
167 |
static cell_t smn_BfWriteString(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
168 |
{ |
|
faluco@505
|
169 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
170 |
HandleError herr; |
|
faluco@505
|
171 |
HandleSecurity sec; |
|
faluco@505
|
172 |
bf_write *pBitBuf; |
|
faluco@505
|
173 |
int err; |
|
faluco@505
|
174 |
|
|
faluco@505
|
175 |
sec.pOwner = NULL; |
|
faluco@505
|
176 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
177 |
|
|
faluco@505
|
178 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
179 |
!= HandleError_None) |
|
faluco@505
|
180 |
{ |
|
faluco@505
|
181 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
182 |
} |
|
faluco@505
|
183 |
|
|
faluco@505
|
184 |
char *str; |
|
faluco@505
|
185 |
if ((err=pCtx->LocalToString(params[2], &str)) != SP_ERROR_NONE) |
|
faluco@505
|
186 |
{ |
|
faluco@505
|
187 |
pCtx->ThrowNativeErrorEx(err, NULL); |
|
faluco@505
|
188 |
return 0; |
|
faluco@505
|
189 |
} |
|
faluco@505
|
190 |
|
|
faluco@505
|
191 |
pBitBuf->WriteString(str); |
|
faluco@505
|
192 |
|
|
faluco@505
|
193 |
return 1; |
|
faluco@505
|
194 |
} |
|
faluco@505
|
195 |
|
|
faluco@505
|
196 |
static cell_t smn_BfWriteEntity(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
197 |
{ |
|
faluco@505
|
198 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
199 |
HandleError herr; |
|
faluco@505
|
200 |
HandleSecurity sec; |
|
faluco@505
|
201 |
bf_write *pBitBuf; |
|
faluco@505
|
202 |
|
|
faluco@505
|
203 |
sec.pOwner = NULL; |
|
faluco@505
|
204 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
205 |
|
|
faluco@505
|
206 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
207 |
!= HandleError_None) |
|
faluco@505
|
208 |
{ |
|
faluco@505
|
209 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
210 |
} |
|
faluco@505
|
211 |
|
|
faluco@505
|
212 |
pBitBuf->WriteShort(params[2]); |
|
faluco@505
|
213 |
|
|
faluco@505
|
214 |
return 1; |
|
faluco@505
|
215 |
} |
|
faluco@505
|
216 |
|
|
faluco@505
|
217 |
static cell_t smn_BfWriteAngle(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
218 |
{ |
|
faluco@505
|
219 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
220 |
HandleError herr; |
|
faluco@505
|
221 |
HandleSecurity sec; |
|
faluco@505
|
222 |
bf_write *pBitBuf; |
|
faluco@505
|
223 |
|
|
faluco@505
|
224 |
sec.pOwner = NULL; |
|
faluco@505
|
225 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
226 |
|
|
faluco@505
|
227 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
228 |
!= HandleError_None) |
|
faluco@505
|
229 |
{ |
|
faluco@505
|
230 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
231 |
} |
|
faluco@505
|
232 |
|
|
faluco@505
|
233 |
pBitBuf->WriteBitAngle(sp_ctof(params[2]), params[3]); |
|
faluco@505
|
234 |
|
|
faluco@505
|
235 |
return 1; |
|
faluco@505
|
236 |
} |
|
faluco@505
|
237 |
|
|
faluco@505
|
238 |
static cell_t smn_BfWriteCoord(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
239 |
{ |
|
faluco@505
|
240 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
241 |
HandleError herr; |
|
faluco@505
|
242 |
HandleSecurity sec; |
|
faluco@505
|
243 |
bf_write *pBitBuf; |
|
faluco@505
|
244 |
|
|
faluco@505
|
245 |
sec.pOwner = NULL; |
|
faluco@505
|
246 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
247 |
|
|
faluco@505
|
248 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
249 |
!= HandleError_None) |
|
faluco@505
|
250 |
{ |
|
faluco@505
|
251 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
252 |
} |
|
faluco@505
|
253 |
|
|
faluco@505
|
254 |
pBitBuf->WriteBitCoord(sp_ctof(params[2])); |
|
faluco@505
|
255 |
|
|
faluco@505
|
256 |
return 1; |
|
faluco@505
|
257 |
} |
|
faluco@505
|
258 |
|
|
faluco@505
|
259 |
static cell_t smn_BfWriteVecCoord(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
260 |
{ |
|
faluco@505
|
261 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
262 |
HandleError herr; |
|
faluco@505
|
263 |
HandleSecurity sec; |
|
faluco@505
|
264 |
bf_write *pBitBuf; |
|
faluco@505
|
265 |
|
|
faluco@505
|
266 |
sec.pOwner = NULL; |
|
faluco@505
|
267 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
268 |
|
|
faluco@505
|
269 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
270 |
!= HandleError_None) |
|
faluco@505
|
271 |
{ |
|
faluco@505
|
272 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
273 |
} |
|
faluco@505
|
274 |
|
|
faluco@505
|
275 |
cell_t *pVec; |
|
faluco@505
|
276 |
pCtx->LocalToPhysAddr(params[2], &pVec); |
|
faluco@505
|
277 |
Vector vec(sp_ctof(pVec[0]), sp_ctof(pVec[1]), sp_ctof(pVec[2])); |
|
faluco@505
|
278 |
pBitBuf->WriteBitVec3Coord(vec); |
|
faluco@505
|
279 |
|
|
faluco@505
|
280 |
return 1; |
|
faluco@505
|
281 |
} |
|
faluco@505
|
282 |
|
|
faluco@505
|
283 |
static cell_t smn_BfWriteVecNormal(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
284 |
{ |
|
faluco@505
|
285 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
286 |
HandleError herr; |
|
faluco@505
|
287 |
HandleSecurity sec; |
|
faluco@505
|
288 |
bf_write *pBitBuf; |
|
faluco@505
|
289 |
|
|
faluco@505
|
290 |
sec.pOwner = NULL; |
|
faluco@505
|
291 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
292 |
|
|
faluco@505
|
293 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
294 |
!= HandleError_None) |
|
faluco@505
|
295 |
{ |
|
faluco@505
|
296 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
297 |
} |
|
faluco@505
|
298 |
|
|
faluco@505
|
299 |
cell_t *pVec; |
|
faluco@505
|
300 |
pCtx->LocalToPhysAddr(params[2], &pVec); |
|
faluco@505
|
301 |
Vector vec(sp_ctof(pVec[0]), sp_ctof(pVec[1]), sp_ctof(pVec[2])); |
|
faluco@505
|
302 |
pBitBuf->WriteBitVec3Normal(vec); |
|
faluco@505
|
303 |
|
|
faluco@505
|
304 |
return 1; |
|
faluco@505
|
305 |
} |
|
faluco@505
|
306 |
|
|
faluco@505
|
307 |
static cell_t smn_BfWriteAngles(IPluginContext *pCtx, const cell_t *params) |
|
faluco@505
|
308 |
{ |
|
faluco@505
|
309 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
faluco@505
|
310 |
HandleError herr; |
|
faluco@505
|
311 |
HandleSecurity sec; |
|
faluco@505
|
312 |
bf_write *pBitBuf; |
|
faluco@505
|
313 |
|
|
faluco@505
|
314 |
sec.pOwner = NULL; |
|
faluco@505
|
315 |
sec.pIdentity = g_pCoreIdent; |
|
faluco@505
|
316 |
|
|
faluco@505
|
317 |
if ((herr=g_HandleSys.ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) |
|
faluco@505
|
318 |
!= HandleError_None) |
|
faluco@505
|
319 |
{ |
|
faluco@505
|
320 |
return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); |
|
faluco@505
|
321 |
} |
|
faluco@505
|
322 |
|
|
faluco@505
|
323 |
cell_t *pAng; |
|
faluco@505
|
324 |
pCtx->LocalToPhysAddr(params[2], &pAng); |
|
faluco@505
|
325 |
QAngle ang(sp_ctof(pAng[0]), sp_ctof(pAng[1]), sp_ctof(pAng[2])); |
|
faluco@505
|
326 |
pBitBuf->WriteBitAngles(ang); |
|
faluco@505
|
327 |
|
|
faluco@505
|
328 |
return 1; |
|
faluco@505
|
329 |
} |
|
faluco@505
|
330 |
|
|
faluco@505
|
331 |
REGISTER_NATIVES(wrbitbufnatives) |
|
faluco@505
|
332 |
{ |
|
faluco@505
|
333 |
{"BfWriteBool", smn_BfWriteBool}, |
|
faluco@505
|
334 |
{"BfWriteByte", smn_BfWriteByte}, |
|
faluco@505
|
335 |
{"BfWriteChar", smn_BfWriteChar}, |
|
faluco@505
|
336 |
{"BfWriteShort", smn_BfWriteShort}, |
|
faluco@505
|
337 |
{"BfWriteWord", smn_BfWriteWord}, |
|
faluco@505
|
338 |
{"BfWriteNum", smn_BfWriteNum}, |
|
faluco@505
|
339 |
{"BfWriteFloat", smn_BfWriteFloat}, |
|
faluco@505
|
340 |
{"BfWriteString", smn_BfWriteString}, |
|
faluco@505
|
341 |
{"BfWriteEntity", smn_BfWriteEntity}, |
|
faluco@505
|
342 |
{"BfWriteAngle", smn_BfWriteAngle}, |
|
faluco@505
|
343 |
{"BfWriteCoord", smn_BfWriteCoord}, |
|
faluco@505
|
344 |
{"BfWriteVecCoord", smn_BfWriteVecCoord}, |
|
faluco@505
|
345 |
{"BfWriteVecNormal", smn_BfWriteVecNormal}, |
|
faluco@505
|
346 |
{"BfWriteAngles", smn_BfWriteAngles}, |
|
faluco@505
|
347 |
{NULL, NULL} |
|
faluco@505
|
348 |
}; |