diff -r 4c2e6bd4d2e8 -r 2365240861a2 core/sourcehook/sourcehook_impl_cvfnptr.h --- a/core/sourcehook/sourcehook_impl_cvfnptr.h Thu Oct 14 18:14:45 2010 -0500 +++ b/core/sourcehook/sourcehook_impl_cvfnptr.h Sat Oct 16 23:21:58 2010 -0700 @@ -1,5 +1,5 @@ /* ======== SourceHook ======== -* Copyright (C) 2004-2008 Metamod:Source Development Team +* Copyright (C) 2004-2010 Metamod:Source Development Team * No warranties of any kind * * License: zlib/libpng @@ -13,6 +13,8 @@ #include "sh_list.h" #include "sh_memory.h" +#include "sh_pagealloc.h" +#include "sourcehook_impl_cleanuptask.h" namespace SourceHook { @@ -20,9 +22,12 @@ { class CVfnPtr { + static CPageAlloc ms_AlignedPageAllocator; + // *** Data *** void *m_Ptr; void *m_OrigEntry; + void *m_OrigCallThunk; // See Init() method List m_HookMans; List m_IfaceList; @@ -31,17 +36,21 @@ typedef void* Descriptor; // *** Interface *** - inline CVfnPtr(void *ptr); - inline ~CVfnPtr(); + CVfnPtr(void *ptr); + ~CVfnPtr(); + bool Init(); inline bool operator==(const Descriptor &other); inline void *GetPtr() const; inline void *GetOrigEntry() const; + void *GetOrigCallAddr() const; inline List &GetIfaceList(); inline const List &GetIfaceList() const; - inline CIface *FindIface(void *iface); + CIface *FindIface(void *iface); CIface &GetIface(void *iface); bool Patch(void *newValue); - inline bool Revert(); + bool Revert(); + + ICleanupTask *GetCleanupTask(); void AddHookMan(CHookManager *pHookMan); // If this returns false, it means that there is no hook manager left @@ -50,16 +59,6 @@ }; // *** Implementation *** - inline CVfnPtr::CVfnPtr(void *ptr) - : m_Ptr(ptr), m_OrigEntry(*reinterpret_cast(m_Ptr)) - { - } - - inline CVfnPtr::~CVfnPtr() - { - if (!m_HookMans.empty()) - m_HookMans.front()->DecrRef(this); - } inline bool CVfnPtr::operator==(const Descriptor &other) { @@ -85,31 +84,6 @@ { return m_IfaceList; } - - inline bool CVfnPtr::Revert() - { - // Only patch the vfnptr back if the module is still in memory - // If it's not, do not remove stuff like we did before - // First off we did it wrong (shutdown the whole hookman, uh..) and secondly applications may be - // confused by RemoveHook returning false then (yeah, I know, I made this one up, no one checks for RemoveHook error) - if (ModuleInMemory(reinterpret_cast(m_Ptr), SH_PTRSIZE)) - { - return Patch(m_OrigEntry); - } - else - { - return true; - } - } - - inline CIface *CVfnPtr::FindIface(void *iface) - { - List::iterator iter = m_IfaceList.find(iface); - if (iter == m_IfaceList.end()) - return NULL; - else - return &(*iter); - } } }