|
faluco@1031
|
1 |
/** |
|
faluco@1031
|
2 |
* vim: set ts=4 : |
|
ds@1330
|
3 |
* ============================================================================= |
|
dvander@1233
|
4 |
* SourceMod SDKTools Extension |
|
ds@3099
|
5 |
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved. |
|
ds@1330
|
6 |
* ============================================================================= |
|
faluco@1031
|
7 |
* |
|
ds@1330
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1330
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1330
|
10 |
* Free Software Foundation. |
|
dvander@1233
|
11 |
* |
|
ds@1330
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1330
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1330
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1330
|
15 |
* details. |
|
dvander@1233
|
16 |
* |
|
ds@1330
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1330
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
dvander@1233
|
19 |
* |
|
ds@1330
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1330
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1330
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1330
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1330
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1330
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1330
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1330
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
faluco@1031
|
28 |
* |
|
faluco@1031
|
29 |
* Version: $Id$ |
|
faluco@1031
|
30 |
*/ |
|
faluco@1031
|
31 |
|
|
dvander@1169
|
32 |
#include <stdlib.h> |
|
dvander@1152
|
33 |
#include <sh_string.h> |
|
dvander@954
|
34 |
#include "extension.h" |
|
dvander@954
|
35 |
#include "vcallbuilder.h" |
|
dvander@954
|
36 |
#include "vnatives.h" |
|
dvander@1169
|
37 |
#include "vhelpers.h" |
|
ds@1240
|
38 |
#include "vglobals.h" |
|
dvander@1169
|
39 |
#include "CellRecipientFilter.h" |
|
pred@2107
|
40 |
#include <inetchannel.h> |
|
pred@2107
|
41 |
#include <iclient.h> |
|
pred@2109
|
42 |
#include "iserver.h" |
|
dvander@954
|
43 |
|
|
faluco@1560
|
44 |
SourceHook::List<ValveCall *> g_RegCalls; |
|
faluco@1560
|
45 |
SourceHook::List<ICallWrapper *> g_CallWraps; |
|
dvander@954
|
46 |
|
|
dvander@985
|
47 |
inline void InitPass(ValvePassInfo &info, ValveType vtype, PassType type, unsigned int flags, unsigned int decflags=0) |
|
dvander@954
|
48 |
{ |
|
dvander@985
|
49 |
info.decflags = decflags; |
|
dvander@954
|
50 |
info.encflags = 0; |
|
dvander@954
|
51 |
info.flags = flags; |
|
dvander@954
|
52 |
info.type = type; |
|
dvander@954
|
53 |
info.vtype = vtype; |
|
dvander@954
|
54 |
} |
|
dvander@954
|
55 |
|
|
dvander@954
|
56 |
#define START_CALL() \ |
|
dvander@954
|
57 |
unsigned char *vptr = pCall->stk_get(); |
|
dvander@954
|
58 |
|
|
dvander@954
|
59 |
#define FINISH_CALL_SIMPLE(vret) \ |
|
dvander@954
|
60 |
pCall->call->Execute(vptr, vret); \ |
|
dvander@954
|
61 |
pCall->stk_put(vptr); |
|
dvander@954
|
62 |
|
|
dvander@954
|
63 |
#define ENCODE_VALVE_PARAM(num, which, vnum) \ |
|
dvander@954
|
64 |
if (EncodeValveParam(pContext, \ |
|
dvander@954
|
65 |
params[num], \ |
|
dvander@987
|
66 |
pCall, \ |
|
dvander@954
|
67 |
&pCall->which[vnum], \ |
|
dvander@987
|
68 |
vptr) \ |
|
dvander@954
|
69 |
== Data_Fail) \ |
|
dvander@954
|
70 |
{ \ |
|
dvander@954
|
71 |
return 0; \ |
|
dvander@954
|
72 |
} |
|
dvander@954
|
73 |
|
|
dvander@954
|
74 |
#define DECODE_VALVE_PARAM(num, which, vnum) \ |
|
dvander@954
|
75 |
if (DecodeValveParam(pContext, \ |
|
dvander@954
|
76 |
params[num], \ |
|
dvander@987
|
77 |
pCall, \ |
|
dvander@954
|
78 |
&pCall->which[vnum], \ |
|
dvander@987
|
79 |
vptr) \ |
|
dvander@954
|
80 |
== Data_Fail) \ |
|
dvander@954
|
81 |
{ \ |
|
dvander@954
|
82 |
return 0; \ |
|
dvander@954
|
83 |
} |
|
dvander@954
|
84 |
|
|
dvander@954
|
85 |
bool CreateBaseCall(const char *name, |
|
dvander@954
|
86 |
ValveCallType vcalltype, |
|
dvander@954
|
87 |
const ValvePassInfo *retinfo, |
|
dvander@954
|
88 |
const ValvePassInfo params[], |
|
dvander@954
|
89 |
unsigned int numParams, |
|
dvander@954
|
90 |
ValveCall **vaddr) |
|
dvander@954
|
91 |
{ |
|
dvander@954
|
92 |
int offset; |
|
dvander@954
|
93 |
ValveCall *call; |
|
dvander@954
|
94 |
if (g_pGameConf->GetOffset(name, &offset)) |
|
dvander@954
|
95 |
{ |
|
dvander@954
|
96 |
call = CreateValveVCall(offset, vcalltype, retinfo, params, numParams); |
|
dvander@954
|
97 |
if (call) |
|
dvander@954
|
98 |
{ |
|
dvander@954
|
99 |
g_RegCalls.push_back(call); |
|
dvander@954
|
100 |
} |
|
dvander@954
|
101 |
*vaddr = call; |
|
dvander@954
|
102 |
return true; |
|
dvander@954
|
103 |
} else { |
|
pred@2485
|
104 |
void *addr = NULL; |
|
pred@2485
|
105 |
if (g_pGameConf->GetMemSig(name, &addr) && addr != NULL) |
|
dvander@954
|
106 |
{ |
|
dvander@954
|
107 |
call = CreateValveCall(addr, vcalltype, retinfo, params, numParams); |
|
dvander@954
|
108 |
if (call) |
|
dvander@954
|
109 |
{ |
|
dvander@954
|
110 |
g_RegCalls.push_back(call); |
|
dvander@954
|
111 |
} |
|
dvander@954
|
112 |
*vaddr = call; |
|
dvander@954
|
113 |
return true; |
|
dvander@954
|
114 |
} |
|
dvander@954
|
115 |
} |
|
dvander@954
|
116 |
return false; |
|
dvander@954
|
117 |
} |
|
dvander@954
|
118 |
|
|
dvander@954
|
119 |
static cell_t RemovePlayerItem(IPluginContext *pContext, const cell_t *params) |
|
dvander@954
|
120 |
{ |
|
dvander@954
|
121 |
static ValveCall *pCall = NULL; |
|
dvander@954
|
122 |
if (!pCall) |
|
dvander@954
|
123 |
{ |
|
dvander@954
|
124 |
ValvePassInfo pass[2]; |
|
ds@1168
|
125 |
InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); |
|
ds@1168
|
126 |
InitPass(pass[1], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); |
|
ds@1168
|
127 |
if (!CreateBaseCall("RemovePlayerItem", ValveCall_Player, &pass[1], pass, 1, &pCall)) |
|
dvander@954
|
128 |
{ |
|
dvander@954
|
129 |
return pContext->ThrowNativeError("\"RemovePlayerItem\" not supported by this mod"); |
|
dvander@954
|
130 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
131 |
return pContext->ThrowNativeError("\"RemovePlayerItem\" wrapper failed to initialize"); |
|
dvander@954
|
132 |
} |
|
dvander@954
|
133 |
} |
|
dvander@954
|
134 |
|
|
dvander@954
|
135 |
bool ret; |
|
dvander@954
|
136 |
START_CALL(); |
|
dvander@954
|
137 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
dvander@954
|
138 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
dvander@954
|
139 |
FINISH_CALL_SIMPLE(&ret); |
|
dvander@954
|
140 |
return ret ? 1 : 0; |
|
dvander@954
|
141 |
} |
|
dvander@954
|
142 |
|
|
dvander@954
|
143 |
static cell_t GiveNamedItem(IPluginContext *pContext, const cell_t *params) |
|
dvander@954
|
144 |
{ |
|
dvander@954
|
145 |
static ValveCall *pCall = NULL; |
|
dvander@954
|
146 |
if (!pCall) |
|
dvander@954
|
147 |
{ |
|
dvander@954
|
148 |
ValvePassInfo pass[3]; |
|
dvander@954
|
149 |
InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL); |
|
dvander@954
|
150 |
InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL); |
|
dvander@954
|
151 |
InitPass(pass[2], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); |
|
dvander@954
|
152 |
if (!CreateBaseCall("GiveNamedItem", ValveCall_Player, &pass[2], pass, 2, &pCall)) |
|
dvander@954
|
153 |
{ |
|
dvander@954
|
154 |
return pContext->ThrowNativeError("\"GiveNamedItem\" not supported by this mod"); |
|
dvander@954
|
155 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
156 |
return pContext->ThrowNativeError("\"GiveNamedItem\" wrapper failed to initialize"); |
|
dvander@954
|
157 |
} |
|
dvander@954
|
158 |
} |
|
dvander@954
|
159 |
|
|
dvander@954
|
160 |
CBaseEntity *pEntity = NULL; |
|
dvander@954
|
161 |
START_CALL(); |
|
dvander@954
|
162 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
dvander@954
|
163 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
dvander@954
|
164 |
DECODE_VALVE_PARAM(3, vparams, 1); |
|
dvander@954
|
165 |
FINISH_CALL_SIMPLE(&pEntity); |
|
dvander@954
|
166 |
|
|
pred@2746
|
167 |
return gamehelpers->EntityToBCompatRef(pEntity); |
|
dvander@954
|
168 |
} |
|
dvander@954
|
169 |
|
|
dvander@954
|
170 |
static cell_t GetPlayerWeaponSlot(IPluginContext *pContext, const cell_t *params) |
|
dvander@954
|
171 |
{ |
|
dvander@954
|
172 |
static ValveCall *pCall = NULL; |
|
dvander@954
|
173 |
if (!pCall) |
|
dvander@954
|
174 |
{ |
|
dvander@954
|
175 |
ValvePassInfo pass[2]; |
|
dvander@954
|
176 |
InitPass(pass[0], Valve_POD, PassType_Basic, PASSFLAG_BYVAL); |
|
dvander@954
|
177 |
InitPass(pass[1], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); |
|
dvander@954
|
178 |
if (!CreateBaseCall("Weapon_GetSlot", ValveCall_Player, &pass[1], pass, 1, &pCall)) |
|
dvander@954
|
179 |
{ |
|
dvander@954
|
180 |
return pContext->ThrowNativeError("\"Weapon_GetSlot\" not supported by this mod"); |
|
dvander@954
|
181 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
182 |
return pContext->ThrowNativeError("\"Weapon_GetSlot\" wrapper failed to initialize"); |
|
dvander@954
|
183 |
} |
|
dvander@954
|
184 |
} |
|
dvander@954
|
185 |
|
|
dvander@954
|
186 |
CBaseEntity *pEntity; |
|
dvander@954
|
187 |
START_CALL(); |
|
dvander@954
|
188 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
dvander@954
|
189 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
dvander@954
|
190 |
FINISH_CALL_SIMPLE(&pEntity); |
|
dvander@954
|
191 |
|
|
pred@2746
|
192 |
return gamehelpers->EntityToBCompatRef(pEntity); |
|
dvander@954
|
193 |
} |
|
dvander@954
|
194 |
|
|
ds@2583
|
195 |
#if SOURCE_ENGINE != SE_DARKMESSIAH |
|
ds@1240
|
196 |
static cell_t IgniteEntity(IPluginContext *pContext, const cell_t *params) |
|
dvander@955
|
197 |
{ |
|
dvander@955
|
198 |
static ValveCall *pCall = NULL; |
|
dvander@955
|
199 |
if (!pCall) |
|
dvander@955
|
200 |
{ |
|
dvander@955
|
201 |
ValvePassInfo pass[4]; |
|
dvander@955
|
202 |
InitPass(pass[0], Valve_Float, PassType_Float, PASSFLAG_BYVAL); |
|
dvander@955
|
203 |
InitPass(pass[1], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); |
|
dvander@955
|
204 |
InitPass(pass[2], Valve_Float, PassType_Float, PASSFLAG_BYVAL); |
|
dvander@955
|
205 |
InitPass(pass[3], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); |
|
dvander@980
|
206 |
if (!CreateBaseCall("Ignite", ValveCall_Entity, NULL, pass, 4, &pCall)) |
|
dvander@955
|
207 |
{ |
|
dvander@955
|
208 |
return pContext->ThrowNativeError("\"Ignite\" not supported by this mod"); |
|
dvander@955
|
209 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
210 |
return pContext->ThrowNativeError("\"Ignite\" wrapper failed to initialize"); |
|
dvander@955
|
211 |
} |
|
dvander@955
|
212 |
} |
|
dvander@955
|
213 |
|
|
dvander@955
|
214 |
START_CALL(); |
|
dvander@955
|
215 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
dvander@955
|
216 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
dvander@955
|
217 |
DECODE_VALVE_PARAM(3, vparams, 1); |
|
dvander@955
|
218 |
DECODE_VALVE_PARAM(4, vparams, 2); |
|
dvander@955
|
219 |
DECODE_VALVE_PARAM(5, vparams, 3); |
|
dvander@955
|
220 |
FINISH_CALL_SIMPLE(NULL); |
|
dvander@955
|
221 |
|
|
dvander@955
|
222 |
return 1; |
|
dvander@955
|
223 |
} |
|
ds@2583
|
224 |
#else |
|
ds@2583
|
225 |
/* Dark Messiah specific version */ |
|
ds@2583
|
226 |
static cell_t IgniteEntity(IPluginContext *pContext, const cell_t *params) |
|
ds@2583
|
227 |
{ |
|
ds@2583
|
228 |
static ValveCall *pCall = NULL; |
|
ds@2583
|
229 |
if (!pCall) |
|
ds@2583
|
230 |
{ |
|
ds@2583
|
231 |
ValvePassInfo pass[6]; |
|
ds@2583
|
232 |
InitPass(pass[0], Valve_Float, PassType_Float, PASSFLAG_BYVAL); |
|
ds@2583
|
233 |
InitPass(pass[1], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); |
|
ds@2583
|
234 |
InitPass(pass[2], Valve_Float, PassType_Float, PASSFLAG_BYVAL); |
|
ds@2583
|
235 |
InitPass(pass[3], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); |
|
ds@2583
|
236 |
InitPass(pass[4], Valve_POD, PassType_Basic, PASSFLAG_BYVAL); |
|
ds@2583
|
237 |
InitPass(pass[5], Valve_POD, PassType_Basic, PASSFLAG_BYVAL); |
|
ds@2583
|
238 |
if (!CreateBaseCall("Ignite", ValveCall_Entity, NULL, pass, 6, &pCall)) |
|
ds@2583
|
239 |
{ |
|
ds@2583
|
240 |
return pContext->ThrowNativeError("\"Ignite\" not supported by this mod"); |
|
ds@2583
|
241 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
242 |
return pContext->ThrowNativeError("\"Ignite\" wrapper failed to initialize"); |
|
ds@2583
|
243 |
} |
|
ds@2583
|
244 |
} |
|
ds@2583
|
245 |
|
|
ds@2583
|
246 |
START_CALL(); |
|
ds@2583
|
247 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
ds@2583
|
248 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
ds@2583
|
249 |
DECODE_VALVE_PARAM(3, vparams, 1); |
|
ds@2583
|
250 |
DECODE_VALVE_PARAM(4, vparams, 2); |
|
ds@2583
|
251 |
DECODE_VALVE_PARAM(5, vparams, 3); |
|
ds@2583
|
252 |
/* Not sure what these params do, but they appear to be the default values */ |
|
ds@2583
|
253 |
*(int *)(vptr + 14) = 3; |
|
ds@2583
|
254 |
*(int *)(vptr + 18) = 0; |
|
ds@2583
|
255 |
FINISH_CALL_SIMPLE(NULL); |
|
ds@2583
|
256 |
|
|
ds@2583
|
257 |
return 1; |
|
ds@2583
|
258 |
} |
|
ds@2583
|
259 |
#endif |
|
dvander@955
|
260 |
|
|
ds@1240
|
261 |
static cell_t ExtinguishEntity(IPluginContext *pContext, const cell_t *params) |
|
dvander@955
|
262 |
{ |
|
dvander@955
|
263 |
static ValveCall *pCall = NULL; |
|
dvander@955
|
264 |
if (!pCall) |
|
dvander@955
|
265 |
{ |
|
dvander@980
|
266 |
if (!CreateBaseCall("Extinguish", ValveCall_Entity, NULL, NULL, 0, &pCall)) |
|
dvander@955
|
267 |
{ |
|
dvander@955
|
268 |
return pContext->ThrowNativeError("\"Extinguish\" not supported by this mod"); |
|
dvander@955
|
269 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
270 |
return pContext->ThrowNativeError("\"Extinguish\" wrapper failed to initialize"); |
|
dvander@955
|
271 |
} |
|
dvander@955
|
272 |
} |
|
dvander@955
|
273 |
|
|
dvander@955
|
274 |
START_CALL(); |
|
dvander@955
|
275 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
dvander@955
|
276 |
FINISH_CALL_SIMPLE(NULL); |
|
dvander@955
|
277 |
|
|
dvander@955
|
278 |
return 1; |
|
dvander@955
|
279 |
} |
|
dvander@955
|
280 |
|
|
ds@1240
|
281 |
static cell_t TeleportEntity(IPluginContext *pContext, const cell_t *params) |
|
dvander@955
|
282 |
{ |
|
dvander@955
|
283 |
static ValveCall *pCall = NULL; |
|
dvander@955
|
284 |
if (!pCall) |
|
dvander@955
|
285 |
{ |
|
dvander@955
|
286 |
ValvePassInfo pass[3]; |
|
dvander@985
|
287 |
InitPass(pass[0], Valve_Vector, PassType_Basic, PASSFLAG_BYVAL, VDECODE_FLAG_ALLOWNULL); |
|
dvander@985
|
288 |
InitPass(pass[1], Valve_QAngle, PassType_Basic, PASSFLAG_BYVAL, VDECODE_FLAG_ALLOWNULL); |
|
dvander@985
|
289 |
InitPass(pass[2], Valve_Vector, PassType_Basic, PASSFLAG_BYVAL, VDECODE_FLAG_ALLOWNULL); |
|
dvander@980
|
290 |
if (!CreateBaseCall("Teleport", ValveCall_Entity, NULL, pass, 3, &pCall)) |
|
dvander@955
|
291 |
{ |
|
dvander@955
|
292 |
return pContext->ThrowNativeError("\"Teleport\" not supported by this mod"); |
|
dvander@955
|
293 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
294 |
return pContext->ThrowNativeError("\"Teleport\" wrapper failed to initialize"); |
|
dvander@955
|
295 |
} |
|
dvander@955
|
296 |
} |
|
dvander@955
|
297 |
|
|
dvander@955
|
298 |
START_CALL(); |
|
dvander@955
|
299 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
dvander@955
|
300 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
dvander@955
|
301 |
DECODE_VALVE_PARAM(3, vparams, 1); |
|
dvander@955
|
302 |
DECODE_VALVE_PARAM(4, vparams, 2); |
|
dvander@955
|
303 |
FINISH_CALL_SIMPLE(NULL); |
|
dvander@955
|
304 |
|
|
dvander@955
|
305 |
return 1; |
|
dvander@955
|
306 |
} |
|
dvander@955
|
307 |
|
|
ds@2400
|
308 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
dvander@1597
|
309 |
/* :TODO: This is Team Fortress 2 specific */ |
|
dvander@1597
|
310 |
static cell_t ForcePlayerSuicide(IPluginContext *pContext, const cell_t *params) |
|
dvander@1597
|
311 |
{ |
|
dvander@1597
|
312 |
static ValveCall *pCall = NULL; |
|
dvander@1597
|
313 |
if (!pCall) |
|
dvander@1597
|
314 |
{ |
|
dvander@1597
|
315 |
ValvePassInfo pass[2]; |
|
dvander@1597
|
316 |
InitPass(pass[0], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); |
|
dvander@1597
|
317 |
InitPass(pass[1], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); |
|
dvander@1597
|
318 |
if (!CreateBaseCall("CommitSuicide", ValveCall_Player, NULL, pass, 2, &pCall)) |
|
dvander@1597
|
319 |
{ |
|
dvander@1597
|
320 |
return pContext->ThrowNativeError("\"CommitSuicide\" not supported by this mod"); |
|
dvander@1597
|
321 |
} |
|
dvander@1597
|
322 |
else if (!pCall) |
|
dvander@1597
|
323 |
{ |
|
fyrenmoo@2710
|
324 |
return pContext->ThrowNativeError("\"CommitSuicide\" wrapper failed to initialize"); |
|
dvander@1597
|
325 |
} |
|
dvander@1597
|
326 |
} |
|
dvander@1597
|
327 |
|
|
dvander@1597
|
328 |
START_CALL(); |
|
dvander@1597
|
329 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
dvander@1597
|
330 |
*(bool *)(vptr + 4) = false; |
|
dvander@1597
|
331 |
*(bool *)(vptr + 5) = false; |
|
dvander@1597
|
332 |
FINISH_CALL_SIMPLE(NULL); |
|
dvander@1597
|
333 |
|
|
dvander@1597
|
334 |
return 1; |
|
dvander@1597
|
335 |
} |
|
dvander@1597
|
336 |
#else |
|
dvander@1151
|
337 |
static cell_t ForcePlayerSuicide(IPluginContext *pContext, const cell_t *params) |
|
dvander@1151
|
338 |
{ |
|
dvander@1151
|
339 |
static ValveCall *pCall = NULL; |
|
dvander@1151
|
340 |
if (!pCall) |
|
dvander@1151
|
341 |
{ |
|
dvander@1151
|
342 |
if (!CreateBaseCall("CommitSuicide", ValveCall_Player, NULL, NULL, 0, &pCall)) |
|
dvander@1151
|
343 |
{ |
|
dvander@1151
|
344 |
return pContext->ThrowNativeError("\"CommitSuicide\" not supported by this mod"); |
|
dvander@1151
|
345 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
346 |
return pContext->ThrowNativeError("\"CommitSuicide\" wrapper failed to initialize"); |
|
dvander@1151
|
347 |
} |
|
dvander@1151
|
348 |
} |
|
dvander@1151
|
349 |
|
|
dvander@1151
|
350 |
START_CALL(); |
|
dvander@1151
|
351 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
dvander@1151
|
352 |
FINISH_CALL_SIMPLE(NULL); |
|
dvander@1151
|
353 |
|
|
dvander@1151
|
354 |
return 1; |
|
dvander@1151
|
355 |
} |
|
dvander@1597
|
356 |
#endif |
|
dvander@1151
|
357 |
|
|
dvander@1106
|
358 |
static cell_t SetClientViewEntity(IPluginContext *pContext, const cell_t *params) |
|
dvander@1106
|
359 |
{ |
|
dvander@1106
|
360 |
IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); |
|
dvander@1106
|
361 |
if (player == NULL) |
|
dvander@1106
|
362 |
{ |
|
dvander@1106
|
363 |
return pContext->ThrowNativeError("Invalid client index %d", params[1]); |
|
dvander@1106
|
364 |
} |
|
dvander@1106
|
365 |
if (!player->IsInGame()) |
|
dvander@1106
|
366 |
{ |
|
dvander@1106
|
367 |
return pContext->ThrowNativeError("Client %d is not in game", params[1]); |
|
dvander@1106
|
368 |
} |
|
dvander@1106
|
369 |
|
|
fyrenmoo@2766
|
370 |
edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[2])); |
|
dvander@1106
|
371 |
if (!pEdict || pEdict->IsFree()) |
|
dvander@1106
|
372 |
{ |
|
dvander@1106
|
373 |
return pContext->ThrowNativeError("Entity %d is not valid", params[2]); |
|
dvander@1106
|
374 |
} |
|
dvander@1106
|
375 |
|
|
skamonkey@3913
|
376 |
#if SOURCE_ENGINE == SE_DOTA |
|
skamonkey@3913
|
377 |
engine->SetView(params[1], params[2]); |
|
skamonkey@3913
|
378 |
#else |
|
dvander@1106
|
379 |
engine->SetView(player->GetEdict(), pEdict); |
|
skamonkey@3913
|
380 |
#endif |
|
dvander@1106
|
381 |
|
|
dvander@1106
|
382 |
return 1; |
|
dvander@1106
|
383 |
} |
|
dvander@1106
|
384 |
|
|
faluco@1560
|
385 |
static SourceHook::String *g_lightstyle[MAX_LIGHTSTYLES] = {NULL}; |
|
dvander@1152
|
386 |
static cell_t SetLightStyle(IPluginContext *pContext, const cell_t *params) |
|
dvander@1152
|
387 |
{ |
|
dvander@1152
|
388 |
int style = params[1]; |
|
dvander@1152
|
389 |
if (style >= MAX_LIGHTSTYLES) |
|
dvander@1152
|
390 |
{ |
|
dvander@1152
|
391 |
return pContext->ThrowNativeError("Light style %d is invalid (range: 0-%d)", style, MAX_LIGHTSTYLES - 1); |
|
dvander@1152
|
392 |
} |
|
dvander@1152
|
393 |
|
|
dvander@1152
|
394 |
if (g_lightstyle[style] == NULL) |
|
dvander@1152
|
395 |
{ |
|
dvander@1154
|
396 |
/* We allocate and never free this because the Engine wants to hold onto it :\ |
|
dvander@1154
|
397 |
* in theory we could hook light style and know whether we're supposed to free |
|
dvander@1154
|
398 |
* this or not on shutdown, but for ~4K of memory MAX, it doesn't seem worth it yet. |
|
dvander@1154
|
399 |
* So, it's a :TODO:! |
|
dvander@1154
|
400 |
*/ |
|
faluco@1560
|
401 |
g_lightstyle[style] = new SourceHook::String(); |
|
dvander@1152
|
402 |
} |
|
dvander@1152
|
403 |
|
|
dvander@1152
|
404 |
char *str; |
|
dvander@1152
|
405 |
pContext->LocalToString(params[2], &str); |
|
dvander@1152
|
406 |
|
|
dvander@1152
|
407 |
g_lightstyle[style]->assign(str); |
|
dvander@1152
|
408 |
|
|
dvander@1153
|
409 |
engine->LightStyle(style, g_lightstyle[style]->c_str()); |
|
dvander@1152
|
410 |
|
|
dvander@1152
|
411 |
return 1; |
|
dvander@1152
|
412 |
} |
|
dvander@1152
|
413 |
|
|
dvander@1169
|
414 |
static cell_t SlapPlayer(IPluginContext *pContext, const cell_t *params) |
|
dvander@1169
|
415 |
{ |
|
dvander@1169
|
416 |
static bool s_slap_supported = false; |
|
dvander@1169
|
417 |
static bool s_slap_setup = false; |
|
dvander@1169
|
418 |
static ICallWrapper *s_teleport = NULL; |
|
ds@1171
|
419 |
static int s_health_offs = 0; |
|
dvander@1169
|
420 |
static int s_sound_count = 0; |
|
dvander@1169
|
421 |
static int s_frag_offs = 0; |
|
dvander@1169
|
422 |
|
|
dvander@1169
|
423 |
if (!s_slap_setup) |
|
dvander@1169
|
424 |
{ |
|
dvander@1169
|
425 |
int tries = 0; |
|
dvander@1169
|
426 |
|
|
dvander@1169
|
427 |
s_slap_setup = true; |
|
dvander@1169
|
428 |
|
|
dvander@1169
|
429 |
if (IsTeleportSupported()) |
|
dvander@1169
|
430 |
{ |
|
dvander@1169
|
431 |
tries++; |
|
dvander@1169
|
432 |
} |
|
dvander@1169
|
433 |
if (IsGetVelocitySupported()) |
|
dvander@1169
|
434 |
{ |
|
dvander@1169
|
435 |
tries++; |
|
dvander@1169
|
436 |
} |
|
dvander@1169
|
437 |
|
|
dvander@1169
|
438 |
/* Setup health */ |
|
dvander@1169
|
439 |
if (g_pGameConf->GetOffset("m_iHealth", &s_health_offs) && s_health_offs) |
|
dvander@1169
|
440 |
{ |
|
dvander@1169
|
441 |
tries++; |
|
dvander@1169
|
442 |
} |
|
dvander@1169
|
443 |
|
|
dvander@1169
|
444 |
if (tries == 3) |
|
dvander@1169
|
445 |
{ |
|
dvander@1169
|
446 |
s_slap_supported = true; |
|
dvander@1169
|
447 |
|
|
dvander@1169
|
448 |
const char *key; |
|
dvander@1169
|
449 |
if ((key = g_pGameConf->GetKeyValue("SlapSoundCount")) != NULL) |
|
dvander@1169
|
450 |
{ |
|
dvander@1169
|
451 |
s_sound_count = atoi(key); |
|
dvander@1169
|
452 |
} |
|
dvander@1169
|
453 |
} |
|
dvander@1169
|
454 |
} |
|
dvander@1169
|
455 |
|
|
dvander@1169
|
456 |
if (!s_slap_supported) |
|
dvander@1169
|
457 |
{ |
|
dvander@1169
|
458 |
return pContext->ThrowNativeError("This function is not supported on this mod"); |
|
dvander@1169
|
459 |
} |
|
dvander@1169
|
460 |
|
|
dvander@1169
|
461 |
/* First check if the client is valid */ |
|
pred@2746
|
462 |
IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); |
|
dvander@1169
|
463 |
if (!player) |
|
dvander@1169
|
464 |
{ |
|
pred@2746
|
465 |
return pContext->ThrowNativeError("Client %d is not valid", params[1]); |
|
dvander@1169
|
466 |
} else if (!player->IsInGame()) { |
|
pred@2746
|
467 |
return pContext->ThrowNativeError("Client %d is not in game", params[1]); |
|
dvander@1169
|
468 |
} |
|
dvander@1169
|
469 |
|
|
dvander@1169
|
470 |
edict_t *pEdict = player->GetEdict(); |
|
dvander@1169
|
471 |
CBaseEntity *pEntity = pEdict->GetUnknown()->GetBaseEntity(); |
|
dvander@1169
|
472 |
|
|
dvander@1169
|
473 |
/* See if we should be taking away health */ |
|
dvander@1169
|
474 |
bool should_slay = false; |
|
dvander@1169
|
475 |
if (params[2]) |
|
dvander@1169
|
476 |
{ |
|
ds@2583
|
477 |
#if SOURCE_ENGINE != SE_DARKMESSIAH |
|
dvander@1169
|
478 |
int *health = (int *)((char *)pEntity + s_health_offs); |
|
ds@2583
|
479 |
|
|
dvander@1169
|
480 |
if (*health - params[2] <= 0) |
|
dvander@1169
|
481 |
{ |
|
dvander@1169
|
482 |
*health = 1; |
|
dvander@1169
|
483 |
should_slay = true; |
|
dvander@1169
|
484 |
} else { |
|
dvander@1169
|
485 |
*health -= params[2]; |
|
dvander@1169
|
486 |
} |
|
ds@2583
|
487 |
#else |
|
ds@2583
|
488 |
float *health = (float *)((char *)pEntity + s_health_offs); |
|
ds@2583
|
489 |
|
|
ds@2583
|
490 |
if (*health - (float)params[2] <= 0) |
|
ds@2583
|
491 |
{ |
|
ds@2583
|
492 |
*health = 1.0f; |
|
ds@2583
|
493 |
should_slay = true; |
|
ds@2583
|
494 |
} else { |
|
ds@2583
|
495 |
*health -= (float)params[2]; |
|
ds@2583
|
496 |
} |
|
ds@2583
|
497 |
#endif |
|
dvander@1169
|
498 |
} |
|
dvander@1169
|
499 |
|
|
dvander@1169
|
500 |
/* Teleport in a random direction - thank you, Mani!*/ |
|
dvander@1169
|
501 |
Vector velocity; |
|
dvander@1169
|
502 |
GetVelocity(pEntity, &velocity, NULL); |
|
dvander@1169
|
503 |
velocity.x += ((rand() % 180) + 50) * (((rand() % 2) == 1) ? -1 : 1); |
|
dvander@1169
|
504 |
velocity.y += ((rand() % 180) + 50) * (((rand() % 2) == 1) ? -1 : 1); |
|
dvander@1169
|
505 |
velocity.z += rand() % 200 + 100; |
|
dvander@1169
|
506 |
Teleport(pEntity, NULL, NULL, &velocity); |
|
dvander@1169
|
507 |
|
|
dvander@1169
|
508 |
/* Play a random sound */ |
|
dvander@1169
|
509 |
if (params[3] && s_sound_count > 0) |
|
dvander@1169
|
510 |
{ |
|
dvander@1169
|
511 |
char name[48]; |
|
dvander@1169
|
512 |
const char *sound_name; |
|
dvander@1169
|
513 |
cell_t player_list[256], total_players = 0; |
|
dvander@1169
|
514 |
int maxClients = playerhelpers->GetMaxClients(); |
|
dvander@1169
|
515 |
|
|
dvander@1169
|
516 |
int r = (rand() % s_sound_count) + 1; |
|
dvander@1169
|
517 |
snprintf(name, sizeof(name), "SlapSound%d", r); |
|
dvander@1169
|
518 |
|
|
dvander@1169
|
519 |
if ((sound_name = g_pGameConf->GetKeyValue(name)) != NULL) |
|
dvander@1169
|
520 |
{ |
|
dvander@1169
|
521 |
IGamePlayer *other; |
|
dvander@1169
|
522 |
for (int i=1; i<=maxClients; i++) |
|
dvander@1169
|
523 |
{ |
|
dvander@1169
|
524 |
other = playerhelpers->GetGamePlayer(i); |
|
dvander@1169
|
525 |
if (other->IsInGame()) |
|
dvander@1169
|
526 |
{ |
|
dvander@1169
|
527 |
player_list[total_players++] = i; |
|
dvander@1169
|
528 |
} |
|
dvander@1169
|
529 |
} |
|
dvander@1169
|
530 |
|
|
dvander@1169
|
531 |
const Vector & pos = pEdict->GetCollideable()->GetCollisionOrigin(); |
|
dvander@1169
|
532 |
CellRecipientFilter rf; |
|
dvander@1169
|
533 |
rf.SetToReliable(true); |
|
dvander@1169
|
534 |
rf.Initialize(player_list, total_players); |
|
skamonkey@3613
|
535 |
#if SOURCE_ENGINE == SE_ORANGEBOXVALVE || SOURCE_ENGINE == SE_CSS |
|
skamonkey@3564
|
536 |
engsound->EmitSound(rf, params[1], CHAN_AUTO, sound_name, VOL_NORM, ATTN_NORM, 0, PITCH_NORM, 0, &pos); |
|
skamonkey@3564
|
537 |
#elif SOURCE_ENGINE < SE_PORTAL2 |
|
pred@2746
|
538 |
engsound->EmitSound(rf, params[1], CHAN_AUTO, sound_name, VOL_NORM, ATTN_NORM, 0, PITCH_NORM, &pos); |
|
skamonkey@3515
|
539 |
#else |
|
skamonkey@3515
|
540 |
engsound->EmitSound(rf, params[1], CHAN_AUTO, sound_name, -1, sound_name, VOL_NORM, ATTN_NORM, 0, 0, PITCH_NORM, &pos); |
|
skamonkey@3515
|
541 |
#endif |
|
dvander@1169
|
542 |
} |
|
dvander@1169
|
543 |
} |
|
dvander@1169
|
544 |
|
|
dvander@1169
|
545 |
if (!s_frag_offs) |
|
dvander@1169
|
546 |
{ |
|
dvander@1169
|
547 |
const char *frag_prop = g_pGameConf->GetKeyValue("m_iFrags"); |
|
dvander@1169
|
548 |
if (frag_prop) |
|
dvander@1169
|
549 |
{ |
|
dvander@1169
|
550 |
datamap_t *pMap = gamehelpers->GetDataMap(pEntity); |
|
dvander@1169
|
551 |
typedescription_t *pType = gamehelpers->FindInDataMap(pMap, frag_prop); |
|
dvander@1169
|
552 |
if (pType != NULL) |
|
dvander@1169
|
553 |
{ |
|
ds@3099
|
554 |
s_frag_offs = GetTypeDescOffs(pType); |
|
dvander@1169
|
555 |
} |
|
dvander@1169
|
556 |
} |
|
dvander@1169
|
557 |
if (!s_frag_offs) |
|
dvander@1169
|
558 |
{ |
|
dvander@1169
|
559 |
s_frag_offs = -1; |
|
dvander@1169
|
560 |
} |
|
dvander@1169
|
561 |
} |
|
dvander@1169
|
562 |
|
|
dvander@1169
|
563 |
int old_frags = 0; |
|
dvander@1169
|
564 |
if (s_frag_offs > 0) |
|
dvander@1169
|
565 |
{ |
|
dvander@1169
|
566 |
old_frags = *(int *)((char *)pEntity + s_frag_offs); |
|
dvander@1169
|
567 |
} |
|
dvander@1169
|
568 |
|
|
dvander@1169
|
569 |
/* Force suicide */ |
|
dvander@1169
|
570 |
if (should_slay) |
|
dvander@1169
|
571 |
{ |
|
skamonkey@3854
|
572 |
#if SOURCE_ENGINE == SE_DOTA |
|
skamonkey@3913
|
573 |
engine->ClientCommand(params[1], "kill\n"); |
|
skamonkey@3854
|
574 |
#else |
|
dvander@1169
|
575 |
pluginhelpers->ClientCommand(pEdict, "kill\n"); |
|
skamonkey@3854
|
576 |
#endif |
|
dvander@1169
|
577 |
} |
|
dvander@1169
|
578 |
|
|
dvander@1169
|
579 |
if (s_frag_offs > 0) |
|
dvander@1169
|
580 |
{ |
|
dvander@1169
|
581 |
*(int *)((char *)pEntity + s_frag_offs) = old_frags; |
|
dvander@1169
|
582 |
} |
|
dvander@1169
|
583 |
|
|
dvander@1169
|
584 |
return 1; |
|
dvander@1169
|
585 |
} |
|
dvander@1169
|
586 |
|
|
faluco@1219
|
587 |
static cell_t GetClientEyePosition(IPluginContext *pContext, const cell_t *params) |
|
faluco@1219
|
588 |
{ |
|
faluco@1219
|
589 |
IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); |
|
faluco@1219
|
590 |
if (player == NULL) |
|
faluco@1219
|
591 |
{ |
|
faluco@1219
|
592 |
return pContext->ThrowNativeError("Invalid client index %d", params[1]); |
|
faluco@1219
|
593 |
} |
|
faluco@1219
|
594 |
if (!player->IsInGame()) |
|
faluco@1219
|
595 |
{ |
|
faluco@1219
|
596 |
return pContext->ThrowNativeError("Client %d is not in game", params[1]); |
|
faluco@1219
|
597 |
} |
|
faluco@1219
|
598 |
|
|
faluco@1219
|
599 |
Vector pos; |
|
skamonkey@3913
|
600 |
#if SOURCE_ENGINE == SE_DOTA |
|
skamonkey@3913
|
601 |
serverClients->ClientEarPosition(params[1], &pos); |
|
skamonkey@3913
|
602 |
#else |
|
faluco@1219
|
603 |
serverClients->ClientEarPosition(player->GetEdict(), &pos); |
|
skamonkey@3913
|
604 |
#endif |
|
faluco@1219
|
605 |
|
|
faluco@1219
|
606 |
cell_t *addr; |
|
faluco@1219
|
607 |
pContext->LocalToPhysAddr(params[2], &addr); |
|
faluco@1219
|
608 |
addr[0] = sp_ftoc(pos.x); |
|
faluco@1219
|
609 |
addr[1] = sp_ftoc(pos.y); |
|
faluco@1219
|
610 |
addr[2] = sp_ftoc(pos.z); |
|
faluco@1219
|
611 |
|
|
faluco@1219
|
612 |
return 1; |
|
faluco@1219
|
613 |
} |
|
faluco@1219
|
614 |
|
|
faluco@1219
|
615 |
static cell_t GetClientEyeAngles(IPluginContext *pContext, const cell_t *params) |
|
faluco@1219
|
616 |
{ |
|
pred@2746
|
617 |
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]); |
|
dvander@1611
|
618 |
|
|
dvander@1611
|
619 |
if (!pPlayer) |
|
faluco@1219
|
620 |
{ |
|
pred@2746
|
621 |
return pContext->ThrowNativeError("Invalid client index %d", params[1]); |
|
dvander@1611
|
622 |
} |
|
dvander@1611
|
623 |
else if (!pPlayer->IsInGame()) |
|
dvander@1611
|
624 |
{ |
|
pred@2746
|
625 |
return pContext->ThrowNativeError("Client %d is not in game", params[1]); |
|
faluco@1219
|
626 |
} |
|
faluco@1219
|
627 |
|
|
dvander@1611
|
628 |
edict_t *pEdict = pPlayer->GetEdict(); |
|
dvander@1611
|
629 |
CBaseEntity *pEntity = pEdict->GetUnknown() ? pEdict->GetUnknown()->GetBaseEntity() : NULL; |
|
dvander@1611
|
630 |
|
|
dvander@1611
|
631 |
/* We always set the angles for backwards compatibility -- |
|
dvander@1611
|
632 |
* The original function had no return value. |
|
dvander@1611
|
633 |
*/ |
|
dvander@1611
|
634 |
QAngle angles; |
|
dvander@1611
|
635 |
bool got_angles = false; |
|
dvander@1611
|
636 |
|
|
dvander@1612
|
637 |
if (pEntity != NULL) |
|
dvander@1611
|
638 |
{ |
|
dvander@1611
|
639 |
got_angles = GetEyeAngles(pEntity, &angles); |
|
dvander@1611
|
640 |
} |
|
faluco@1219
|
641 |
|
|
faluco@1219
|
642 |
cell_t *addr; |
|
faluco@1219
|
643 |
pContext->LocalToPhysAddr(params[2], &addr); |
|
dvander@1611
|
644 |
addr[0] = sp_ftoc(angles.x); |
|
dvander@1611
|
645 |
addr[1] = sp_ftoc(angles.y); |
|
dvander@1611
|
646 |
addr[2] = sp_ftoc(angles.z); |
|
faluco@1219
|
647 |
|
|
dvander@1611
|
648 |
return got_angles ? 1 : 0; |
|
faluco@1219
|
649 |
} |
|
faluco@1219
|
650 |
|
|
skamonkey@3280
|
651 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
skamonkey@3352
|
652 |
static cell_t NativeFindEntityByClassname(IPluginContext *pContext, const cell_t *params) |
|
skamonkey@3280
|
653 |
{ |
|
skamonkey@3280
|
654 |
char *searchname; |
|
skamonkey@3280
|
655 |
CBaseEntity *pEntity; |
|
skamonkey@3280
|
656 |
|
|
skamonkey@3280
|
657 |
if (params[1] == -1) |
|
skamonkey@3280
|
658 |
{ |
|
skamonkey@3280
|
659 |
pEntity = (CBaseEntity *)servertools->FirstEntity(); |
|
skamonkey@3280
|
660 |
} |
|
skamonkey@3280
|
661 |
else |
|
skamonkey@3280
|
662 |
{ |
|
skamonkey@3280
|
663 |
pEntity = gamehelpers->ReferenceToEntity(params[1]); |
|
skamonkey@3280
|
664 |
if (!pEntity) |
|
skamonkey@3280
|
665 |
{ |
|
skamonkey@3280
|
666 |
return pContext->ThrowNativeError("Entity %d (%d) is invalid", |
|
skamonkey@3280
|
667 |
gamehelpers->ReferenceToIndex(params[1]), |
|
skamonkey@3280
|
668 |
params[1]); |
|
skamonkey@3280
|
669 |
} |
|
john@3292
|
670 |
pEntity = (CBaseEntity *)servertools->NextEntity(pEntity); |
|
skamonkey@3280
|
671 |
} |
|
skamonkey@3280
|
672 |
|
|
skamonkey@3352
|
673 |
// it's tough to find a good ent these days |
|
skamonkey@3352
|
674 |
if (!pEntity) |
|
skamonkey@3352
|
675 |
{ |
|
skamonkey@3352
|
676 |
return -1; |
|
skamonkey@3352
|
677 |
} |
|
skamonkey@3352
|
678 |
|
|
skamonkey@3280
|
679 |
pContext->LocalToString(params[2], &searchname); |
|
skamonkey@3280
|
680 |
|
|
skamonkey@3352
|
681 |
const char *classname; |
|
skamonkey@3352
|
682 |
int lastletterpos; |
|
skamonkey@3352
|
683 |
|
|
skamonkey@3352
|
684 |
static int offset = -1; |
|
skamonkey@3352
|
685 |
if (offset == -1) |
|
skamonkey@3352
|
686 |
{ |
|
skamonkey@3352
|
687 |
offset = GetTypeDescOffs( |
|
skamonkey@3352
|
688 |
gamehelpers->FindInDataMap(gamehelpers->GetDataMap(pEntity), |
|
skamonkey@3352
|
689 |
"m_iClassname") |
|
skamonkey@3352
|
690 |
); |
|
skamonkey@3352
|
691 |
} |
|
skamonkey@3352
|
692 |
|
|
skamonkey@3352
|
693 |
string_t s; |
|
skamonkey@3280
|
694 |
|
|
skamonkey@3280
|
695 |
while (pEntity) |
|
skamonkey@3280
|
696 |
{ |
|
skamonkey@3352
|
697 |
if ((s = *(string_t *)((uint8_t *)pEntity + offset)) == NULL_STRING) |
|
skamonkey@3280
|
698 |
{ |
|
skamonkey@3280
|
699 |
pEntity = (CBaseEntity *)servertools->NextEntity(pEntity); |
|
skamonkey@3280
|
700 |
continue; |
|
skamonkey@3280
|
701 |
} |
|
skamonkey@3280
|
702 |
|
|
skamonkey@3352
|
703 |
classname = STRING(s); |
|
skamonkey@3352
|
704 |
|
|
skamonkey@3352
|
705 |
lastletterpos = strlen(searchname) - 1; |
|
skamonkey@3352
|
706 |
if (searchname[lastletterpos] == '*') |
|
skamonkey@3280
|
707 |
{ |
|
skamonkey@3352
|
708 |
if (strncasecmp(searchname, classname, lastletterpos) == 0) |
|
skamonkey@3280
|
709 |
{ |
|
skamonkey@3352
|
710 |
return gamehelpers->EntityToBCompatRef(pEntity); |
|
skamonkey@3280
|
711 |
} |
|
skamonkey@3280
|
712 |
} |
|
skamonkey@3280
|
713 |
else if (strcasecmp(searchname, classname) == 0) |
|
skamonkey@3280
|
714 |
{ |
|
skamonkey@3280
|
715 |
return gamehelpers->EntityToBCompatRef(pEntity); |
|
skamonkey@3280
|
716 |
} |
|
skamonkey@3280
|
717 |
|
|
skamonkey@3280
|
718 |
pEntity = (CBaseEntity *)servertools->NextEntity(pEntity); |
|
skamonkey@3280
|
719 |
} |
|
skamonkey@3280
|
720 |
|
|
skamonkey@3280
|
721 |
return -1; |
|
skamonkey@3280
|
722 |
} |
|
skamonkey@3352
|
723 |
#endif |
|
skamonkey@3352
|
724 |
|
|
ds@1240
|
725 |
static cell_t FindEntityByClassname(IPluginContext *pContext, const cell_t *params) |
|
ds@1240
|
726 |
{ |
|
ds@1240
|
727 |
static ValveCall *pCall = NULL; |
|
skamonkey@3352
|
728 |
static bool bProbablyNoFEBC = false; |
|
skamonkey@3352
|
729 |
|
|
skamonkey@3352
|
730 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
skamonkey@3352
|
731 |
if (bProbablyNoFEBC) |
|
skamonkey@3352
|
732 |
{ |
|
skamonkey@3352
|
733 |
return NativeFindEntityByClassname(pContext, params); |
|
skamonkey@3352
|
734 |
} |
|
skamonkey@3352
|
735 |
#endif |
|
skamonkey@3352
|
736 |
|
|
ds@1240
|
737 |
if (!pCall) |
|
ds@1240
|
738 |
{ |
|
ds@1240
|
739 |
ValvePassInfo pass[3]; |
|
ds@1240
|
740 |
InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL, VDECODE_FLAG_ALLOWNULL|VDECODE_FLAG_ALLOWWORLD); |
|
ds@1240
|
741 |
InitPass(pass[1], Valve_String, PassType_Basic, PASSFLAG_BYVAL); |
|
ds@1240
|
742 |
InitPass(pass[2], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); |
|
skamonkey@3352
|
743 |
|
|
skamonkey@3352
|
744 |
char error[256]; |
|
skamonkey@3352
|
745 |
error[0] = '\0'; |
|
ds@1240
|
746 |
if (!CreateBaseCall("FindEntityByClassname", ValveCall_EntityList, &pass[2], pass, 2, &pCall)) |
|
ds@1240
|
747 |
{ |
|
skamonkey@3352
|
748 |
g_pSM->Format(error, sizeof(error), "\"FindEntityByClassname\" not supported by this mod"); |
|
ds@1240
|
749 |
} else if (!pCall) { |
|
skamonkey@3352
|
750 |
g_pSM->Format(error, sizeof(error), "\"FindEntityByClassname\" wrapper failed to initialize"); |
|
skamonkey@3352
|
751 |
} |
|
skamonkey@3352
|
752 |
|
|
skamonkey@3352
|
753 |
if (error[0] != '\0') |
|
skamonkey@3352
|
754 |
{ |
|
skamonkey@3352
|
755 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
skamonkey@3352
|
756 |
if (!bProbablyNoFEBC) |
|
skamonkey@3352
|
757 |
{ |
|
skamonkey@3352
|
758 |
bProbablyNoFEBC = true; |
|
skamonkey@3352
|
759 |
g_pSM->LogError(myself, "%s, falling back to IServerTools method.", error); |
|
skamonkey@3352
|
760 |
} |
|
skamonkey@3352
|
761 |
return NativeFindEntityByClassname(pContext, params); |
|
skamonkey@3352
|
762 |
#else |
|
skamonkey@3352
|
763 |
return pContext->ThrowNativeError("%s", error); |
|
skamonkey@3352
|
764 |
#endif |
|
ds@1240
|
765 |
} |
|
ds@1240
|
766 |
} |
|
ds@1240
|
767 |
|
|
ds@1240
|
768 |
CBaseEntity *pEntity; |
|
ds@1240
|
769 |
START_CALL(); |
|
ds@1240
|
770 |
*(void **)vptr = g_EntList; |
|
ds@1240
|
771 |
DECODE_VALVE_PARAM(1, vparams, 0); |
|
ds@1240
|
772 |
DECODE_VALVE_PARAM(2, vparams, 1); |
|
ds@1240
|
773 |
FINISH_CALL_SIMPLE(&pEntity); |
|
ds@1240
|
774 |
|
|
pred@2746
|
775 |
return gamehelpers->EntityToBCompatRef(pEntity); |
|
ds@1240
|
776 |
} |
|
ds@1240
|
777 |
|
|
skamonkey@3280
|
778 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
ds@2400
|
779 |
static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params) |
|
ds@2400
|
780 |
{ |
|
skamonkey@3401
|
781 |
if (!g_pSM->IsMapRunning()) |
|
skamonkey@3401
|
782 |
{ |
|
skamonkey@3401
|
783 |
return pContext->ThrowNativeError("Cannot create new entity when no map is running"); |
|
skamonkey@3401
|
784 |
} |
|
skamonkey@3401
|
785 |
|
|
skamonkey@3280
|
786 |
char *classname; |
|
skamonkey@3280
|
787 |
pContext->LocalToString(params[1], &classname); |
|
skamonkey@3280
|
788 |
CBaseEntity *pEntity = (CBaseEntity *)servertools->CreateEntityByName(classname); |
|
pred@2746
|
789 |
return gamehelpers->EntityToBCompatRef(pEntity); |
|
ds@2400
|
790 |
} |
|
ds@2400
|
791 |
#else |
|
faluco@1428
|
792 |
static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params) |
|
faluco@1428
|
793 |
{ |
|
skamonkey@3401
|
794 |
if (!g_pSM->IsMapRunning()) |
|
skamonkey@3401
|
795 |
{ |
|
skamonkey@3401
|
796 |
return pContext->ThrowNativeError("Cannot create new entity when no map is running"); |
|
skamonkey@3401
|
797 |
} |
|
skamonkey@3401
|
798 |
|
|
faluco@1428
|
799 |
static ValveCall *pCall = NULL; |
|
faluco@1428
|
800 |
if (!pCall) |
|
faluco@1428
|
801 |
{ |
|
faluco@1428
|
802 |
ValvePassInfo pass[3]; |
|
faluco@1428
|
803 |
InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1428
|
804 |
InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1428
|
805 |
InitPass(pass[2], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1428
|
806 |
if (!CreateBaseCall("CreateEntityByName", ValveCall_Static, &pass[2], pass, 2, &pCall)) |
|
faluco@1428
|
807 |
{ |
|
faluco@1428
|
808 |
return pContext->ThrowNativeError("\"CreateEntityByName\" not supported by this mod"); |
|
faluco@1428
|
809 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
810 |
return pContext->ThrowNativeError("\"CreateEntityByName\" wrapper failed to initialize"); |
|
faluco@1428
|
811 |
} |
|
faluco@1428
|
812 |
} |
|
faluco@1428
|
813 |
|
|
faluco@1428
|
814 |
CBaseEntity *pEntity = NULL; |
|
faluco@1428
|
815 |
START_CALL(); |
|
faluco@1428
|
816 |
DECODE_VALVE_PARAM(1, vparams, 0); |
|
faluco@1428
|
817 |
DECODE_VALVE_PARAM(2, vparams, 1); |
|
faluco@1428
|
818 |
FINISH_CALL_SIMPLE(&pEntity); |
|
faluco@1428
|
819 |
|
|
pred@2746
|
820 |
return gamehelpers->EntityToBCompatRef(pEntity); |
|
faluco@1428
|
821 |
} |
|
ds@2400
|
822 |
#endif |
|
faluco@1428
|
823 |
|
|
skamonkey@3280
|
824 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
pred@2848
|
825 |
static cell_t DispatchSpawn(IPluginContext *pContext, const cell_t *params) |
|
pred@2848
|
826 |
{ |
|
skamonkey@3280
|
827 |
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(params[1]); |
|
skamonkey@3280
|
828 |
if (!pEntity) |
|
pred@2848
|
829 |
{ |
|
skamonkey@3280
|
830 |
return pContext->ThrowNativeError("Entity %d (%d) is invalid", gamehelpers->ReferenceToIndex(params[1]), params[1]); |
|
pred@2848
|
831 |
} |
|
pred@2848
|
832 |
|
|
skamonkey@3280
|
833 |
servertools->DispatchSpawn(pEntity); |
|
pred@2848
|
834 |
|
|
skamonkey@3280
|
835 |
return 1; |
|
pred@2848
|
836 |
} |
|
pred@2848
|
837 |
#else |
|
faluco@1428
|
838 |
static cell_t DispatchSpawn(IPluginContext *pContext, const cell_t *params) |
|
faluco@1428
|
839 |
{ |
|
faluco@1428
|
840 |
static ValveCall *pCall = NULL; |
|
faluco@1428
|
841 |
if (!pCall) |
|
faluco@1428
|
842 |
{ |
|
faluco@1428
|
843 |
ValvePassInfo pass[2]; |
|
faluco@1428
|
844 |
InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1428
|
845 |
InitPass(pass[1], Valve_POD, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1428
|
846 |
if (!CreateBaseCall("DispatchSpawn", ValveCall_Static, &pass[1], pass, 1, &pCall)) |
|
faluco@1428
|
847 |
{ |
|
faluco@1428
|
848 |
return pContext->ThrowNativeError("\"DispatchSpawn\" not supported by this mod"); |
|
faluco@1428
|
849 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
850 |
return pContext->ThrowNativeError("\"DispatchSpawn\" wrapper failed to initialize"); |
|
faluco@1428
|
851 |
} |
|
faluco@1428
|
852 |
} |
|
faluco@1428
|
853 |
|
|
faluco@1428
|
854 |
int ret; |
|
faluco@1428
|
855 |
START_CALL(); |
|
faluco@1428
|
856 |
DECODE_VALVE_PARAM(1, vparams, 0); |
|
faluco@1428
|
857 |
FINISH_CALL_SIMPLE(&ret); |
|
faluco@1428
|
858 |
|
|
faluco@1428
|
859 |
return (ret == -1) ? 0 : 1; |
|
teame06@1239
|
860 |
} |
|
pred@2848
|
861 |
#endif |
|
teame06@1239
|
862 |
|
|
skamonkey@3280
|
863 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
skamonkey@3280
|
864 |
static cell_t DispatchKeyValue(IPluginContext *pContext, const cell_t *params) |
|
skamonkey@3280
|
865 |
{ |
|
skamonkey@3280
|
866 |
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(params[1]); |
|
skamonkey@3280
|
867 |
if (!pEntity) |
|
skamonkey@3280
|
868 |
{ |
|
skamonkey@3280
|
869 |
return pContext->ThrowNativeError("Entity %d (%d) is invalid", gamehelpers->ReferenceToIndex(params[1]), params[1]); |
|
skamonkey@3280
|
870 |
} |
|
skamonkey@3280
|
871 |
|
|
skamonkey@3280
|
872 |
char *key; |
|
skamonkey@3280
|
873 |
char *value; |
|
skamonkey@3280
|
874 |
pContext->LocalToString(params[2], &key); |
|
skamonkey@3280
|
875 |
pContext->LocalToString(params[3], &value); |
|
skamonkey@3280
|
876 |
|
|
skamonkey@3280
|
877 |
return (servertools->SetKeyValue(pEntity, key, value) ? 1 : 0); |
|
skamonkey@3280
|
878 |
} |
|
skamonkey@3280
|
879 |
#else |
|
faluco@1504
|
880 |
static cell_t DispatchKeyValue(IPluginContext *pContext, const cell_t *params) |
|
faluco@1504
|
881 |
{ |
|
faluco@1504
|
882 |
static ValveCall *pCall = NULL; |
|
faluco@1504
|
883 |
if (!pCall) |
|
faluco@1504
|
884 |
{ |
|
faluco@1504
|
885 |
ValvePassInfo pass[3]; |
|
faluco@1504
|
886 |
InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1504
|
887 |
InitPass(pass[1], Valve_String, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1504
|
888 |
InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1504
|
889 |
if (!CreateBaseCall("DispatchKeyValue", ValveCall_Entity, &pass[2], pass, 2, &pCall)) |
|
faluco@1504
|
890 |
{ |
|
faluco@1504
|
891 |
return pContext->ThrowNativeError("\"DispatchKeyValue\" not supported by this mod"); |
|
faluco@1504
|
892 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
893 |
return pContext->ThrowNativeError("\"DispatchKeyValue\" wrapper failed to initialize"); |
|
faluco@1504
|
894 |
} |
|
faluco@1504
|
895 |
} |
|
faluco@1504
|
896 |
|
|
faluco@1504
|
897 |
bool ret; |
|
faluco@1504
|
898 |
START_CALL(); |
|
faluco@1504
|
899 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
faluco@1504
|
900 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
faluco@1504
|
901 |
DECODE_VALVE_PARAM(3, vparams, 1); |
|
faluco@1504
|
902 |
FINISH_CALL_SIMPLE(&ret); |
|
faluco@1504
|
903 |
|
|
fyrenmoo@2710
|
904 |
return ret ? 1 : 0; |
|
faluco@1504
|
905 |
} |
|
skamonkey@3280
|
906 |
#endif |
|
faluco@1504
|
907 |
|
|
skamonkey@3280
|
908 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
skamonkey@3280
|
909 |
static cell_t DispatchKeyValueFloat(IPluginContext *pContext, const cell_t *params) |
|
skamonkey@3280
|
910 |
{ |
|
skamonkey@3280
|
911 |
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(params[1]); |
|
skamonkey@3280
|
912 |
if (!pEntity) |
|
skamonkey@3280
|
913 |
{ |
|
skamonkey@3280
|
914 |
return pContext->ThrowNativeError("Entity %d (%d) is invalid", gamehelpers->ReferenceToIndex(params[1]), params[1]); |
|
skamonkey@3280
|
915 |
} |
|
skamonkey@3280
|
916 |
|
|
skamonkey@3280
|
917 |
char *key; |
|
skamonkey@3280
|
918 |
pContext->LocalToString(params[2], &key); |
|
skamonkey@3280
|
919 |
|
|
skamonkey@3280
|
920 |
float value = sp_ctof(params[3]); |
|
skamonkey@3280
|
921 |
|
|
skamonkey@3280
|
922 |
return (servertools->SetKeyValue(pEntity, key, value) ? 1 : 0); |
|
skamonkey@3280
|
923 |
} |
|
skamonkey@3280
|
924 |
#else |
|
faluco@1504
|
925 |
static cell_t DispatchKeyValueFloat(IPluginContext *pContext, const cell_t *params) |
|
faluco@1504
|
926 |
{ |
|
faluco@1504
|
927 |
static ValveCall *pCall = NULL; |
|
faluco@1504
|
928 |
if (!pCall) |
|
faluco@1504
|
929 |
{ |
|
faluco@1504
|
930 |
ValvePassInfo pass[3]; |
|
faluco@1504
|
931 |
InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1515
|
932 |
InitPass(pass[1], Valve_Float, PassType_Float, PASSFLAG_BYVAL); |
|
faluco@1504
|
933 |
InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1504
|
934 |
if (!CreateBaseCall("DispatchKeyValueFloat", ValveCall_Entity, &pass[2], pass, 2, &pCall)) |
|
faluco@1504
|
935 |
{ |
|
faluco@1504
|
936 |
return pContext->ThrowNativeError("\"DispatchKeyValueFloat\" not supported by this mod"); |
|
faluco@1504
|
937 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
938 |
return pContext->ThrowNativeError("\"DispatchKeyValueFloat\" wrapper failed to initialize"); |
|
faluco@1504
|
939 |
} |
|
faluco@1504
|
940 |
} |
|
faluco@1504
|
941 |
|
|
faluco@1504
|
942 |
bool ret; |
|
faluco@1504
|
943 |
START_CALL(); |
|
faluco@1504
|
944 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
faluco@1504
|
945 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
faluco@1504
|
946 |
DECODE_VALVE_PARAM(3, vparams, 1); |
|
faluco@1504
|
947 |
FINISH_CALL_SIMPLE(&ret); |
|
faluco@1504
|
948 |
|
|
fyrenmoo@2710
|
949 |
return ret ? 1 : 0; |
|
faluco@1504
|
950 |
} |
|
skamonkey@3280
|
951 |
#endif |
|
faluco@1504
|
952 |
|
|
skamonkey@3280
|
953 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
skamonkey@3280
|
954 |
static cell_t DispatchKeyValueVector(IPluginContext *pContext, const cell_t *params) |
|
skamonkey@3280
|
955 |
{ |
|
skamonkey@3280
|
956 |
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(params[1]); |
|
skamonkey@3280
|
957 |
if (!pEntity) |
|
skamonkey@3280
|
958 |
{ |
|
skamonkey@3280
|
959 |
return pContext->ThrowNativeError("Entity %d (%d) is invalid", gamehelpers->ReferenceToIndex(params[1]), params[1]); |
|
skamonkey@3280
|
960 |
} |
|
skamonkey@3280
|
961 |
|
|
skamonkey@3280
|
962 |
char *key; |
|
skamonkey@3280
|
963 |
pContext->LocalToString(params[2], &key); |
|
skamonkey@3280
|
964 |
|
|
skamonkey@3280
|
965 |
cell_t *vec; |
|
skamonkey@3280
|
966 |
pContext->LocalToPhysAddr(params[3], &vec); |
|
skamonkey@3280
|
967 |
|
|
skamonkey@3280
|
968 |
const Vector *v = new Vector( |
|
skamonkey@3280
|
969 |
sp_ctof(vec[0]), |
|
skamonkey@3280
|
970 |
sp_ctof(vec[1]), |
|
skamonkey@3280
|
971 |
sp_ctof(vec[2])); |
|
skamonkey@3280
|
972 |
|
|
skamonkey@3280
|
973 |
return (servertools->SetKeyValue(pEntity, key, *v) ? 1 : 0); |
|
skamonkey@3280
|
974 |
} |
|
skamonkey@3280
|
975 |
#else |
|
faluco@1504
|
976 |
static cell_t DispatchKeyValueVector(IPluginContext *pContext, const cell_t *params) |
|
faluco@1504
|
977 |
{ |
|
faluco@1504
|
978 |
static ValveCall *pCall = NULL; |
|
faluco@1504
|
979 |
if (!pCall) |
|
faluco@1504
|
980 |
{ |
|
faluco@1504
|
981 |
ValvePassInfo pass[3]; |
|
faluco@1504
|
982 |
InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL); |
|
ds@2400
|
983 |
#if SOURCE_ENGINE >= SE_ORANGEBOX |
|
faluco@1596
|
984 |
InitPass(pass[1], Valve_Vector, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1596
|
985 |
#else |
|
faluco@1515
|
986 |
InitPass(pass[1], Valve_Vector, PassType_Object, PASSFLAG_BYVAL|PASSFLAG_OCTOR|PASSFLAG_OASSIGNOP); |
|
faluco@1596
|
987 |
#endif |
|
faluco@1504
|
988 |
InitPass(pass[2], Valve_Bool, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1504
|
989 |
if (!CreateBaseCall("DispatchKeyValueVector", ValveCall_Entity, &pass[2], pass, 2, &pCall)) |
|
faluco@1504
|
990 |
{ |
|
faluco@1504
|
991 |
return pContext->ThrowNativeError("\"DispatchKeyValueVector\" not supported by this mod"); |
|
faluco@1504
|
992 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
993 |
return pContext->ThrowNativeError("\"DispatchKeyValueVector\" wrapper failed to initialize"); |
|
faluco@1504
|
994 |
} |
|
faluco@1504
|
995 |
} |
|
faluco@1504
|
996 |
|
|
faluco@1504
|
997 |
bool ret; |
|
faluco@1504
|
998 |
START_CALL(); |
|
faluco@1504
|
999 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
faluco@1504
|
1000 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
faluco@1504
|
1001 |
DECODE_VALVE_PARAM(3, vparams, 1); |
|
faluco@1504
|
1002 |
FINISH_CALL_SIMPLE(&ret); |
|
faluco@1504
|
1003 |
|
|
fyrenmoo@2710
|
1004 |
return ret ? 1 : 0; |
|
faluco@1504
|
1005 |
} |
|
skamonkey@3280
|
1006 |
#endif |
|
faluco@1504
|
1007 |
|
|
dvander@1628
|
1008 |
static cell_t sm_GetClientAimTarget(IPluginContext *pContext, const cell_t *params) |
|
dvander@1611
|
1009 |
{ |
|
pred@2746
|
1010 |
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]); |
|
dvander@1611
|
1011 |
|
|
dvander@1611
|
1012 |
if (!pPlayer) |
|
dvander@1611
|
1013 |
{ |
|
pred@2746
|
1014 |
return pContext->ThrowNativeError("Invalid client index %d", params[1]); |
|
dvander@1611
|
1015 |
} |
|
dvander@1611
|
1016 |
else if (!pPlayer->IsInGame()) |
|
dvander@1611
|
1017 |
{ |
|
pred@2746
|
1018 |
return pContext->ThrowNativeError("Client %d is not in game", params[1]); |
|
dvander@1611
|
1019 |
} |
|
dvander@1611
|
1020 |
|
|
dvander@1628
|
1021 |
return GetClientAimTarget(pPlayer->GetEdict(), params[2] ? true : false); |
|
dvander@1611
|
1022 |
} |
|
dvander@1611
|
1023 |
|
|
faluco@1720
|
1024 |
static cell_t sm_SetEntityModel(IPluginContext *pContext, const cell_t *params) |
|
faluco@1720
|
1025 |
{ |
|
faluco@1720
|
1026 |
static ValveCall *pCall = NULL; |
|
faluco@1720
|
1027 |
if (!pCall) |
|
faluco@1720
|
1028 |
{ |
|
faluco@1720
|
1029 |
ValvePassInfo pass[1]; |
|
faluco@1720
|
1030 |
InitPass(pass[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL); |
|
faluco@1720
|
1031 |
if (!CreateBaseCall("SetEntityModel", ValveCall_Entity, NULL, pass, 1, &pCall)) |
|
faluco@1720
|
1032 |
{ |
|
faluco@1720
|
1033 |
return pContext->ThrowNativeError("\"SetEntityModel\" not supported by this mod"); |
|
faluco@1720
|
1034 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
1035 |
return pContext->ThrowNativeError("\"SetEntityModel\" wrapper failed to initialize"); |
|
faluco@1720
|
1036 |
} |
|
faluco@1720
|
1037 |
} |
|
faluco@1720
|
1038 |
|
|
faluco@1720
|
1039 |
START_CALL(); |
|
faluco@1720
|
1040 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
faluco@1720
|
1041 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
faluco@1720
|
1042 |
FINISH_CALL_SIMPLE(NULL); |
|
faluco@1720
|
1043 |
|
|
faluco@1720
|
1044 |
return 1; |
|
faluco@1720
|
1045 |
} |
|
faluco@1720
|
1046 |
|
|
faluco@1769
|
1047 |
static cell_t GetPlayerDecalFile(IPluginContext *pContext, const cell_t *params) |
|
faluco@1769
|
1048 |
{ |
|
faluco@1769
|
1049 |
IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); |
|
faluco@1769
|
1050 |
if (player == NULL) |
|
faluco@1769
|
1051 |
{ |
|
faluco@1769
|
1052 |
return pContext->ThrowNativeError("Invalid client index %d", params[1]); |
|
faluco@1769
|
1053 |
} |
|
faluco@1769
|
1054 |
if (!player->IsInGame()) |
|
faluco@1769
|
1055 |
{ |
|
faluco@1769
|
1056 |
return pContext->ThrowNativeError("Client %d is not in game", params[1]); |
|
faluco@1769
|
1057 |
} |
|
faluco@1769
|
1058 |
|
|
faluco@1769
|
1059 |
player_info_t info; |
|
faluco@1769
|
1060 |
char *buffer; |
|
faluco@1769
|
1061 |
|
|
faluco@1769
|
1062 |
if (!GetPlayerInfo(params[1], &info) || !info.customFiles[0]) |
|
faluco@1769
|
1063 |
{ |
|
faluco@1769
|
1064 |
return 0; |
|
faluco@1769
|
1065 |
} |
|
faluco@1769
|
1066 |
|
|
faluco@1769
|
1067 |
pContext->LocalToString(params[2], &buffer); |
|
faluco@1769
|
1068 |
Q_binarytohex((byte *)&info.customFiles[0], sizeof(info.customFiles[0]), buffer, params[3]); |
|
faluco@1769
|
1069 |
|
|
faluco@1769
|
1070 |
return 1; |
|
faluco@1769
|
1071 |
} |
|
faluco@1769
|
1072 |
|
|
faluco@1769
|
1073 |
static cell_t GetServerNetStats(IPluginContext *pContext, const cell_t *params) |
|
faluco@1769
|
1074 |
{ |
|
faluco@1773
|
1075 |
if (iserver == NULL) |
|
faluco@1773
|
1076 |
{ |
|
faluco@1773
|
1077 |
return pContext->ThrowNativeError("IServer interface not supported, file a bug report."); |
|
faluco@1773
|
1078 |
} |
|
faluco@1773
|
1079 |
|
|
faluco@1769
|
1080 |
float in, out; |
|
faluco@1769
|
1081 |
cell_t *pIn, *pOut; |
|
faluco@1769
|
1082 |
|
|
faluco@1769
|
1083 |
pContext->LocalToPhysAddr(params[1], &pIn); |
|
faluco@1769
|
1084 |
pContext->LocalToPhysAddr(params[2], &pOut); |
|
faluco@1769
|
1085 |
iserver->GetNetStats(in, out); |
|
faluco@1769
|
1086 |
|
|
faluco@1769
|
1087 |
*pIn = sp_ftoc(in); |
|
faluco@1769
|
1088 |
*pOut = sp_ftoc(out); |
|
faluco@1769
|
1089 |
|
|
faluco@1769
|
1090 |
return 1; |
|
faluco@1769
|
1091 |
} |
|
faluco@1769
|
1092 |
|
|
pred@1956
|
1093 |
static cell_t WeaponEquip(IPluginContext *pContext, const cell_t *params) |
|
pred@1956
|
1094 |
{ |
|
pred@1956
|
1095 |
static ValveCall *pCall = NULL; |
|
pred@1956
|
1096 |
if (!pCall) |
|
pred@1956
|
1097 |
{ |
|
pred@1956
|
1098 |
ValvePassInfo pass[1]; |
|
pred@1956
|
1099 |
InitPass(pass[0], Valve_CBaseEntity, PassType_Basic, PASSFLAG_BYVAL); |
|
pred@1956
|
1100 |
if (!CreateBaseCall("WeaponEquip", ValveCall_Player, NULL, pass, 1, &pCall)) |
|
pred@1956
|
1101 |
{ |
|
pred@1956
|
1102 |
return pContext->ThrowNativeError("\"WeaponEquip\" not supported by this mod"); |
|
pred@1956
|
1103 |
} else if (!pCall) { |
|
fyrenmoo@2710
|
1104 |
return pContext->ThrowNativeError("\"WeaponEquip\" wrapper failed to initialize"); |
|
pred@1956
|
1105 |
} |
|
pred@1956
|
1106 |
} |
|
pred@1956
|
1107 |
|
|
pred@1956
|
1108 |
START_CALL(); |
|
pred@1956
|
1109 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
bl4nkeh@2744
|
1110 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
pred@1956
|
1111 |
FINISH_CALL_SIMPLE(NULL); |
|
pred@1956
|
1112 |
|
|
pred@1956
|
1113 |
return 1; |
|
pred@1956
|
1114 |
} |
|
pred@1956
|
1115 |
|
|
dvander@2007
|
1116 |
static cell_t ActivateEntity(IPluginContext *pContext, const cell_t *params) |
|
dvander@2007
|
1117 |
{ |
|
dvander@2007
|
1118 |
static ValveCall *pCall = NULL; |
|
dvander@2007
|
1119 |
if (!pCall) |
|
dvander@2007
|
1120 |
{ |
|
dvander@2007
|
1121 |
if (!CreateBaseCall("Activate", ValveCall_Entity, NULL, NULL, 0, &pCall)) |
|
dvander@2007
|
1122 |
{ |
|
dvander@2007
|
1123 |
return pContext->ThrowNativeError("\"Activate\" not supported by this mod"); |
|
dvander@2007
|
1124 |
} |
|
dvander@2007
|
1125 |
else if (!pCall) |
|
dvander@2007
|
1126 |
{ |
|
fyrenmoo@2710
|
1127 |
return pContext->ThrowNativeError("\"Activate\" wrapper failed to initialize"); |
|
dvander@2007
|
1128 |
} |
|
dvander@2007
|
1129 |
} |
|
dvander@2007
|
1130 |
|
|
dvander@2007
|
1131 |
START_CALL(); |
|
dvander@2007
|
1132 |
DECODE_VALVE_PARAM(1, thisinfo, 0); |
|
dvander@2007
|
1133 |
FINISH_CALL_SIMPLE(NULL); |
|
dvander@2007
|
1134 |
|
|
dvander@2007
|
1135 |
return 1; |
|
dvander@2007
|
1136 |
} |
|
dvander@2007
|
1137 |
|
|
pred@2107
|
1138 |
static cell_t SetClientInfo(IPluginContext *pContext, const cell_t *params) |
|
pred@2107
|
1139 |
{ |
|
ds@2535
|
1140 |
if (iserver == NULL) |
|
ds@2535
|
1141 |
{ |
|
ds@2535
|
1142 |
return pContext->ThrowNativeError("IServer interface not supported, file a bug report."); |
|
ds@2535
|
1143 |
} |
|
ds@2535
|
1144 |
|
|
pred@2107
|
1145 |
IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); |
|
ds@2535
|
1146 |
IClient *pClient = iserver->GetClient(params[1] - 1); |
|
ds@2535
|
1147 |
|
|
pred@2109
|
1148 |
if (player == NULL || pClient == NULL) |
|
pred@2107
|
1149 |
{ |
|
pred@2107
|
1150 |
return pContext->ThrowNativeError("Invalid client index %d", params[1]); |
|
pred@2107
|
1151 |
} |
|
pred@2107
|
1152 |
if (!player->IsConnected()) |
|
pred@2107
|
1153 |
{ |
|
pred@2107
|
1154 |
return pContext->ThrowNativeError("Client %d is not connected", params[1]); |
|
pred@2107
|
1155 |
} |
|
pred@2107
|
1156 |
|
|
pred@2107
|
1157 |
static ValveCall *pCall = NULL; |
|
pred@2107
|
1158 |
if (!pCall) |
|
pred@2107
|
1159 |
{ |
|
pred@2107
|
1160 |
ValvePassInfo params[2]; |
|
pred@2107
|
1161 |
InitPass(params[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL); |
|
pred@2107
|
1162 |
InitPass(params[1], Valve_String, PassType_Basic, PASSFLAG_BYVAL); |
|
pred@2107
|
1163 |
|
|
pred@2107
|
1164 |
if (!CreateBaseCall("SetUserCvar", ValveCall_Entity, NULL, params, 2, &pCall)) |
|
pred@2107
|
1165 |
{ |
|
pred@2107
|
1166 |
return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod"); |
|
pred@2107
|
1167 |
} |
|
pred@2107
|
1168 |
else if (!pCall) |
|
pred@2107
|
1169 |
{ |
|
fyrenmoo@2710
|
1170 |
return pContext->ThrowNativeError("\"SetUserCvar\" wrapper failed to initialize"); |
|
pred@2107
|
1171 |
} |
|
pred@2107
|
1172 |
} |
|
pred@2107
|
1173 |
|
|
ds@2583
|
1174 |
/* TODO: Use UpdateUserSettings function for all engines */ |
|
ds@2583
|
1175 |
#if SOURCE_ENGINE == SE_DARKMESSIAH |
|
ds@2583
|
1176 |
static ValveCall *pUpdateSettings = NULL; |
|
ds@2583
|
1177 |
if (!pUpdateSettings) |
|
ds@2583
|
1178 |
{ |
|
ds@2583
|
1179 |
if (!CreateBaseCall("UpdateUserSettings", ValveCall_Entity, NULL, NULL, 0, &pUpdateSettings)) |
|
ds@2583
|
1180 |
{ |
|
ds@2583
|
1181 |
return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod"); |
|
ds@2583
|
1182 |
} |
|
ds@2583
|
1183 |
else if (!pUpdateSettings) |
|
ds@2583
|
1184 |
{ |
|
fyrenmoo@2710
|
1185 |
return pContext->ThrowNativeError("\"SetUserCvar\" wrapper failed to initialize"); |
|
ds@2583
|
1186 |
} |
|
ds@2583
|
1187 |
} |
|
ds@2583
|
1188 |
#else |
|
pred@2107
|
1189 |
static int changedOffset = -1; |
|
pred@2107
|
1190 |
|
|
pred@2107
|
1191 |
if (changedOffset == -1) |
|
pred@2107
|
1192 |
{ |
|
pred@2107
|
1193 |
if (!g_pGameConf->GetOffset("InfoChanged", &changedOffset)) |
|
pred@2107
|
1194 |
{ |
|
pred@2107
|
1195 |
return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod"); |
|
pred@2107
|
1196 |
} |
|
pred@2107
|
1197 |
} |
|
ds@2583
|
1198 |
#endif |
|
pred@2107
|
1199 |
|
|
pred@2107
|
1200 |
unsigned char *CGameClient = (unsigned char *)pClient - 4; |
|
pred@2107
|
1201 |
|
|
pred@2107
|
1202 |
START_CALL(); |
|
pred@2107
|
1203 |
/* Not really a CBaseEntity* but this works */ |
|
pred@2107
|
1204 |
CBaseEntity **ebuf = (CBaseEntity **)vptr; |
|
pred@2107
|
1205 |
*ebuf = (CBaseEntity *)CGameClient; |
|
pred@2107
|
1206 |
DECODE_VALVE_PARAM(2, vparams, 0); |
|
pred@2107
|
1207 |
DECODE_VALVE_PARAM(3, vparams, 1); |
|
pred@2107
|
1208 |
FINISH_CALL_SIMPLE(NULL); |
|
pred@2107
|
1209 |
|
|
ds@2583
|
1210 |
#if SOURCE_ENGINE == SE_DARKMESSIAH |
|
ds@2583
|
1211 |
unsigned char *args = pUpdateSettings->stk_get(); |
|
ds@2583
|
1212 |
*(void **)args = CGameClient; |
|
ds@2583
|
1213 |
pUpdateSettings->call->Execute(args, NULL); |
|
ds@2583
|
1214 |
pUpdateSettings->stk_put(args); |
|
ds@2583
|
1215 |
#else |
|
pred@2107
|
1216 |
uint8_t* changed = (uint8_t *)(CGameClient + changedOffset); |
|
pred@2107
|
1217 |
*changed = 1; |
|
ds@2583
|
1218 |
#endif |
|
pred@2107
|
1219 |
|
|
pred@2107
|
1220 |
return 1; |
|
pred@2107
|
1221 |
} |
|
pred@2107
|
1222 |
|
|
skamonkey@3816
|
1223 |
static cell_t GetPlayerResourceEntity(IPluginContext *pContext, const cell_t *params) |
|
skamonkey@3816
|
1224 |
{ |
|
skamonkey@3816
|
1225 |
if (gamehelpers->GetHandleEntity(g_ResourceEntity) != NULL) |
|
skamonkey@3816
|
1226 |
{ |
|
skamonkey@3816
|
1227 |
return g_ResourceEntity.GetEntryIndex(); |
|
skamonkey@3816
|
1228 |
} |
|
skamonkey@3816
|
1229 |
|
|
skamonkey@3816
|
1230 |
return -1; |
|
skamonkey@3816
|
1231 |
} |
|
skamonkey@3816
|
1232 |
|
|
dvander@954
|
1233 |
sp_nativeinfo_t g_Natives[] = |
|
dvander@954
|
1234 |
{ |
|
ds@1240
|
1235 |
{"ExtinguishEntity", ExtinguishEntity}, |
|
faluco@1219
|
1236 |
{"ForcePlayerSuicide", ForcePlayerSuicide}, |
|
faluco@1219
|
1237 |
{"GivePlayerItem", GiveNamedItem}, |
|
faluco@1219
|
1238 |
{"GetPlayerWeaponSlot", GetPlayerWeaponSlot}, |
|
ds@1240
|
1239 |
{"IgniteEntity", IgniteEntity}, |
|
faluco@1219
|
1240 |
{"RemovePlayerItem", RemovePlayerItem}, |
|
ds@1240
|
1241 |
{"TeleportEntity", TeleportEntity}, |
|
faluco@1219
|
1242 |
{"SetClientViewEntity", SetClientViewEntity}, |
|
faluco@1219
|
1243 |
{"SetLightStyle", SetLightStyle}, |
|
faluco@1219
|
1244 |
{"SlapPlayer", SlapPlayer}, |
|
faluco@1219
|
1245 |
{"GetClientEyePosition", GetClientEyePosition}, |
|
faluco@1219
|
1246 |
{"GetClientEyeAngles", GetClientEyeAngles}, |
|
ds@1240
|
1247 |
{"FindEntityByClassname", FindEntityByClassname}, |
|
faluco@1428
|
1248 |
{"CreateEntityByName", CreateEntityByName}, |
|
faluco@1428
|
1249 |
{"DispatchSpawn", DispatchSpawn}, |
|
faluco@1504
|
1250 |
{"DispatchKeyValue", DispatchKeyValue}, |
|
faluco@1504
|
1251 |
{"DispatchKeyValueFloat", DispatchKeyValueFloat}, |
|
faluco@1504
|
1252 |
{"DispatchKeyValueVector", DispatchKeyValueVector}, |
|
dvander@1628
|
1253 |
{"GetClientAimTarget", sm_GetClientAimTarget}, |
|
faluco@1720
|
1254 |
{"SetEntityModel", sm_SetEntityModel}, |
|
faluco@1769
|
1255 |
{"GetPlayerDecalFile", GetPlayerDecalFile}, |
|
faluco@1769
|
1256 |
{"GetServerNetStats", GetServerNetStats}, |
|
pred@1956
|
1257 |
{"EquipPlayerWeapon", WeaponEquip}, |
|
dvander@2007
|
1258 |
{"ActivateEntity", ActivateEntity}, |
|
pred@2107
|
1259 |
{"SetClientInfo", SetClientInfo}, |
|
skamonkey@3816
|
1260 |
{"GetPlayerResourceEntity", GetPlayerResourceEntity}, |
|
faluco@1219
|
1261 |
{NULL, NULL}, |
|
dvander@954
|
1262 |
}; |