|
ds@576
|
1 |
/** |
|
ds@653
|
2 |
* vim: set ts=4 : |
|
dvander@1231
|
3 |
* ================================================================ |
|
dvander@1231
|
4 |
* SourceMod |
|
dvander@1231
|
5 |
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. |
|
dvander@1231
|
6 |
* ================================================================ |
|
ds@653
|
7 |
* |
|
dvander@1231
|
8 |
* This program is free software; you can redistribute it and/or |
|
dvander@1231
|
9 |
* modify it under the terms of the GNU General Public License, |
|
dvander@1231
|
10 |
* version 3.0, as published by the Free Software Foundation. |
|
dvander@1231
|
11 |
* |
|
dvander@1231
|
12 |
* This program is distributed in the hope that it will be useful, |
|
dvander@1231
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
dvander@1231
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
dvander@1231
|
15 |
* GNU General Public License for more details. |
|
dvander@1231
|
16 |
* |
|
dvander@1231
|
17 |
* You should have received a copy of the GNU General Public License |
|
dvander@1231
|
18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
dvander@1231
|
19 |
* |
|
dvander@1231
|
20 |
* As a special exception, AlliedModders LLC gives you permission to |
|
dvander@1231
|
21 |
* link the code of this program (as well as its derivative works) to |
|
dvander@1231
|
22 |
* "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any |
|
dvander@1231
|
23 |
* Game MODs that run on software by the Valve Corporation. You must |
|
dvander@1231
|
24 |
* obey the GNU General Public License in all respects for all other |
|
dvander@1231
|
25 |
* code used. Additionally, AlliedModders LLC grants this exception |
|
dvander@1231
|
26 |
* to all derivative works. AlliedModders LLC defines further |
|
dvander@1231
|
27 |
* exceptions, found in LICENSE.txt (as of this writing, version |
|
dvander@1231
|
28 |
* JULY-31-2007), or <http://www.sourcemod.net/license.php>. |
|
ds@653
|
29 |
* |
|
ds@653
|
30 |
* Version: $Id$ |
|
ds@653
|
31 |
*/ |
|
ds@576
|
32 |
|
|
ds@582
|
33 |
#ifndef _INCLUDE_SOURCEMOD_EVENTMANAGER_H_ |
|
ds@582
|
34 |
#define _INCLUDE_SOURCEMOD_EVENTMANAGER_H_ |
|
ds@576
|
35 |
|
|
ds@576
|
36 |
#include "sm_globals.h" |
|
ds@576
|
37 |
#include "sourcemm_api.h" |
|
ds@576
|
38 |
#include "sm_trie.h" |
|
ds@576
|
39 |
#include <sh_list.h> |
|
ds@577
|
40 |
#include <sh_stack.h> |
|
ds@576
|
41 |
#include <IHandleSys.h> |
|
ds@576
|
42 |
#include <IForwardSys.h> |
|
ds@576
|
43 |
#include <IPluginSys.h> |
|
ds@576
|
44 |
|
|
ds@576
|
45 |
using namespace SourceHook; |
|
ds@576
|
46 |
|
|
ds@576
|
47 |
struct EventInfo |
|
ds@576
|
48 |
{ |
|
ds@576
|
49 |
IGameEvent *pEvent; |
|
ds@577
|
50 |
IdentityToken_t *pOwner; |
|
ds@576
|
51 |
}; |
|
ds@576
|
52 |
|
|
ds@576
|
53 |
struct EventHook |
|
ds@576
|
54 |
{ |
|
ds@576
|
55 |
EventHook() |
|
ds@576
|
56 |
{ |
|
ds@576
|
57 |
pPreHook = NULL; |
|
ds@576
|
58 |
pPostHook = NULL; |
|
ds@576
|
59 |
postCopy = false; |
|
ds@684
|
60 |
pEventCopy = NULL; |
|
ds@576
|
61 |
refCount = 0; |
|
ds@576
|
62 |
} |
|
ds@576
|
63 |
IChangeableForward *pPreHook; |
|
ds@576
|
64 |
IChangeableForward *pPostHook; |
|
ds@576
|
65 |
bool postCopy; |
|
ds@684
|
66 |
IGameEvent *pEventCopy; |
|
ds@576
|
67 |
unsigned int refCount; |
|
ds@576
|
68 |
}; |
|
ds@576
|
69 |
|
|
ds@576
|
70 |
enum EventHookMode |
|
ds@576
|
71 |
{ |
|
ds@576
|
72 |
EventHookMode_Pre, |
|
ds@576
|
73 |
EventHookMode_Post, |
|
ds@576
|
74 |
EventHookMode_PostNoCopy |
|
ds@576
|
75 |
}; |
|
ds@576
|
76 |
|
|
ds@576
|
77 |
enum EventHookError |
|
ds@576
|
78 |
{ |
|
ds@576
|
79 |
EventHookErr_Okay = 0, /**< No error */ |
|
ds@576
|
80 |
EventHookErr_InvalidEvent, /**< Specified event does not exist */ |
|
ds@576
|
81 |
EventHookErr_NotActive, /**< Specified event has no active hook */ |
|
ds@576
|
82 |
EventHookErr_InvalidCallback, /**< Specified event does not fire specified callback */ |
|
ds@576
|
83 |
}; |
|
ds@576
|
84 |
|
|
ds@576
|
85 |
class EventManager : |
|
ds@576
|
86 |
public SMGlobalClass, |
|
ds@576
|
87 |
public IHandleTypeDispatch, |
|
ds@576
|
88 |
public IPluginsListener, |
|
ds@576
|
89 |
public IGameEventListener2 |
|
ds@576
|
90 |
{ |
|
ds@576
|
91 |
public: |
|
ds@576
|
92 |
EventManager(); |
|
ds@576
|
93 |
~EventManager(); |
|
ds@576
|
94 |
public: // SMGlobalClass |
|
ds@576
|
95 |
void OnSourceModAllInitialized(); |
|
ds@576
|
96 |
void OnSourceModShutdown(); |
|
ds@576
|
97 |
public: // IHandleTypeDispatch |
|
ds@576
|
98 |
void OnHandleDestroy(HandleType_t type, void *object); |
|
ds@576
|
99 |
public: // IPluginsListener |
|
ds@576
|
100 |
void OnPluginUnloaded(IPlugin *plugin); |
|
ds@576
|
101 |
public: // IGameEventListener2 |
|
ds@576
|
102 |
void FireGameEvent(IGameEvent *pEvent); |
|
ds@576
|
103 |
public: |
|
ds@576
|
104 |
/** |
|
ds@576
|
105 |
* Get the 'GameEvent' handle type ID. |
|
ds@576
|
106 |
*/ |
|
ds@576
|
107 |
inline HandleType_t GetHandleType() |
|
ds@576
|
108 |
{ |
|
ds@577
|
109 |
return m_EventType; |
|
ds@576
|
110 |
} |
|
ds@576
|
111 |
public: |
|
ds@576
|
112 |
EventHookError HookEvent(const char *name, IPluginFunction *pFunction, EventHookMode mode=EventHookMode_Post); |
|
ds@576
|
113 |
EventHookError UnhookEvent(const char *name, IPluginFunction *pFunction, EventHookMode mode=EventHookMode_Post); |
|
ds@713
|
114 |
EventInfo *CreateEvent(IPluginContext *pContext, const char *name, bool force=false); |
|
ds@712
|
115 |
void FireEvent(EventInfo *pInfo, bool bDontBroadcast=false); |
|
ds@687
|
116 |
void CancelCreatedEvent(EventInfo *pInfo); |
|
ds@576
|
117 |
private: // IGameEventManager2 hooks |
|
ds@576
|
118 |
bool OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast); |
|
ds@576
|
119 |
bool OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast); |
|
ds@576
|
120 |
private: |
|
ds@576
|
121 |
HandleType_t m_EventType; |
|
ds@576
|
122 |
Trie *m_EventHooks; |
|
ds@577
|
123 |
CStack<EventInfo *> m_FreeEvents; |
|
ds@684
|
124 |
CStack<const char *> m_EventNames; |
|
ds@576
|
125 |
}; |
|
ds@576
|
126 |
|
|
ds@576
|
127 |
extern EventManager g_EventManager; |
|
ds@576
|
128 |
|
|
ds@582
|
129 |
#endif // _INCLUDE_SOURCEMOD_EVENTMANAGER_H_ |