core/sourcehook/sourcehook_impl_cvfnptr.h
author Scott Ehlert <ds@alliedmods.net>
Sat Apr 23 21:35:10 2011 -0500 (2011-04-23)
changeset 747 9563de0165f7
parent 733 2365240861a2
permissions -rw-r--r--
Added detection for clang compiler and fixed various warnings triggered by it (bug 4877, r=dvander).
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2010 Metamod:Source Development Team
     3 * No warranties of any kind
     4 *
     5 * License: zlib/libpng
     6 *
     7 * Author(s): Pavol "PM OnoTo" Marko
     8 * ============================
     9 */
    10 
    11 #ifndef __SOURCEHOOK_IMPL_CVFNPTR_H__
    12 #define __SOURCEHOOK_IMPL_CVFNPTR_H__
    13 
    14 #include "sh_list.h"
    15 #include "sh_memory.h"
    16 #include "sh_pagealloc.h"
    17 #include "sourcehook_impl_cleanuptask.h"
    18 
    19 namespace SourceHook
    20 {
    21 	namespace Impl
    22 	{
    23 		class CVfnPtr
    24 		{
    25 			static CPageAlloc ms_AlignedPageAllocator;
    26 
    27 			// *** Data ***
    28 			void *m_Ptr;
    29 			void *m_OrigEntry;
    30 			void *m_OrigCallThunk;		// See Init() method
    31 
    32 			List<CHookManager*> m_HookMans;
    33 			List<CIface> m_IfaceList;
    34 		public:
    35 			// *** Descriptor ***
    36 			typedef void* Descriptor;
    37 
    38 			// *** Interface ***
    39 			CVfnPtr(void *ptr);
    40 			~CVfnPtr();
    41 			bool Init();
    42 			inline bool operator==(const Descriptor &other);
    43 			inline void *GetPtr() const;
    44 			inline void *GetOrigEntry() const;
    45 			void *GetOrigCallAddr() const;
    46 			inline List<CIface> &GetIfaceList();
    47 			inline const List<CIface> &GetIfaceList() const;
    48 			CIface *FindIface(void *iface);
    49 			CIface &GetIface(void *iface);
    50 			bool Patch(void *newValue);
    51 			bool Revert();
    52 
    53 			ICleanupTask *GetCleanupTask();
    54 
    55 			void AddHookMan(CHookManager *pHookMan);
    56 			// If this returns false, it means that there is no hook manager left
    57 			// to use and that this vfnptr should be removed.
    58 			bool HookManRemoved(CHookManager *pHookMan);
    59 		};
    60 
    61 		// *** Implementation ***
    62 
    63 		inline bool CVfnPtr::operator==(const Descriptor &other)
    64 		{
    65 			return m_Ptr == other;
    66 		}
    67 
    68 		inline void *CVfnPtr::GetPtr() const
    69 		{
    70 			return m_Ptr;
    71 		}
    72 
    73 		inline void *CVfnPtr::GetOrigEntry() const
    74 		{
    75 			return m_OrigEntry;
    76 		}
    77 
    78 		inline List<CIface> &CVfnPtr::GetIfaceList()
    79 		{
    80 			return m_IfaceList;
    81 		}
    82 
    83 		inline const List<CIface> &CVfnPtr::GetIfaceList() const
    84 		{
    85 			return m_IfaceList;
    86 		}
    87 	}
    88 }
    89 
    90 #endif
    91