sourcehook/sourcehook_impl.h
changeset 1 586787053c73
child 6 4803fd7d28bb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sourcehook/sourcehook_impl.h	Thu Apr 14 12:54:13 2005 +0000
     1.3 @@ -0,0 +1,136 @@
     1.4 +/* ======== SourceHook ========
     1.5 +* By PM
     1.6 +* No warranties of any kind
     1.7 +*
     1.8 +* This file declares necessary stuff for the sourcehook implementation.
     1.9 +* ============================
    1.10 +*/
    1.11 +
    1.12 +#ifndef __SOURCEHOOK_IMPL_H__
    1.13 +#define __SOURCEHOOK_IMPL_H__
    1.14 +
    1.15 +#include "sourcehook.h"
    1.16 +
    1.17 +// Set this to 1 to enable runtime code generation (faster)
    1.18 +#define SH_RUNTIME_CODEGEN 1
    1.19 +
    1.20 +namespace SourceHook
    1.21 +{
    1.22 +	/**
    1.23 +	*	@brief The SourceHook implementation class
    1.24 +	*/
    1.25 +	class CSourceHookImpl : public ISourceHook
    1.26 +	{
    1.27 +		/**
    1.28 +		*	@brief A list of HookerInfo structures
    1.29 +		*/
    1.30 +		typedef std::list<HookerInfo> HookerInfoList;
    1.31 +
    1.32 +
    1.33 +		/**
    1.34 +		*	@brief A list of Impl_CallClass structures
    1.35 +		*/
    1.36 +		typedef std::list<CallClass> Impl_CallClassList;
    1.37 +
    1.38 +		Impl_CallClassList m_CallClasses;			//!< A list of already generated callclasses
    1.39 +		HookerInfoList m_Hookers;					//!< A list of hookers
    1.40 +
    1.41 +		int m_PageSize;								//!< Stores the system's page size
    1.42 +
    1.43 +		/**
    1.44 +		*	@brief Finds a hooker for a function based on a text-prototype, a vtable offset and a vtable index
    1.45 +		*/
    1.46 +		HookerInfoList::iterator FindHooker(HookerInfoList::iterator begin, HookerInfoList::iterator end, 
    1.47 +			const char *proto, int vtblofs, int vtblidx, int thisptrofs);
    1.48 +
    1.49 +		void FreeCallClass(CallClass &cc);
    1.50 +		bool ApplyCallClassPatch(CallClass &cc, int vtbl_offs, int vtbl_idx, void *orig_entry);
    1.51 +
    1.52 +		static const int MAX_VTABLE_LEN = 4096;		//!< Maximal vtable length in bytes
    1.53 +
    1.54 +		META_RES m_Status, m_PrevRes, m_CurRes;
    1.55 +		const void *m_OrigRet;
    1.56 +		const void *m_OverrideRet;
    1.57 +		void *m_IfacePtr;
    1.58 +	public:
    1.59 +		CSourceHookImpl();
    1.60 +		~CSourceHookImpl();
    1.61 +
    1.62 +		/**
    1.63 +		*	@brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hookers
    1.64 +		*/
    1.65 +		void UnloadPlugin(Plugin plug);
    1.66 +
    1.67 +		/**
    1.68 +		*	@brief Shut down the whole system, unregister all hookers
    1.69 +		*/
    1.70 +		void CompleteShutdown();
    1.71 +
    1.72 +		/**
    1.73 +		*	@brief Add a hook.
    1.74 +		*
    1.75 +		*	@return True if the function succeeded, false otherwise
    1.76 +		*
    1.77 +		*	@param plug The unique identifier of the plugin that calls this function
    1.78 +		*	@param iface The interface pointer
    1.79 +		*	@param myHooker A hooker (hook manager) function that should be capable of handling the corresponding function
    1.80 +		*	@param handler A pointer to a FastDelegate containing the hook handler
    1.81 +		*	@param post Set to true if you want a post handler
    1.82 +		*/
    1.83 +		bool AddHook(Plugin plug, void *iface, int ifacesize, Hooker myHooker, ISHDelegate *handler, bool post);
    1.84 +
    1.85 +		/**
    1.86 +		*	@brief Removes a hook.
    1.87 +		*
    1.88 +		*	@return True if the function succeeded, false otherwise
    1.89 +		*
    1.90 +		*	@param plug The unique identifier of the plugin that calls this function
    1.91 +		*	@param iface The interface pointer
    1.92 +		*	@param vtableoffset Offset to the vtable, in bytes
    1.93 +		*	@param vtableidx Pointer to the vtable index of the function
    1.94 +		*	@param proto A text version of the function prototype; generated by the macros
    1.95 +		*	@param handler A pointer to a FastDelegate containing the hook handler
    1.96 +		*	@param post Set to true if you want a post handler
    1.97 +		*/
    1.98 +		bool RemoveHook(Plugin plug, void *iface, Hooker myHooker, ISHDelegate *handler, bool post);
    1.99 +
   1.100 +		/**
   1.101 +		*	@brief Checks whether a plugin has (a) hooker(s) that is/are currently used by other plugins
   1.102 +		*
   1.103 +		*	@param plug The unique identifier of the plugin in question
   1.104 +		*/
   1.105 +		bool IsPluginInUse(Plugin plug);
   1.106 +
   1.107 +		/**
   1.108 +		*	@brief Return a pointer to a callclass. Generate a new one if required.
   1.109 +		*
   1.110 +		*	@param iface The interface pointer
   1.111 +		*/
   1.112 +		void *GetCallClass(void *iface, size_t size);
   1.113 +
   1.114 +		/**
   1.115 +		*	@brief Release a callclass
   1.116 +		*
   1.117 +		*	@param ptr Pointer to the callclass
   1.118 +		*/
   1.119 +		virtual void ReleaseCallClass(void *ptr);
   1.120 +
   1.121 +		virtual void SetRes(META_RES res);				//!< Sets the meta result
   1.122 +		virtual META_RES GetPrevRes();					//!< Gets the meta result of the previously called handler
   1.123 +		virtual META_RES GetStatus();					//!< Gets the highest meta result
   1.124 +		virtual const void *GetOrigRet();				//!< Gets the original result. If not in post function, undefined
   1.125 +		virtual const void *GetOverrideRet();			//!< Gets the override result. If none is specified, NULL
   1.126 +		virtual void *GetIfacePtr();					//!< Gets the interface pointer
   1.127 +
   1.128 +		//////////////////////////////////////////////////////////////////////////
   1.129 +		// For hookers
   1.130 +		virtual META_RES &GetCurResRef();				//!< Gets the pointer to the current meta result
   1.131 +		virtual META_RES &GetPrevResRef();				//!< Gets the pointer to the previous meta result
   1.132 +		virtual META_RES &GetStatusRef();				//!< Gets the pointer to the status variable
   1.133 +		virtual void SetOrigRet(const void *ptr);		//!< Sets the original return pointer
   1.134 +		virtual void SetOverrideRet(const void *ptr);	//!< Sets the override result pointer
   1.135 +		virtual void SetIfacePtr(void *ptr);			//!< Sets the interface this pointer
   1.136 +	};
   1.137 +}
   1.138 +
   1.139 +#endif
   1.140 \ No newline at end of file