sourcehook/sourcehook_impl_chookmaninfo.h
branchhookman_autogen
changeset 531 0180319136ba
parent 479 b43ebc944319
child 532 9729de2d7551
     1.1 --- a/sourcehook/sourcehook_impl_chookmaninfo.h	Sun Nov 25 01:22:41 2007 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,199 +0,0 @@
     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 -#include "sourcehook_hookmangen.h"
    1.20 -
    1.21 -namespace SourceHook
    1.22 -{
    1.23 -	namespace Impl
    1.24 -	{
    1.25 -		class CVfnPtr;
    1.26 -		
    1.27 -		class CHookManager : public IHookManagerInfo
    1.28 -		{
    1.29 -			// *** Data ***
    1.30 -			Plugin m_OwnerPlugin;
    1.31 -			HookManagerPubFunc m_PubFunc;
    1.32 -			int m_VtblOffs;
    1.33 -			int m_VtblIdx;
    1.34 -			CProto m_Proto;
    1.35 -			int m_Version;
    1.36 -
    1.37 -			void *m_HookfuncVfnptr;
    1.38 -
    1.39 -			List<CVfnPtr*> m_VfnPtrs;
    1.40 -		public:
    1.41 -			// *** Descriptor ***
    1.42 -			struct Descriptor
    1.43 -			{
    1.44 -				Plugin m_OwnerPlugin;
    1.45 -				HookManagerPubFunc m_PubFunc;
    1.46 -				Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
    1.47 -					: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
    1.48 -				{
    1.49 -				}
    1.50 -			};
    1.51 -
    1.52 -			// *** Interface ***
    1.53 -			inline CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
    1.54 -
    1.55 -			inline bool operator==(const Descriptor &other) const;
    1.56 -			inline bool operator==(const CHookManager &other) const;
    1.57 -
    1.58 -			inline operator bool()  const;
    1.59 -			inline Plugin GetOwnerPlugin()  const;
    1.60 -			inline int GetVtblOffs()  const;
    1.61 -			inline int GetVtblIdx()  const;
    1.62 -			inline const CProto &GetProto()  const;
    1.63 -			inline int GetVersion()  const;
    1.64 -			inline void *GetHookFunc() const;
    1.65 -			inline HookManagerPubFunc GetPubFunc() const;
    1.66 -
    1.67 -			inline void Register();
    1.68 -			inline void Unregister();
    1.69 -
    1.70 -			inline void IncrRef(CVfnPtr *pVfnPtr);
    1.71 -			inline void DecrRef(CVfnPtr *pVfnPtr);
    1.72 -
    1.73 -			List<CVfnPtr*> &GetVfnPtrList()
    1.74 -			{
    1.75 -				return m_VfnPtrs;
    1.76 -			}
    1.77 -
    1.78 -			// *** IHookManagerInfo interface ***
    1.79 -			void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
    1.80 -				ProtoInfo *proto, void *hookfunc_vfnptr);
    1.81 -		};
    1.82 -
    1.83 -		class CHookManList : public List<CHookManager>
    1.84 -		{
    1.85 -		public:
    1.86 -			inline CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
    1.87 -			inline CHookManager *GetHookMan(CHookManager &hm);
    1.88 -		};
    1.89 -
    1.90 -		// *** Implementation ***
    1.91 -		inline CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
    1.92 -			: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
    1.93 -		{
    1.94 -			// Query pubfunc
    1.95 -			//  -> Should call SetInfo and set all the other variables!
    1.96 -			if (m_PubFunc(false, this) != 0)
    1.97 -			{
    1.98 -				// Error!
    1.99 -				m_Version = -1;
   1.100 -			}
   1.101 -		}
   1.102 -
   1.103 -		inline CHookManager::operator bool() const
   1.104 -		{
   1.105 -			return m_Version != -1;
   1.106 -		}
   1.107 -
   1.108 -		inline bool CHookManager::operator==(const Descriptor &other) const
   1.109 -		{
   1.110 -			return m_OwnerPlugin == other.m_OwnerPlugin
   1.111 -				&& m_PubFunc == other.m_PubFunc;
   1.112 -		}
   1.113 -
   1.114 -		inline bool CHookManager::operator==(const CHookManager &other) const
   1.115 -		{
   1.116 -			return m_OwnerPlugin == other.m_OwnerPlugin
   1.117 -				&& m_PubFunc == other.m_PubFunc;
   1.118 -		}
   1.119 -
   1.120 -		inline Plugin CHookManager::GetOwnerPlugin() const
   1.121 -		{
   1.122 -			return m_OwnerPlugin;
   1.123 -		}
   1.124 -
   1.125 -		inline int CHookManager::GetVtblOffs() const
   1.126 -		{
   1.127 -			return m_VtblOffs;
   1.128 -		}
   1.129 -
   1.130 -		inline int CHookManager::GetVtblIdx() const
   1.131 -		{
   1.132 -			return m_VtblIdx;
   1.133 -		}
   1.134 -
   1.135 -		inline const CProto &CHookManager::GetProto() const
   1.136 -		{
   1.137 -			return m_Proto;
   1.138 -		}
   1.139 -
   1.140 -		inline int CHookManager::GetVersion() const
   1.141 -		{
   1.142 -			return m_Version;
   1.143 -		}
   1.144 -
   1.145 -		inline void *CHookManager::GetHookFunc() const
   1.146 -		{
   1.147 -			return *reinterpret_cast<void**>(m_HookfuncVfnptr);
   1.148 -		}
   1.149 -
   1.150 -		inline HookManagerPubFunc CHookManager::GetPubFunc() const
   1.151 -		{
   1.152 -			return m_PubFunc;
   1.153 -		}
   1.154 -
   1.155 -		inline void CHookManager::Register()
   1.156 -		{
   1.157 -			m_PubFunc(true, this);
   1.158 -		}
   1.159 -
   1.160 -		inline void CHookManager::Unregister()
   1.161 -		{
   1.162 -			m_PubFunc(true, NULL);
   1.163 -		}
   1.164 -
   1.165 -		inline void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
   1.166 -		{
   1.167 -			m_VfnPtrs.push_back(pVfnPtr);
   1.168 -			if (m_VfnPtrs.size() == 1)
   1.169 -				Register();
   1.170 -		}
   1.171 -
   1.172 -		inline void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
   1.173 -		{
   1.174 -			m_VfnPtrs.remove(pVfnPtr);
   1.175 -			if (m_VfnPtrs.empty())
   1.176 -				Unregister();
   1.177 -		}
   1.178 -
   1.179 -		inline CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
   1.180 -		{
   1.181 -			CHookManager hm(plug, pubFunc);
   1.182 -			return GetHookMan(hm);
   1.183 -		}
   1.184 -
   1.185 -		inline CHookManager *CHookManList::GetHookMan(CHookManager &hm)
   1.186 -		{
   1.187 -			iterator iter = find(hm);
   1.188 -			if (iter == end())
   1.189 -			{
   1.190 -				push_back(hm);
   1.191 -				return &(back());
   1.192 -			}
   1.193 -			else
   1.194 -			{
   1.195 -				return &(*iter);
   1.196 -			}
   1.197 -		}
   1.198 -	}
   1.199 -}
   1.200 -
   1.201 -#endif
   1.202 -