core/sourcehook/sourcehook_impl_chookmaninfo.h
author Scott Ehlert <ds@alliedmods.net>
Mon Apr 22 21:54:21 2013 -0500 (2013-04-22)
changeset 834 3cabb288e70a
parent 733 2365240861a2
permissions -rw-r--r--
Triggering a build.
     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_CHOOKMANINFO_H__
    12 #define __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
    13 
    14 #include "sh_list.h"
    15 #include "sourcehook_impl_cproto.h"
    16 
    17 namespace SourceHook
    18 {
    19 	namespace Impl
    20 	{
    21 		class CVfnPtr;
    22 		
    23 		class CHookManager : public IHookManagerInfo
    24 		{
    25 			// *** Data ***
    26 			Plugin m_OwnerPlugin;
    27 			HookManagerPubFunc m_PubFunc;
    28 			int m_VtblOffs;
    29 			int m_VtblIdx;
    30 			CProto m_Proto;
    31 			int m_Version;
    32 
    33 			void *m_HookfuncVfnptr;
    34 
    35 			List<CVfnPtr*> m_VfnPtrs;
    36 		public:
    37 			// *** Descriptor ***
    38 			struct Descriptor
    39 			{
    40 				Plugin m_OwnerPlugin;
    41 				HookManagerPubFunc m_PubFunc;
    42 				Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
    43 					: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
    44 				{
    45 				}
    46 			};
    47 
    48 			// *** Interface ***
    49 			CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
    50 
    51 			inline bool operator==(const Descriptor &other) const;
    52 			inline bool operator==(const CHookManager &other) const;
    53 
    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;
    62 
    63 			void Register();
    64 			void Unregister();
    65 
    66 			void IncrRef(CVfnPtr *pVfnPtr);
    67 			void DecrRef(CVfnPtr *pVfnPtr);
    68 
    69 			List<CVfnPtr*> &GetVfnPtrList()
    70 			{
    71 				return m_VfnPtrs;
    72 			}
    73 
    74 			// *** IHookManagerInfo interface ***
    75 			void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
    76 				ProtoInfo *proto, void *hookfunc_vfnptr);
    77 		};
    78 
    79 		class CHookManList : public List<CHookManager>
    80 		{
    81 		public:
    82 			CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
    83 			CHookManager *GetHookMan(CHookManager &hm);
    84 		};
    85 
    86 		// *** Implementation **/
    87 
    88 		inline CHookManager::operator bool() const
    89 		{
    90 			return m_Version != -1;
    91 		}
    92 
    93 		inline bool CHookManager::operator==(const Descriptor &other) const
    94 		{
    95 			return m_OwnerPlugin == other.m_OwnerPlugin
    96 				&& m_PubFunc == other.m_PubFunc;
    97 		}
    98 
    99 		inline bool CHookManager::operator==(const CHookManager &other) const
   100 		{
   101 			return m_OwnerPlugin == other.m_OwnerPlugin
   102 				&& m_PubFunc == other.m_PubFunc;
   103 		}
   104 
   105 		inline Plugin CHookManager::GetOwnerPlugin() const
   106 		{
   107 			return m_OwnerPlugin;
   108 		}
   109 
   110 		inline int CHookManager::GetVtblOffs() const
   111 		{
   112 			return m_VtblOffs;
   113 		}
   114 
   115 		inline int CHookManager::GetVtblIdx() const
   116 		{
   117 			return m_VtblIdx;
   118 		}
   119 
   120 		inline const CProto &CHookManager::GetProto() const
   121 		{
   122 			return m_Proto;
   123 		}
   124 
   125 		inline int CHookManager::GetVersion() const
   126 		{
   127 			return m_Version;
   128 		}
   129 
   130 		inline void *CHookManager::GetHookFunc() const
   131 		{
   132 			return *reinterpret_cast<void**>(m_HookfuncVfnptr);
   133 		}
   134 
   135 		inline HookManagerPubFunc CHookManager::GetPubFunc() const
   136 		{
   137 			return m_PubFunc;
   138 		}
   139 	}
   140 }
   141 
   142 #endif
   143