1 /* ======== SourceHook ========
2 * Copyright (C) 2004-2007 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): Pavol "PM OnoTo" Marko
8 * ============================
11 #ifndef __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
12 #define __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
15 #include "sourcehook_impl_cproto.h"
16 #include "sourcehook_hookmangen.h"
24 class CHookManager : public IHookManagerInfo
28 HookManagerPubFunc m_PubFunc;
34 void *m_HookfuncVfnptr;
36 List<CVfnPtr*> m_VfnPtrs;
42 HookManagerPubFunc m_PubFunc;
43 Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
44 : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
50 inline CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
52 inline bool operator==(const Descriptor &other) const;
53 inline bool operator==(const CHookManager &other) const;
55 inline operator bool() const;
56 inline Plugin GetOwnerPlugin() const;
57 inline int GetVtblOffs() const;
58 inline int GetVtblIdx() const;
59 inline const CProto &GetProto() const;
60 inline int GetVersion() const;
61 inline void *GetHookFunc() const;
62 inline HookManagerPubFunc GetPubFunc() const;
64 inline void Register();
65 inline void Unregister();
67 inline void IncrRef(CVfnPtr *pVfnPtr);
68 inline void DecrRef(CVfnPtr *pVfnPtr);
70 List<CVfnPtr*> &GetVfnPtrList()
75 // *** IHookManagerInfo interface ***
76 void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
77 ProtoInfo *proto, void *hookfunc_vfnptr);
80 class CHookManList : public List<CHookManager>
83 inline CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
84 inline CHookManager *GetHookMan(CHookManager &hm);
87 // *** Implementation ***
88 inline CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
89 : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
92 // -> Should call SetInfo and set all the other variables!
93 if (m_PubFunc(false, this) != 0)
100 inline CHookManager::operator bool() const
102 return m_Version != -1;
105 inline bool CHookManager::operator==(const Descriptor &other) const
107 return m_OwnerPlugin == other.m_OwnerPlugin
108 && m_PubFunc == other.m_PubFunc;
111 inline bool CHookManager::operator==(const CHookManager &other) const
113 return m_OwnerPlugin == other.m_OwnerPlugin
114 && m_PubFunc == other.m_PubFunc;
117 inline Plugin CHookManager::GetOwnerPlugin() const
119 return m_OwnerPlugin;
122 inline int CHookManager::GetVtblOffs() const
127 inline int CHookManager::GetVtblIdx() const
132 inline const CProto &CHookManager::GetProto() const
137 inline int CHookManager::GetVersion() const
142 inline void *CHookManager::GetHookFunc() const
144 return *reinterpret_cast<void**>(m_HookfuncVfnptr);
147 inline HookManagerPubFunc CHookManager::GetPubFunc() const
152 inline void CHookManager::Register()
154 m_PubFunc(true, this);
157 inline void CHookManager::Unregister()
159 m_PubFunc(true, NULL);
162 inline void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
164 m_VfnPtrs.push_back(pVfnPtr);
165 if (m_VfnPtrs.size() == 1)
169 inline void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
171 m_VfnPtrs.remove(pVfnPtr);
172 if (m_VfnPtrs.empty())
176 inline CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
178 CHookManager hm(plug, pubFunc);
179 return GetHookMan(hm);
182 inline CHookManager *CHookManList::GetHookMan(CHookManager &hm)
184 iterator iter = find(hm);