core/sourcehook/sourcehook_impl_ciface.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_CIFACE_H__
    12 #define __SOURCEHOOK_IMPL_CIFACE_H__
    13 
    14 #include "sh_list.h"
    15 
    16 namespace SourceHook
    17 {
    18 	namespace Impl
    19 	{
    20 		class CIface
    21 		{
    22 			// *** Data ***
    23 			void *m_Ptr;
    24 
    25 			List<CHook> m_PreHooks;
    26 			List<CHook> m_PostHooks;
    27 		public:
    28 
    29 			// *** Descriptor ***
    30 			typedef void* Descriptor;
    31 
    32 			// *** Interface ***
    33 			inline CIface(void *ptr);
    34 			inline ~CIface();
    35 			inline bool operator==(const Descriptor &other);
    36 			inline void *GetPtr() const;
    37 			inline List<CHook> &GetPreHookList();
    38 			inline List<CHook> &GetPostHookList();
    39 			inline const List<CHook> &GetPreHookList() const;
    40 			inline const List<CHook> &GetPostHookList() const;
    41 		};
    42 
    43 		// *** Implementation ***
    44 		inline CIface::CIface(void *ptr)
    45 			: m_Ptr(ptr)
    46 		{
    47 		}
    48 
    49 		inline CIface::~CIface()
    50 		{
    51 			// Before getting deleted, delete all remaining hook handlers
    52 			for (List<CHook>::iterator iter = m_PreHooks.begin(); iter != m_PreHooks.end(); ++iter)
    53 			{
    54 				iter->GetHandler()->DeleteThis();
    55 			}
    56 
    57 			for (List<CHook>::iterator iter = m_PostHooks.begin(); iter != m_PostHooks.end(); ++iter)
    58 			{
    59 				iter->GetHandler()->DeleteThis();
    60 			}
    61 		}
    62 
    63 		inline bool CIface::operator==(const Descriptor &other)
    64 		{
    65 			return m_Ptr == other;
    66 		}
    67 
    68 		inline void *CIface::GetPtr() const
    69 		{
    70 			return m_Ptr;
    71 		}
    72 
    73 		inline List<CHook> &CIface::GetPreHookList()
    74 		{
    75 			return m_PreHooks;
    76 		}
    77 
    78 		inline List<CHook> &CIface::GetPostHookList()
    79 		{
    80 			return m_PostHooks;
    81 		}
    82 
    83 		inline const List<CHook> &CIface::GetPreHookList() const
    84 		{
    85 			return m_PreHooks;
    86 		}
    87 
    88 		inline const List<CHook> &CIface::GetPostHookList() const
    89 		{
    90 			return m_PostHooks;
    91 		}
    92 	}
    93 }
    94 
    95 #endif
    96