|
faluco@1498
|
1 |
/** |
|
faluco@1498
|
2 |
* vim: set ts=4 : |
|
faluco@1498
|
3 |
* ============================================================================= |
|
faluco@1498
|
4 |
* SourceMod SDKTools Extension |
|
ds@1947
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. |
|
faluco@1498
|
6 |
* ============================================================================= |
|
faluco@1498
|
7 |
* |
|
faluco@1498
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
faluco@1498
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
faluco@1498
|
10 |
* Free Software Foundation. |
|
faluco@1498
|
11 |
* |
|
faluco@1498
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
faluco@1498
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
faluco@1498
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
faluco@1498
|
15 |
* details. |
|
faluco@1498
|
16 |
* |
|
faluco@1498
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
faluco@1498
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
faluco@1498
|
19 |
* |
|
faluco@1498
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
faluco@1498
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
faluco@1498
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
faluco@1498
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
faluco@1498
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
faluco@1498
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
faluco@1498
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
faluco@1498
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
faluco@1498
|
28 |
* |
|
faluco@1498
|
29 |
* Version: $Id$ |
|
faluco@1498
|
30 |
*/ |
|
faluco@1498
|
31 |
|
|
faluco@1498
|
32 |
#include "extension.h" |
|
faluco@1498
|
33 |
#include <datamap.h> |
|
faluco@1498
|
34 |
|
|
faluco@1498
|
35 |
#define SIZEOF_VARIANT_T 20 |
|
faluco@1498
|
36 |
|
|
faluco@1498
|
37 |
ICallWrapper *g_pAcceptInput = NULL; |
|
faluco@1498
|
38 |
unsigned char g_Variant_t[SIZEOF_VARIANT_T] = {0}; |
|
faluco@1498
|
39 |
|
|
pred@2746
|
40 |
#define ENTINDEX_TO_CBASEENTITY(ref, buffer) \ |
|
pred@2746
|
41 |
buffer = gamehelpers->ReferenceToEntity(ref); \ |
|
faluco@1498
|
42 |
if (!buffer) \ |
|
faluco@1498
|
43 |
{ \ |
|
pred@2746
|
44 |
return pContext->ThrowNativeError("Entity %d (%d) is not a CBaseEntity", gamehelpers->ReferenceToIndex(ref), ref); \ |
|
faluco@1498
|
45 |
} |
|
faluco@1498
|
46 |
|
|
faluco@1498
|
47 |
/* Hack to init the variant_t object for the first time */ |
|
faluco@1498
|
48 |
class VariantFirstTimeInit |
|
faluco@1498
|
49 |
{ |
|
faluco@1498
|
50 |
public: |
|
faluco@1498
|
51 |
VariantFirstTimeInit() |
|
faluco@1498
|
52 |
{ |
|
faluco@1498
|
53 |
*(unsigned int *)(&g_Variant_t[12]) = INVALID_EHANDLE_INDEX; |
|
faluco@1498
|
54 |
} |
|
faluco@1498
|
55 |
} g_VariantFirstTimeInit; |
|
faluco@1498
|
56 |
|
|
faluco@1498
|
57 |
inline void _init_variant_t() |
|
faluco@1498
|
58 |
{ |
|
faluco@1498
|
59 |
unsigned char *vptr = g_Variant_t; |
|
faluco@1498
|
60 |
|
|
faluco@1498
|
61 |
*(int *)vptr = 0; |
|
faluco@1498
|
62 |
vptr += sizeof(int)*3; |
|
faluco@1498
|
63 |
*(unsigned long *)vptr = INVALID_EHANDLE_INDEX; |
|
faluco@1498
|
64 |
vptr += sizeof(unsigned long); |
|
faluco@1498
|
65 |
*(fieldtype_t *)vptr = FIELD_VOID; |
|
faluco@1498
|
66 |
} |
|
faluco@1498
|
67 |
|
|
faluco@1498
|
68 |
static cell_t AcceptEntityInput(IPluginContext *pContext, const cell_t *params) |
|
faluco@1498
|
69 |
{ |
|
faluco@1498
|
70 |
if (!g_pAcceptInput) |
|
faluco@1498
|
71 |
{ |
|
faluco@1498
|
72 |
int offset; |
|
faluco@1498
|
73 |
if (!g_pGameConf->GetOffset("AcceptInput", &offset)) |
|
faluco@1498
|
74 |
{ |
|
faluco@1498
|
75 |
return pContext->ThrowNativeError("\"AcceptEntityInput\" not supported by this mod"); |
|
faluco@1498
|
76 |
} |
|
faluco@1498
|
77 |
|
|
faluco@1498
|
78 |
PassInfo pass[6]; |
|
faluco@1498
|
79 |
pass[0].type = PassType_Basic; |
|
faluco@1498
|
80 |
pass[0].flags = PASSFLAG_BYVAL; |
|
faluco@1498
|
81 |
pass[0].size = sizeof(const char *); |
|
faluco@1498
|
82 |
pass[1].type = pass[2].type = PassType_Basic; |
|
faluco@1498
|
83 |
pass[1].flags = pass[2].flags = PASSFLAG_BYVAL; |
|
faluco@1498
|
84 |
pass[1].size = pass[2].size = sizeof(CBaseEntity *); |
|
faluco@1498
|
85 |
pass[3].type = PassType_Object; |
|
faluco@1515
|
86 |
pass[3].flags = PASSFLAG_BYVAL|PASSFLAG_OCTOR|PASSFLAG_ODTOR|PASSFLAG_OASSIGNOP; |
|
faluco@1498
|
87 |
pass[3].size = SIZEOF_VARIANT_T; |
|
faluco@1498
|
88 |
pass[4].type = PassType_Basic; |
|
faluco@1498
|
89 |
pass[4].flags = PASSFLAG_BYVAL; |
|
faluco@1498
|
90 |
pass[4].size = sizeof(int); |
|
faluco@1498
|
91 |
pass[5].type = PassType_Basic; |
|
faluco@1498
|
92 |
pass[5].flags = PASSFLAG_BYVAL; |
|
faluco@1498
|
93 |
pass[5].size = sizeof(bool); |
|
faluco@1498
|
94 |
|
|
faluco@1498
|
95 |
if (!(g_pAcceptInput=g_pBinTools->CreateVCall(offset, 0, 0, &pass[5], pass, 5))) |
|
faluco@1498
|
96 |
{ |
|
faluco@1498
|
97 |
pContext->ThrowNativeError("\"AcceptEntityInput\" wrapper failed to initialized"); |
|
faluco@1498
|
98 |
} |
|
faluco@1498
|
99 |
} |
|
faluco@1498
|
100 |
|
|
faluco@1498
|
101 |
CBaseEntity *pActivator, *pCaller, *pDest; |
|
faluco@1498
|
102 |
|
|
faluco@1498
|
103 |
char *inputname; |
|
faluco@1498
|
104 |
unsigned char vstk[sizeof(void *) + sizeof(const char *) + sizeof(CBaseEntity *)*2 + SIZEOF_VARIANT_T + sizeof(int)]; |
|
faluco@1498
|
105 |
unsigned char *vptr = vstk; |
|
faluco@1498
|
106 |
|
|
faluco@1498
|
107 |
ENTINDEX_TO_CBASEENTITY(params[1], pDest); |
|
faluco@1498
|
108 |
pContext->LocalToString(params[2], &inputname); |
|
faluco@1498
|
109 |
if (params[3] == -1) |
|
faluco@1498
|
110 |
{ |
|
faluco@1498
|
111 |
pActivator = NULL; |
|
faluco@1498
|
112 |
} else { |
|
faluco@1498
|
113 |
ENTINDEX_TO_CBASEENTITY(params[3], pActivator); |
|
faluco@1498
|
114 |
} |
|
faluco@1498
|
115 |
if (params[4] == -1) |
|
faluco@1498
|
116 |
{ |
|
faluco@1498
|
117 |
pCaller = NULL; |
|
faluco@1498
|
118 |
} else { |
|
faluco@1498
|
119 |
ENTINDEX_TO_CBASEENTITY(params[4], pCaller); |
|
faluco@1498
|
120 |
} |
|
faluco@1498
|
121 |
|
|
faluco@1498
|
122 |
*(void **)vptr = pDest; |
|
faluco@1498
|
123 |
vptr += sizeof(void *); |
|
faluco@1498
|
124 |
*(const char **)vptr = inputname; |
|
faluco@1498
|
125 |
vptr += sizeof(const char *); |
|
faluco@1498
|
126 |
*(CBaseEntity **)vptr = pActivator; |
|
faluco@1498
|
127 |
vptr += sizeof(CBaseEntity *); |
|
faluco@1498
|
128 |
*(CBaseEntity **)vptr = pCaller; |
|
faluco@1498
|
129 |
vptr += sizeof(CBaseEntity *); |
|
faluco@1498
|
130 |
memcpy(vptr, g_Variant_t, SIZEOF_VARIANT_T); |
|
faluco@1498
|
131 |
vptr += SIZEOF_VARIANT_T; |
|
faluco@1498
|
132 |
*(int *)vptr = params[5]; |
|
faluco@1498
|
133 |
|
|
faluco@1498
|
134 |
bool ret; |
|
faluco@1498
|
135 |
g_pAcceptInput->Execute(vstk, &ret); |
|
faluco@1498
|
136 |
|
|
faluco@1498
|
137 |
_init_variant_t(); |
|
faluco@1498
|
138 |
|
|
faluco@1498
|
139 |
return (ret) ? 1 : 0; |
|
faluco@1498
|
140 |
} |
|
faluco@1498
|
141 |
|
|
faluco@1498
|
142 |
static cell_t SetVariantBool(IPluginContext *pContext, const cell_t *params) |
|
faluco@1498
|
143 |
{ |
|
faluco@1498
|
144 |
unsigned char *vptr = g_Variant_t; |
|
faluco@1498
|
145 |
|
|
faluco@1498
|
146 |
*(bool *)vptr = (params[1]) ? true : false; |
|
faluco@1498
|
147 |
vptr += sizeof(int)*3 + sizeof(unsigned long); |
|
faluco@1498
|
148 |
*(fieldtype_t *)vptr = FIELD_BOOLEAN; |
|
faluco@1498
|
149 |
|
|
faluco@1498
|
150 |
return 1; |
|
faluco@1498
|
151 |
} |
|
faluco@1498
|
152 |
|
|
faluco@1498
|
153 |
static cell_t SetVariantString(IPluginContext *pContext, const cell_t *params) |
|
faluco@1498
|
154 |
{ |
|
faluco@1498
|
155 |
char *str; |
|
faluco@1498
|
156 |
unsigned char *vptr = g_Variant_t; |
|
faluco@1498
|
157 |
|
|
faluco@1498
|
158 |
pContext->LocalToString(params[1], &str); |
|
faluco@1498
|
159 |
|
|
faluco@1498
|
160 |
*(string_t *)vptr = MAKE_STRING(str); |
|
faluco@1498
|
161 |
vptr += sizeof(int)*3 + sizeof(unsigned long); |
|
faluco@1498
|
162 |
*(fieldtype_t *)vptr = FIELD_STRING; |
|
faluco@1498
|
163 |
|
|
faluco@1498
|
164 |
return 1; |
|
faluco@1498
|
165 |
} |
|
faluco@1498
|
166 |
|
|
faluco@1498
|
167 |
static cell_t SetVariantInt(IPluginContext *pContext, const cell_t *params) |
|
faluco@1498
|
168 |
{ |
|
faluco@1498
|
169 |
unsigned char *vptr = g_Variant_t; |
|
faluco@1498
|
170 |
|
|
faluco@1498
|
171 |
*(int *)vptr = params[1]; |
|
faluco@1498
|
172 |
vptr += sizeof(int)*3 + sizeof(unsigned long); |
|
faluco@1498
|
173 |
*(fieldtype_t *)vptr = FIELD_INTEGER; |
|
faluco@1498
|
174 |
|
|
faluco@1498
|
175 |
return 1; |
|
faluco@1498
|
176 |
} |
|
faluco@1498
|
177 |
|
|
faluco@1498
|
178 |
static cell_t SetVariantFloat(IPluginContext *pContext, const cell_t *params) |
|
faluco@1498
|
179 |
{ |
|
faluco@1498
|
180 |
unsigned char *vptr = g_Variant_t; |
|
faluco@1498
|
181 |
|
|
faluco@1498
|
182 |
*(float *)vptr = sp_ctof(params[1]); |
|
faluco@1498
|
183 |
vptr += sizeof(int)*3 + sizeof(unsigned long); |
|
faluco@1498
|
184 |
*(fieldtype_t *)vptr = FIELD_FLOAT; |
|
faluco@1498
|
185 |
|
|
faluco@1498
|
186 |
return 1; |
|
faluco@1498
|
187 |
} |
|
faluco@1498
|
188 |
|
|
faluco@1498
|
189 |
static cell_t SetVariantVector3D(IPluginContext *pContext, const cell_t *params) |
|
faluco@1498
|
190 |
{ |
|
faluco@1498
|
191 |
cell_t *val; |
|
faluco@1498
|
192 |
unsigned char *vptr = g_Variant_t; |
|
faluco@1498
|
193 |
|
|
faluco@1498
|
194 |
pContext->LocalToPhysAddr(params[1], &val); |
|
faluco@1498
|
195 |
|
|
faluco@1498
|
196 |
*(float *)vptr = sp_ctof(val[0]); |
|
faluco@1498
|
197 |
vptr += sizeof(float); |
|
faluco@1498
|
198 |
*(float *)vptr = sp_ctof(val[1]); |
|
faluco@1498
|
199 |
vptr += sizeof(float); |
|
faluco@1498
|
200 |
*(float *)vptr = sp_ctof(val[2]); |
|
faluco@1498
|
201 |
vptr += sizeof(float) + sizeof(unsigned long); |
|
faluco@1498
|
202 |
*(fieldtype_t *)vptr = FIELD_VECTOR; |
|
faluco@1498
|
203 |
|
|
faluco@1498
|
204 |
return 1; |
|
faluco@1498
|
205 |
} |
|
faluco@1498
|
206 |
|
|
faluco@1498
|
207 |
static cell_t SetVariantPosVector3D(IPluginContext *pContext, const cell_t *params) |
|
faluco@1498
|
208 |
{ |
|
faluco@1498
|
209 |
cell_t *val; |
|
faluco@1498
|
210 |
unsigned char *vptr = g_Variant_t; |
|
faluco@1498
|
211 |
|
|
faluco@1498
|
212 |
pContext->LocalToPhysAddr(params[1], &val); |
|
faluco@1498
|
213 |
|
|
faluco@1498
|
214 |
*(float *)vptr = sp_ctof(val[0]); |
|
faluco@1498
|
215 |
vptr += sizeof(float); |
|
faluco@1498
|
216 |
*(float *)vptr = sp_ctof(val[1]); |
|
faluco@1498
|
217 |
vptr += sizeof(float); |
|
faluco@1498
|
218 |
*(float *)vptr = sp_ctof(val[2]); |
|
faluco@1498
|
219 |
vptr += sizeof(float) + sizeof(unsigned long); |
|
faluco@1498
|
220 |
*(fieldtype_t *)vptr = FIELD_POSITION_VECTOR; |
|
faluco@1498
|
221 |
|
|
faluco@1498
|
222 |
return 1; |
|
faluco@1498
|
223 |
} |
|
faluco@1498
|
224 |
|
|
faluco@1498
|
225 |
static cell_t SetVariantColor(IPluginContext *pContext, const cell_t *params) |
|
faluco@1498
|
226 |
{ |
|
faluco@1498
|
227 |
cell_t *val; |
|
faluco@1498
|
228 |
unsigned char *vptr = g_Variant_t; |
|
faluco@1498
|
229 |
|
|
faluco@1498
|
230 |
pContext->LocalToPhysAddr(params[1], &val); |
|
faluco@1498
|
231 |
|
|
faluco@1498
|
232 |
*(unsigned char *)vptr = val[0]; |
|
faluco@1498
|
233 |
vptr += sizeof(unsigned char); |
|
faluco@1498
|
234 |
*(unsigned char *)vptr = val[1]; |
|
faluco@1498
|
235 |
vptr += sizeof(unsigned char); |
|
faluco@1498
|
236 |
*(unsigned char *)vptr = val[2]; |
|
faluco@1498
|
237 |
vptr += sizeof(unsigned char); |
|
faluco@1498
|
238 |
*(unsigned char *)vptr = val[3]; |
|
faluco@1498
|
239 |
vptr += sizeof(unsigned char) + sizeof(int)*2 + sizeof(unsigned long); |
|
faluco@1498
|
240 |
*(fieldtype_t *)vptr = FIELD_COLOR32; |
|
faluco@1498
|
241 |
|
|
faluco@1498
|
242 |
return 1; |
|
faluco@1498
|
243 |
} |
|
faluco@1498
|
244 |
|
|
faluco@1498
|
245 |
static cell_t SetVariantEntity(IPluginContext *pContext, const cell_t *params) |
|
faluco@1498
|
246 |
{ |
|
faluco@1498
|
247 |
CBaseEntity *pEntity; |
|
faluco@1498
|
248 |
unsigned char *vptr = g_Variant_t; |
|
faluco@1498
|
249 |
CBaseHandle bHandle; |
|
faluco@1498
|
250 |
|
|
faluco@1498
|
251 |
ENTINDEX_TO_CBASEENTITY(params[1], pEntity); |
|
faluco@1498
|
252 |
bHandle = reinterpret_cast<IHandleEntity *>(pEntity)->GetRefEHandle(); |
|
faluco@1498
|
253 |
|
|
faluco@1498
|
254 |
vptr += sizeof(int)*3; |
|
faluco@1498
|
255 |
*(unsigned long *)vptr = (unsigned long)(bHandle.ToInt()); |
|
faluco@1498
|
256 |
vptr += sizeof(unsigned long); |
|
faluco@1498
|
257 |
*(fieldtype_t *)vptr = FIELD_EHANDLE; |
|
faluco@1498
|
258 |
|
|
faluco@1498
|
259 |
return 1; |
|
faluco@1498
|
260 |
} |
|
faluco@1498
|
261 |
|
|
faluco@1498
|
262 |
sp_nativeinfo_t g_EntInputNatives[] = |
|
faluco@1498
|
263 |
{ |
|
faluco@1498
|
264 |
{"AcceptEntityInput", AcceptEntityInput}, |
|
faluco@1498
|
265 |
{"SetVariantBool", SetVariantBool}, |
|
faluco@1498
|
266 |
{"SetVariantString", SetVariantString}, |
|
faluco@1498
|
267 |
{"SetVariantInt", SetVariantInt}, |
|
faluco@1498
|
268 |
{"SetVariantFloat", SetVariantFloat}, |
|
faluco@1498
|
269 |
{"SetVariantVector3D", SetVariantVector3D}, |
|
faluco@1498
|
270 |
{"SetVariantPosVector3D", SetVariantPosVector3D}, |
|
faluco@1498
|
271 |
{"SetVariantColor", SetVariantColor}, |
|
faluco@1498
|
272 |
{"SetVariantEntity", SetVariantEntity}, |
|
faluco@1498
|
273 |
{NULL, NULL}, |
|
faluco@1498
|
274 |
}; |