core/sourcehook/sourcehook_impl_cvfnptr.h
changeset 733 2365240861a2
parent 539 db914129ae01
     1.1 --- a/core/sourcehook/sourcehook_impl_cvfnptr.h	Thu Oct 14 18:14:45 2010 -0500
     1.2 +++ b/core/sourcehook/sourcehook_impl_cvfnptr.h	Sat Oct 16 23:21:58 2010 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /* ======== SourceHook ========
     1.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
     1.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
     1.7  * No warranties of any kind
     1.8  *
     1.9  * License: zlib/libpng
    1.10 @@ -13,6 +13,8 @@
    1.11  
    1.12  #include "sh_list.h"
    1.13  #include "sh_memory.h"
    1.14 +#include "sh_pagealloc.h"
    1.15 +#include "sourcehook_impl_cleanuptask.h"
    1.16  
    1.17  namespace SourceHook
    1.18  {
    1.19 @@ -20,9 +22,12 @@
    1.20  	{
    1.21  		class CVfnPtr
    1.22  		{
    1.23 +			static CPageAlloc ms_AlignedPageAllocator;
    1.24 +
    1.25  			// *** Data ***
    1.26  			void *m_Ptr;
    1.27  			void *m_OrigEntry;
    1.28 +			void *m_OrigCallThunk;		// See Init() method
    1.29  
    1.30  			List<CHookManager*> m_HookMans;
    1.31  			List<CIface> m_IfaceList;
    1.32 @@ -31,17 +36,21 @@
    1.33  			typedef void* Descriptor;
    1.34  
    1.35  			// *** Interface ***
    1.36 -			inline CVfnPtr(void *ptr);
    1.37 -			inline ~CVfnPtr();
    1.38 +			CVfnPtr(void *ptr);
    1.39 +			~CVfnPtr();
    1.40 +			bool Init();
    1.41  			inline bool operator==(const Descriptor &other);
    1.42  			inline void *GetPtr() const;
    1.43  			inline void *GetOrigEntry() const;
    1.44 +			void *GetOrigCallAddr() const;
    1.45  			inline List<CIface> &GetIfaceList();
    1.46  			inline const List<CIface> &GetIfaceList() const;
    1.47 -			inline CIface *FindIface(void *iface);
    1.48 +			CIface *FindIface(void *iface);
    1.49  			CIface &GetIface(void *iface);
    1.50  			bool Patch(void *newValue);
    1.51 -			inline bool Revert();
    1.52 +			bool Revert();
    1.53 +
    1.54 +			ICleanupTask *GetCleanupTask();
    1.55  
    1.56  			void AddHookMan(CHookManager *pHookMan);
    1.57  			// If this returns false, it means that there is no hook manager left
    1.58 @@ -50,16 +59,6 @@
    1.59  		};
    1.60  
    1.61  		// *** Implementation ***
    1.62 -		inline CVfnPtr::CVfnPtr(void *ptr)
    1.63 -			: m_Ptr(ptr), m_OrigEntry(*reinterpret_cast<void**>(m_Ptr))
    1.64 -		{
    1.65 -		}
    1.66 -
    1.67 -		inline CVfnPtr::~CVfnPtr()
    1.68 -		{
    1.69 -			if (!m_HookMans.empty())
    1.70 -				m_HookMans.front()->DecrRef(this);
    1.71 -		}
    1.72  
    1.73  		inline bool CVfnPtr::operator==(const Descriptor &other)
    1.74  		{
    1.75 @@ -85,31 +84,6 @@
    1.76  		{
    1.77  			return m_IfaceList;
    1.78  		}
    1.79 -
    1.80 -		inline bool CVfnPtr::Revert()
    1.81 -		{
    1.82 -			// Only patch the vfnptr back if the module is still in memory
    1.83 -			// If it's not, do not remove stuff like we did before
    1.84 -			// First off we did it wrong (shutdown the whole hookman, uh..) and secondly applications may be
    1.85 -			// confused by RemoveHook returning false then (yeah, I know, I made this one up, no one checks for RemoveHook error)
    1.86 -			if (ModuleInMemory(reinterpret_cast<char*>(m_Ptr), SH_PTRSIZE))
    1.87 -			{
    1.88 -				return Patch(m_OrigEntry);
    1.89 -			}
    1.90 -			else
    1.91 -			{
    1.92 -				return true;
    1.93 -			}
    1.94 -		}
    1.95 -
    1.96 -		inline CIface *CVfnPtr::FindIface(void *iface)
    1.97 -		{
    1.98 -			List<CIface>::iterator iter = m_IfaceList.find(iface);
    1.99 -			if (iter == m_IfaceList.end())
   1.100 -				return NULL;
   1.101 -			else
   1.102 -				return &(*iter);
   1.103 -		}
   1.104  	}
   1.105  }
   1.106