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_CVFNPTR_H__
12 #define __SOURCEHOOK_IMPL_CVFNPTR_H__
15 #include "sh_memory.h"
27 List<CHookManager*> m_HookMans;
28 List<CIface> m_IfaceList;
31 typedef void* Descriptor;
34 inline CVfnPtr(void *ptr);
36 inline bool operator==(const Descriptor &other);
37 inline void *GetPtr() const;
38 inline void *GetOrigEntry() const;
39 inline List<CIface> &GetIfaceList();
40 inline const List<CIface> &GetIfaceList() const;
41 inline CIface *FindIface(void *iface);
42 CIface &GetIface(void *iface);
43 bool Patch(void *newValue);
46 void AddHookMan(CHookManager *pHookMan);
47 // If this returns false, it means that there is no hook manager left
48 // to use and that this vfnptr should be removed.
49 bool HookManRemoved(CHookManager *pHookMan);
52 // *** Implementation ***
53 inline CVfnPtr::CVfnPtr(void *ptr)
54 : m_Ptr(ptr), m_OrigEntry(*reinterpret_cast<void**>(m_Ptr))
58 inline CVfnPtr::~CVfnPtr()
60 if (!m_HookMans.empty())
61 m_HookMans.front()->DecrRef(this);
64 inline bool CVfnPtr::operator==(const Descriptor &other)
66 return m_Ptr == other;
69 inline void *CVfnPtr::GetPtr() const
74 inline void *CVfnPtr::GetOrigEntry() const
79 inline List<CIface> &CVfnPtr::GetIfaceList()
84 inline const List<CIface> &CVfnPtr::GetIfaceList() const
89 inline bool CVfnPtr::Revert()
91 // Only patch the vfnptr back if the module is still in memory
92 // If it's not, do not remove stuff like we did before
93 // First off we did it wrong (shutdown the whole hookman, uh..) and secondly applications may be
94 // confused by RemoveHook returning false then (yeah, I know, I made this one up, no one checks for RemoveHook error)
95 if (ModuleInMemory(reinterpret_cast<char*>(m_Ptr), SH_PTRSIZE))
97 return Patch(m_OrigEntry);
105 inline CIface *CVfnPtr::FindIface(void *iface)
107 List<CIface>::iterator iter = m_IfaceList.find(iface);
108 if (iter == m_IfaceList.end())