sourcehook/sourcehook_impl_chookmaninfo.h
changeset 380 f9e21a2ac558
child 381 8eded451c936
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sourcehook/sourcehook_impl_chookmaninfo.h	Sun Oct 07 22:10:07 2007 +0000
     1.3 @@ -0,0 +1,160 @@
     1.4 +/* ======== SourceHook ========
     1.5 +* Copyright (C) 2004-2007 Metamod:Source Development Team
     1.6 +* No warranties of any kind
     1.7 +*
     1.8 +* License: zlib/libpng
     1.9 +*
    1.10 +* Author(s): Pavol "PM OnoTo" Marko
    1.11 +* ============================
    1.12 +*/
    1.13 +
    1.14 +#ifndef __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
    1.15 +#define __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
    1.16 +
    1.17 +#include "sh_list.h"
    1.18 +#include "sourcehook_impl_cproto.h"
    1.19 +
    1.20 +namespace SourceHook
    1.21 +{
    1.22 +	namespace Impl
    1.23 +	{
    1.24 +		class CHookManager : public IHookManagerInfo
    1.25 +		{
    1.26 +			// *** Data ***
    1.27 +			Plugin m_OwnerPlugin;
    1.28 +			HookManagerPubFunc m_PubFunc;
    1.29 +			int m_VtblOffs;
    1.30 +			int m_VtblIdx;
    1.31 +			CProto m_Proto;
    1.32 +			int m_Version;
    1.33 +
    1.34 +			void *m_HookfuncVfnptr;
    1.35 +			List<CVfnPtr> m_VfnPtrList;
    1.36 +		public:
    1.37 +			// *** Descriptor ***
    1.38 +			struct Descriptor
    1.39 +			{
    1.40 +				Plugin m_OwnerPlugin;
    1.41 +				HookManagerPubFunc m_PubFunc;
    1.42 +				Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
    1.43 +					: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
    1.44 +				{
    1.45 +				}
    1.46 +			};
    1.47 +
    1.48 +			// *** Interface ***
    1.49 +			inline CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
    1.50 +
    1.51 +			inline bool operator==(const Descriptor &other) const;
    1.52 +			inline bool operator==(const CHookManager &other) const;
    1.53 +
    1.54 +			inline operator bool()  const;
    1.55 +			inline Plugin GetOwnerPlugin()  const;
    1.56 +			inline int GetVtblOffs()  const;
    1.57 +			inline int GetVtblIdx()  const;
    1.58 +			inline const CProto &GetProto()  const;
    1.59 +			inline int GetVersion()  const;
    1.60 +			inline void *GetHookFunc() const;
    1.61 +			inline HookManagerPubFunc GetPubFunc() const;
    1.62 +
    1.63 +			inline List<CVfnPtr> &GetVfnPtrList();
    1.64 +			inline const List<CVfnPtr> &GetVfnPtrList() const;
    1.65 +
    1.66 +			inline void Register();
    1.67 +			inline void Unregister();
    1.68 +
    1.69 +			CVfnPtr &GetVfnPtr(void *vfnptr);
    1.70 +
    1.71 +			// *** IHookManagerInfo interface ***
    1.72 +			void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
    1.73 +				ProtoInfo *proto, void *hookfunc_vfnptr);
    1.74 +		};
    1.75 +
    1.76 +		// *** Implementation ***
    1.77 +		inline CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
    1.78 +			: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
    1.79 +		{
    1.80 +			// Query pubfunc
    1.81 +			//  -> Should call SetInfo and set all the other variables!
    1.82 +			if (m_PubFunc(false, this) != 0)
    1.83 +			{
    1.84 +				// Error!
    1.85 +				m_Version = -1;
    1.86 +			}
    1.87 +		}
    1.88 +
    1.89 +		inline CHookManager::operator bool() const
    1.90 +		{
    1.91 +			return m_Version != -1;
    1.92 +		}
    1.93 +
    1.94 +		inline bool CHookManager::operator==(const Descriptor &other) const
    1.95 +		{
    1.96 +			return m_OwnerPlugin == other.m_OwnerPlugin
    1.97 +				&& m_PubFunc == other.m_PubFunc;
    1.98 +		}
    1.99 +
   1.100 +		inline bool CHookManager::operator==(const CHookManager &other) const
   1.101 +		{
   1.102 +			return m_OwnerPlugin == other.m_OwnerPlugin
   1.103 +				&& m_PubFunc == other.m_PubFunc;
   1.104 +		}
   1.105 +
   1.106 +		inline Plugin CHookManager::GetOwnerPlugin() const
   1.107 +		{
   1.108 +			return m_OwnerPlugin;
   1.109 +		}
   1.110 +
   1.111 +		inline int CHookManager::GetVtblOffs() const
   1.112 +		{
   1.113 +			return m_VtblOffs;
   1.114 +		}
   1.115 +
   1.116 +		inline int CHookManager::GetVtblIdx() const
   1.117 +		{
   1.118 +			return m_VtblIdx;
   1.119 +		}
   1.120 +
   1.121 +		inline const CProto &CHookManager::GetProto() const
   1.122 +		{
   1.123 +			return m_Proto;
   1.124 +		}
   1.125 +
   1.126 +		inline int CHookManager::GetVersion() const
   1.127 +		{
   1.128 +			return m_Version;
   1.129 +		}
   1.130 +
   1.131 +		inline void *CHookManager::GetHookFunc() const
   1.132 +		{
   1.133 +			return *reinterpret_cast<void**>(m_HookfuncVfnptr);
   1.134 +		}
   1.135 +
   1.136 +		inline HookManagerPubFunc CHookManager::GetPubFunc() const
   1.137 +		{
   1.138 +			return m_PubFunc;
   1.139 +		}
   1.140 +
   1.141 +		inline List<CVfnPtr> &CHookManager::GetVfnPtrList()
   1.142 +		{
   1.143 +			return m_VfnPtrList;
   1.144 +		}
   1.145 +
   1.146 +		inline const List<CVfnPtr> &CHookManager::GetVfnPtrList() const
   1.147 +		{
   1.148 +			return m_VfnPtrList;
   1.149 +		}
   1.150 +
   1.151 +		inline void CHookManager::Register()
   1.152 +		{
   1.153 +			m_PubFunc(true, this);
   1.154 +		}
   1.155 +
   1.156 +		inline void CHookManager::Unregister()
   1.157 +		{
   1.158 +			m_PubFunc(true, NULL);
   1.159 +		}
   1.160 +	}
   1.161 +}
   1.162 +
   1.163 +#endif
   1.164 \ No newline at end of file