1.1 --- a/core/sourcehook/generate/sourcehook.hxx Thu Oct 14 18:14:45 2010 -0500
1.2 +++ b/core/sourcehook/generate/sourcehook.hxx Sat Oct 16 23:21:58 2010 -0700
1.3 @@ -1,5 +1,5 @@
1.4 /* ======== SourceHook ========
1.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
1.6 +* Copyright (C) 2004-2010 Metamod:Source Development Team
1.7 * No warranties of any kind
1.8 *
1.9 * License: zlib/libpng
1.10 @@ -307,6 +307,20 @@
1.11 };
1.12 };
1.13
1.14 + template <class T> struct ReferenceUtil
1.15 + {
1.16 + typedef T plain_type;
1.17 + typedef T* pointer_type;
1.18 + typedef T& reference_type;
1.19 + };
1.20 +
1.21 + template <class T> struct ReferenceUtil<T&>
1.22 + {
1.23 + typedef T plain_type;
1.24 + typedef T* pointer_type;
1.25 + typedef T& reference_type;
1.26 + };
1.27 +
1.28 struct IHookContext
1.29 {
1.30 virtual ISHDelegate *GetNext() = 0;
1.31 @@ -480,7 +494,7 @@
1.32 * @return Override Return Pointer the hookfunc should use (may differ from overrideRetPtr
1.33 * when the hook func is being called as part of a recall
1.34 */
1.35 - virtual IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origentry,
1.36 + virtual IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origCallAddr,
1.37 META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
1.38 const void *origRetPtr, void *overrideRetPtr) = 0;
1.39
1.40 @@ -579,10 +593,14 @@
1.41
1.42 // only call these from the hook handlers directly!
1.43
1.44 +#define MAKE_NOREF_VALUE(rettype) \
1.45 + *reinterpret_cast< ::SourceHook::ReferenceUtil<rettype>::pointer_type >(0)
1.46 +
1.47 // If a hook on a function which returns a reference does not want to specify a return value,
1.48 // it can use this macro.
1.49 // ONLY USE THIS WITH MRES_IGNORED AND MRES_HANDLED !!!
1.50 -#define RETURN_META_NOREF(result, rettype) do { SET_META_RESULT(result); return reinterpret_cast<rettype>(*SH_GLOB_SHPTR); } while(0)
1.51 +#define RETURN_META_NOREF(result, rettype) \
1.52 + RETURN_META_VALUE(result, MAKE_NOREF_VALUE(rettype))
1.53
1.54 // Why take a memfuncptr instead of iface and func when we have to deduce the iface anyway now?
1.55 // Well, without it, there'd be no way to specify which overloaded version we want in _VALUE
1.56 @@ -1163,7 +1181,7 @@
1.57 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
1.58 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
1.59 { \
1.60 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
1.61 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
1.62 }
1.63
1.64 #define SH_DECL_MANUALEXTERN$1(hookname, rettype@[$2,1,$1:, param$2@]) \
1.65 @@ -1196,7 +1214,7 @@
1.66 __SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
1.67 void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
1.68 { \
1.69 - ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
1.70 + ::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>()(shptr, value); \
1.71 }
1.72
1.73 #define SH_DECL_MANUALEXTERN$1_vafmt(hookname, rettype@[$2,1,$1:, param$2@]) \
1.74 @@ -1415,12 +1433,6 @@
1.75
1.76 namespace SourceHook
1.77 {
1.78 - template <class RetType>
1.79 - void SetOverrideResult(ISourceHook *shptr, const RetType res)
1.80 - {
1.81 - *reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
1.82 - }
1.83 -
1.84 // SetOverrideResult used to be implemented like this:
1.85 // SetOverrideResult(shptr, memfuncptr, return);
1.86 // normally the compiler can deduce the return type from memfuncptr, but (at least msvc8) failed when it was a reference
1.87 @@ -1444,6 +1456,14 @@
1.88 *reinterpret_cast<typename ReferenceCarrier<T&>::type *>(shptr->GetOverrideRetPtr()) = res;
1.89 }
1.90 };
1.91 +
1.92 + // For manual hooks:
1.93 + // The rettype is passed in manually
1.94 + template <class RetType>
1.95 + OverrideFunctor<RetType> SetOverrideResult()
1.96 + {
1.97 + return OverrideFunctor<RetType>();
1.98 + }
1.99 @[$1,0,$a:
1.100 template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
1.101 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(@[$2,1,$1|, :Param$2@]))