Rewrote user message caching code to always use IServerGameDLL::GetUserMessageInfo (
bug 4117, r=dvander).
Games where the above function can crash are handled by detouring tier0's Error() function and jumping back to our own code. So in theory this should work on all games now.
1 /* ======== SourceHook ========
2 * Copyright (C) 2004-2008 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"
23 class CHookManager : public IHookManagerInfo
27 HookManagerPubFunc m_PubFunc;
33 void *m_HookfuncVfnptr;
35 List<CVfnPtr*> m_VfnPtrs;
41 HookManagerPubFunc m_PubFunc;
42 Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
43 : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
49 inline CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
51 inline bool operator==(const Descriptor &other) const;
52 inline bool operator==(const CHookManager &other) const;
54 inline operator bool() const;
55 inline Plugin GetOwnerPlugin() const;
56 inline int GetVtblOffs() const;
57 inline int GetVtblIdx() const;
58 inline const CProto &GetProto() const;
59 inline int GetVersion() const;
60 inline void *GetHookFunc() const;
61 inline HookManagerPubFunc GetPubFunc() const;
63 inline void Register();
64 inline void Unregister();
66 inline void IncrRef(CVfnPtr *pVfnPtr);
67 inline void DecrRef(CVfnPtr *pVfnPtr);
69 List<CVfnPtr*> &GetVfnPtrList()
74 // *** IHookManagerInfo interface ***
75 void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
76 ProtoInfo *proto, void *hookfunc_vfnptr);
79 class CHookManList : public List<CHookManager>
82 inline CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
83 inline CHookManager *GetHookMan(CHookManager &hm);
86 // *** Implementation ***
87 inline CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
88 : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
91 // -> Should call SetInfo and set all the other variables!
92 if (m_PubFunc(false, this) != 0)
99 inline CHookManager::operator bool() const
101 return m_Version != -1;
104 inline bool CHookManager::operator==(const Descriptor &other) const
106 return m_OwnerPlugin == other.m_OwnerPlugin
107 && m_PubFunc == other.m_PubFunc;
110 inline bool CHookManager::operator==(const CHookManager &other) const
112 return m_OwnerPlugin == other.m_OwnerPlugin
113 && m_PubFunc == other.m_PubFunc;
116 inline Plugin CHookManager::GetOwnerPlugin() const
118 return m_OwnerPlugin;
121 inline int CHookManager::GetVtblOffs() const
126 inline int CHookManager::GetVtblIdx() const
131 inline const CProto &CHookManager::GetProto() const
136 inline int CHookManager::GetVersion() const
141 inline void *CHookManager::GetHookFunc() const
143 return *reinterpret_cast<void**>(m_HookfuncVfnptr);
146 inline HookManagerPubFunc CHookManager::GetPubFunc() const
151 inline void CHookManager::Register()
153 m_PubFunc(true, this);
156 inline void CHookManager::Unregister()
158 m_PubFunc(true, NULL);
161 inline void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
163 m_VfnPtrs.push_back(pVfnPtr);
164 if (m_VfnPtrs.size() == 1)
168 inline void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
170 m_VfnPtrs.remove(pVfnPtr);
171 if (m_VfnPtrs.empty())
175 inline CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
177 CHookManager hm(plug, pubFunc);
178 return GetHookMan(hm);
181 inline CHookManager *CHookManList::GetHookMan(CHookManager &hm)
183 iterator iter = find(hm);