core/sourcehook/sourcehook_impl_chookmaninfo.h
author Nicholas Hastings <skamonkey@gmail.com>
Sat Aug 03 13:56:58 2013 -0400 (2013-08-03)
changeset 855 2b6068989da7
parent 733 2365240861a2
permissions -rw-r--r--
Fixed MetamodVersionInfo::GetGameDir always returning NULL or garbage.
ds@658
     1
/* ======== SourceHook ========
pavolmarko@733
     2
* Copyright (C) 2004-2010 Metamod:Source Development Team
ds@658
     3
* No warranties of any kind
ds@658
     4
*
ds@658
     5
* License: zlib/libpng
ds@658
     6
*
ds@658
     7
* Author(s): Pavol "PM OnoTo" Marko
ds@658
     8
* ============================
ds@658
     9
*/
ds@658
    10
ds@658
    11
#ifndef __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
ds@658
    12
#define __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
ds@658
    13
ds@658
    14
#include "sh_list.h"
ds@658
    15
#include "sourcehook_impl_cproto.h"
ds@658
    16
ds@658
    17
namespace SourceHook
ds@658
    18
{
ds@658
    19
	namespace Impl
ds@658
    20
	{
ds@658
    21
		class CVfnPtr;
ds@658
    22
		
ds@658
    23
		class CHookManager : public IHookManagerInfo
ds@658
    24
		{
ds@658
    25
			// *** Data ***
ds@658
    26
			Plugin m_OwnerPlugin;
ds@658
    27
			HookManagerPubFunc m_PubFunc;
ds@658
    28
			int m_VtblOffs;
ds@658
    29
			int m_VtblIdx;
ds@658
    30
			CProto m_Proto;
ds@658
    31
			int m_Version;
ds@658
    32
ds@658
    33
			void *m_HookfuncVfnptr;
ds@658
    34
ds@658
    35
			List<CVfnPtr*> m_VfnPtrs;
ds@658
    36
		public:
ds@658
    37
			// *** Descriptor ***
ds@658
    38
			struct Descriptor
ds@658
    39
			{
ds@658
    40
				Plugin m_OwnerPlugin;
ds@658
    41
				HookManagerPubFunc m_PubFunc;
ds@658
    42
				Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
ds@658
    43
					: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
ds@658
    44
				{
ds@658
    45
				}
ds@658
    46
			};
ds@658
    47
ds@658
    48
			// *** Interface ***
pavolmarko@733
    49
			CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
ds@658
    50
ds@658
    51
			inline bool operator==(const Descriptor &other) const;
ds@658
    52
			inline bool operator==(const CHookManager &other) const;
ds@658
    53
ds@658
    54
			inline operator bool()  const;
ds@658
    55
			inline Plugin GetOwnerPlugin()  const;
ds@658
    56
			inline int GetVtblOffs()  const;
ds@658
    57
			inline int GetVtblIdx()  const;
ds@658
    58
			inline const CProto &GetProto()  const;
ds@658
    59
			inline int GetVersion()  const;
ds@658
    60
			inline void *GetHookFunc() const;
ds@658
    61
			inline HookManagerPubFunc GetPubFunc() const;
ds@658
    62
pavolmarko@733
    63
			void Register();
pavolmarko@733
    64
			void Unregister();
ds@658
    65
pavolmarko@733
    66
			void IncrRef(CVfnPtr *pVfnPtr);
pavolmarko@733
    67
			void DecrRef(CVfnPtr *pVfnPtr);
ds@658
    68
ds@658
    69
			List<CVfnPtr*> &GetVfnPtrList()
ds@658
    70
			{
ds@658
    71
				return m_VfnPtrs;
ds@658
    72
			}
ds@658
    73
ds@658
    74
			// *** IHookManagerInfo interface ***
pavolmarko@380
    75
			void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
ds@658
    76
				ProtoInfo *proto, void *hookfunc_vfnptr);
ds@658
    77
		};
ds@658
    78
ds@658
    79
		class CHookManList : public List<CHookManager>
ds@658
    80
		{
ds@658
    81
		public:
pavolmarko@733
    82
			CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
pavolmarko@733
    83
			CHookManager *GetHookMan(CHookManager &hm);
ds@658
    84
		};
ds@658
    85
pavolmarko@733
    86
		// *** Implementation **/
ds@658
    87
ds@658
    88
		inline CHookManager::operator bool() const
ds@658
    89
		{
ds@658
    90
			return m_Version != -1;
ds@658
    91
		}
ds@658
    92
ds@658
    93
		inline bool CHookManager::operator==(const Descriptor &other) const
ds@658
    94
		{
ds@658
    95
			return m_OwnerPlugin == other.m_OwnerPlugin
ds@658
    96
				&& m_PubFunc == other.m_PubFunc;
ds@658
    97
		}
ds@658
    98
ds@658
    99
		inline bool CHookManager::operator==(const CHookManager &other) const
ds@658
   100
		{
ds@658
   101
			return m_OwnerPlugin == other.m_OwnerPlugin
ds@658
   102
				&& m_PubFunc == other.m_PubFunc;
ds@658
   103
		}
ds@658
   104
ds@658
   105
		inline Plugin CHookManager::GetOwnerPlugin() const
ds@658
   106
		{
ds@658
   107
			return m_OwnerPlugin;
ds@658
   108
		}
ds@658
   109
ds@658
   110
		inline int CHookManager::GetVtblOffs() const
ds@658
   111
		{
ds@658
   112
			return m_VtblOffs;
ds@658
   113
		}
ds@658
   114
ds@658
   115
		inline int CHookManager::GetVtblIdx() const
ds@658
   116
		{
ds@658
   117
			return m_VtblIdx;
ds@658
   118
		}
ds@658
   119
ds@658
   120
		inline const CProto &CHookManager::GetProto() const
ds@658
   121
		{
ds@658
   122
			return m_Proto;
ds@658
   123
		}
ds@658
   124
ds@658
   125
		inline int CHookManager::GetVersion() const
ds@658
   126
		{
ds@658
   127
			return m_Version;
ds@658
   128
		}
ds@658
   129
ds@658
   130
		inline void *CHookManager::GetHookFunc() const
ds@658
   131
		{
ds@658
   132
			return *reinterpret_cast<void**>(m_HookfuncVfnptr);
ds@658
   133
		}
ds@658
   134
ds@658
   135
		inline HookManagerPubFunc CHookManager::GetPubFunc() const
ds@658
   136
		{
ds@658
   137
			return m_PubFunc;
ds@658
   138
		}
ds@658
   139
	}
ds@658
   140
}
ds@658
   141
pavolmarko@381
   142
#endif
pavolmarko@381
   143