|
ds@1952
|
1 |
/** |
|
ds@1952
|
2 |
* vim: set ts=4 : |
|
ds@1952
|
3 |
* ============================================================================= |
|
ds@1952
|
4 |
* SourceMod |
|
ds@1952
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. |
|
ds@1952
|
6 |
* ============================================================================= |
|
ds@1952
|
7 |
* |
|
ds@1952
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1952
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1952
|
10 |
* Free Software Foundation. |
|
ds@1952
|
11 |
* |
|
ds@1952
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1952
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1952
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1952
|
15 |
* details. |
|
ds@1952
|
16 |
* |
|
ds@1952
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1952
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ds@1952
|
19 |
* |
|
ds@1952
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1952
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1952
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1952
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1952
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1952
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1952
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1952
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@1952
|
28 |
* |
|
ds@1952
|
29 |
* Version: $Id$ |
|
ds@1952
|
30 |
*/ |
|
ds@1952
|
31 |
|
|
ds@1952
|
32 |
#include "sm_globals.h" |
|
ds@1952
|
33 |
#include "PluginSys.h" |
|
ds@1952
|
34 |
#include "ForwardSys.h" |
|
ds@1952
|
35 |
#include "HandleSys.h" |
|
ds@1952
|
36 |
|
|
ds@1952
|
37 |
HandleType_t g_GlobalFwdType = 0; |
|
ds@1952
|
38 |
HandleType_t g_PrivateFwdType = 0; |
|
ds@1952
|
39 |
|
|
ds@1952
|
40 |
static bool s_CallStarted = false; |
|
ds@1952
|
41 |
static ICallable *s_pCallable = NULL; |
|
ds@1952
|
42 |
static IPluginFunction *s_pFunction = NULL; |
|
ds@1952
|
43 |
static IForward *s_pForward = NULL; |
|
ds@1952
|
44 |
|
|
ds@1952
|
45 |
class ForwardNativeHelpers : |
|
ds@1952
|
46 |
public SMGlobalClass, |
|
ds@1952
|
47 |
public IHandleTypeDispatch |
|
ds@1952
|
48 |
{ |
|
ds@1952
|
49 |
public: |
|
ds@1952
|
50 |
void OnSourceModAllInitialized() |
|
ds@1952
|
51 |
{ |
|
ds@1952
|
52 |
HandleAccess sec; |
|
ds@1952
|
53 |
|
|
ds@1952
|
54 |
/* Set GlobalFwd handle access security */ |
|
ds@1952
|
55 |
g_HandleSys.InitAccessDefaults(NULL, &sec); |
|
ds@1952
|
56 |
sec.access[HandleAccess_Read] = 0; |
|
ds@1952
|
57 |
sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; |
|
ds@1952
|
58 |
|
|
ds@1952
|
59 |
/* Create 'GlobalFwd' handle type */ |
|
ds@1952
|
60 |
g_GlobalFwdType = g_HandleSys.CreateType("GlobalFwd", this, 0, NULL, &sec, g_pCoreIdent, NULL); |
|
ds@1952
|
61 |
|
|
ds@1952
|
62 |
/* Private forwards are cloneable */ |
|
ds@1952
|
63 |
sec.access[HandleAccess_Clone] = 0; |
|
ds@1952
|
64 |
|
|
ds@1952
|
65 |
/* Create 'PrivateFwd' handle type */ |
|
ds@1952
|
66 |
g_PrivateFwdType = g_HandleSys.CreateType("PrivateFwd", this, g_GlobalFwdType, NULL, &sec, g_pCoreIdent, NULL); |
|
ds@1952
|
67 |
} |
|
ds@1952
|
68 |
|
|
ds@1952
|
69 |
void OnSourceModShutdown() |
|
ds@1952
|
70 |
{ |
|
ds@1952
|
71 |
g_HandleSys.RemoveType(g_PrivateFwdType, g_pCoreIdent); |
|
ds@1952
|
72 |
g_HandleSys.RemoveType(g_GlobalFwdType, g_pCoreIdent); |
|
ds@1952
|
73 |
} |
|
ds@1952
|
74 |
|
|
ds@1952
|
75 |
void OnHandleDestroy(HandleType_t type, void *object) |
|
ds@1952
|
76 |
{ |
|
ds@1952
|
77 |
IForward *pForward = static_cast<IForward *>(object); |
|
ds@1952
|
78 |
|
|
ds@1952
|
79 |
g_Forwards.ReleaseForward(pForward); |
|
ds@1952
|
80 |
} |
|
ds@1952
|
81 |
|
|
ds@1952
|
82 |
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize) |
|
ds@1952
|
83 |
{ |
|
ds@1952
|
84 |
*pSize = sizeof(CForward) + (((IForward *)object)->GetFunctionCount() * 12); |
|
ds@1952
|
85 |
return true; |
|
ds@1952
|
86 |
} |
|
ds@1952
|
87 |
} g_ForwardNativeHelpers; |
|
ds@1952
|
88 |
|
|
ds@1952
|
89 |
|
|
ds@1952
|
90 |
/* Turn a public index into a function ID */ |
|
ds@1952
|
91 |
inline funcid_t PublicIndexToFuncId(uint32_t idx) |
|
ds@1952
|
92 |
{ |
|
ds@1952
|
93 |
return (idx << 1) | (1 << 0); |
|
ds@1952
|
94 |
} |
|
ds@1952
|
95 |
|
|
ds@1952
|
96 |
/* Reset global function/forward call variables */ |
|
ds@1952
|
97 |
inline void ResetCall() |
|
ds@1952
|
98 |
{ |
|
ds@1952
|
99 |
s_CallStarted = false; |
|
ds@1952
|
100 |
s_pFunction = NULL; |
|
ds@1952
|
101 |
s_pForward = NULL; |
|
ds@1952
|
102 |
s_pCallable = NULL; |
|
ds@1952
|
103 |
} |
|
ds@1952
|
104 |
|
|
ds@1952
|
105 |
static cell_t sm_GetFunctionByName(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
106 |
{ |
|
ds@1952
|
107 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
ds@1952
|
108 |
HandleError err; |
|
ds@1952
|
109 |
char *name; |
|
ds@1952
|
110 |
uint32_t idx; |
|
ds@1952
|
111 |
IPlugin *pPlugin; |
|
ds@1952
|
112 |
|
|
ds@1952
|
113 |
if (hndl == 0) |
|
ds@1952
|
114 |
{ |
|
ds@1952
|
115 |
pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); |
|
ds@1952
|
116 |
} else { |
|
ds@1952
|
117 |
pPlugin = g_PluginSys.PluginFromHandle(hndl, &err); |
|
ds@1952
|
118 |
|
|
ds@1952
|
119 |
if (!pPlugin) |
|
ds@1952
|
120 |
{ |
|
ds@1952
|
121 |
return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", hndl, err); |
|
ds@1952
|
122 |
} |
|
ds@1952
|
123 |
} |
|
ds@1952
|
124 |
|
|
ds@1952
|
125 |
pContext->LocalToString(params[2], &name); |
|
ds@1952
|
126 |
|
|
ds@1952
|
127 |
/* Get public function index */ |
|
ds@1952
|
128 |
if (pPlugin->GetBaseContext()->FindPublicByName(name, &idx) == SP_ERROR_NOT_FOUND) |
|
ds@1952
|
129 |
{ |
|
ds@1952
|
130 |
/* Return INVALID_FUNCTION if not found */ |
|
ds@1952
|
131 |
return -1; |
|
ds@1952
|
132 |
} |
|
ds@1952
|
133 |
|
|
ds@1952
|
134 |
/* Return function ID */ |
|
ds@1952
|
135 |
return PublicIndexToFuncId(idx); |
|
ds@1952
|
136 |
} |
|
ds@1952
|
137 |
|
|
ds@1952
|
138 |
static cell_t sm_CreateGlobalForward(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
139 |
{ |
|
ds@1952
|
140 |
cell_t count = params[0]; |
|
ds@1952
|
141 |
char *name; |
|
ds@1952
|
142 |
ParamType forwardParams[SP_MAX_EXEC_PARAMS]; |
|
ds@1952
|
143 |
|
|
ds@1952
|
144 |
if (count - 2 > SP_MAX_EXEC_PARAMS) |
|
ds@1952
|
145 |
{ |
|
ds@1952
|
146 |
return pContext->ThrowNativeErrorEx(SP_ERROR_PARAMS_MAX, NULL); |
|
ds@1952
|
147 |
} |
|
ds@1952
|
148 |
|
|
ds@1952
|
149 |
pContext->LocalToString(params[1], &name); |
|
ds@1952
|
150 |
|
|
ds@1952
|
151 |
cell_t *addr; |
|
ds@1952
|
152 |
for (int i = 3; i <= count; i++) |
|
ds@1952
|
153 |
{ |
|
ds@1952
|
154 |
pContext->LocalToPhysAddr(params[i], &addr); |
|
ds@1952
|
155 |
forwardParams[i - 3] = static_cast<ParamType>(*addr); |
|
ds@1952
|
156 |
} |
|
ds@1952
|
157 |
|
|
ds@1952
|
158 |
IForward *pForward = g_Forwards.CreateForward(name, static_cast<ExecType>(params[2]), count - 2, forwardParams); |
|
ds@1952
|
159 |
|
|
ds@1952
|
160 |
return g_HandleSys.CreateHandle(g_GlobalFwdType, pForward, pContext->GetIdentity(), g_pCoreIdent, NULL); |
|
ds@1952
|
161 |
} |
|
ds@1952
|
162 |
|
|
ds@1952
|
163 |
static cell_t sm_CreateForward(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
164 |
{ |
|
ds@1952
|
165 |
cell_t count = params[0]; |
|
ds@1952
|
166 |
ParamType forwardParams[SP_MAX_EXEC_PARAMS]; |
|
ds@1952
|
167 |
|
|
ds@1952
|
168 |
if (count - 1 > SP_MAX_EXEC_PARAMS) |
|
ds@1952
|
169 |
{ |
|
ds@1952
|
170 |
return pContext->ThrowNativeErrorEx(SP_ERROR_PARAMS_MAX, NULL); |
|
ds@1952
|
171 |
} |
|
ds@1952
|
172 |
|
|
ds@1952
|
173 |
cell_t *addr; |
|
ds@1952
|
174 |
for (int i = 2; i <= count; i++) |
|
ds@1952
|
175 |
{ |
|
ds@1952
|
176 |
pContext->LocalToPhysAddr(params[i], &addr); |
|
ds@1952
|
177 |
forwardParams[i - 2] = static_cast<ParamType>(*addr); |
|
ds@1952
|
178 |
} |
|
ds@1952
|
179 |
|
|
ds@1952
|
180 |
IChangeableForward *pForward = g_Forwards.CreateForwardEx(NULL, static_cast<ExecType>(params[1]), count - 1, forwardParams); |
|
ds@1952
|
181 |
|
|
ds@1952
|
182 |
return g_HandleSys.CreateHandle(g_PrivateFwdType, pForward, pContext->GetIdentity(), g_pCoreIdent, NULL); |
|
ds@1952
|
183 |
} |
|
ds@1952
|
184 |
|
|
ds@1952
|
185 |
static cell_t sm_GetForwardFunctionCount(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
186 |
{ |
|
ds@1952
|
187 |
Handle_t hndl = static_cast<Handle_t>(params[1]); |
|
ds@1952
|
188 |
HandleError err; |
|
ds@1952
|
189 |
IForward *pForward; |
|
ds@1952
|
190 |
|
|
ds@1952
|
191 |
if ((err=g_HandleSys.ReadHandle(hndl, g_GlobalFwdType, NULL, (void **)&pForward)) |
|
ds@1952
|
192 |
!= HandleError_None) |
|
ds@1952
|
193 |
{ |
|
ds@1952
|
194 |
return pContext->ThrowNativeError("Invalid forward handle %x (error %d)", hndl, err); |
|
ds@1952
|
195 |
} |
|
ds@1952
|
196 |
|
|
ds@1952
|
197 |
return pForward->GetFunctionCount(); |
|
ds@1952
|
198 |
} |
|
ds@1952
|
199 |
|
|
ds@1952
|
200 |
static cell_t sm_AddToForward(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
201 |
{ |
|
ds@1952
|
202 |
Handle_t fwdHandle = static_cast<Handle_t>(params[1]); |
|
ds@1952
|
203 |
Handle_t plHandle = static_cast<Handle_t>(params[2]); |
|
ds@1952
|
204 |
HandleError err; |
|
ds@1952
|
205 |
IChangeableForward *pForward; |
|
ds@1952
|
206 |
IPlugin *pPlugin; |
|
ds@1952
|
207 |
|
|
ds@1952
|
208 |
if ((err=g_HandleSys.ReadHandle(fwdHandle, g_PrivateFwdType, NULL, (void **)&pForward)) |
|
ds@1952
|
209 |
!= HandleError_None) |
|
ds@1952
|
210 |
{ |
|
ds@1952
|
211 |
return pContext->ThrowNativeError("Invalid private forward handle %x (error %d)", fwdHandle, err); |
|
ds@1952
|
212 |
} |
|
ds@1952
|
213 |
|
|
ds@1952
|
214 |
if (plHandle == 0) |
|
ds@1952
|
215 |
{ |
|
ds@1952
|
216 |
pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); |
|
ds@1952
|
217 |
} else { |
|
ds@1952
|
218 |
pPlugin = g_PluginSys.PluginFromHandle(plHandle, &err); |
|
ds@1952
|
219 |
|
|
ds@1952
|
220 |
if (!pPlugin) |
|
ds@1952
|
221 |
{ |
|
ds@1952
|
222 |
return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", plHandle, err); |
|
ds@1952
|
223 |
} |
|
ds@1952
|
224 |
} |
|
ds@1952
|
225 |
|
|
ds@1952
|
226 |
IPluginFunction *pFunction = pPlugin->GetBaseContext()->GetFunctionById(params[3]); |
|
ds@1952
|
227 |
|
|
ds@1952
|
228 |
if (!pFunction) |
|
ds@1952
|
229 |
{ |
|
ds@1952
|
230 |
return pContext->ThrowNativeError("Invalid function id (%X)", params[3]); |
|
ds@1952
|
231 |
} |
|
ds@1952
|
232 |
|
|
ds@1952
|
233 |
return pForward->AddFunction(pFunction); |
|
ds@1952
|
234 |
} |
|
ds@1952
|
235 |
|
|
ds@1952
|
236 |
static cell_t sm_RemoveFromForward(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
237 |
{ |
|
ds@1952
|
238 |
Handle_t fwdHandle = static_cast<Handle_t>(params[1]); |
|
ds@1952
|
239 |
Handle_t plHandle = static_cast<Handle_t>(params[2]); |
|
ds@1952
|
240 |
HandleError err; |
|
ds@1952
|
241 |
IChangeableForward *pForward; |
|
ds@1952
|
242 |
IPlugin *pPlugin; |
|
ds@1952
|
243 |
|
|
ds@1952
|
244 |
if ((err=g_HandleSys.ReadHandle(fwdHandle, g_PrivateFwdType, NULL, (void **)&pForward)) |
|
ds@1952
|
245 |
!= HandleError_None) |
|
ds@1952
|
246 |
{ |
|
ds@1952
|
247 |
return pContext->ThrowNativeError("Invalid private forward handle %x (error %d)", fwdHandle, err); |
|
ds@1952
|
248 |
} |
|
ds@1952
|
249 |
|
|
ds@1952
|
250 |
if (plHandle == 0) |
|
ds@1952
|
251 |
{ |
|
ds@1952
|
252 |
pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); |
|
ds@1952
|
253 |
} else { |
|
ds@1952
|
254 |
pPlugin = g_PluginSys.PluginFromHandle(plHandle, &err); |
|
ds@1952
|
255 |
|
|
ds@1952
|
256 |
if (!pPlugin) |
|
ds@1952
|
257 |
{ |
|
ds@1952
|
258 |
return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", plHandle, err); |
|
ds@1952
|
259 |
} |
|
ds@1952
|
260 |
} |
|
ds@1952
|
261 |
|
|
ds@1952
|
262 |
IPluginFunction *pFunction = pPlugin->GetBaseContext()->GetFunctionById(params[3]); |
|
ds@1952
|
263 |
|
|
ds@1952
|
264 |
if (!pFunction) |
|
ds@1952
|
265 |
{ |
|
ds@1952
|
266 |
return pContext->ThrowNativeError("Invalid function id (%X)", params[3]); |
|
ds@1952
|
267 |
} |
|
ds@1952
|
268 |
|
|
ds@1952
|
269 |
return pForward->RemoveFunction(pFunction); |
|
ds@1952
|
270 |
} |
|
ds@1952
|
271 |
|
|
ds@1952
|
272 |
static cell_t sm_RemoveAllFromForward(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
273 |
{ |
|
ds@1952
|
274 |
Handle_t fwdHandle = static_cast<Handle_t>(params[1]); |
|
ds@1952
|
275 |
Handle_t plHandle = static_cast<Handle_t>(params[2]); |
|
ds@1952
|
276 |
HandleError err; |
|
ds@1952
|
277 |
IChangeableForward *pForward; |
|
ds@1952
|
278 |
IPlugin *pPlugin; |
|
ds@1952
|
279 |
|
|
ds@1952
|
280 |
if ((err=g_HandleSys.ReadHandle(fwdHandle, g_PrivateFwdType, NULL, (void **)&pForward)) |
|
ds@1952
|
281 |
!= HandleError_None) |
|
ds@1952
|
282 |
{ |
|
ds@1952
|
283 |
return pContext->ThrowNativeError("Invalid private forward handle %x (error %d)", fwdHandle, err); |
|
ds@1952
|
284 |
} |
|
ds@1952
|
285 |
|
|
ds@1952
|
286 |
if (plHandle == 0) |
|
ds@1952
|
287 |
{ |
|
ds@1952
|
288 |
pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); |
|
ds@1952
|
289 |
} else { |
|
ds@1952
|
290 |
pPlugin = g_PluginSys.PluginFromHandle(plHandle, &err); |
|
ds@1952
|
291 |
|
|
ds@1952
|
292 |
if (!pPlugin) |
|
ds@1952
|
293 |
{ |
|
ds@1952
|
294 |
return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", plHandle, err); |
|
ds@1952
|
295 |
} |
|
ds@1952
|
296 |
} |
|
ds@1952
|
297 |
|
|
ds@1952
|
298 |
return pForward->RemoveFunctionsOfPlugin(pPlugin); |
|
ds@1952
|
299 |
} |
|
ds@1952
|
300 |
|
|
ds@1952
|
301 |
static cell_t sm_CallStartFunction(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
302 |
{ |
|
ds@1952
|
303 |
Handle_t hndl; |
|
ds@1952
|
304 |
HandleError err; |
|
ds@1952
|
305 |
IPlugin *pPlugin; |
|
ds@1952
|
306 |
|
|
ds@1952
|
307 |
if (s_CallStarted) |
|
ds@1952
|
308 |
{ |
|
ds@1952
|
309 |
return pContext->ThrowNativeError("Cannot start a call while one is already in progress"); |
|
ds@1952
|
310 |
} |
|
ds@1952
|
311 |
|
|
ds@1952
|
312 |
hndl = static_cast<Handle_t>(params[1]); |
|
ds@1952
|
313 |
|
|
ds@1952
|
314 |
if (hndl == 0) |
|
ds@1952
|
315 |
{ |
|
ds@1952
|
316 |
pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); |
|
ds@1952
|
317 |
} else { |
|
ds@1952
|
318 |
pPlugin = g_PluginSys.PluginFromHandle(hndl, &err); |
|
ds@1952
|
319 |
|
|
ds@1952
|
320 |
if (!pPlugin) |
|
ds@1952
|
321 |
{ |
|
ds@1952
|
322 |
return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", hndl, err); |
|
ds@1952
|
323 |
} |
|
ds@1952
|
324 |
} |
|
ds@1952
|
325 |
|
|
ds@1952
|
326 |
s_pFunction = pPlugin->GetBaseContext()->GetFunctionById(params[2]); |
|
ds@1952
|
327 |
|
|
ds@1952
|
328 |
if (!s_pFunction) |
|
ds@1952
|
329 |
{ |
|
ds@1952
|
330 |
return pContext->ThrowNativeError("Invalid function id (%X)", params[2]); |
|
ds@1952
|
331 |
} |
|
ds@1952
|
332 |
|
|
ds@1952
|
333 |
s_pCallable = static_cast<ICallable *>(s_pFunction); |
|
ds@1952
|
334 |
|
|
ds@1952
|
335 |
s_CallStarted = true; |
|
ds@1952
|
336 |
|
|
ds@1952
|
337 |
return 1; |
|
ds@1952
|
338 |
} |
|
ds@1952
|
339 |
|
|
ds@1952
|
340 |
static cell_t sm_CallStartForward(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
341 |
{ |
|
ds@1952
|
342 |
Handle_t hndl; |
|
ds@1952
|
343 |
HandleError err; |
|
ds@1952
|
344 |
IForward *pForward; |
|
ds@1952
|
345 |
|
|
ds@1952
|
346 |
if (s_CallStarted) |
|
ds@1952
|
347 |
{ |
|
ds@1952
|
348 |
return pContext->ThrowNativeError("Cannot start a call while one is already in progress"); |
|
ds@1952
|
349 |
} |
|
ds@1952
|
350 |
|
|
ds@1952
|
351 |
hndl = static_cast<Handle_t>(params[1]); |
|
ds@1952
|
352 |
|
|
ds@1952
|
353 |
if ((err=g_HandleSys.ReadHandle(hndl, g_GlobalFwdType, NULL, (void **)&pForward)) |
|
ds@1952
|
354 |
!= HandleError_None) |
|
ds@1952
|
355 |
{ |
|
ds@1952
|
356 |
return pContext->ThrowNativeError("Invalid forward handle %x (error %d)", hndl, err); |
|
ds@1952
|
357 |
} |
|
ds@1952
|
358 |
|
|
ds@1952
|
359 |
s_pForward = pForward; |
|
ds@1952
|
360 |
|
|
ds@1952
|
361 |
s_pCallable = static_cast<ICallable *>(pForward); |
|
ds@1952
|
362 |
|
|
ds@1952
|
363 |
s_CallStarted = true; |
|
ds@1952
|
364 |
|
|
ds@1952
|
365 |
return 1; |
|
ds@1952
|
366 |
} |
|
ds@1952
|
367 |
|
|
ds@1952
|
368 |
static cell_t sm_CallPushCell(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
369 |
{ |
|
ds@1952
|
370 |
int err; |
|
ds@1952
|
371 |
|
|
ds@1952
|
372 |
if (!s_CallStarted) |
|
ds@1952
|
373 |
{ |
|
ds@1952
|
374 |
return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress"); |
|
ds@1952
|
375 |
} |
|
ds@1952
|
376 |
|
|
ds@1952
|
377 |
err = s_pCallable->PushCell(params[1]); |
|
ds@1952
|
378 |
|
|
ds@1952
|
379 |
if (err) |
|
ds@1952
|
380 |
{ |
|
ds@1952
|
381 |
s_pCallable->Cancel(); |
|
ds@1952
|
382 |
ResetCall(); |
|
ds@1952
|
383 |
return pContext->ThrowNativeErrorEx(err, NULL); |
|
ds@1952
|
384 |
} |
|
ds@1952
|
385 |
|
|
ds@1952
|
386 |
return 1; |
|
ds@1952
|
387 |
} |
|
ds@1952
|
388 |
|
|
ds@1952
|
389 |
static cell_t sm_CallPushCellRef(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
390 |
{ |
|
ds@1952
|
391 |
int err; |
|
ds@1952
|
392 |
cell_t *addr; |
|
ds@1952
|
393 |
|
|
ds@1952
|
394 |
if (!s_CallStarted) |
|
ds@1952
|
395 |
{ |
|
ds@1952
|
396 |
return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress"); |
|
ds@1952
|
397 |
} |
|
ds@1952
|
398 |
|
|
ds@1952
|
399 |
pContext->LocalToPhysAddr(params[1], &addr); |
|
ds@1952
|
400 |
|
|
ds@1952
|
401 |
err = s_pCallable->PushCellByRef(addr); |
|
ds@1952
|
402 |
|
|
ds@1952
|
403 |
if (err) |
|
ds@1952
|
404 |
{ |
|
ds@1952
|
405 |
s_pCallable->Cancel(); |
|
ds@1952
|
406 |
ResetCall(); |
|
ds@1952
|
407 |
return pContext->ThrowNativeErrorEx(err, NULL); |
|
ds@1952
|
408 |
} |
|
ds@1952
|
409 |
|
|
ds@1952
|
410 |
return 1; |
|
ds@1952
|
411 |
} |
|
ds@1952
|
412 |
|
|
ds@1952
|
413 |
static cell_t sm_CallPushFloat(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
414 |
{ |
|
ds@1952
|
415 |
int err; |
|
ds@1952
|
416 |
|
|
ds@1952
|
417 |
if (!s_CallStarted) |
|
ds@1952
|
418 |
{ |
|
ds@1952
|
419 |
return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress"); |
|
ds@1952
|
420 |
} |
|
ds@1952
|
421 |
|
|
ds@1952
|
422 |
err = s_pCallable->PushFloat(sp_ctof(params[1])); |
|
ds@1952
|
423 |
|
|
ds@1952
|
424 |
if (err) |
|
ds@1952
|
425 |
{ |
|
ds@1952
|
426 |
s_pCallable->Cancel(); |
|
ds@1952
|
427 |
ResetCall(); |
|
ds@1952
|
428 |
return pContext->ThrowNativeErrorEx(err, NULL); |
|
ds@1952
|
429 |
} |
|
ds@1952
|
430 |
|
|
ds@1952
|
431 |
return 1; |
|
ds@1952
|
432 |
} |
|
ds@1952
|
433 |
|
|
ds@1952
|
434 |
static cell_t sm_CallPushFloatRef(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
435 |
{ |
|
ds@1952
|
436 |
int err; |
|
ds@1952
|
437 |
cell_t *addr; |
|
ds@1952
|
438 |
|
|
ds@1952
|
439 |
if (!s_CallStarted) |
|
ds@1952
|
440 |
{ |
|
ds@1952
|
441 |
return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress"); |
|
ds@1952
|
442 |
} |
|
ds@1952
|
443 |
|
|
ds@1952
|
444 |
pContext->LocalToPhysAddr(params[1], &addr); |
|
ds@1952
|
445 |
|
|
ds@1952
|
446 |
err = s_pCallable->PushFloatByRef(reinterpret_cast<float *>(addr)); |
|
ds@1952
|
447 |
|
|
ds@1952
|
448 |
if (err) |
|
ds@1952
|
449 |
{ |
|
ds@1952
|
450 |
s_pCallable->Cancel(); |
|
ds@1952
|
451 |
ResetCall(); |
|
ds@1952
|
452 |
return pContext->ThrowNativeErrorEx(err, NULL); |
|
ds@1952
|
453 |
} |
|
ds@1952
|
454 |
|
|
ds@1952
|
455 |
return 1; |
|
ds@1952
|
456 |
} |
|
ds@1952
|
457 |
|
|
ds@1952
|
458 |
static cell_t sm_CallPushArray(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
459 |
{ |
|
ds@1952
|
460 |
int err; |
|
ds@1952
|
461 |
cell_t *addr; |
|
ds@1952
|
462 |
|
|
ds@1952
|
463 |
if (!s_CallStarted) |
|
ds@1952
|
464 |
{ |
|
ds@1952
|
465 |
return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress"); |
|
ds@1952
|
466 |
} |
|
ds@1952
|
467 |
|
|
ds@1952
|
468 |
pContext->LocalToPhysAddr(params[1], &addr); |
|
ds@1952
|
469 |
|
|
ds@1952
|
470 |
err = s_pCallable->PushArray(addr, params[2]); |
|
ds@1952
|
471 |
|
|
ds@1952
|
472 |
if (err) |
|
ds@1952
|
473 |
{ |
|
ds@1952
|
474 |
s_pCallable->Cancel(); |
|
ds@1952
|
475 |
ResetCall(); |
|
ds@1952
|
476 |
return pContext->ThrowNativeErrorEx(err, NULL); |
|
ds@1952
|
477 |
} |
|
ds@1952
|
478 |
|
|
ds@1952
|
479 |
return 1; |
|
ds@1952
|
480 |
} |
|
ds@1952
|
481 |
|
|
ds@1952
|
482 |
static cell_t sm_CallPushArrayEx(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
483 |
{ |
|
ds@1952
|
484 |
int err; |
|
ds@1952
|
485 |
cell_t *addr; |
|
ds@1952
|
486 |
|
|
ds@1952
|
487 |
if (!s_CallStarted) |
|
ds@1952
|
488 |
{ |
|
ds@1952
|
489 |
return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress"); |
|
ds@1952
|
490 |
} |
|
ds@1952
|
491 |
|
|
ds@1952
|
492 |
pContext->LocalToPhysAddr(params[1], &addr); |
|
ds@1952
|
493 |
|
|
ds@1952
|
494 |
err = s_pCallable->PushArray(addr, params[2], params[3]); |
|
ds@1952
|
495 |
|
|
ds@1952
|
496 |
if (err) |
|
ds@1952
|
497 |
{ |
|
ds@1952
|
498 |
s_pCallable->Cancel(); |
|
ds@1952
|
499 |
ResetCall(); |
|
ds@1952
|
500 |
return pContext->ThrowNativeErrorEx(err, NULL); |
|
ds@1952
|
501 |
} |
|
ds@1952
|
502 |
|
|
ds@1952
|
503 |
return 1; |
|
ds@1952
|
504 |
} |
|
ds@1952
|
505 |
|
|
ds@1952
|
506 |
static cell_t sm_CallPushString(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
507 |
{ |
|
ds@1952
|
508 |
int err; |
|
ds@1952
|
509 |
char *value; |
|
ds@1952
|
510 |
|
|
ds@1952
|
511 |
if (!s_CallStarted) |
|
ds@1952
|
512 |
{ |
|
ds@1952
|
513 |
return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress"); |
|
ds@1952
|
514 |
} |
|
ds@1952
|
515 |
|
|
ds@1952
|
516 |
pContext->LocalToString(params[1], &value); |
|
ds@1952
|
517 |
|
|
ds@1952
|
518 |
err = s_pCallable->PushString(value); |
|
ds@1952
|
519 |
|
|
ds@1952
|
520 |
if (err) |
|
ds@1952
|
521 |
{ |
|
ds@1952
|
522 |
s_pCallable->Cancel(); |
|
ds@1952
|
523 |
ResetCall(); |
|
ds@1952
|
524 |
return pContext->ThrowNativeErrorEx(err, NULL); |
|
ds@1952
|
525 |
} |
|
ds@1952
|
526 |
|
|
ds@1952
|
527 |
return 1; |
|
ds@1952
|
528 |
} |
|
ds@1952
|
529 |
|
|
ds@1952
|
530 |
static cell_t sm_CallPushStringEx(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
531 |
{ |
|
ds@1952
|
532 |
int err; |
|
ds@1952
|
533 |
char *value; |
|
ds@1952
|
534 |
|
|
ds@1952
|
535 |
if (!s_CallStarted) |
|
ds@1952
|
536 |
{ |
|
ds@1952
|
537 |
return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress"); |
|
ds@1952
|
538 |
} |
|
ds@1952
|
539 |
|
|
ds@1952
|
540 |
pContext->LocalToString(params[1], &value); |
|
ds@1952
|
541 |
|
|
ds@1952
|
542 |
err = s_pCallable->PushStringEx(value, params[2], params[3], params[4]); |
|
ds@1952
|
543 |
|
|
ds@1952
|
544 |
if (err) |
|
ds@1952
|
545 |
{ |
|
ds@1952
|
546 |
s_pCallable->Cancel(); |
|
ds@1952
|
547 |
ResetCall(); |
|
ds@1952
|
548 |
return pContext->ThrowNativeErrorEx(err, NULL); |
|
ds@1952
|
549 |
} |
|
ds@1952
|
550 |
|
|
ds@1952
|
551 |
return 1; |
|
ds@1952
|
552 |
} |
|
ds@1952
|
553 |
|
|
ds@1952
|
554 |
static cell_t sm_CallFinish(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
555 |
{ |
|
ds@1952
|
556 |
int err = SP_ERROR_NOT_RUNNABLE; |
|
ds@1952
|
557 |
cell_t *result; |
|
ds@1952
|
558 |
|
|
ds@1952
|
559 |
if (!s_CallStarted) |
|
ds@1952
|
560 |
{ |
|
ds@1952
|
561 |
return pContext->ThrowNativeError("Cannot finish call when there is no call in progress"); |
|
ds@1952
|
562 |
} |
|
ds@1952
|
563 |
|
|
ds@1952
|
564 |
pContext->LocalToPhysAddr(params[1], &result); |
|
ds@1952
|
565 |
|
|
ds@1952
|
566 |
if (s_pFunction) |
|
ds@1952
|
567 |
{ |
|
ds@1952
|
568 |
IPluginFunction *pFunction = s_pFunction; |
|
ds@1952
|
569 |
ResetCall(); |
|
ds@1952
|
570 |
err = pFunction->Execute(result); |
|
ds@1952
|
571 |
} else if (s_pForward) { |
|
ds@1952
|
572 |
IForward *pForward = s_pForward; |
|
ds@1952
|
573 |
ResetCall(); |
|
ds@1952
|
574 |
err = pForward->Execute(result, NULL); |
|
ds@1952
|
575 |
} |
|
ds@1952
|
576 |
|
|
ds@1952
|
577 |
return err; |
|
ds@1952
|
578 |
} |
|
ds@1952
|
579 |
|
|
ds@1952
|
580 |
static cell_t sm_CallCancel(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
581 |
{ |
|
ds@1952
|
582 |
if (!s_CallStarted) |
|
ds@1952
|
583 |
{ |
|
ds@1952
|
584 |
return pContext->ThrowNativeError("Cannot cancel call when there is no call in progress"); |
|
ds@1952
|
585 |
} |
|
ds@1952
|
586 |
|
|
ds@1952
|
587 |
s_pCallable->Cancel(); |
|
ds@1952
|
588 |
ResetCall(); |
|
ds@1952
|
589 |
|
|
ds@1952
|
590 |
return 1; |
|
ds@1952
|
591 |
} |
|
ds@1952
|
592 |
|
|
ds@1952
|
593 |
REGISTER_NATIVES(functionNatives) |
|
ds@1952
|
594 |
{ |
|
ds@1952
|
595 |
{"GetFunctionByName", sm_GetFunctionByName}, |
|
ds@1952
|
596 |
{"CreateGlobalForward", sm_CreateGlobalForward}, |
|
ds@1952
|
597 |
{"CreateForward", sm_CreateForward}, |
|
ds@1952
|
598 |
{"GetForwardFunctionCount", sm_GetForwardFunctionCount}, |
|
ds@1952
|
599 |
{"AddToForward", sm_AddToForward}, |
|
ds@1952
|
600 |
{"RemoveFromForward", sm_RemoveFromForward}, |
|
ds@1952
|
601 |
{"RemoveAllFromForward", sm_RemoveAllFromForward}, |
|
ds@1952
|
602 |
{"Call_StartFunction", sm_CallStartFunction}, |
|
ds@1952
|
603 |
{"Call_StartForward", sm_CallStartForward}, |
|
ds@1952
|
604 |
{"Call_PushCell", sm_CallPushCell}, |
|
ds@1952
|
605 |
{"Call_PushCellRef", sm_CallPushCellRef}, |
|
ds@1952
|
606 |
{"Call_PushFloat", sm_CallPushFloat}, |
|
ds@1952
|
607 |
{"Call_PushFloatRef", sm_CallPushFloatRef}, |
|
ds@1952
|
608 |
{"Call_PushArray", sm_CallPushArray}, |
|
ds@1952
|
609 |
{"Call_PushArrayEx", sm_CallPushArrayEx}, |
|
ds@1952
|
610 |
{"Call_PushString", sm_CallPushString}, |
|
ds@1952
|
611 |
{"Call_PushStringEx", sm_CallPushStringEx}, |
|
ds@1952
|
612 |
{"Call_Finish", sm_CallFinish}, |
|
ds@1952
|
613 |
{"Call_Cancel", sm_CallCancel}, |
|
ds@1952
|
614 |
{NULL, NULL}, |
|
ds@1952
|
615 |
}; |