120 lines
3.1 KiB
C
120 lines
3.1 KiB
C
|
/**
|
||
|
* ===============================================================
|
||
|
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
||
|
* ===============================================================
|
||
|
*
|
||
|
* This file is not open source and may not be copied without explicit
|
||
|
* written permission of AlliedModders LLC. This file may not be redistributed
|
||
|
* in whole or significant part.
|
||
|
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
|
||
|
*
|
||
|
* Version: $$
|
||
|
*/
|
||
|
|
||
|
#ifndef _INCLUDE_SOURCEMOD_CGAMEEVENTMANAGER_H_
|
||
|
#define _INCLUDE_SOURCEMOD_CGAMEEVENTMANAGER_H_
|
||
|
|
||
|
#include "sm_globals.h"
|
||
|
#include "sourcemm_api.h"
|
||
|
#include "sm_trie.h"
|
||
|
#include <sh_list.h>
|
||
|
#include <IHandleSys.h>
|
||
|
#include <IForwardSys.h>
|
||
|
#include <IPluginSys.h>
|
||
|
|
||
|
using namespace SourceHook;
|
||
|
|
||
|
//#define EVENT_PASSTHRU (1<<0)
|
||
|
#define EVENT_PASSTHRU_ALL (1<<1)
|
||
|
|
||
|
struct EventInfo
|
||
|
{
|
||
|
IGameEvent *pEvent;
|
||
|
bool canDelete;
|
||
|
};
|
||
|
|
||
|
struct EventHook
|
||
|
{
|
||
|
EventHook()
|
||
|
{
|
||
|
pPreHook = NULL;
|
||
|
pPostHook = NULL;
|
||
|
postCopy = false;
|
||
|
refCount = 0;
|
||
|
}
|
||
|
IChangeableForward *pPreHook;
|
||
|
IChangeableForward *pPostHook;
|
||
|
bool postCopy;
|
||
|
unsigned int refCount;
|
||
|
};
|
||
|
|
||
|
enum EventHookMode
|
||
|
{
|
||
|
EventHookMode_Pre,
|
||
|
EventHookMode_Post,
|
||
|
EventHookMode_PostNoCopy
|
||
|
};
|
||
|
|
||
|
enum EventHookError
|
||
|
{
|
||
|
EventHookErr_Okay = 0, /**< No error */
|
||
|
EventHookErr_InvalidEvent, /**< Specified event does not exist */
|
||
|
EventHookErr_NotActive, /**< Specified event has no active hook */
|
||
|
EventHookErr_InvalidCallback, /**< Specified event does not fire specified callback */
|
||
|
};
|
||
|
|
||
|
class EventManager :
|
||
|
public SMGlobalClass,
|
||
|
public IHandleTypeDispatch,
|
||
|
public IPluginsListener,
|
||
|
public IGameEventListener2
|
||
|
{
|
||
|
public:
|
||
|
EventManager();
|
||
|
~EventManager();
|
||
|
public: // SMGlobalClass
|
||
|
void OnSourceModAllInitialized();
|
||
|
void OnSourceModShutdown();
|
||
|
public: // IHandleTypeDispatch
|
||
|
void OnHandleDestroy(HandleType_t type, void *object);
|
||
|
public: // IPluginsListener
|
||
|
void OnPluginUnloaded(IPlugin *plugin);
|
||
|
public: // IGameEventListener2
|
||
|
void FireGameEvent(IGameEvent *pEvent);
|
||
|
public:
|
||
|
/**
|
||
|
* Get the 'GameEvent' handle type ID.
|
||
|
*/
|
||
|
inline HandleType_t GetHandleType()
|
||
|
{
|
||
|
return EventManager::m_EventType;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Sets the current SourceMod event notification state.
|
||
|
*
|
||
|
* If notify is set to true, SourceMod plugins will be notified of events. If false, they will not.
|
||
|
* This is temporarily used to make EVENT_PASSTHRU work when firing events from plugins.
|
||
|
*/
|
||
|
inline void SetNotifyState(bool notify)
|
||
|
{
|
||
|
m_NotifyState = notify;
|
||
|
}
|
||
|
public:
|
||
|
EventHookError HookEvent(const char *name, IPluginFunction *pFunction, EventHookMode mode=EventHookMode_Post);
|
||
|
EventHookError UnhookEvent(const char *name, IPluginFunction *pFunction, EventHookMode mode=EventHookMode_Post);
|
||
|
private: // IGameEventManager2 hooks
|
||
|
bool OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast);
|
||
|
bool OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast);
|
||
|
private:
|
||
|
HandleType_t m_EventType;
|
||
|
Trie *m_EventHooks;
|
||
|
bool m_NotifyState;
|
||
|
IGameEvent *m_EventCopy;
|
||
|
const char *m_EventName;
|
||
|
};
|
||
|
|
||
|
extern EventManager g_EventManager;
|
||
|
|
||
|
#endif // _INCLUDE_SOURCEMOD_CGAMEEVENTMANAGER_H_
|