core/sourcehook/sourcehook_impl_chookmaninfo.h
changeset 658 8353605c1d97
parent 539 db914129ae01
child 733 2365240861a2
     1.1 --- a/core/sourcehook/sourcehook_impl_chookmaninfo.h	Fri Feb 27 00:19:50 2009 -0600
     1.2 +++ b/core/sourcehook/sourcehook_impl_chookmaninfo.h	Thu Oct 29 00:07:23 2009 -0500
     1.3 @@ -1,198 +1,198 @@
     1.4 -/* ======== SourceHook ========
     1.5 -* Copyright (C) 2004-2008 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 CVfnPtr;
    1.25 -		
    1.26 -		class CHookManager : public IHookManagerInfo
    1.27 -		{
    1.28 -			// *** Data ***
    1.29 -			Plugin m_OwnerPlugin;
    1.30 -			HookManagerPubFunc m_PubFunc;
    1.31 -			int m_VtblOffs;
    1.32 -			int m_VtblIdx;
    1.33 -			CProto m_Proto;
    1.34 -			int m_Version;
    1.35 -
    1.36 -			void *m_HookfuncVfnptr;
    1.37 -
    1.38 -			List<CVfnPtr*> m_VfnPtrs;
    1.39 -		public:
    1.40 -			// *** Descriptor ***
    1.41 -			struct Descriptor
    1.42 -			{
    1.43 -				Plugin m_OwnerPlugin;
    1.44 -				HookManagerPubFunc m_PubFunc;
    1.45 -				Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
    1.46 -					: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
    1.47 -				{
    1.48 -				}
    1.49 -			};
    1.50 -
    1.51 -			// *** Interface ***
    1.52 -			inline CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
    1.53 -
    1.54 -			inline bool operator==(const Descriptor &other) const;
    1.55 -			inline bool operator==(const CHookManager &other) const;
    1.56 -
    1.57 -			inline operator bool()  const;
    1.58 -			inline Plugin GetOwnerPlugin()  const;
    1.59 -			inline int GetVtblOffs()  const;
    1.60 -			inline int GetVtblIdx()  const;
    1.61 -			inline const CProto &GetProto()  const;
    1.62 -			inline int GetVersion()  const;
    1.63 -			inline void *GetHookFunc() const;
    1.64 -			inline HookManagerPubFunc GetPubFunc() const;
    1.65 -
    1.66 -			inline void Register();
    1.67 -			inline void Unregister();
    1.68 -
    1.69 -			inline void IncrRef(CVfnPtr *pVfnPtr);
    1.70 -			inline void DecrRef(CVfnPtr *pVfnPtr);
    1.71 -
    1.72 -			List<CVfnPtr*> &GetVfnPtrList()
    1.73 -			{
    1.74 -				return m_VfnPtrs;
    1.75 -			}
    1.76 -
    1.77 -			// *** IHookManagerInfo interface ***
    1.78 +/* ======== SourceHook ========
    1.79 +* Copyright (C) 2004-2008 Metamod:Source Development Team
    1.80 +* No warranties of any kind
    1.81 +*
    1.82 +* License: zlib/libpng
    1.83 +*
    1.84 +* Author(s): Pavol "PM OnoTo" Marko
    1.85 +* ============================
    1.86 +*/
    1.87 +
    1.88 +#ifndef __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
    1.89 +#define __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
    1.90 +
    1.91 +#include "sh_list.h"
    1.92 +#include "sourcehook_impl_cproto.h"
    1.93 +
    1.94 +namespace SourceHook
    1.95 +{
    1.96 +	namespace Impl
    1.97 +	{
    1.98 +		class CVfnPtr;
    1.99 +		
   1.100 +		class CHookManager : public IHookManagerInfo
   1.101 +		{
   1.102 +			// *** Data ***
   1.103 +			Plugin m_OwnerPlugin;
   1.104 +			HookManagerPubFunc m_PubFunc;
   1.105 +			int m_VtblOffs;
   1.106 +			int m_VtblIdx;
   1.107 +			CProto m_Proto;
   1.108 +			int m_Version;
   1.109 +
   1.110 +			void *m_HookfuncVfnptr;
   1.111 +
   1.112 +			List<CVfnPtr*> m_VfnPtrs;
   1.113 +		public:
   1.114 +			// *** Descriptor ***
   1.115 +			struct Descriptor
   1.116 +			{
   1.117 +				Plugin m_OwnerPlugin;
   1.118 +				HookManagerPubFunc m_PubFunc;
   1.119 +				Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
   1.120 +					: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
   1.121 +				{
   1.122 +				}
   1.123 +			};
   1.124 +
   1.125 +			// *** Interface ***
   1.126 +			inline CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
   1.127 +
   1.128 +			inline bool operator==(const Descriptor &other) const;
   1.129 +			inline bool operator==(const CHookManager &other) const;
   1.130 +
   1.131 +			inline operator bool()  const;
   1.132 +			inline Plugin GetOwnerPlugin()  const;
   1.133 +			inline int GetVtblOffs()  const;
   1.134 +			inline int GetVtblIdx()  const;
   1.135 +			inline const CProto &GetProto()  const;
   1.136 +			inline int GetVersion()  const;
   1.137 +			inline void *GetHookFunc() const;
   1.138 +			inline HookManagerPubFunc GetPubFunc() const;
   1.139 +
   1.140 +			inline void Register();
   1.141 +			inline void Unregister();
   1.142 +
   1.143 +			inline void IncrRef(CVfnPtr *pVfnPtr);
   1.144 +			inline void DecrRef(CVfnPtr *pVfnPtr);
   1.145 +
   1.146 +			List<CVfnPtr*> &GetVfnPtrList()
   1.147 +			{
   1.148 +				return m_VfnPtrs;
   1.149 +			}
   1.150 +
   1.151 +			// *** IHookManagerInfo interface ***
   1.152  			void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
   1.153 -				ProtoInfo *proto, void *hookfunc_vfnptr);
   1.154 -		};
   1.155 -
   1.156 -		class CHookManList : public List<CHookManager>
   1.157 -		{
   1.158 -		public:
   1.159 -			inline CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
   1.160 -			inline CHookManager *GetHookMan(CHookManager &hm);
   1.161 -		};
   1.162 -
   1.163 -		// *** Implementation ***
   1.164 -		inline CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
   1.165 -			: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
   1.166 -		{
   1.167 -			// Query pubfunc
   1.168 -			//  -> Should call SetInfo and set all the other variables!
   1.169 -			if (m_PubFunc(false, this) != 0)
   1.170 -			{
   1.171 -				// Error!
   1.172 -				m_Version = -1;
   1.173 -			}
   1.174 -		}
   1.175 -
   1.176 -		inline CHookManager::operator bool() const
   1.177 -		{
   1.178 -			return m_Version != -1;
   1.179 -		}
   1.180 -
   1.181 -		inline bool CHookManager::operator==(const Descriptor &other) const
   1.182 -		{
   1.183 -			return m_OwnerPlugin == other.m_OwnerPlugin
   1.184 -				&& m_PubFunc == other.m_PubFunc;
   1.185 -		}
   1.186 -
   1.187 -		inline bool CHookManager::operator==(const CHookManager &other) const
   1.188 -		{
   1.189 -			return m_OwnerPlugin == other.m_OwnerPlugin
   1.190 -				&& m_PubFunc == other.m_PubFunc;
   1.191 -		}
   1.192 -
   1.193 -		inline Plugin CHookManager::GetOwnerPlugin() const
   1.194 -		{
   1.195 -			return m_OwnerPlugin;
   1.196 -		}
   1.197 -
   1.198 -		inline int CHookManager::GetVtblOffs() const
   1.199 -		{
   1.200 -			return m_VtblOffs;
   1.201 -		}
   1.202 -
   1.203 -		inline int CHookManager::GetVtblIdx() const
   1.204 -		{
   1.205 -			return m_VtblIdx;
   1.206 -		}
   1.207 -
   1.208 -		inline const CProto &CHookManager::GetProto() const
   1.209 -		{
   1.210 -			return m_Proto;
   1.211 -		}
   1.212 -
   1.213 -		inline int CHookManager::GetVersion() const
   1.214 -		{
   1.215 -			return m_Version;
   1.216 -		}
   1.217 -
   1.218 -		inline void *CHookManager::GetHookFunc() const
   1.219 -		{
   1.220 -			return *reinterpret_cast<void**>(m_HookfuncVfnptr);
   1.221 -		}
   1.222 -
   1.223 -		inline HookManagerPubFunc CHookManager::GetPubFunc() const
   1.224 -		{
   1.225 -			return m_PubFunc;
   1.226 -		}
   1.227 -
   1.228 -		inline void CHookManager::Register()
   1.229 -		{
   1.230 -			m_PubFunc(true, this);
   1.231 -		}
   1.232 -
   1.233 -		inline void CHookManager::Unregister()
   1.234 -		{
   1.235 -			m_PubFunc(true, NULL);
   1.236 -		}
   1.237 -
   1.238 -		inline void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
   1.239 -		{
   1.240 -			m_VfnPtrs.push_back(pVfnPtr);
   1.241 -			if (m_VfnPtrs.size() == 1)
   1.242 -				Register();
   1.243 -		}
   1.244 -
   1.245 -		inline void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
   1.246 -		{
   1.247 -			m_VfnPtrs.remove(pVfnPtr);
   1.248 -			if (m_VfnPtrs.empty())
   1.249 -				Unregister();
   1.250 -		}
   1.251 -
   1.252 -		inline CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
   1.253 -		{
   1.254 -			CHookManager hm(plug, pubFunc);
   1.255 -			return GetHookMan(hm);
   1.256 -		}
   1.257 -
   1.258 -		inline CHookManager *CHookManList::GetHookMan(CHookManager &hm)
   1.259 -		{
   1.260 -			iterator iter = find(hm);
   1.261 -			if (iter == end())
   1.262 -			{
   1.263 -				push_back(hm);
   1.264 -				return &(back());
   1.265 -			}
   1.266 -			else
   1.267 -			{
   1.268 -				return &(*iter);
   1.269 -			}
   1.270 -		}
   1.271 -	}
   1.272 -}
   1.273 -
   1.274 +				ProtoInfo *proto, void *hookfunc_vfnptr);
   1.275 +		};
   1.276 +
   1.277 +		class CHookManList : public List<CHookManager>
   1.278 +		{
   1.279 +		public:
   1.280 +			inline CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
   1.281 +			inline CHookManager *GetHookMan(CHookManager &hm);
   1.282 +		};
   1.283 +
   1.284 +		// *** Implementation ***
   1.285 +		inline CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
   1.286 +			: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
   1.287 +		{
   1.288 +			// Query pubfunc
   1.289 +			//  -> Should call SetInfo and set all the other variables!
   1.290 +			if (m_PubFunc(false, this) != 0)
   1.291 +			{
   1.292 +				// Error!
   1.293 +				m_Version = -1;
   1.294 +			}
   1.295 +		}
   1.296 +
   1.297 +		inline CHookManager::operator bool() const
   1.298 +		{
   1.299 +			return m_Version != -1;
   1.300 +		}
   1.301 +
   1.302 +		inline bool CHookManager::operator==(const Descriptor &other) const
   1.303 +		{
   1.304 +			return m_OwnerPlugin == other.m_OwnerPlugin
   1.305 +				&& m_PubFunc == other.m_PubFunc;
   1.306 +		}
   1.307 +
   1.308 +		inline bool CHookManager::operator==(const CHookManager &other) const
   1.309 +		{
   1.310 +			return m_OwnerPlugin == other.m_OwnerPlugin
   1.311 +				&& m_PubFunc == other.m_PubFunc;
   1.312 +		}
   1.313 +
   1.314 +		inline Plugin CHookManager::GetOwnerPlugin() const
   1.315 +		{
   1.316 +			return m_OwnerPlugin;
   1.317 +		}
   1.318 +
   1.319 +		inline int CHookManager::GetVtblOffs() const
   1.320 +		{
   1.321 +			return m_VtblOffs;
   1.322 +		}
   1.323 +
   1.324 +		inline int CHookManager::GetVtblIdx() const
   1.325 +		{
   1.326 +			return m_VtblIdx;
   1.327 +		}
   1.328 +
   1.329 +		inline const CProto &CHookManager::GetProto() const
   1.330 +		{
   1.331 +			return m_Proto;
   1.332 +		}
   1.333 +
   1.334 +		inline int CHookManager::GetVersion() const
   1.335 +		{
   1.336 +			return m_Version;
   1.337 +		}
   1.338 +
   1.339 +		inline void *CHookManager::GetHookFunc() const
   1.340 +		{
   1.341 +			return *reinterpret_cast<void**>(m_HookfuncVfnptr);
   1.342 +		}
   1.343 +
   1.344 +		inline HookManagerPubFunc CHookManager::GetPubFunc() const
   1.345 +		{
   1.346 +			return m_PubFunc;
   1.347 +		}
   1.348 +
   1.349 +		inline void CHookManager::Register()
   1.350 +		{
   1.351 +			m_PubFunc(true, this);
   1.352 +		}
   1.353 +
   1.354 +		inline void CHookManager::Unregister()
   1.355 +		{
   1.356 +			m_PubFunc(true, NULL);
   1.357 +		}
   1.358 +
   1.359 +		inline void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
   1.360 +		{
   1.361 +			m_VfnPtrs.push_back(pVfnPtr);
   1.362 +			if (m_VfnPtrs.size() == 1)
   1.363 +				Register();
   1.364 +		}
   1.365 +
   1.366 +		inline void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
   1.367 +		{
   1.368 +			m_VfnPtrs.remove(pVfnPtr);
   1.369 +			if (m_VfnPtrs.empty())
   1.370 +				Unregister();
   1.371 +		}
   1.372 +
   1.373 +		inline CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
   1.374 +		{
   1.375 +			CHookManager hm(plug, pubFunc);
   1.376 +			return GetHookMan(hm);
   1.377 +		}
   1.378 +
   1.379 +		inline CHookManager *CHookManList::GetHookMan(CHookManager &hm)
   1.380 +		{
   1.381 +			iterator iter = find(hm);
   1.382 +			if (iter == end())
   1.383 +			{
   1.384 +				push_back(hm);
   1.385 +				return &(back());
   1.386 +			}
   1.387 +			else
   1.388 +			{
   1.389 +				return &(*iter);
   1.390 +			}
   1.391 +		}
   1.392 +	}
   1.393 +}
   1.394 +
   1.395  #endif
   1.396