sourcehook/sourcehook_impl_chookmaninfo.h
author Pavol Marko <pavolmarko@gmail.com>
Sun Oct 07 22:45:22 2007 +0000 (2007-10-07)
changeset 384 264cab8ff2cc
parent 381 8eded451c936
child 418 109309ff6350
permissions -rw-r--r--
correct version now... i guess i'm just tired :)
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2007 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 CHookManager : public IHookManagerInfo
    22 		{
    23 			// *** Data ***
    24 			Plugin m_OwnerPlugin;
    25 			HookManagerPubFunc m_PubFunc;
    26 			int m_VtblOffs;
    27 			int m_VtblIdx;
    28 			CProto m_Proto;
    29 			int m_Version;
    30 
    31 			void *m_HookfuncVfnptr;
    32 			List<CVfnPtr> m_VfnPtrList;
    33 		public:
    34 			// *** Descriptor ***
    35 			struct Descriptor
    36 			{
    37 				Plugin m_OwnerPlugin;
    38 				HookManagerPubFunc m_PubFunc;
    39 				Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
    40 					: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
    41 				{
    42 				}
    43 			};
    44 
    45 			// *** Interface ***
    46 			inline CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
    47 
    48 			inline bool operator==(const Descriptor &other) const;
    49 			inline bool operator==(const CHookManager &other) const;
    50 
    51 			inline operator bool()  const;
    52 			inline Plugin GetOwnerPlugin()  const;
    53 			inline int GetVtblOffs()  const;
    54 			inline int GetVtblIdx()  const;
    55 			inline const CProto &GetProto()  const;
    56 			inline int GetVersion()  const;
    57 			inline void *GetHookFunc() const;
    58 			inline HookManagerPubFunc GetPubFunc() const;
    59 
    60 			inline List<CVfnPtr> &GetVfnPtrList();
    61 			inline const List<CVfnPtr> &GetVfnPtrList() const;
    62 
    63 			inline void Register();
    64 			inline void Unregister();
    65 
    66 			CVfnPtr &GetVfnPtr(void *vfnptr);
    67 
    68 			// *** IHookManagerInfo interface ***
    69 			void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
    70 				ProtoInfo *proto, void *hookfunc_vfnptr);
    71 		};
    72 
    73 		// *** Implementation ***
    74 		inline CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
    75 			: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
    76 		{
    77 			// Query pubfunc
    78 			//  -> Should call SetInfo and set all the other variables!
    79 			if (m_PubFunc(false, this) != 0)
    80 			{
    81 				// Error!
    82 				m_Version = -1;
    83 			}
    84 		}
    85 
    86 		inline CHookManager::operator bool() const
    87 		{
    88 			return m_Version != -1;
    89 		}
    90 
    91 		inline bool CHookManager::operator==(const Descriptor &other) const
    92 		{
    93 			return m_OwnerPlugin == other.m_OwnerPlugin
    94 				&& m_PubFunc == other.m_PubFunc;
    95 		}
    96 
    97 		inline bool CHookManager::operator==(const CHookManager &other) const
    98 		{
    99 			return m_OwnerPlugin == other.m_OwnerPlugin
   100 				&& m_PubFunc == other.m_PubFunc;
   101 		}
   102 
   103 		inline Plugin CHookManager::GetOwnerPlugin() const
   104 		{
   105 			return m_OwnerPlugin;
   106 		}
   107 
   108 		inline int CHookManager::GetVtblOffs() const
   109 		{
   110 			return m_VtblOffs;
   111 		}
   112 
   113 		inline int CHookManager::GetVtblIdx() const
   114 		{
   115 			return m_VtblIdx;
   116 		}
   117 
   118 		inline const CProto &CHookManager::GetProto() const
   119 		{
   120 			return m_Proto;
   121 		}
   122 
   123 		inline int CHookManager::GetVersion() const
   124 		{
   125 			return m_Version;
   126 		}
   127 
   128 		inline void *CHookManager::GetHookFunc() const
   129 		{
   130 			return *reinterpret_cast<void**>(m_HookfuncVfnptr);
   131 		}
   132 
   133 		inline HookManagerPubFunc CHookManager::GetPubFunc() const
   134 		{
   135 			return m_PubFunc;
   136 		}
   137 
   138 		inline List<CVfnPtr> &CHookManager::GetVfnPtrList()
   139 		{
   140 			return m_VfnPtrList;
   141 		}
   142 
   143 		inline const List<CVfnPtr> &CHookManager::GetVfnPtrList() const
   144 		{
   145 			return m_VfnPtrList;
   146 		}
   147 
   148 		inline void CHookManager::Register()
   149 		{
   150 			m_PubFunc(true, this);
   151 		}
   152 
   153 		inline void CHookManager::Unregister()
   154 		{
   155 			m_PubFunc(true, NULL);
   156 		}
   157 	}
   158 }
   159 
   160 #endif
   161