fixed a state bug in the gameconf parser that would break parsing after a signature section was done
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #include "sm_globals.h"
16 #include "sourcemm_api.h"
17 #include "HandleSys.h"
18 #include "EventManager.h"
20 static cell_t sm_HookEvent(IPluginContext *pContext, const cell_t *params)
23 IPluginFunction *pFunction;
25 pContext->LocalToString(params[1], &name);
26 pFunction = pContext->GetFunctionById(params[2]);
30 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
33 if (g_EventManager.HookEvent(name, pFunction, static_cast<EventHookMode>(params[3])) == EventHookErr_InvalidEvent)
35 return pContext->ThrowNativeError("Game event \"%s\" does not exist", name);
41 static cell_t sm_HookEventEx(IPluginContext *pContext, const cell_t *params)
44 IPluginFunction *pFunction;
46 pContext->LocalToString(params[1], &name);
47 pFunction = pContext->GetFunctionById(params[2]);
51 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
54 if (g_EventManager.HookEvent(name, pFunction, static_cast<EventHookMode>(params[3])) == EventHookErr_InvalidEvent)
62 static cell_t sm_UnhookEvent(IPluginContext *pContext, const cell_t *params)
65 IPluginFunction *pFunction;
67 pContext->LocalToString(params[1], &name);
68 pFunction = pContext->GetFunctionById(params[2]);
72 return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
75 EventHookError err = g_EventManager.UnhookEvent(name, pFunction, static_cast<EventHookMode>(params[3]));
77 /* Possible errors that UnhookGameEvent can return */
78 if (err == EventHookErr_NotActive)
80 return pContext->ThrowNativeError("Game event \"%s\" has no active hook", name);
81 } else if (err == EventHookErr_InvalidCallback) {
82 return pContext->ThrowNativeError("Invalid hook callback specified for game event \"%s\"", name);
88 static cell_t sm_CreateEvent(IPluginContext *pContext, const cell_t *params)
93 pContext->LocalToString(params[1], &name);
95 pInfo = g_EventManager.CreateEvent(pContext, name, params[2] ? true : false);
99 return g_HandleSys.CreateHandle(g_EventManager.GetHandleType(), pInfo, pContext->GetIdentity(), g_pCoreIdent, NULL);
105 static cell_t sm_FireEvent(IPluginContext *pContext, const cell_t *params)
107 Handle_t hndl = static_cast<Handle_t>(params[1]);
111 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
114 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
117 /* If identities do not match, don't fire event */
118 if (pContext->GetIdentity() != pInfo->pOwner)
120 return pContext->ThrowNativeError("Game event \"%s\" could not be fired because it was not created by this plugin", pInfo->pEvent->GetName());
123 g_EventManager.FireEvent(pInfo, params[2] ? true : false);
125 /* Free handle on game event */
126 HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
127 g_HandleSys.FreeHandle(hndl, &sec);
132 static cell_t sm_CancelCreatedEvent(IPluginContext *pContext, const cell_t *params)
134 Handle_t hndl = static_cast<Handle_t>(params[1]);
138 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
141 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
144 /* If identities do not match, don't cancel event */
145 if (pContext->GetIdentity() != pInfo->pOwner)
147 return pContext->ThrowNativeError("Game event \"%s\" could not be canceled because it was not created by this plugin", pInfo->pEvent->GetName());
150 g_EventManager.CancelCreatedEvent(pInfo);
152 /* Free handle on game event */
153 HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
154 g_HandleSys.FreeHandle(hndl, &sec);
159 static cell_t sm_GetEventName(IPluginContext *pContext, const cell_t *params)
161 Handle_t hndl = static_cast<Handle_t>(params[1]);
165 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
168 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
171 pContext->StringToLocalUTF8(params[2], params[3], pInfo->pEvent->GetName(), NULL);
176 static cell_t sm_GetEventBool(IPluginContext *pContext, const cell_t *params)
178 Handle_t hndl = static_cast<Handle_t>(params[1]);
182 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
185 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
189 pContext->LocalToString(params[2], &key);
191 return pInfo->pEvent->GetBool(key);
194 static cell_t sm_GetEventInt(IPluginContext *pContext, const cell_t *params)
196 Handle_t hndl = static_cast<Handle_t>(params[1]);
200 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
203 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
207 pContext->LocalToString(params[2], &key);
209 return pInfo->pEvent->GetInt(key);
212 static cell_t sm_GetEventFloat(IPluginContext *pContext, const cell_t *params)
214 Handle_t hndl = static_cast<Handle_t>(params[1]);
218 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
221 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
225 pContext->LocalToString(params[2], &key);
227 float value = pInfo->pEvent->GetFloat(key);
229 return sp_ftoc(value);
232 static cell_t sm_GetEventString(IPluginContext *pContext, const cell_t *params)
234 Handle_t hndl = static_cast<Handle_t>(params[1]);
238 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
241 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
245 pContext->LocalToString(params[2], &key);
247 pContext->StringToLocalUTF8(params[3], params[4], pInfo->pEvent->GetString(key), NULL);
252 static cell_t sm_SetEventBool(IPluginContext *pContext, const cell_t *params)
254 Handle_t hndl = static_cast<Handle_t>(params[1]);
258 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
261 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
265 pContext->LocalToString(params[2], &key);
267 pInfo->pEvent->SetBool(key, params[3] ? true : false);
272 static cell_t sm_SetEventInt(IPluginContext *pContext, const cell_t *params)
274 Handle_t hndl = static_cast<Handle_t>(params[1]);
278 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
281 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
285 pContext->LocalToString(params[2], &key);
287 pInfo->pEvent->SetInt(key, params[3]);
292 static cell_t sm_SetEventFloat(IPluginContext *pContext, const cell_t *params)
294 Handle_t hndl = static_cast<Handle_t>(params[1]);
298 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
301 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
305 pContext->LocalToString(params[2], &key);
307 float value = sp_ctof(params[3]);
308 pInfo->pEvent->SetFloat(key, value);
313 static cell_t sm_SetEventString(IPluginContext *pContext, const cell_t *params)
315 Handle_t hndl = static_cast<Handle_t>(params[1]);
319 if ((err=g_HandleSys.ReadHandle(hndl, g_EventManager.GetHandleType(), NULL, (void **)&pInfo))
322 return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err);
326 pContext->LocalToString(params[2], &key);
327 pContext->LocalToString(params[3], &value);
329 pInfo->pEvent->SetString(key, value);
334 REGISTER_NATIVES(gameEventNatives)
336 {"HookEvent", sm_HookEvent},
337 {"HookEventEx", sm_HookEventEx},
338 {"UnhookEvent", sm_UnhookEvent},
339 {"CreateEvent", sm_CreateEvent},
340 {"FireEvent", sm_FireEvent},
341 {"CancelCreatedEvent", sm_CancelCreatedEvent},
342 {"GetEventName", sm_GetEventName},
343 {"GetEventBool", sm_GetEventBool},
344 {"GetEventInt", sm_GetEventInt},
345 {"GetEventFloat", sm_GetEventFloat},
346 {"GetEventString", sm_GetEventString},
347 {"SetEventBool", sm_SetEventBool},
348 {"SetEventInt", sm_SetEventInt},
349 {"SetEventFloat", sm_SetEventFloat},
350 {"SetEventString", sm_SetEventString},