sourcehook/sourcehook.h
changeset 333 3813f1ac0cfe
parent 332 030b917a8dcc
child 380 f9e21a2ac558
     1.1 --- a/sourcehook/sourcehook.h	Sat May 12 19:05:16 2007 +0000
     1.2 +++ b/sourcehook/sourcehook.h	Sat May 12 19:48:31 2007 +0000
     1.3 @@ -534,6 +534,14 @@
     1.4  		*	@param vfnptr The virtual function pointer of the function in question
     1.5  		*/
     1.6  		virtual void ResetIgnoreHooks(Plugin plug, void *vfnptr) = 0;
     1.7 +
     1.8 +		/**
     1.9 +		*	@brief Finds the original entry of a virtual function pointer
    1.10 +		*
    1.11 +		*	@param vfnptr The virtual function pointer
    1.12 +		*	@return The original entry if the virtual function pointer has been patched; NULL otherwise.
    1.13 +		*/
    1.14 +		virtual void *GetOrigVfnPtrEntry(void *vfnptr) = 0;
    1.15  	};
    1.16  
    1.17  	// For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
    1.18 @@ -595,6 +603,19 @@
    1.19  		delete p;
    1.20  	}
    1.21  
    1.22 +	template <class X, class MFP>
    1.23 +	void *GetOrigVfnPtrEntry(X *pInstance, MFP mfp, ISourceHook *pSH)
    1.24 +	{
    1.25 +		SourceHook::MemFuncInfo info = {true, -1, 0, 0};
    1.26 +		SourceHook::GetFuncInfo(pInstance, mfp, info);
    1.27 +
    1.28 +		void *vfnptr = reinterpret_cast<void*>(
    1.29 +			*reinterpret_cast<void***>(reinterpret_cast<char*>(pInstance) + info.thisptroffs + info.vtbloffs) + info.vtblindex);
    1.30 +
    1.31 +		void *origentry = pSH->GetOrigVfnPtrEntry(vfnptr);
    1.32 +		
    1.33 +		return origentry ? origentry : *reinterpret_cast<void**>(vfnptr);
    1.34 +	}
    1.35  }
    1.36  
    1.37  /************************************************************************/
    1.38 @@ -707,6 +728,9 @@
    1.39  		SH_MFHCls(hookname)::ms_MFI.vtbloffs = pvtbloffs; \
    1.40  	} while (0)
    1.41  
    1.42 +
    1.43 +#define SH_GET_ORIG_VFNPTR_ENTRY(inst, mfp) (SourceHook::GetOrigVfnPtrEntry(inst, mfp, SH_GLOB_SHPTR))
    1.44 +
    1.45  // For source-level compatibility
    1.46  
    1.47  #define SH_GET_CALLCLASS(ptr) SourceHook::GetCallClass(ptr)