core/sourcehook/sourcehook_impl_chook.h
author Scott Ehlert <ds@alliedmods.net>
Thu Dec 10 00:59:50 2009 -0600 (2009-12-10)
changeset 689 4065ba5e9155
parent 539 db914129ae01
child 733 2365240861a2
permissions -rw-r--r--
Rewrote user message caching code to always use IServerGameDLL::GetUserMessageInfo (bug 4117, r=dvander).

Games where the above function can crash are handled by detouring tier0's Error() function and jumping back to our own code. So in theory this should work on all games now.
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2008 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_CHOOK_H__
    12 #define __SOURCEHOOK_IMPL_CHOOK_H__
    13 
    14 namespace SourceHook
    15 {
    16 	namespace Impl
    17 	{
    18 		class CHook
    19 		{
    20 			// *** Data ***
    21 			Plugin m_OwnerPlugin;
    22 			int m_ThisPointerOffset;
    23 			ISHDelegate *m_pHandler;
    24 			int m_HookID;
    25 			bool m_Paused;
    26 		public:
    27 
    28 			// *** Descriptor ***
    29 			struct Descriptor
    30 			{
    31 				Plugin m_OwnerPlugin;
    32 				int m_ThisPointerOffset;
    33 				ISHDelegate *m_pHandler;
    34 
    35 				Descriptor(Plugin ownerPlugin, int thisPtrOffset, ISHDelegate *pHandler)
    36 					: m_OwnerPlugin(ownerPlugin), m_ThisPointerOffset(thisPtrOffset),
    37 					m_pHandler(pHandler)
    38 				{
    39 				}
    40 			};
    41 
    42 			// *** Interface ***
    43 			inline CHook(Plugin ownerPlugin, int thisPtrOffset, ISHDelegate *pHandler, int hookid, bool paused=false);
    44 			inline bool operator==(const Descriptor &other) const;
    45 			inline bool operator==(int hookid) const;
    46 			inline Plugin GetOwnerPlugin() const;
    47 			inline int GetThisPointerOffset() const;
    48 			inline ISHDelegate *GetHandler() const;
    49 			inline void SetPaused(bool value);
    50 			inline bool IsPaused() const;
    51 			inline int GetID() const;
    52 		};
    53 
    54 		// *** Implementation ***
    55 		inline CHook::CHook(Plugin ownerPlugin, int thisPtrOffset, ISHDelegate *pHandler, int hookid, bool paused)
    56 			: m_OwnerPlugin(ownerPlugin), m_ThisPointerOffset(thisPtrOffset),
    57 			m_pHandler(pHandler), m_HookID(hookid), m_Paused(paused)
    58 		{
    59 		}
    60 
    61 		inline bool CHook::operator==(const Descriptor &other) const
    62 		{
    63 			return m_OwnerPlugin == other.m_OwnerPlugin
    64 				&& m_ThisPointerOffset == other.m_ThisPointerOffset
    65 				&& m_pHandler == other.m_pHandler;
    66 		}
    67 
    68 		inline bool CHook::operator==(int hookid) const
    69 		{
    70 			return m_HookID == hookid;
    71 		}
    72 
    73 		inline Plugin CHook::GetOwnerPlugin() const
    74 		{
    75 			return m_OwnerPlugin;
    76 		}
    77 
    78 		inline int CHook::GetThisPointerOffset() const
    79 		{
    80 			return m_ThisPointerOffset;
    81 		}
    82 
    83 		inline ISHDelegate *CHook::GetHandler() const
    84 		{
    85 			return m_pHandler;
    86 		}
    87 
    88 		inline void CHook::SetPaused(bool value)
    89 		{
    90 			m_Paused = value;
    91 		}
    92 
    93 		inline bool CHook::IsPaused() const
    94 		{
    95 			return m_Paused;
    96 		}
    97 
    98 		inline int CHook::GetID() const
    99 		{
   100 			return m_HookID;
   101 		}
   102 	}
   103 }
   104 
   105 #endif
   106