sourcehook/sourcehook.h
changeset 386 08583103ba6f
parent 385 e3d55ad50ba6
child 387 093c72464b35
     1.1 --- a/sourcehook/sourcehook.h	Sun Oct 07 22:45:51 2007 +0000
     1.2 +++ b/sourcehook/sourcehook.h	Sun Oct 07 23:00:38 2007 +0000
     1.3 @@ -391,6 +391,14 @@
     1.4  		*/
     1.5  		virtual void ResetIgnoreHooks(void *vfnptr) = 0;
     1.6  
     1.7 +		/**
     1.8 +		*	@brief Finds the original entry of a virtual function pointer
     1.9 +		*
    1.10 +		*	@param vfnptr The virtual function pointer
    1.11 +		*	@return The original entry if the virtual function pointer has been patched; NULL otherwise.
    1.12 +		*/
    1.13 +		virtual void *GetOrigVfnPtrEntry(void *vfnptr) = 0;
    1.14 +
    1.15  		//////////////////////////////////////////////////////////////////////////
    1.16  
    1.17  		// For hook managers	
    1.18 @@ -466,6 +474,20 @@
    1.19  			return &ref;
    1.20  		}
    1.21  	};
    1.22 +
    1.23 +	template <class X, class MFP>
    1.24 +		void *GetOrigVfnPtrEntry(X *pInstance, MFP mfp, ISourceHook *pSH)
    1.25 +	{
    1.26 +		SourceHook::MemFuncInfo info = {true, -1, 0, 0};
    1.27 +		SourceHook::GetFuncInfo(pInstance, mfp, info);
    1.28 +
    1.29 +		void *vfnptr = reinterpret_cast<void*>(
    1.30 +			*reinterpret_cast<void***>(reinterpret_cast<char*>(pInstance) + info.thisptroffs + info.vtbloffs) + info.vtblindex);
    1.31 +
    1.32 +		void *origentry = pSH->GetOrigVfnPtrEntry(vfnptr);
    1.33 +
    1.34 +		return origentry ? origentry : *reinterpret_cast<void**>(vfnptr);
    1.35 +	}
    1.36  }
    1.37  
    1.38  /************************************************************************/
    1.39 @@ -588,6 +610,8 @@
    1.40  		SH_MFHCls(hookname)::ms_MFI.vtbloffs = pvtbloffs; \
    1.41  	} while (0)
    1.42  
    1.43 +#define SH_GET_ORIG_VFNPTR_ENTRY(inst, mfp) (SourceHook::GetOrigVfnPtrEntry(inst, mfp, SH_GLOB_SHPTR))
    1.44 +
    1.45  // New ADD / REMOVE macros.
    1.46  #define SH_STATIC(func) fastdelegate::MakeDelegate(func)
    1.47  #define SH_MEMBER(inst, func) fastdelegate::MakeDelegate(inst, func)