2005-04-14 14:54:13 +02:00
|
|
|
/* ======== SourceHook ========
|
2007-03-02 03:43:22 +01:00
|
|
|
* Copyright (C) 2004-2007 Metamod:Source Development Team
|
2005-04-14 14:54:13 +02:00
|
|
|
* No warranties of any kind
|
2005-05-05 12:40:47 +02:00
|
|
|
*
|
|
|
|
* License: zlib/libpng
|
|
|
|
*
|
|
|
|
* Author(s): Pavol "PM OnoTo" Marko
|
2005-04-14 14:54:13 +02:00
|
|
|
* ============================
|
2007-10-08 00:45:22 +02:00
|
|
|
*/
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sourcehook.h
|
|
|
|
* @brief Contains the public SourceHook API
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SOURCEHOOK_H__
|
|
|
|
#define __SOURCEHOOK_H__
|
|
|
|
|
2005-10-06 22:46:49 +02:00
|
|
|
// Interface revisions:
|
|
|
|
// 1 - Initial revision
|
|
|
|
// 2 - Changed to virtual functions for iterators and all queries
|
|
|
|
// 3 - Added "hook loop status variable"
|
2005-10-12 22:25:15 +02:00
|
|
|
// 4 - Reentrant
|
2007-10-08 00:45:22 +02:00
|
|
|
// 5 - New "V2" interface
|
|
|
|
#define SH_IFACE_VERSION 5
|
2007-05-07 20:35:59 +02:00
|
|
|
|
|
|
|
// Impl versions:
|
|
|
|
// ???
|
|
|
|
// 4 - addition of hook ids and vp hooks (with them, AddHookNew and RemoveHookNew)
|
|
|
|
// This is not a SH_IFACE_VERSION change so that old plugins continue working!
|
2007-10-08 00:45:22 +02:00
|
|
|
// 5 - implementation of the new "V2" interface
|
2007-05-12 10:08:01 +02:00
|
|
|
#define SH_IMPL_VERSION 5
|
2005-05-05 12:40:47 +02:00
|
|
|
|
2005-12-24 00:00:55 +01:00
|
|
|
// Hookman version:
|
2007-10-08 00:45:22 +02:00
|
|
|
// 1 - standard
|
2005-12-24 00:00:55 +01:00
|
|
|
#define SH_HOOKMAN_VERSION 1
|
|
|
|
|
2005-10-15 19:55:31 +02:00
|
|
|
// The value of SH_GLOB_SHPTR has to be a pointer to SourceHook::ISourceHook
|
|
|
|
// It's used in various macros
|
2005-04-16 18:55:53 +02:00
|
|
|
#ifndef SH_GLOB_SHPTR
|
|
|
|
#define SH_GLOB_SHPTR g_SHPtr
|
|
|
|
#endif
|
|
|
|
|
2005-10-15 19:55:31 +02:00
|
|
|
// Used to identify the current plugin
|
2005-04-16 18:55:53 +02:00
|
|
|
#ifndef SH_GLOB_PLUGPTR
|
2005-04-16 22:26:33 +02:00
|
|
|
#define SH_GLOB_PLUGPTR g_PLID
|
2005-04-16 18:55:53 +02:00
|
|
|
#endif
|
|
|
|
|
2005-05-01 14:36:48 +02:00
|
|
|
#ifdef SH_DEBUG
|
2005-09-23 22:14:10 +02:00
|
|
|
# include <stdio.h>
|
|
|
|
# include <stdlib.h>
|
2005-10-03 19:20:22 +02:00
|
|
|
|
|
|
|
# define SH_ASSERT(x, info) \
|
|
|
|
do { \
|
|
|
|
if (!(x)) \
|
|
|
|
{ \
|
|
|
|
printf("SOURCEHOOK DEBUG ASSERTION FAILED: %s:%u(%s): %s: ", __FILE__, __LINE__, __FUNCTION__, #x); \
|
|
|
|
printf info; \
|
|
|
|
putchar('\n'); \
|
|
|
|
abort(); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2005-05-01 14:36:48 +02:00
|
|
|
#else
|
|
|
|
# define SH_ASSERT(x, info)
|
|
|
|
#endif
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
// System
|
|
|
|
#define SH_SYS_WIN32 1
|
|
|
|
#define SH_SYS_LINUX 2
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# define SH_SYS SH_SYS_WIN32
|
|
|
|
#elif defined __linux__
|
|
|
|
# define SH_SYS SH_SYS_LINUX
|
|
|
|
#else
|
|
|
|
# error Unsupported system
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Compiler
|
|
|
|
#define SH_COMP_GCC 1
|
|
|
|
#define SH_COMP_MSVC 2
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# define SH_COMP SH_COMP_MSVC
|
|
|
|
#elif defined __GNUC__
|
|
|
|
# define SH_COMP SH_COMP_GCC
|
|
|
|
#else
|
|
|
|
# error Unsupported compiler
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SH_COMP==SH_COMP_MSVC
|
|
|
|
# define vsnprintf _vsnprintf
|
|
|
|
#endif
|
|
|
|
|
2005-12-24 00:32:21 +01:00
|
|
|
#if SH_SYS != SH_SYS_WIN32
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2005-05-05 16:43:40 +02:00
|
|
|
#define SH_PTRSIZE sizeof(void*)
|
2005-10-03 19:20:22 +02:00
|
|
|
|
2005-04-14 14:54:13 +02:00
|
|
|
#include "sh_memfuncinfo.h"
|
2007-10-08 00:45:22 +02:00
|
|
|
#include "FastDelegate.h"
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
// Good old metamod!
|
|
|
|
|
|
|
|
// Flags returned by a plugin's api function.
|
|
|
|
// NOTE: order is crucial, as greater/less comparisons are made.
|
|
|
|
enum META_RES
|
|
|
|
{
|
|
|
|
MRES_IGNORED=0, // plugin didn't take any action
|
|
|
|
MRES_HANDLED, // plugin did something, but real function should still be called
|
|
|
|
MRES_OVERRIDE, // call real function, but use my return value
|
2005-05-01 14:36:48 +02:00
|
|
|
MRES_SUPERCEDE // skip real function; use my return value
|
2005-04-14 14:54:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
namespace SourceHook
|
|
|
|
{
|
2005-04-29 22:29:46 +02:00
|
|
|
/**
|
2005-10-03 19:20:22 +02:00
|
|
|
* @brief Specifies the size (in bytes) for the internal buffer of vafmt(printf-like) function handlers
|
|
|
|
*/
|
|
|
|
const int STRBUF_LEN=4096;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief An empty class. No inheritance used. Used for original-function-call hacks
|
2005-04-29 22:29:46 +02:00
|
|
|
*/
|
|
|
|
class EmptyClass
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2005-05-05 12:40:47 +02:00
|
|
|
/**
|
|
|
|
* @brief Implicit cast.
|
|
|
|
*/
|
|
|
|
template <class In, class Out>
|
|
|
|
inline Out implicit_cast(In input)
|
|
|
|
{
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2005-04-14 14:54:13 +02:00
|
|
|
/**
|
|
|
|
* @brief A plugin typedef
|
|
|
|
*
|
2005-10-03 19:20:22 +02:00
|
|
|
* SourceHook doesn't really care what this is. As long as the ==, != and = operators work on it and every
|
|
|
|
* plugin has a unique identifier, everything is ok.
|
|
|
|
* It should also be possible to set it to 0.
|
2005-04-14 14:54:13 +02:00
|
|
|
*/
|
2005-04-16 22:26:33 +02:00
|
|
|
typedef int Plugin;
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2005-12-10 23:37:53 +01:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
template <class T> class CallClass : public T
|
2005-04-14 14:54:13 +02:00
|
|
|
{
|
|
|
|
};
|
2007-10-08 00:45:22 +02:00
|
|
|
typedef void ManualCallClass;
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
/**
|
2007-10-08 00:45:22 +02:00
|
|
|
* @brief Describes the way a parameter/retval is passed.
|
2005-04-14 14:54:13 +02:00
|
|
|
*/
|
2007-10-08 00:45:22 +02:00
|
|
|
struct PassInfo
|
2005-04-14 14:54:13 +02:00
|
|
|
{
|
2007-10-08 00:45:22 +02:00
|
|
|
enum PassType
|
2005-04-14 14:54:13 +02:00
|
|
|
{
|
2007-10-08 00:45:22 +02:00
|
|
|
PassType_Unknown=0, /**< Unknown -- no extra info available */
|
|
|
|
PassType_Basic, /**< Plain old register data (pointers, integers) */
|
|
|
|
PassType_Float, /**< Floating point data */
|
|
|
|
PassType_Object, /**< Object or structure */
|
|
|
|
};
|
2005-05-01 11:55:51 +02:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
enum PassFlags
|
2005-04-14 14:54:13 +02:00
|
|
|
{
|
2007-10-08 00:45:22 +02:00
|
|
|
PassFlag_ByVal = (1<<0), /**< Passing by value */
|
|
|
|
PassFlag_ByRef = (1<<1), /**< Passing by reference */
|
|
|
|
PassFlag_ODtor = (1<<2), /**< Object has a destructor */
|
2007-10-12 21:17:52 +02:00
|
|
|
PassFlag_OCtor = (1<<3), /**< Object has a normal non-trivial constructor */
|
|
|
|
PassFlag_AssignOp = (1<<4), /**< Object has a non-trivial assignment operator */
|
|
|
|
PassFlag_CCtor = (1<<5) /**< Object has a copy constructor (which takes const Object& as only parameter) */
|
2007-10-08 00:45:22 +02:00
|
|
|
};
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
size_t size; //!< Size of the data being passed
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
// Extra info:
|
|
|
|
// (might be used in future versions for automatic hookfunc generation)
|
|
|
|
int type; //!< PassType value
|
|
|
|
unsigned int flags; //!< Pass/return flags
|
2007-10-12 21:17:52 +02:00
|
|
|
|
|
|
|
struct V2Info
|
|
|
|
{
|
|
|
|
void *pNormalCtor;
|
2007-10-14 13:59:13 +02:00
|
|
|
void *pCopyCtor;
|
|
|
|
void *pDtor;
|
2007-10-12 21:17:52 +02:00
|
|
|
void *pAssignOperator;
|
|
|
|
};
|
2005-04-14 14:54:13 +02:00
|
|
|
};
|
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
struct ProtoInfo
|
2005-04-14 14:54:13 +02:00
|
|
|
{
|
2007-10-08 00:45:22 +02:00
|
|
|
enum CallConvention
|
2005-04-14 14:54:13 +02:00
|
|
|
{
|
2007-10-08 00:45:22 +02:00
|
|
|
CallConv_Unknown, /**< Unknown -- no extra info available */
|
|
|
|
CallConv_ThisCall, /**< This call (object pointer required) */
|
|
|
|
CallConv_Cdecl, /**< Standard C call */
|
2005-04-14 14:54:13 +02:00
|
|
|
};
|
2005-05-01 11:55:51 +02:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
int numOfParams; //!< number of parameters
|
|
|
|
PassInfo retPassInfo; //!< PassInfo for the return value. size=0 -> no retval
|
|
|
|
const PassInfo *paramsPassInfo; //!< PassInfos for the parameters
|
2005-10-03 19:20:22 +02:00
|
|
|
|
2007-10-12 21:17:52 +02:00
|
|
|
// paramsPassInfo[0] is basically a dummy parameter.
|
|
|
|
// However, paramsPassInfo[0].size stores the version of the ProtoInfo structure.
|
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
// Extra info:
|
|
|
|
int convention;
|
2007-10-12 21:17:52 +02:00
|
|
|
|
|
|
|
// Version2:
|
2007-10-14 13:59:13 +02:00
|
|
|
PassInfo::V2Info retPassInfo2;
|
|
|
|
const PassInfo::V2Info *paramsPassInfo2;
|
2005-04-14 14:54:13 +02:00
|
|
|
};
|
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
struct IHookManagerInfo;
|
2005-12-24 00:00:55 +01:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
/**
|
|
|
|
* @brief Pointer to hook manager interface function
|
|
|
|
*
|
|
|
|
* The hook manager should store hi for later use if store==true. It should then call hi->SetInfo(...) if hi
|
|
|
|
* is non-null. The hook manager can return 0 for success or a non-zero value if it doesn't want to be used.
|
|
|
|
*
|
|
|
|
* @param hi A pointer to IHookManagerInfo
|
|
|
|
*/
|
|
|
|
typedef int (*HookManagerPubFunc)(bool store, IHookManagerInfo *hi);
|
2005-10-03 19:20:22 +02:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
class ISHDelegate
|
2005-10-03 19:20:22 +02:00
|
|
|
{
|
|
|
|
public:
|
2007-10-08 00:45:22 +02:00
|
|
|
virtual bool IsEqual(ISHDelegate *pOtherDeleg) = 0; // pOtherDeleg is from the same plugin and hookman
|
|
|
|
virtual void DeleteThis() = 0;
|
2005-10-03 19:20:22 +02:00
|
|
|
};
|
2005-04-29 22:29:46 +02:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
struct IHookManagerInfo
|
2005-04-14 14:54:13 +02:00
|
|
|
{
|
2007-10-08 00:45:22 +02:00
|
|
|
virtual void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
|
|
|
|
ProtoInfo *proto, void *hookfunc_vfnptr) = 0;
|
2005-04-14 14:54:13 +02:00
|
|
|
};
|
|
|
|
|
2006-08-09 08:46:11 +02:00
|
|
|
// I'm adding support for functions which return references.
|
|
|
|
|
|
|
|
// How it works:
|
|
|
|
// SH_SETUPCALLS doesn't use plain rettype to store the temporary return values (plugin ret, orig ret,
|
|
|
|
// override ret) anymore; instead, it uses SourceHook::ReferenceCarrier<rettype>::type
|
|
|
|
// this is typedefed to the original rettype normally, but if the rettype is a reference, it's a special class
|
|
|
|
// which stores the reference as a pointer, and implements constructors, operator= and a conversion operator.
|
|
|
|
// special cases were needed for getoverrideret / getorigret; these are implemented through the
|
|
|
|
// SourceHook::MacroRefHelpers structs.
|
|
|
|
// Furthermore, SetOverrideRet had to be changed a bit; see SourceHook::OverrideFunctor somewhere down in this file.
|
|
|
|
template <class T> struct ReferenceCarrier
|
|
|
|
{
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T> struct ReferenceCarrier<T&>
|
|
|
|
{
|
|
|
|
class type
|
|
|
|
{
|
|
|
|
T *m_StoredRef;
|
|
|
|
public:
|
|
|
|
type() : m_StoredRef(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
type(T& ref) : m_StoredRef(&ref)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
T& operator= (T& ref)
|
|
|
|
{
|
|
|
|
m_StoredRef = &ref;
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator T& () const
|
|
|
|
{
|
|
|
|
return *m_StoredRef;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
struct IHookContext
|
|
|
|
{
|
|
|
|
virtual ISHDelegate *GetNext() = 0;
|
|
|
|
virtual void *GetOverrideRetPtr() = 0;
|
|
|
|
virtual const void *GetOrigRetPtr() = 0;
|
|
|
|
virtual bool ShouldCallOrig() = 0;
|
|
|
|
};
|
|
|
|
|
2005-04-14 14:54:13 +02:00
|
|
|
/**
|
|
|
|
* @brief The main SourceHook interface
|
|
|
|
*/
|
|
|
|
class ISourceHook
|
|
|
|
{
|
|
|
|
public:
|
2005-05-05 12:40:47 +02:00
|
|
|
/**
|
|
|
|
* @brief Return interface version
|
|
|
|
*/
|
|
|
|
virtual int GetIfaceVersion() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Return implementation version
|
|
|
|
*/
|
|
|
|
virtual int GetImplVersion() = 0;
|
|
|
|
|
2005-04-14 14:54:13 +02:00
|
|
|
/**
|
2007-10-08 00:45:22 +02:00
|
|
|
* @brief Modes for the new AddHook
|
|
|
|
*/
|
|
|
|
enum AddHookMode
|
|
|
|
{
|
|
|
|
Hook_Normal,
|
|
|
|
Hook_VP,
|
|
|
|
Hook_DVP
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Add a (VP) hook.
|
2005-04-14 14:54:13 +02:00
|
|
|
*
|
2007-10-08 00:45:22 +02:00
|
|
|
* @return non-zero hook id on success, 0 otherwise
|
2005-04-14 14:54:13 +02:00
|
|
|
*
|
|
|
|
* @param plug The unique identifier of the plugin that calls this function
|
2007-10-08 00:45:22 +02:00
|
|
|
* @param mode Can be either Hook_Normal or Hook_VP (vtable-wide hook)
|
2005-04-14 14:54:13 +02:00
|
|
|
* @param iface The interface pointer
|
|
|
|
* @param ifacesize The size of the class iface points to
|
2005-04-16 18:55:53 +02:00
|
|
|
* @param myHookMan A hook manager function that should be capable of handling the function
|
2007-10-08 00:45:22 +02:00
|
|
|
* @param handler A pointer to the hook handler something
|
2005-04-14 14:54:13 +02:00
|
|
|
* @param post Set to true if you want a post handler
|
|
|
|
*/
|
2007-10-08 00:45:22 +02:00
|
|
|
virtual int AddHook(Plugin plug, AddHookMode mode, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
|
|
|
|
ISHDelegate *handler, bool post) = 0;
|
|
|
|
|
|
|
|
// Source backwarts compat (only for normal hooks)
|
|
|
|
virtual bool RemoveHook(Plugin plug, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
|
2005-10-03 19:20:22 +02:00
|
|
|
ISHDelegate *handler, bool post) = 0;
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
/**
|
2007-10-08 00:45:22 +02:00
|
|
|
* @brief Remove a hook by ID.
|
2005-04-14 14:54:13 +02:00
|
|
|
*
|
2007-10-08 00:45:22 +02:00
|
|
|
* @return true on success, false otherwise
|
2005-04-14 14:54:13 +02:00
|
|
|
*
|
2007-10-08 00:45:22 +02:00
|
|
|
* @param hookid The hook id (returned by AddHook)
|
2005-04-14 14:54:13 +02:00
|
|
|
*/
|
2007-10-08 00:45:22 +02:00
|
|
|
virtual bool RemoveHookByID(int hookid) = 0;
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
/**
|
2007-10-08 00:45:22 +02:00
|
|
|
* @brief Pause a hook by ID.
|
2005-04-14 14:54:13 +02:00
|
|
|
*
|
2007-10-08 00:45:22 +02:00
|
|
|
* @return true on success, false otherwise
|
|
|
|
*
|
|
|
|
* @param hookid The hook id (returned by AddHook)
|
2005-04-14 14:54:13 +02:00
|
|
|
*/
|
2007-10-08 00:45:22 +02:00
|
|
|
virtual bool PauseHookByID(int hookid) = 0;
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
/**
|
2007-10-08 00:45:22 +02:00
|
|
|
* @brief Unpause a hook by ID.
|
2005-04-14 14:54:13 +02:00
|
|
|
*
|
2007-10-08 00:45:22 +02:00
|
|
|
* @return true on success, false otherwise
|
|
|
|
*
|
|
|
|
* @param hookid The hook id (returned by AddHook)
|
2005-04-14 14:54:13 +02:00
|
|
|
*/
|
2007-10-08 00:45:22 +02:00
|
|
|
virtual bool UnpauseHookByID(int hookid) = 0;
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
/**
|
2007-10-08 00:45:22 +02:00
|
|
|
* @brief Checks whether a plugin has (a) hook manager(s) that is/are currently used by other plugins
|
2005-04-14 14:54:13 +02:00
|
|
|
*
|
2007-10-08 00:45:22 +02:00
|
|
|
* @param plug The unique identifier of the plugin in question
|
2005-04-14 14:54:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
virtual void SetRes(META_RES res) = 0; //!< Sets the meta result
|
2005-10-03 19:20:22 +02:00
|
|
|
virtual META_RES GetPrevRes() = 0; //!< Gets the meta result of the
|
|
|
|
//!< previously calledhandler
|
2005-04-14 14:54:13 +02:00
|
|
|
virtual META_RES GetStatus() = 0; //!< Gets the highest meta result
|
2005-10-03 19:20:22 +02:00
|
|
|
virtual const void *GetOrigRet() = 0; //!< Gets the original result.
|
|
|
|
//!< If not in post function, undefined
|
|
|
|
virtual const void *GetOverrideRet() = 0; //!< Gets the override result.
|
|
|
|
//!< If none is specified, NULL
|
2005-04-14 14:54:13 +02:00
|
|
|
virtual void *GetIfacePtr() = 0; //!< Gets the interface pointer
|
2007-10-08 00:45:22 +02:00
|
|
|
|
|
|
|
virtual void *GetOverrideRetPtr() = 0; //!< Used for setting the override return value
|
2005-12-10 23:37:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Remove a hook manager. Auto-removes all hooks attached to it from plugin plug.
|
|
|
|
*
|
|
|
|
* @param plug The owner of the hook manager
|
|
|
|
* @param pubFunc The hook manager's info function
|
|
|
|
*/
|
|
|
|
virtual void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc) = 0;
|
2005-12-23 12:58:11 +01:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
// For SH_CALL:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Makes sure that hooks are going to be ignored on the next call of vfnptr
|
|
|
|
*
|
|
|
|
* @param plug The unique identifier of the plugin that calls this function
|
|
|
|
* @param vfnptr The virtual function pointer of the function in question
|
|
|
|
*/
|
|
|
|
virtual void SetIgnoreHooks(void *vfnptr) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reverses SetIgnoreHooks' effect
|
|
|
|
*
|
|
|
|
* @param plug The unique identifier of the plugin that calls this function
|
|
|
|
* @param vfnptr The virtual function pointer of the function in question
|
|
|
|
*/
|
|
|
|
virtual void ResetIgnoreHooks(void *vfnptr) = 0;
|
|
|
|
|
2007-10-08 01:00:38 +02:00
|
|
|
/**
|
|
|
|
* @brief Finds the original entry of a virtual function pointer
|
|
|
|
*
|
|
|
|
* @param vfnptr The virtual function pointer
|
|
|
|
* @return The original entry if the virtual function pointer has been patched; NULL otherwise.
|
|
|
|
*/
|
|
|
|
virtual void *GetOrigVfnPtrEntry(void *vfnptr) = 0;
|
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For hook managers
|
|
|
|
|
|
|
|
// Returns the current iface ptr
|
2005-12-23 12:58:11 +01:00
|
|
|
virtual void DoRecall() = 0; //!< Initiates a recall sequence
|
2007-10-08 00:45:22 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
/*
|
|
|
|
HOW RECALLS WORK:
|
|
|
|
|
|
|
|
The problem:
|
|
|
|
Users want the ability to change parameters of the called function
|
|
|
|
from inside their handler.
|
|
|
|
The solution:
|
|
|
|
1) Mark as "recall"
|
|
|
|
2) Recall the function
|
|
|
|
3) => SH's hook func gets called:
|
|
|
|
4) The first iterator points at the first hook the last hookfunc didn't execute yet
|
|
|
|
5) does all iteration and returns normally
|
|
|
|
6) The user's handler returns immediately
|
|
|
|
7) The hook func returns immediately as well
|
|
|
|
|
|
|
|
Also note that the recalled hookfunc starts with the status the recalling hookfunc
|
|
|
|
ended with. The last handler (doing the recall) is also able to specify its own
|
|
|
|
META_RES.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2007-10-08 00:45:22 +02:00
|
|
|
* @brief Set up the hook loop.
|
2005-12-23 12:58:11 +01:00
|
|
|
*
|
|
|
|
* @param statusPtr pointer to status variable
|
|
|
|
* @param prevResPtr pointer to previous result variable
|
|
|
|
* @param curResPtr pointer to current result variable
|
|
|
|
* @param ifacePtrPtr pointer to interface this pointer variable
|
|
|
|
* @param origRetPr pointer to original return value variable. NULL for void funcs
|
|
|
|
* @param overrideRetPtr pointer to override return value variable. NULL for void funcs
|
|
|
|
*
|
|
|
|
* @return Override Return Pointer the hookfunc should use (may differ from overrideRetPtr
|
|
|
|
* when the hook func is being called as part of a recall
|
|
|
|
*/
|
2007-10-08 00:45:22 +02:00
|
|
|
virtual IHookContext *SetupHookLoop(IHookManagerInfo *hi, void *vfnptr, void *thisptr, void **origentry,
|
|
|
|
META_RES *statusPtr, META_RES *prevResPtr, META_RES *curResPtr,
|
|
|
|
const void *origRetPtr, void *overrideRetPtr) = 0;
|
2007-05-07 20:35:59 +02:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
virtual void EndContext(IHookContext *pCtx) = 0;
|
2005-04-14 14:54:13 +02:00
|
|
|
};
|
2006-08-09 08:46:11 +02:00
|
|
|
|
|
|
|
// For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
|
|
|
|
// These have to be able to return references. If T is a reference, the pointers returned
|
|
|
|
// from the SH_GLOB_SHPTR are pointers to instances of ReferenceCarrier<T>::type.
|
|
|
|
template <class T> struct MacroRefHelpers
|
|
|
|
{
|
|
|
|
inline static const T* GetOrigRet(ISourceHook *shptr)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<const T*>(shptr->GetOrigRet());
|
|
|
|
}
|
|
|
|
inline static const T* GetOverrideRet(ISourceHook *shptr)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<const T*>(shptr->GetOverrideRet());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T> struct MacroRefHelpers<T&>
|
|
|
|
{
|
|
|
|
inline static T* GetOrigRet(ISourceHook *shptr)
|
|
|
|
{
|
2006-08-09 09:25:48 +02:00
|
|
|
T &ref = *reinterpret_cast<const typename ReferenceCarrier<T&>::type *>(shptr->GetOrigRet());
|
2006-08-09 08:46:11 +02:00
|
|
|
return &ref;
|
|
|
|
}
|
|
|
|
inline static T* GetOverrideRet(ISourceHook *shptr)
|
|
|
|
{
|
2006-08-09 09:25:48 +02:00
|
|
|
T &ref = *reinterpret_cast<const typename ReferenceCarrier<T&>::type *>(shptr->GetOverrideRet());
|
2006-08-09 08:46:11 +02:00
|
|
|
return &ref;
|
|
|
|
}
|
|
|
|
};
|
2007-10-08 01:00:38 +02:00
|
|
|
|
|
|
|
template <class X, class MFP>
|
|
|
|
void *GetOrigVfnPtrEntry(X *pInstance, MFP mfp, ISourceHook *pSH)
|
|
|
|
{
|
|
|
|
SourceHook::MemFuncInfo info = {true, -1, 0, 0};
|
|
|
|
SourceHook::GetFuncInfo(pInstance, mfp, info);
|
|
|
|
|
|
|
|
void *vfnptr = reinterpret_cast<void*>(
|
|
|
|
*reinterpret_cast<void***>(reinterpret_cast<char*>(pInstance) + info.thisptroffs + info.vtbloffs) + info.vtblindex);
|
|
|
|
|
|
|
|
void *origentry = pSH->GetOrigVfnPtrEntry(vfnptr);
|
|
|
|
|
|
|
|
return origentry ? origentry : *reinterpret_cast<void**>(vfnptr);
|
|
|
|
}
|
2007-10-12 21:17:52 +02:00
|
|
|
|
|
|
|
template <class T> struct GetPassInfo
|
|
|
|
{
|
|
|
|
static const int type = 0;
|
|
|
|
static const unsigned int flags = PassInfo::PassFlag_ByVal;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T> struct GetPassInfo<T&>
|
|
|
|
{
|
|
|
|
static const int type = 0;
|
|
|
|
static const unsigned int flags = PassInfo::PassFlag_ByRef;
|
|
|
|
};
|
2005-04-14 14:54:13 +02:00
|
|
|
}
|
|
|
|
|
2005-05-01 11:55:51 +02:00
|
|
|
/************************************************************************/
|
|
|
|
/* High level interface */
|
|
|
|
/************************************************************************/
|
2005-04-16 18:55:53 +02:00
|
|
|
#define META_RESULT_STATUS SH_GLOB_SHPTR->GetStatus()
|
|
|
|
#define META_RESULT_PREVIOUS SH_GLOB_SHPTR->GetPrevRes()
|
2006-08-09 08:46:11 +02:00
|
|
|
#define META_RESULT_ORIG_RET(type) *SourceHook::MacroRefHelpers<type>::GetOrigRet(SH_GLOB_SHPTR)
|
|
|
|
#define META_RESULT_OVERRIDE_RET(type) *SourceHook::MacroRefHelpers<type>::GetOverrideRet(SH_GLOB_SHPTR)
|
2005-10-14 19:45:36 +02:00
|
|
|
#define META_IFACEPTR(type) reinterpret_cast<type*>(SH_GLOB_SHPTR->GetIfacePtr())
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
#define SET_META_RESULT(result) SH_GLOB_SHPTR->SetRes(result)
|
|
|
|
#define RETURN_META(result) do { SET_META_RESULT(result); return; } while(0)
|
|
|
|
#define RETURN_META_VALUE(result, value) do { SET_META_RESULT(result); return (value); } while(0)
|
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
SourceHook::CallClass<T> *SH_GET_CALLCLASS(T *p)
|
|
|
|
{
|
|
|
|
return static_cast< SourceHook::CallClass<T> *>(p);
|
|
|
|
}
|
|
|
|
#define SH_RELEASE_CALLCLASS(p)
|
|
|
|
|
|
|
|
#define SH_GET_MCALLCLASS(p, size) reinterpret_cast<void*>(p)
|
|
|
|
|
|
|
|
// only call these from the hook handlers directly!
|
|
|
|
|
2006-08-09 08:46:11 +02:00
|
|
|
// If a hook on a function which returns a reference does not want to specify a return value,
|
|
|
|
// it can use this macro.
|
|
|
|
// ONLY USE THIS WITH MRES_IGNORED AND MRES_HANDLED !!!
|
|
|
|
#define RETURN_META_NOREF(result, rettype) do { SET_META_RESULT(result); return reinterpret_cast<rettype>(*SH_GLOB_SHPTR); } while(0)
|
2005-12-23 12:58:11 +01:00
|
|
|
|
2005-12-24 00:00:55 +01:00
|
|
|
// Why take a memfuncptr instead of iface and func when we have to deduce the iface anyway now?
|
|
|
|
// Well, without it, there'd be no way to specify which overloaded version we want in _VALUE
|
2005-12-23 12:58:11 +01:00
|
|
|
|
|
|
|
// SourceHook::SetOverrideRet is defined later.
|
2005-12-24 00:00:55 +01:00
|
|
|
#define RETURN_META_NEWPARAMS(result, memfuncptr, newparams) \
|
2005-12-23 12:58:11 +01:00
|
|
|
do { \
|
|
|
|
SET_META_RESULT(result); \
|
|
|
|
SH_GLOB_SHPTR->DoRecall(); \
|
2005-12-24 00:00:55 +01:00
|
|
|
(SourceHook::RecallGetIface(SH_GLOB_SHPTR, memfuncptr)->*(memfuncptr)) newparams; \
|
2005-12-23 12:58:11 +01:00
|
|
|
RETURN_META(MRES_SUPERCEDE); \
|
|
|
|
} while (0)
|
|
|
|
|
2005-12-24 00:00:55 +01:00
|
|
|
#define RETURN_META_VALUE_NEWPARAMS(result, value, memfuncptr, newparams) \
|
2005-12-23 12:58:11 +01:00
|
|
|
do { \
|
|
|
|
SET_META_RESULT(result); \
|
|
|
|
SH_GLOB_SHPTR->DoRecall(); \
|
|
|
|
if ((result) >= MRES_OVERRIDE) \
|
|
|
|
{ \
|
|
|
|
/* meh, set the override result here because we don't get a chance to return */ \
|
|
|
|
/* before continuing the hook loop through the recall */ \
|
2006-08-09 08:46:11 +02:00
|
|
|
SourceHook::SetOverrideResult(memfuncptr)(SH_GLOB_SHPTR, value); \
|
2005-12-23 12:58:11 +01:00
|
|
|
} \
|
2005-12-24 00:00:55 +01:00
|
|
|
RETURN_META_VALUE(MRES_SUPERCEDE, \
|
|
|
|
(SourceHook::RecallGetIface(SH_GLOB_SHPTR, memfuncptr)->*(memfuncptr)) newparams); \
|
2005-12-23 12:58:11 +01:00
|
|
|
} while (0)
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2006-06-08 20:34:18 +02:00
|
|
|
// :TODO: thisptroffs in MNEWPARAMS ??
|
|
|
|
|
|
|
|
#if SH_COMP == SH_COMP_MSVC
|
|
|
|
|
|
|
|
#define SOUREHOOK__MNEWPARAMS_PREPAREMFP(hookname) \
|
|
|
|
union \
|
|
|
|
{ \
|
|
|
|
SH_MFHCls(hookname)::ECMFP mfp; \
|
|
|
|
void *addr; \
|
|
|
|
} u; \
|
|
|
|
u.addr = (*reinterpret_cast<void***>(reinterpret_cast<char*>(thisptr) + SH_MFHCls(hookname)::ms_MFI.vtbloffs))[ \
|
|
|
|
SH_MFHCls(hookname)::ms_MFI.vtblindex];
|
|
|
|
|
|
|
|
#elif SH_COMP == SH_COMP_GCC
|
|
|
|
|
|
|
|
#define SOUREHOOK__MNEWPARAMS_PREPAREMFP(hookname) \
|
|
|
|
union \
|
|
|
|
{ \
|
|
|
|
SH_MFHCls(hookname)::ECMFP mfp; \
|
|
|
|
struct \
|
|
|
|
{ \
|
|
|
|
void *addr; \
|
|
|
|
intptr_t adjustor; \
|
|
|
|
} s; \
|
|
|
|
} u; \
|
|
|
|
u.s.addr = (*reinterpret_cast<void***>(reinterpret_cast<char*>(thisptr) + SH_MFHCls(hookname)::ms_MFI.vtbloffs))[ \
|
|
|
|
SH_MFHCls(hookname)::ms_MFI.vtblindex]; \
|
|
|
|
u.s.adjustor = 0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define RETURN_META_MNEWPARAMS(result, hookname, newparams) \
|
|
|
|
do { \
|
|
|
|
SET_META_RESULT(result); \
|
|
|
|
SH_GLOB_SHPTR->DoRecall(); \
|
2007-11-02 15:36:47 +01:00
|
|
|
SourceHook::EmptyClass *thisptr = reinterpret_cast<SourceHook::EmptyClass*>(SH_GLOB_SHPTR->GetIfacePtr()); \
|
|
|
|
(thisptr->*(__SoureceHook_FHM_GetRecallMFP##hookname(thisptr))) newparams; \
|
2006-06-08 20:34:18 +02:00
|
|
|
RETURN_META(MRES_SUPERCEDE); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define RETURN_META_VALUE_MNEWPARAMS(result, value, hookname, newparams) \
|
|
|
|
do { \
|
|
|
|
SET_META_RESULT(result); \
|
|
|
|
SH_GLOB_SHPTR->DoRecall(); \
|
|
|
|
if ((result) >= MRES_OVERRIDE) \
|
|
|
|
{ \
|
|
|
|
/* see RETURN_META_VALUE_NEWPARAMS */ \
|
2007-11-02 15:36:47 +01:00
|
|
|
__SoureceHook_FHM_SetOverrideResult##hookname(SH_GLOB_SHPTR, value); \
|
2006-06-08 20:34:18 +02:00
|
|
|
} \
|
2007-11-02 15:36:47 +01:00
|
|
|
SourceHook::EmptyClass *thisptr = reinterpret_cast<SourceHook::EmptyClass*>(SH_GLOB_SHPTR->GetIfacePtr()); \
|
|
|
|
RETURN_META_VALUE(MRES_SUPERCEDE, (thisptr->*(__SoureceHook_FHM_GetRecallMFP##hookname(thisptr))) newparams); \
|
2006-06-08 20:34:18 +02:00
|
|
|
} while (0)
|
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SH_MANUALHOOK_RECONFIGURE(hookname, pvtblindex, pvtbloffs, pthisptroffs) \
|
2007-11-02 15:36:47 +01:00
|
|
|
__SourceHook_FHM_Reconfigure##hookname(pvtblindex, pvtbloffs, pthisptroffs)
|
2005-12-10 23:37:53 +01:00
|
|
|
|
2007-10-08 01:00:38 +02:00
|
|
|
#define SH_GET_ORIG_VFNPTR_ENTRY(inst, mfp) (SourceHook::GetOrigVfnPtrEntry(inst, mfp, SH_GLOB_SHPTR))
|
|
|
|
|
2007-05-07 20:35:59 +02:00
|
|
|
// New ADD / REMOVE macros.
|
|
|
|
#define SH_STATIC(func) fastdelegate::MakeDelegate(func)
|
|
|
|
#define SH_MEMBER(inst, func) fastdelegate::MakeDelegate(inst, func)
|
|
|
|
|
2005-04-14 14:54:13 +02:00
|
|
|
#define SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
|
2005-05-05 12:40:47 +02:00
|
|
|
__SourceHook_FHAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
|
2007-10-08 00:45:22 +02:00
|
|
|
SourceHook::ISourceHook::Hook_Normal, post, handler)
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
#define SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
|
2005-05-05 12:40:47 +02:00
|
|
|
__SourceHook_FHRemove##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
|
2007-05-07 20:35:59 +02:00
|
|
|
post, handler)
|
|
|
|
|
|
|
|
#define SH_ADD_MANUALHOOK(hookname, ifaceptr, handler, post) \
|
2007-10-08 00:45:22 +02:00
|
|
|
__SourceHook_FHMAdd##hookname(reinterpret_cast<void*>(ifaceptr), \
|
|
|
|
SourceHook::ISourceHook::Hook_Normal, post, handler)
|
2007-05-07 20:35:59 +02:00
|
|
|
|
|
|
|
#define SH_REMOVE_MANUALHOOK(hookname, ifaceptr, handler, post) \
|
|
|
|
__SourceHook_FHMRemove##hookname(reinterpret_cast<void*>(ifaceptr), post, handler)
|
|
|
|
|
|
|
|
#define SH_ADD_VPHOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
|
2007-10-08 00:45:22 +02:00
|
|
|
__SourceHook_FHAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
|
|
|
|
SourceHook::ISourceHook::Hook_VP, post, handler)
|
2007-05-12 10:08:01 +02:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
#define SH_ADD_DVPHOOK(ifacetype, ifacefunc, ifaceptr, handler, post) \
|
|
|
|
__SourceHook_FHAdd##ifacetype##ifacefunc((void*)SourceHook::implicit_cast<ifacetype*>(ifaceptr), \
|
|
|
|
SourceHook::ISourceHook::Hook_DVP, post, handler)
|
2007-05-07 20:35:59 +02:00
|
|
|
|
|
|
|
#define SH_ADD_MANUALVPHOOK(hookname, ifaceptr, handler, post) \
|
2007-10-08 00:45:22 +02:00
|
|
|
__SourceHook_FHMAdd##hookname(reinterpret_cast<void*>(ifaceptr), SourceHook::ISourceHook::Hook_VP, post, handler)
|
2007-05-12 10:08:01 +02:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
#define SH_ADD_MANUALDVPHOOK(hookname, ifaceptr, handler, post) \
|
|
|
|
__SourceHook_FHMAdd##hookname(reinterpret_cast<void*>(ifaceptr), SourceHook::ISourceHook::Hook_DVP, post, handler)
|
2007-05-07 20:35:59 +02:00
|
|
|
|
|
|
|
#define SH_REMOVE_HOOK_ID(hookid) \
|
2007-10-08 00:45:22 +02:00
|
|
|
(SH_GLOB_SHPTR->RemoveHookByID(hookid))
|
2007-05-07 20:35:59 +02:00
|
|
|
|
|
|
|
// Old macros
|
|
|
|
// !! These are now deprecated. Instead, use one of these:
|
|
|
|
// SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
|
|
|
|
// SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(inst, func), post)
|
|
|
|
|
|
|
|
#define SH_ADD_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
|
|
|
|
SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
|
|
|
|
#define SH_ADD_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
|
|
|
|
SH_ADD_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
|
|
|
|
|
|
|
|
// SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
|
|
|
|
// SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(inst, func), post)
|
|
|
|
|
2005-04-14 14:54:13 +02:00
|
|
|
#define SH_REMOVE_HOOK_STATICFUNC(ifacetype, ifacefunc, ifaceptr, handler, post) \
|
2007-05-07 20:35:59 +02:00
|
|
|
SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_STATIC(handler), post)
|
2005-04-14 14:54:13 +02:00
|
|
|
#define SH_REMOVE_HOOK_MEMFUNC(ifacetype, ifacefunc, ifaceptr, handler_inst, handler_func, post) \
|
2007-05-07 20:35:59 +02:00
|
|
|
SH_REMOVE_HOOK(ifacetype, ifacefunc, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2007-05-07 20:35:59 +02:00
|
|
|
// SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
|
|
|
|
// SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(inst, func), post)
|
2005-12-10 23:37:53 +01:00
|
|
|
|
|
|
|
#define SH_ADD_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
|
2007-05-07 20:35:59 +02:00
|
|
|
SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SH_ADD_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
|
2007-05-07 20:35:59 +02:00
|
|
|
SH_ADD_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
|
|
|
|
|
|
|
|
// SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
|
|
|
|
// SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(inst, func), post)
|
2005-12-10 23:37:53 +01:00
|
|
|
|
|
|
|
#define SH_REMOVE_MANUALHOOK_STATICFUNC(hookname, ifaceptr, handler, post) \
|
2007-05-07 20:35:59 +02:00
|
|
|
SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_STATIC(handler), post)
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SH_REMOVE_MANUALHOOK_MEMFUNC(hookname, ifaceptr, handler_inst, handler_func, post) \
|
2007-05-07 20:35:59 +02:00
|
|
|
SH_REMOVE_MANUALHOOK(hookname, ifaceptr, SH_MEMBER(handler_inst, handler_func), post)
|
2005-12-10 23:37:53 +01:00
|
|
|
|
2005-04-14 14:54:13 +02:00
|
|
|
#define SH_NOATTRIB
|
|
|
|
|
|
|
|
|
2005-04-29 22:29:46 +02:00
|
|
|
|
2005-05-01 11:55:51 +02:00
|
|
|
|
2005-04-29 22:29:46 +02:00
|
|
|
#if SH_COMP == SH_COMP_MSVC
|
|
|
|
# define SH_SETUP_MFP(mfp) \
|
2005-10-06 22:46:49 +02:00
|
|
|
reinterpret_cast<void**>(&mfp)[0] = vfnptr_origentry;
|
2005-04-29 22:29:46 +02:00
|
|
|
#elif SH_COMP == SH_COMP_GCC
|
|
|
|
# define SH_SETUP_MFP(mfp) \
|
2005-10-06 22:46:49 +02:00
|
|
|
reinterpret_cast<void**>(&mfp)[0] = vfnptr_origentry; \
|
2005-04-29 22:29:46 +02:00
|
|
|
reinterpret_cast<void**>(&mfp)[1] = 0;
|
|
|
|
#else
|
|
|
|
# error Not supported yet.
|
|
|
|
#endif
|
|
|
|
|
2005-04-14 14:54:13 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2005-04-30 21:09:51 +02:00
|
|
|
#define SH_FHCls(ift, iff, ov) __SourceHook_FHCls_##ift##iff##ov
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SH_MFHCls(hookname) __SourceHook_MFHCls_##hookname
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2005-04-16 18:55:53 +02:00
|
|
|
#define SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr) \
|
2007-10-08 00:45:22 +02:00
|
|
|
static int HookManPubFunc(bool store, ::SourceHook::IHookManagerInfo *hi) \
|
2005-04-14 14:54:13 +02:00
|
|
|
{ \
|
2005-04-30 21:09:51 +02:00
|
|
|
using namespace ::SourceHook; \
|
2005-10-03 19:20:22 +02:00
|
|
|
GetFuncInfo(funcptr, ms_MFI); \
|
2005-05-05 12:40:47 +02:00
|
|
|
/* Verify interface version */ \
|
|
|
|
if (SH_GLOB_SHPTR->GetIfaceVersion() != SH_IFACE_VERSION) \
|
|
|
|
return 1; \
|
2007-05-07 20:35:59 +02:00
|
|
|
if (SH_GLOB_SHPTR->GetImplVersion() < SH_IMPL_VERSION) \
|
|
|
|
return 1; \
|
2007-10-08 00:45:22 +02:00
|
|
|
if (store) \
|
|
|
|
ms_HI = hi; \
|
|
|
|
if (hi) \
|
2005-04-14 14:54:13 +02:00
|
|
|
{ \
|
2006-08-13 13:34:30 +02:00
|
|
|
MemFuncInfo mfi = {true, -1, 0, 0}; \
|
2005-04-14 14:54:13 +02:00
|
|
|
GetFuncInfo(&SH_FHCls(ifacetype,ifacefunc,overload)::Func, mfi); \
|
2007-10-08 00:45:22 +02:00
|
|
|
hi->SetInfo(SH_HOOKMAN_VERSION, ms_MFI.vtbloffs, ms_MFI.vtblindex, &ms_Proto, \
|
|
|
|
reinterpret_cast<void**>(reinterpret_cast<char*>(&ms_Inst) + mfi.vtbloffs)[mfi.vtblindex] ); \
|
2005-04-14 14:54:13 +02:00
|
|
|
} \
|
2007-10-08 00:45:22 +02:00
|
|
|
return 0; \
|
2005-04-14 14:54:13 +02:00
|
|
|
}
|
|
|
|
|
2005-04-30 21:09:51 +02:00
|
|
|
// It has to be possible to use the macros in namespaces
|
|
|
|
// -> So we need to access and extend the global SourceHook namespace
|
|
|
|
// We use a namespace alias for this
|
2005-04-14 14:54:13 +02:00
|
|
|
#define SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, funcptr) \
|
2005-04-30 21:09:51 +02:00
|
|
|
struct SH_FHCls(ifacetype,ifacefunc,overload) \
|
2005-04-14 14:54:13 +02:00
|
|
|
{ \
|
2005-04-30 21:09:51 +02:00
|
|
|
static SH_FHCls(ifacetype,ifacefunc,overload) ms_Inst; \
|
2005-10-03 19:20:22 +02:00
|
|
|
static ::SourceHook::MemFuncInfo ms_MFI; \
|
|
|
|
static ::SourceHook::IHookManagerInfo *ms_HI; \
|
2005-12-10 23:37:53 +01:00
|
|
|
static ::SourceHook::ProtoInfo ms_Proto; \
|
2005-04-30 21:09:51 +02:00
|
|
|
SHINT_MAKE_HOOKMANPUBFUNC(ifacetype, ifacefunc, overload, funcptr)
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, funcptr) \
|
2005-04-30 21:09:51 +02:00
|
|
|
}; \
|
|
|
|
SH_FHCls(ifacetype,ifacefunc,overload) SH_FHCls(ifacetype,ifacefunc,overload)::ms_Inst; \
|
2005-10-03 19:20:22 +02:00
|
|
|
::SourceHook::MemFuncInfo SH_FHCls(ifacetype,ifacefunc,overload)::ms_MFI; \
|
|
|
|
::SourceHook::IHookManagerInfo *SH_FHCls(ifacetype,ifacefunc,overload)::ms_HI; \
|
2007-10-08 00:45:22 +02:00
|
|
|
int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
|
2005-04-30 21:09:51 +02:00
|
|
|
SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
|
|
|
|
{ \
|
|
|
|
using namespace ::SourceHook; \
|
2006-08-13 13:34:30 +02:00
|
|
|
MemFuncInfo mfi = {true, -1, 0, 0}; \
|
2005-04-30 21:09:51 +02:00
|
|
|
GetFuncInfo(funcptr, mfi); \
|
2005-12-23 12:58:11 +01:00
|
|
|
if (mfi.thisptroffs < 0 || !mfi.isVirtual) \
|
|
|
|
return false; /* No non-virtual functions / virtual inheritance supported */ \
|
2005-04-30 21:09:51 +02:00
|
|
|
\
|
2007-10-08 00:45:22 +02:00
|
|
|
return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, mode, \
|
2007-05-12 10:08:01 +02:00
|
|
|
iface, mfi.thisptroffs, SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, \
|
2007-10-08 00:45:22 +02:00
|
|
|
new SH_FHCls(ifacetype,ifacefunc,overload)::CMyDelegateImpl(handler), post); \
|
2005-04-30 21:09:51 +02:00
|
|
|
} \
|
|
|
|
bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
|
|
|
|
SH_FHCls(ifacetype,ifacefunc,overload)::FD handler) \
|
|
|
|
{ \
|
|
|
|
using namespace ::SourceHook; \
|
2006-08-13 13:34:30 +02:00
|
|
|
MemFuncInfo mfi = {true, -1, 0, 0}; \
|
2005-04-30 21:09:51 +02:00
|
|
|
GetFuncInfo(funcptr, mfi); \
|
2007-10-08 00:45:22 +02:00
|
|
|
SH_FHCls(ifacetype,ifacefunc,overload)::CMyDelegateImpl tmp(handler); \
|
2005-04-30 21:09:51 +02:00
|
|
|
return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, mfi.thisptroffs, \
|
|
|
|
SH_FHCls(ifacetype,ifacefunc,overload)::HookManPubFunc, &tmp, post); \
|
|
|
|
} \
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, pvtbloffs, pvtblidx, pthisptroffs) \
|
|
|
|
struct SH_MFHCls(hookname) \
|
|
|
|
{ \
|
|
|
|
static SH_MFHCls(hookname) ms_Inst; \
|
|
|
|
static ::SourceHook::MemFuncInfo ms_MFI; \
|
|
|
|
static ::SourceHook::IHookManagerInfo *ms_HI; \
|
|
|
|
static ::SourceHook::ProtoInfo ms_Proto; \
|
|
|
|
\
|
|
|
|
SH_MFHCls(hookname)() \
|
|
|
|
{ \
|
|
|
|
ms_MFI.isVirtual = true; \
|
|
|
|
ms_MFI.thisptroffs = pthisptroffs; \
|
|
|
|
ms_MFI.vtblindex = pvtblidx; \
|
|
|
|
ms_MFI.vtbloffs = pvtbloffs; \
|
|
|
|
} \
|
2007-10-08 00:45:22 +02:00
|
|
|
static int HookManPubFunc(bool store, ::SourceHook::IHookManagerInfo *hi) \
|
2005-12-10 23:37:53 +01:00
|
|
|
{ \
|
|
|
|
using namespace ::SourceHook; \
|
|
|
|
/* Verify interface version */ \
|
|
|
|
if (SH_GLOB_SHPTR->GetIfaceVersion() != SH_IFACE_VERSION) \
|
|
|
|
return 1; \
|
2007-05-07 20:35:59 +02:00
|
|
|
if (SH_GLOB_SHPTR->GetImplVersion() < SH_IMPL_VERSION) \
|
|
|
|
return 1; \
|
2007-10-08 00:45:22 +02:00
|
|
|
if (store) \
|
|
|
|
ms_HI = hi; \
|
|
|
|
if (hi) \
|
2005-12-10 23:37:53 +01:00
|
|
|
{ \
|
2006-08-13 13:34:30 +02:00
|
|
|
MemFuncInfo mfi = {true, -1, 0, 0}; \
|
2005-12-10 23:37:53 +01:00
|
|
|
GetFuncInfo(&SH_MFHCls(hookname)::Func, mfi); \
|
2007-10-08 00:45:22 +02:00
|
|
|
hi->SetInfo(SH_HOOKMAN_VERSION, ms_MFI.vtbloffs, ms_MFI.vtblindex, &ms_Proto, \
|
|
|
|
reinterpret_cast<void**>(reinterpret_cast<char*>(&ms_Inst) + mfi.vtbloffs)[mfi.vtblindex] ); \
|
2005-12-10 23:37:53 +01:00
|
|
|
} \
|
2007-10-08 00:45:22 +02:00
|
|
|
return 0; \
|
2005-12-10 23:37:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, pvtbloffs, pvtblidx, pthisptroffs) \
|
|
|
|
}; \
|
|
|
|
SH_MFHCls(hookname) SH_MFHCls(hookname)::ms_Inst; \
|
|
|
|
::SourceHook::MemFuncInfo SH_MFHCls(hookname)::ms_MFI; \
|
|
|
|
::SourceHook::IHookManagerInfo *SH_MFHCls(hookname)::ms_HI; \
|
2007-10-08 00:45:22 +02:00
|
|
|
int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
|
2007-05-07 20:35:59 +02:00
|
|
|
SH_MFHCls(hookname)::FD handler) \
|
|
|
|
{ \
|
2007-10-08 00:45:22 +02:00
|
|
|
return SH_GLOB_SHPTR->AddHook(SH_GLOB_PLUGPTR, mode, \
|
2007-05-12 10:08:01 +02:00
|
|
|
iface, pthisptroffs, SH_MFHCls(hookname)::HookManPubFunc, \
|
2007-10-08 00:45:22 +02:00
|
|
|
new SH_MFHCls(hookname)::CMyDelegateImpl(handler), post); \
|
2005-12-10 23:37:53 +01:00
|
|
|
} \
|
|
|
|
bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
|
|
|
|
SH_MFHCls(hookname)::FD handler) \
|
|
|
|
{ \
|
2007-10-08 00:45:22 +02:00
|
|
|
SH_MFHCls(hookname)::CMyDelegateImpl tmp(handler); \
|
2005-12-10 23:37:53 +01:00
|
|
|
return SH_GLOB_SHPTR->RemoveHook(SH_GLOB_PLUGPTR, iface, pthisptroffs, \
|
|
|
|
SH_MFHCls(hookname)::HookManPubFunc, &tmp, post); \
|
|
|
|
} \
|
2007-11-02 15:36:47 +01:00
|
|
|
SH_MFHCls(hookname)::ECMFP __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) \
|
|
|
|
{ \
|
|
|
|
SOUREHOOK__MNEWPARAMS_PREPAREMFP(hookname); \
|
|
|
|
return u.mfp; \
|
|
|
|
} \
|
|
|
|
SH_MFHCls(hookname)::CallEC __SoureceHook_FHM_SHCall##hookname(void *ptr) \
|
|
|
|
{ \
|
|
|
|
SH_MFHCls(hookname)::ECMFP mfp; \
|
|
|
|
void *vfnptr = reinterpret_cast<void*>( \
|
2007-11-04 14:14:35 +01:00
|
|
|
*reinterpret_cast<void***>( (reinterpret_cast<char*>(ptr) + SH_MFHCls(hookname)::ms_MFI.thisptroffs + SH_MFHCls(hookname)::ms_MFI.vtbloffs) ) + SH_MFHCls(hookname)::ms_MFI.vtblindex); \
|
2007-11-02 15:36:47 +01:00
|
|
|
/* patch mfp */ \
|
|
|
|
*reinterpret_cast<void**>(&mfp) = *reinterpret_cast<void**>(vfnptr); \
|
2007-11-02 16:33:51 +01:00
|
|
|
return SH_MFHCls(hookname)::CallEC(reinterpret_cast< ::SourceHook::EmptyClass* >(ptr), mfp, vfnptr, SH_GLOB_SHPTR); \
|
2007-11-02 15:36:47 +01:00
|
|
|
} \
|
|
|
|
void __SourceHook_FHM_Reconfigure##hookname(int p_vtblindex, int p_vtbloffs, int p_thisptroffs) \
|
|
|
|
{ \
|
|
|
|
SH_GLOB_SHPTR->RemoveHookManager(SH_GLOB_PLUGPTR, SH_MFHCls(hookname)::HookManPubFunc); \
|
|
|
|
SH_MFHCls(hookname)::ms_MFI.thisptroffs = p_thisptroffs; \
|
|
|
|
SH_MFHCls(hookname)::ms_MFI.vtblindex = p_vtblindex; \
|
|
|
|
SH_MFHCls(hookname)::ms_MFI.vtbloffs = p_vtbloffs; \
|
|
|
|
}
|
2005-12-10 23:37:53 +01:00
|
|
|
|
2005-04-29 22:29:46 +02:00
|
|
|
#define SH_SETUPCALLS(rettype, paramtypes, params) \
|
2007-10-08 00:45:22 +02:00
|
|
|
/* 1) Set up */ \
|
2005-04-30 21:09:51 +02:00
|
|
|
using namespace ::SourceHook; \
|
2005-04-29 22:29:46 +02:00
|
|
|
void *ourvfnptr = reinterpret_cast<void*>( \
|
2005-10-03 19:20:22 +02:00
|
|
|
*reinterpret_cast<void***>(reinterpret_cast<char*>(this) + ms_MFI.vtbloffs) + ms_MFI.vtblindex); \
|
2007-10-08 00:45:22 +02:00
|
|
|
void *vfnptr_origentry; \
|
2005-04-29 22:29:46 +02:00
|
|
|
\
|
2005-10-12 22:25:15 +02:00
|
|
|
META_RES status = MRES_IGNORED; \
|
|
|
|
META_RES prev_res; \
|
|
|
|
META_RES cur_res; \
|
2007-10-08 00:45:22 +02:00
|
|
|
\
|
2007-10-12 21:17:52 +02:00
|
|
|
typedef ReferenceCarrier< rettype >::type my_rettype; \
|
2006-08-09 08:46:11 +02:00
|
|
|
my_rettype orig_ret; \
|
|
|
|
my_rettype override_ret; \
|
|
|
|
my_rettype plugin_ret; \
|
2007-10-08 00:45:22 +02:00
|
|
|
IMyDelegate *iter; \
|
|
|
|
IHookContext *pContext = SH_GLOB_SHPTR->SetupHookLoop(ms_HI, ourvfnptr, reinterpret_cast<void*>(this), \
|
|
|
|
&vfnptr_origentry, &status, &prev_res, &cur_res, &orig_ret, &override_ret);
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
#define SH_CALL_HOOKS(post, params) \
|
2007-10-08 00:45:22 +02:00
|
|
|
prev_res = MRES_IGNORED; \
|
2007-10-08 16:20:51 +02:00
|
|
|
while ( (iter = static_cast<IMyDelegate*>(pContext->GetNext())) ) \
|
2005-04-14 14:54:13 +02:00
|
|
|
{ \
|
2007-10-08 00:45:22 +02:00
|
|
|
cur_res = MRES_IGNORED; \
|
|
|
|
plugin_ret = iter->Call params; \
|
|
|
|
prev_res = cur_res; \
|
|
|
|
if (cur_res > status) \
|
|
|
|
status = cur_res; \
|
|
|
|
if (cur_res >= MRES_OVERRIDE) \
|
|
|
|
*reinterpret_cast<my_rettype*>(pContext->GetOverrideRetPtr()) = plugin_ret; \
|
2005-04-14 14:54:13 +02:00
|
|
|
}
|
|
|
|
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SH_CALL_ORIG(rettype, paramtypes, params) \
|
2007-10-08 00:45:22 +02:00
|
|
|
if (status != MRES_SUPERCEDE && pContext->ShouldCallOrig()) \
|
2005-04-29 22:29:46 +02:00
|
|
|
{ \
|
|
|
|
rettype (EmptyClass::*mfp)paramtypes; \
|
|
|
|
SH_SETUP_MFP(mfp); \
|
2005-10-06 22:46:49 +02:00
|
|
|
orig_ret = (reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
|
2005-04-29 22:29:46 +02:00
|
|
|
} \
|
2005-04-14 14:54:13 +02:00
|
|
|
else \
|
2007-10-08 00:45:22 +02:00
|
|
|
orig_ret = override_ret; /* :TODO: ??? : use pContext->GetOverrideRetPtr() or not? */
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
#define SH_RETURN() \
|
2007-10-08 00:45:22 +02:00
|
|
|
const my_rettype *retptr = reinterpret_cast<const my_rettype*>( \
|
|
|
|
(status >= MRES_OVERRIDE) ? pContext->GetOverrideRetPtr() : pContext->GetOrigRetPtr()); \
|
|
|
|
SH_GLOB_SHPTR->EndContext(pContext); \
|
|
|
|
return *retptr;
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SH_HANDLEFUNC(paramtypes, params, rettype) \
|
2005-04-29 22:29:46 +02:00
|
|
|
SH_SETUPCALLS(rettype, paramtypes, params) \
|
2005-04-14 14:54:13 +02:00
|
|
|
SH_CALL_HOOKS(pre, params) \
|
2005-12-10 23:37:53 +01:00
|
|
|
SH_CALL_ORIG(rettype, paramtypes, params) \
|
2005-04-14 14:54:13 +02:00
|
|
|
SH_CALL_HOOKS(post, params) \
|
|
|
|
SH_RETURN()
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2005-04-29 22:29:46 +02:00
|
|
|
#define SH_SETUPCALLS_void(paramtypes, params) \
|
2007-10-08 00:45:22 +02:00
|
|
|
/* 1) Set up */ \
|
2005-10-03 19:20:22 +02:00
|
|
|
using namespace ::SourceHook; \
|
2005-04-29 22:29:46 +02:00
|
|
|
void *ourvfnptr = reinterpret_cast<void*>( \
|
2005-10-03 19:20:22 +02:00
|
|
|
*reinterpret_cast<void***>(reinterpret_cast<char*>(this) + ms_MFI.vtbloffs) + ms_MFI.vtblindex); \
|
2007-10-08 00:45:22 +02:00
|
|
|
void *vfnptr_origentry; \
|
2005-04-29 22:29:46 +02:00
|
|
|
\
|
2005-10-12 22:25:15 +02:00
|
|
|
META_RES status = MRES_IGNORED; \
|
|
|
|
META_RES prev_res; \
|
|
|
|
META_RES cur_res; \
|
2007-10-08 00:45:22 +02:00
|
|
|
\
|
|
|
|
IMyDelegate *iter; \
|
|
|
|
IHookContext *pContext = SH_GLOB_SHPTR->SetupHookLoop(ms_HI, ourvfnptr, reinterpret_cast<void*>(this), \
|
|
|
|
&vfnptr_origentry, &status, &prev_res, &cur_res, NULL, NULL);
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
#define SH_CALL_HOOKS_void(post, params) \
|
2007-10-08 00:45:22 +02:00
|
|
|
prev_res = MRES_IGNORED; \
|
2007-10-08 16:20:51 +02:00
|
|
|
while ( (iter = static_cast<IMyDelegate*>(pContext->GetNext())) ) \
|
2005-04-14 14:54:13 +02:00
|
|
|
{ \
|
2007-10-08 00:45:22 +02:00
|
|
|
cur_res = MRES_IGNORED; \
|
|
|
|
iter->Call params; \
|
|
|
|
prev_res = cur_res; \
|
|
|
|
if (cur_res > status) \
|
|
|
|
status = cur_res; \
|
2005-04-14 14:54:13 +02:00
|
|
|
}
|
|
|
|
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SH_CALL_ORIG_void(paramtypes, params) \
|
2007-10-08 00:45:22 +02:00
|
|
|
if (status != MRES_SUPERCEDE && pContext->ShouldCallOrig()) \
|
2005-04-29 22:29:46 +02:00
|
|
|
{ \
|
|
|
|
void (EmptyClass::*mfp)paramtypes; \
|
|
|
|
SH_SETUP_MFP(mfp); \
|
2005-10-06 22:46:49 +02:00
|
|
|
(reinterpret_cast<EmptyClass*>(this)->*mfp)params; \
|
2005-04-29 22:29:46 +02:00
|
|
|
}
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2005-10-12 22:25:15 +02:00
|
|
|
#define SH_RETURN_void() \
|
2007-10-08 00:45:22 +02:00
|
|
|
SH_GLOB_SHPTR->EndContext(pContext);
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SH_HANDLEFUNC_void(paramtypes, params) \
|
2005-04-29 22:29:46 +02:00
|
|
|
SH_SETUPCALLS_void(paramtypes, params) \
|
2005-04-14 14:54:13 +02:00
|
|
|
SH_CALL_HOOKS_void(pre, params) \
|
2005-12-10 23:37:53 +01:00
|
|
|
SH_CALL_ORIG_void(paramtypes, params) \
|
2005-04-14 14:54:13 +02:00
|
|
|
SH_CALL_HOOKS_void(post, params) \
|
|
|
|
SH_RETURN_void()
|
|
|
|
|
|
|
|
|
|
|
|
// Special vafmt handlers
|
2005-12-23 12:58:11 +01:00
|
|
|
// :TODO: what
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SH_HANDLEFUNC_vafmt(paramtypes, params_orig, params_plug, rettype) \
|
2005-04-29 22:29:46 +02:00
|
|
|
SH_SETUPCALLS(rettype, paramtypes, params_orig) \
|
2005-04-14 14:54:13 +02:00
|
|
|
SH_CALL_HOOKS(pre, params_plug) \
|
2005-12-10 23:37:53 +01:00
|
|
|
SH_CALL_ORIG(rettype, paramtypes, params_orig) \
|
2005-04-14 14:54:13 +02:00
|
|
|
SH_CALL_HOOKS(post, params_plug) \
|
|
|
|
SH_RETURN()
|
|
|
|
|
2005-12-10 23:37:53 +01:00
|
|
|
#define SH_HANDLEFUNC_void_vafmt(paramtypes, params_orig, params_plug) \
|
2005-04-29 22:29:46 +02:00
|
|
|
SH_SETUPCALLS_void(paramtypes, params_orig) \
|
2005-04-14 14:54:13 +02:00
|
|
|
SH_CALL_HOOKS_void(pre, params_plug) \
|
2005-12-10 23:37:53 +01:00
|
|
|
SH_CALL_ORIG_void(paramtypes, params_orig) \
|
2005-04-14 14:54:13 +02:00
|
|
|
SH_CALL_HOOKS_void(post, params_plug) \
|
|
|
|
SH_RETURN_void()
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
#define MAKE_DELEG(ret_type, params_decl, params_pass) \
|
|
|
|
struct IMyDelegate : ::SourceHook::ISHDelegate { virtual ret_type Call params_decl = 0; }; \
|
|
|
|
struct CMyDelegateImpl : IMyDelegate \
|
|
|
|
{ \
|
|
|
|
FD m_Deleg; \
|
|
|
|
CMyDelegateImpl(FD deleg) : m_Deleg(deleg) {} \
|
|
|
|
ret_type Call params_decl { return m_Deleg params_pass; } \
|
|
|
|
void DeleteThis() { delete this; } \
|
|
|
|
bool IsEqual(ISHDelegate *pOtherDeleg) { return m_Deleg == static_cast<CMyDelegateImpl*>(pOtherDeleg)->m_Deleg; } \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAKE_DELEG_void(params_decl, params_pass) \
|
|
|
|
struct IMyDelegate : ::SourceHook::ISHDelegate { virtual void Call params_decl = 0; }; \
|
|
|
|
struct CMyDelegateImpl : IMyDelegate \
|
|
|
|
{ \
|
|
|
|
FD m_Deleg; \
|
|
|
|
CMyDelegateImpl(FD deleg) : m_Deleg(deleg) {} \
|
|
|
|
void Call params_decl { m_Deleg params_pass; } \
|
|
|
|
void DeleteThis() { delete this; } \
|
|
|
|
bool IsEqual(ISHDelegate *pOtherDeleg) { return m_Deleg == static_cast<CMyDelegateImpl*>(pOtherDeleg)->m_Deleg; } \
|
|
|
|
};
|
|
|
|
|
2007-10-12 21:19:17 +02:00
|
|
|
// GetPassInfo -> easier access. __SH_GPI generates a SourceHook::PassInfo instance.
|
2007-10-12 21:17:52 +02:00
|
|
|
#define __SH_GPI(tt) { sizeof(tt), ::SourceHook::GetPassInfo< tt >::type, ::SourceHook::GetPassInfo< tt >::flags }
|
2007-10-14 13:59:13 +02:00
|
|
|
// Extra pass info V2
|
|
|
|
#define __SH_EPI { 0, 0, 0, 0 }
|
2007-10-12 21:17:52 +02:00
|
|
|
|
2007-11-09 23:51:31 +01:00
|
|
|
#define __SH_VAFMT_SEQ(fmt, buf) \
|
|
|
|
char buf[::SourceHook::STRBUF_LEN]; \
|
|
|
|
va_list ap; \
|
|
|
|
va_start(ap, fmt); \
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap); \
|
|
|
|
va_end(ap);
|
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
@[$1,0,$a:
|
|
|
|
// ********* Support for $1 arguments *********
|
|
|
|
#define SH_DECL_HOOK$1(ifacetype, ifacefunc, attr, overload, rettype@[$2,1,$1:, param$2@]) \
|
|
|
|
SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr> \
|
2005-04-14 14:54:13 +02:00
|
|
|
(&ifacetype::ifacefunc))) \
|
2006-05-13 19:57:35 +02:00
|
|
|
typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> FD; \
|
2007-10-08 00:45:22 +02:00
|
|
|
MAKE_DELEG(rettype, (@[$2,1,$1|, :param$2 p$2@]), (@[$2,1,$1|, :p$2@])); \
|
2006-05-13 19:57:35 +02:00
|
|
|
virtual rettype Func(@[$2,1,$1|, :param$2 p$2@]) \
|
|
|
|
{ SH_HANDLEFUNC((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@]), rettype); } \
|
2005-12-10 23:37:53 +01:00
|
|
|
SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
|
2006-05-13 19:57:35 +02:00
|
|
|
(static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr>(&ifacetype::ifacefunc))) \
|
2005-12-10 23:37:53 +01:00
|
|
|
\
|
2007-10-14 13:59:13 +02:00
|
|
|
const ::SourceHook::PassInfo __SourceHook_ParamInfos_##ifacetype##ifacefunc##overload[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
|
|
|
|
const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
|
2007-10-12 21:17:52 +02:00
|
|
|
::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto = { $1, __SH_GPI(rettype), \
|
2007-10-14 13:59:13 +02:00
|
|
|
__SourceHook_ParamInfos_##ifacetype##ifacefunc##overload, 0, __SH_EPI, __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload };
|
2007-10-08 00:45:22 +02:00
|
|
|
|
2007-10-14 18:25:39 +02:00
|
|
|
#define SH_DECL_EXTERN$1(ifacetype, ifacefunc, attr, overload, rettype@[$2,1,$1:, param$2@]) \
|
|
|
|
int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
|
|
|
|
fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> handler); \
|
|
|
|
bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
|
|
|
|
fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> handler);
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
#define SH_DECL_HOOK$1_void(ifacetype, ifacefunc, attr, overload@[$2,1,$1:, param$2@]) \
|
|
|
|
SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr> \
|
2005-04-14 14:54:13 +02:00
|
|
|
(&ifacetype::ifacefunc))) \
|
2006-05-13 19:57:35 +02:00
|
|
|
typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> FD; \
|
2007-10-08 00:45:22 +02:00
|
|
|
MAKE_DELEG_void((@[$2,1,$1|, :param$2 p$2@]), (@[$2,1,$1|, :p$2@])); \
|
2006-05-13 19:57:35 +02:00
|
|
|
virtual void Func(@[$2,1,$1|, :param$2 p$2@]) \
|
|
|
|
{ SH_HANDLEFUNC_void((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@])); } \
|
2005-12-10 23:37:53 +01:00
|
|
|
SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
|
2006-05-13 19:57:35 +02:00
|
|
|
(static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]) attr>(&ifacetype::ifacefunc))) \
|
2005-12-10 23:37:53 +01:00
|
|
|
\
|
2007-10-14 13:59:13 +02:00
|
|
|
const ::SourceHook::PassInfo __SourceHook_ParamInfos_##ifacetype##ifacefunc##overload[] = { {1, 0, 0}@[$2,1,$1:,__SH_GPI(param$2)@] }; \
|
|
|
|
const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
|
2007-10-08 00:45:22 +02:00
|
|
|
::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto = { $1, { 0, 0, 0 }, \
|
2007-10-14 13:59:13 +02:00
|
|
|
__SourceHook_ParamInfos_##ifacetype##ifacefunc##overload, 0, __SH_EPI, __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload };
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2007-10-14 18:25:39 +02:00
|
|
|
#define SH_DECL_EXTERN$1_void(ifacetype, ifacefunc, attr, overload@[$2,1,$1:, param$2@]) \
|
|
|
|
int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
|
|
|
|
fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> handler); \
|
|
|
|
bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
|
|
|
|
fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> handler);
|
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
#define SH_DECL_HOOK$1_vafmt(ifacetype, ifacefunc, attr, overload, rettype@[$2,1,$1:, param$2@]) \
|
|
|
|
SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr> \
|
2005-04-14 14:54:13 +02:00
|
|
|
(&ifacetype::ifacefunc))) \
|
2006-05-13 19:57:35 +02:00
|
|
|
typedef fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, rettype> FD; \
|
2007-10-08 00:45:22 +02:00
|
|
|
MAKE_DELEG(rettype, (@[$2,1,$1|, :param$2 p$2@]@[$1!=0:, @]const char *px), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]px)); \
|
|
|
|
virtual rettype Func(@[$2,1,$1|, :param$2 p$2@] @[$1!=0:, @]const char *fmt, ...) \
|
2005-04-14 14:54:13 +02:00
|
|
|
{ \
|
2007-11-09 23:51:31 +01:00
|
|
|
__SH_VAFMT_SEQ(fmt, buf); \
|
|
|
|
SH_HANDLEFUNC_vafmt((@[$2,1,$1:param$2, @]const char *, ...), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]"%s", buf), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]buf), rettype); \
|
2005-04-14 14:54:13 +02:00
|
|
|
} \
|
2005-12-10 23:37:53 +01:00
|
|
|
SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
|
2006-05-13 19:57:35 +02:00
|
|
|
(static_cast<rettype (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr>(&ifacetype::ifacefunc))) \
|
2005-12-10 23:37:53 +01:00
|
|
|
\
|
2007-10-14 13:59:13 +02:00
|
|
|
const ::SourceHook::PassInfo __SourceHook_ParamInfos_##ifacetype##ifacefunc##overload[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
|
|
|
|
const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
|
2007-10-12 21:17:52 +02:00
|
|
|
::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto = { $1, __SH_GPI(rettype), \
|
2007-10-14 13:59:13 +02:00
|
|
|
__SourceHook_ParamInfos_##ifacetype##ifacefunc##overload, 0, __SH_EPI, __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload };
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2007-10-14 18:25:39 +02:00
|
|
|
#define SH_DECL_EXTERN$1_vafmt(ifacetype, ifacefunc, attr, overload, rettype@[$2,1,$1:, param$2@]) \
|
|
|
|
int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
|
|
|
|
fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, rettype> handler); \
|
|
|
|
bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
|
|
|
|
fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, rettype> handler);
|
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
#define SH_DECL_HOOK$1_void_vafmt(ifacetype, ifacefunc, attr, overload@[$2,1,$1:, param$2@]) \
|
|
|
|
SHINT_MAKE_GENERICSTUFF_BEGIN(ifacetype, ifacefunc, overload, (static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr> \
|
2005-04-14 14:54:13 +02:00
|
|
|
(&ifacetype::ifacefunc))) \
|
2006-05-13 19:57:35 +02:00
|
|
|
typedef fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *> FD; \
|
2007-10-08 00:45:22 +02:00
|
|
|
MAKE_DELEG_void((@[$2,1,$1|, :param$2 p$2@]@[$1!=0:, @]const char *px), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]px)); \
|
2006-05-13 19:57:35 +02:00
|
|
|
virtual void Func(@[$2,1,$1|, :param$2 p$2@]@[$1!=0:, @]const char *fmt, ...) \
|
2005-04-14 14:54:13 +02:00
|
|
|
{ \
|
2007-11-09 23:51:31 +01:00
|
|
|
__SH_VAFMT_SEQ(fmt, buf); \
|
|
|
|
SH_HANDLEFUNC_void_vafmt((@[$2,1,$1:param$2, @]const char *, ...), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]"%s", buf), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]buf)); \
|
2005-04-14 14:54:13 +02:00
|
|
|
} \
|
2005-12-10 23:37:53 +01:00
|
|
|
SHINT_MAKE_GENERICSTUFF_END(ifacetype, ifacefunc, overload, \
|
2006-05-13 19:57:35 +02:00
|
|
|
(static_cast<void (ifacetype::*)(@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *, ...) attr>(&ifacetype::ifacefunc))) \
|
2005-12-10 23:37:53 +01:00
|
|
|
\
|
2007-10-14 13:59:13 +02:00
|
|
|
const ::SourceHook::PassInfo __SourceHook_ParamInfos_##ifacetype##ifacefunc##overload[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
|
|
|
|
const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
|
2007-10-08 00:45:22 +02:00
|
|
|
::SourceHook::ProtoInfo SH_FHCls(ifacetype, ifacefunc, overload)::ms_Proto = { $1, { 0, 0, 0 }, \
|
2007-10-14 13:59:13 +02:00
|
|
|
__SourceHook_ParamInfos_##ifacetype##ifacefunc##overload, 0, __SH_EPI, __SourceHook_ParamInfos2_##ifacetype##ifacefunc##overload };
|
2005-12-10 23:37:53 +01:00
|
|
|
|
2007-10-14 18:25:39 +02:00
|
|
|
#define SH_DECL_EXTERN$1_void_vafmt(ifacetype, ifacefunc, attr, overload@[$2,1,$1:, param$2@]) \
|
|
|
|
int __SourceHook_FHAdd##ifacetype##ifacefunc(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
|
|
|
|
fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *> handler); \
|
|
|
|
bool __SourceHook_FHRemove##ifacetype##ifacefunc(void *iface, bool post, \
|
|
|
|
fastdelegate::FastDelegate@($1+1)<@[$2,1,$1|, :param$2@]@[$1!=0:, @]const char *> handler);
|
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
#define SH_DECL_MANUALHOOK$1(hookname, vtblidx, vtbloffs, thisptroffs, rettype@[$2,1,$1:, param$2@]) \
|
2005-12-10 23:37:53 +01:00
|
|
|
SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
|
2006-05-13 19:57:35 +02:00
|
|
|
typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> FD; \
|
2007-10-08 00:45:22 +02:00
|
|
|
MAKE_DELEG(rettype, (@[$2,1,$1|, :param$2 p$2@]), (@[$2,1,$1|, :p$2@])); \
|
2006-05-13 19:57:35 +02:00
|
|
|
virtual rettype Func(@[$2,1,$1|, :param$2 p$2@]) \
|
|
|
|
{ SH_HANDLEFUNC((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@]), rettype); } \
|
2006-05-14 20:29:35 +02:00
|
|
|
typedef rettype(::SourceHook::EmptyClass::*ECMFP)(@[$2,1,$1|, :param$2@]); \
|
2007-11-04 14:19:08 +01:00
|
|
|
typedef SourceHook::ExecutableClass$1< ::SourceHook::EmptyClass, ECMFP, rettype@[$2,1,$1:, param$2@] > CallEC; \
|
2006-06-08 20:34:18 +02:00
|
|
|
typedef rettype RetType; \
|
2005-12-10 23:37:53 +01:00
|
|
|
SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
|
|
|
|
\
|
2007-10-14 13:59:13 +02:00
|
|
|
const ::SourceHook::PassInfo __SourceHook_ParamInfosM_##hookname[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
|
|
|
|
const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2M_##hookname[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
|
2007-10-12 21:17:52 +02:00
|
|
|
::SourceHook::ProtoInfo SH_MFHCls(hookname)::ms_Proto = { $1, __SH_GPI(rettype), \
|
2007-11-02 15:36:47 +01:00
|
|
|
__SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
|
2007-11-04 14:14:35 +01:00
|
|
|
void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
|
2007-11-02 15:36:47 +01:00
|
|
|
{ \
|
|
|
|
::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
|
|
|
|
}
|
2005-12-10 23:37:53 +01:00
|
|
|
|
2007-10-14 18:25:39 +02:00
|
|
|
#define SH_DECL_MANUALEXTERN$1(hookname, rettype@[$2,1,$1:, param$2@]) \
|
|
|
|
int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
|
|
|
|
fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> handler); \
|
|
|
|
bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
|
2007-11-02 15:36:47 +01:00
|
|
|
fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]@[$1!=0:, @]rettype> handler); \
|
|
|
|
rettype(::SourceHook::EmptyClass::* __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) )(@[$2,1,$1|, :param$2@]); \
|
|
|
|
SourceHook::ExecutableClass$1<SourceHook::EmptyClass, rettype(::SourceHook::EmptyClass::*)(@[$2,1,$1|, :param$2@]), rettype@[$2,1,$1:, param$2@]> __SoureceHook_FHM_SHCall##hookname(void *ptr); \
|
2007-11-04 14:14:35 +01:00
|
|
|
void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype res); \
|
2007-11-02 15:36:47 +01:00
|
|
|
void __SourceHook_FHM_Reconfigure##hookname(int pvtblindex, int pvtbloffs, int pthisptroffs);
|
2007-10-14 18:25:39 +02:00
|
|
|
|
2007-11-09 23:51:31 +01:00
|
|
|
#define SH_DECL_MANUALHOOK$1_vafmt(hookname, vtblidx, vtbloffs, thisptroffs, rettype@[$2,1,$1:, param$2@]) \
|
|
|
|
SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
|
|
|
|
typedef fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *, rettype> FD; \
|
|
|
|
MAKE_DELEG(rettype, (@[$2,1,$1:param$2 p$2, @]const char *px), (@[$2,1,$1:p$2, @]px)); \
|
|
|
|
virtual rettype Func(@[$2,1,$1:param$2 p$2, @]const char *fmt, ...) \
|
|
|
|
{ \
|
|
|
|
__SH_VAFMT_SEQ(fmt, buf); \
|
|
|
|
SH_HANDLEFUNC_vafmt((@[$2,1,$1:param$2, @]const char *, ...), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]"%s", buf), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]buf), rettype); \
|
|
|
|
} \
|
|
|
|
typedef rettype(::SourceHook::EmptyClass::*ECMFP)(@[$2,1,$1:param$2, @]const char *, ...); \
|
|
|
|
typedef SourceHook::ExecutableClass@($1+1)< ::SourceHook::EmptyClass, ECMFP, rettype@[$2,1,$1:, param$2@], const char * > CallEC; \
|
|
|
|
typedef rettype RetType; \
|
|
|
|
SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
|
|
|
|
\
|
|
|
|
const ::SourceHook::PassInfo __SourceHook_ParamInfosM_##hookname[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
|
|
|
|
const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2M_##hookname[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
|
|
|
|
::SourceHook::ProtoInfo SH_MFHCls(hookname)::ms_Proto = { $1, __SH_GPI(rettype), \
|
|
|
|
__SourceHook_ParamInfosM_##hookname, 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname }; \
|
|
|
|
void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype value) \
|
|
|
|
{ \
|
|
|
|
::SourceHook::SetOverrideResult<SH_MFHCls(hookname)::RetType>(shptr, value); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SH_DECL_MANUALEXTERN$1_vafmt(hookname, rettype@[$2,1,$1:, param$2@]) \
|
|
|
|
int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
|
|
|
|
fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *, rettype> handler); \
|
|
|
|
bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
|
|
|
|
fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *, rettype> handler); \
|
|
|
|
rettype(::SourceHook::EmptyClass::* __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) )(@[$2,1,$1:param$2, @]const char *, ...); \
|
|
|
|
SourceHook::ExecutableClass@($1+1)<SourceHook::EmptyClass, rettype(::SourceHook::EmptyClass::*)(@[$2,1,$1:param$2, @]const char *, ...), rettype@[$2,1,$1:, param$2@], const char*> __SoureceHook_FHM_SHCall##hookname(void *ptr); \
|
|
|
|
void __SoureceHook_FHM_SetOverrideResult##hookname(::SourceHook::ISourceHook *shptr, rettype res); \
|
|
|
|
void __SourceHook_FHM_Reconfigure##hookname(int pvtblindex, int pvtbloffs, int pthisptroffs);
|
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
#define SH_DECL_MANUALHOOK$1_void(hookname, vtblidx, vtbloffs, thisptroffs@[$2,1,$1:, param$2@]) \
|
2005-12-10 23:37:53 +01:00
|
|
|
SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
|
2006-05-13 19:57:35 +02:00
|
|
|
typedef fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> FD; \
|
2007-10-08 00:45:22 +02:00
|
|
|
MAKE_DELEG_void((@[$2,1,$1|, :param$2 p$2@]), (@[$2,1,$1|, :p$2@])); \
|
2006-05-13 19:57:35 +02:00
|
|
|
virtual void Func(@[$2,1,$1|, :param$2 p$2@]) \
|
|
|
|
{ SH_HANDLEFUNC_void((@[$2,1,$1|, :param$2@]), (@[$2,1,$1|, :p$2@])); } \
|
2006-05-14 20:29:35 +02:00
|
|
|
typedef void(::SourceHook::EmptyClass::*ECMFP)(@[$2,1,$1|, :param$2@]); \
|
2007-11-02 15:36:47 +01:00
|
|
|
typedef SourceHook::ExecutableClass$1<SourceHook::EmptyClass, ECMFP, void@[$2,1,$1:, param$2@]> CallEC; \
|
2005-12-10 23:37:53 +01:00
|
|
|
SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
|
|
|
|
\
|
2007-10-14 13:59:13 +02:00
|
|
|
const ::SourceHook::PassInfo __SourceHook_ParamInfosM_##hookname[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
|
|
|
|
const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2M_##hookname[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
|
2007-10-08 00:45:22 +02:00
|
|
|
::SourceHook::ProtoInfo SH_MFHCls(hookname)::ms_Proto = { $1, { 0, 0, 0 }, \
|
2007-11-09 23:51:31 +01:00
|
|
|
__SourceHook_ParamInfosM_##hookname , 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname };
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2007-10-14 18:25:39 +02:00
|
|
|
#define SH_DECL_MANUALEXTERN$1_void(hookname@[$2,1,$1:, param$2@]) \
|
|
|
|
int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
|
|
|
|
fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> handler); \
|
|
|
|
bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
|
2007-11-02 15:36:47 +01:00
|
|
|
fastdelegate::FastDelegate$1<@[$2,1,$1|, :param$2@]> handler); \
|
|
|
|
void(::SourceHook::EmptyClass::* __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) )(@[$2,1,$1|, :param$2@]); \
|
|
|
|
SourceHook::ExecutableClass$1<SourceHook::EmptyClass, void(::SourceHook::EmptyClass::*)(@[$2,1,$1|, :param$2@]), void@[$2,1,$1:, param$2@]> __SoureceHook_FHM_SHCall##hookname(void *ptr); \
|
|
|
|
void __SourceHook_FHM_Reconfigure##hookname(int pvtblindex, int pvtbloffs, int pthisptroffs);
|
|
|
|
|
2007-11-09 23:51:31 +01:00
|
|
|
#define SH_DECL_MANUALHOOK$1_void_vafmt(hookname, vtblidx, vtbloffs, thisptroffs@[$2,1,$1:, param$2@]) \
|
|
|
|
SHINT_MAKE_GENERICSTUFF_BEGIN_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
|
|
|
|
typedef fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *> FD; \
|
|
|
|
MAKE_DELEG_void((@[$2,1,$1:param$2 p$2, @]const char *px), (@[$2,1,$1:p$2, @]px)); \
|
|
|
|
virtual void Func(@[$2,1,$1:param$2 p$2, @]const char *fmt, ...) \
|
|
|
|
{ \
|
|
|
|
__SH_VAFMT_SEQ(fmt, buf); \
|
|
|
|
SH_HANDLEFUNC_void_vafmt((@[$2,1,$1:param$2, @]const char *, ...), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]"%s", buf), (@[$2,1,$1|, :p$2@]@[$1!=0:, @]buf)); \
|
|
|
|
} \
|
|
|
|
typedef void(::SourceHook::EmptyClass::*ECMFP)(@[$2,1,$1:param$2, @]const char *, ...); \
|
|
|
|
typedef SourceHook::ExecutableClass@($1+1)< ::SourceHook::EmptyClass, ECMFP, void@[$2,1,$1:, param$2@], const char * > CallEC; \
|
|
|
|
SHINT_MAKE_GENERICSTUFF_END_MANUAL(hookname, vtbloffs, vtblidx, thisptroffs) \
|
|
|
|
\
|
|
|
|
const ::SourceHook::PassInfo __SourceHook_ParamInfosM_##hookname[] = { {1, 0, 0}@[$2,1,$1:, __SH_GPI(param$2)@] }; \
|
|
|
|
const ::SourceHook::PassInfo::V2Info __SourceHook_ParamInfos2M_##hookname[] = { __SH_EPI@[$2,1,$1:, __SH_EPI@] }; \
|
|
|
|
::SourceHook::ProtoInfo SH_MFHCls(hookname)::ms_Proto = { $1, { 0, 0, 0 }, \
|
|
|
|
__SourceHook_ParamInfosM_##hookname , 0, __SH_EPI, __SourceHook_ParamInfos2M_##hookname };
|
|
|
|
|
|
|
|
#define SH_DECL_MANUALEXTERN$1_void_vafmt(hookname@[$2,1,$1:, param$2@]) \
|
|
|
|
int __SourceHook_FHMAdd##hookname(void *iface, ::SourceHook::ISourceHook::AddHookMode mode, bool post, \
|
|
|
|
fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *> handler); \
|
|
|
|
bool __SourceHook_FHMRemove##hookname(void *iface, bool post, \
|
|
|
|
fastdelegate::FastDelegate@($1+1)<@[$2,1,$1:param$2, @]const char *> handler); \
|
|
|
|
void(::SourceHook::EmptyClass::* __SoureceHook_FHM_GetRecallMFP##hookname(::SourceHook::EmptyClass *thisptr) )(@[$2,1,$1:param$2, @]const char *, ...); \
|
|
|
|
SourceHook::ExecutableClass@($1+1)<SourceHook::EmptyClass, void(::SourceHook::EmptyClass::*)(@[$2,1,$1:param$2, @]const char *, ...), void@[$2,1,$1:, param$2@], const char*> __SoureceHook_FHM_SHCall##hookname(void *ptr); \
|
|
|
|
void __SourceHook_FHM_Reconfigure##hookname(int pvtblindex, int pvtbloffs, int pthisptroffs);
|
2006-05-13 19:57:35 +02:00
|
|
|
@]
|
2005-04-14 14:54:13 +02:00
|
|
|
|
|
|
|
|
2005-04-29 22:29:46 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// SH_CALL
|
|
|
|
|
2007-05-12 10:08:01 +02:00
|
|
|
#define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
|
2005-04-29 22:29:46 +02:00
|
|
|
{ \
|
2005-04-30 21:09:51 +02:00
|
|
|
using namespace ::SourceHook; \
|
2005-04-29 22:29:46 +02:00
|
|
|
\
|
2007-10-08 00:45:22 +02:00
|
|
|
m_pSH->SetIgnoreHooks(m_VfnPtr); \
|
2007-05-12 10:08:01 +02:00
|
|
|
RetType tmpret = (m_ThisPtr->*m_MFP)call; \
|
2007-10-08 00:45:22 +02:00
|
|
|
m_pSH->ResetIgnoreHooks(m_VfnPtr); \
|
2007-05-12 10:08:01 +02:00
|
|
|
return tmpret; \
|
2005-04-29 22:29:46 +02:00
|
|
|
}
|
|
|
|
|
2007-05-12 10:08:01 +02:00
|
|
|
#define SH_MAKE_EXECUTABLECLASS_OB_void(call, prms) \
|
2006-05-14 20:29:35 +02:00
|
|
|
{ \
|
|
|
|
using namespace ::SourceHook; \
|
|
|
|
\
|
2007-10-08 00:45:22 +02:00
|
|
|
m_pSH->SetIgnoreHooks(m_VfnPtr); \
|
2007-05-12 10:08:01 +02:00
|
|
|
(m_ThisPtr->*m_MFP)call; \
|
2007-10-08 00:45:22 +02:00
|
|
|
m_pSH->ResetIgnoreHooks(m_VfnPtr); \
|
2006-05-14 20:29:35 +02:00
|
|
|
}
|
|
|
|
|
2007-05-12 10:08:01 +02:00
|
|
|
namespace SourceHook
|
|
|
|
{
|
2006-05-13 19:57:35 +02:00
|
|
|
@[$1,0,$a:
|
|
|
|
// Support for $1 arguments
|
2007-10-08 00:45:22 +02:00
|
|
|
template<class ObjType, class MFPType, class RetType@[$2,1,$1:, class Param$2@]> class ExecutableClass$1
|
2005-04-29 22:29:46 +02:00
|
|
|
{
|
2007-05-12 10:08:01 +02:00
|
|
|
ObjType *m_ThisPtr;
|
|
|
|
void *m_VfnPtr;
|
2007-10-08 00:45:22 +02:00
|
|
|
MFPType m_MFP;
|
2007-05-12 10:57:10 +02:00
|
|
|
ISourceHook *m_pSH;
|
2005-04-29 22:29:46 +02:00
|
|
|
public:
|
2007-10-08 00:45:22 +02:00
|
|
|
ExecutableClass$1(ObjType *tp, MFPType mfp, void *vp, ISourceHook *pSH) : m_ThisPtr(tp),
|
|
|
|
m_VfnPtr(vp), m_MFP(mfp), m_pSH(pSH) { }
|
2006-05-13 19:57:35 +02:00
|
|
|
|
2007-05-12 10:08:01 +02:00
|
|
|
RetType operator()(@[$2,1,$1|, :Param$2 p$2@]) const
|
|
|
|
SH_MAKE_EXECUTABLECLASS_OB((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
|
2006-05-13 19:57:35 +02:00
|
|
|
|
2007-05-12 10:08:01 +02:00
|
|
|
@[$2,$1+1,$a:
|
|
|
|
template <@[$3,$1+1,$2|, :class Param$3@]> RetType operator()(@[$3,1,$2|, :Param$3 p$3@]) const
|
|
|
|
SH_MAKE_EXECUTABLECLASS_OB((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
|
|
|
|
@]
|
2005-04-29 22:29:46 +02:00
|
|
|
};
|
2006-05-14 20:29:35 +02:00
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
template<class ObjType, class MFPType@[$2,1,$1:, class Param$2@]> class ExecutableClass$1<ObjType, MFPType, void@[$2,1,$1:, Param$2@]>
|
2006-05-14 20:29:35 +02:00
|
|
|
{
|
2007-10-08 00:45:22 +02:00
|
|
|
ObjType *m_ThisPtr;
|
|
|
|
void *m_VfnPtr;
|
|
|
|
MFPType m_MFP;
|
|
|
|
ISourceHook *m_pSH;
|
2006-05-14 20:29:35 +02:00
|
|
|
public:
|
2007-10-08 00:45:22 +02:00
|
|
|
ExecutableClass$1(ObjType *tp, MFPType mfp, void *vp, ISourceHook *pSH) : m_ThisPtr(tp),
|
|
|
|
m_VfnPtr(vp), m_MFP(mfp), m_pSH(pSH) { }
|
2007-05-12 10:08:01 +02:00
|
|
|
|
|
|
|
void operator()(@[$2,1,$1|, :Param$2 p$2@]) const
|
|
|
|
SH_MAKE_EXECUTABLECLASS_OB_void((@[$2,1,$1|, :p$2@]), (@[$2,1,$1|, :Param$2@]))
|
|
|
|
|
|
|
|
@[$2,$1+1,$a:
|
|
|
|
template <@[$3,$1+1,$2|, :class Param$3@]> void operator()(@[$3,1,$2|, :Param$3 p$3@]) const
|
|
|
|
SH_MAKE_EXECUTABLECLASS_OB_void((@[$3,1,$2|, :p$3@]), (@[$3,1,$2|, :Param$3@]))
|
|
|
|
@]
|
2006-05-14 20:29:35 +02:00
|
|
|
};
|
2006-05-13 19:57:35 +02:00
|
|
|
@]
|
|
|
|
|
2005-04-29 22:29:46 +02:00
|
|
|
}
|
|
|
|
|
2007-05-12 10:08:01 +02:00
|
|
|
#define SH__CALL_GET_VFNPTR_NORMAL \
|
|
|
|
using namespace ::SourceHook; \
|
|
|
|
MemFuncInfo mfi = {true, -1, 0, 0}; \
|
2007-10-08 00:45:22 +02:00
|
|
|
GetFuncInfo(ptr, mfp, mfi); \
|
2007-05-12 10:08:01 +02:00
|
|
|
void *vfnptr = reinterpret_cast<void*>( \
|
|
|
|
*reinterpret_cast<void***>(reinterpret_cast<char*>(ptr) + mfi.thisptroffs + mfi.vtbloffs) + mfi.vtblindex);
|
|
|
|
|
|
|
|
#define SH__CALL_GET_VFNPTR_MANUAL \
|
|
|
|
using namespace ::SourceHook; \
|
|
|
|
void *vfnptr = reinterpret_cast<void*>( \
|
2007-10-08 00:45:22 +02:00
|
|
|
*reinterpret_cast<void***>( (reinterpret_cast<char*>(ptr) + thisptroffs + vtbloffs) ) + vtblidx); \
|
2007-05-12 10:08:01 +02:00
|
|
|
/* patch mfp */ \
|
|
|
|
*reinterpret_cast<void**>(&mfp) = *reinterpret_cast<void**>(vfnptr);
|
|
|
|
|
2005-05-05 12:40:47 +02:00
|
|
|
// SH_CALL needs to deduce the return type -> it uses templates and function overloading
|
|
|
|
// That's why SH_CALL takes two parameters: "mfp2" of type RetType(X::*mfp)(params), and "mfp" of type MFP
|
|
|
|
// The only purpose of the mfp2 parameter is to extract the return type
|
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
@[$1,0,$a:
|
|
|
|
// Support for $1 arguments
|
|
|
|
template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
|
2007-10-08 00:45:22 +02:00
|
|
|
SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>
|
|
|
|
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]), SourceHook::ISourceHook *shptr)
|
2005-04-29 22:29:46 +02:00
|
|
|
{
|
2007-05-12 10:08:01 +02:00
|
|
|
SH__CALL_GET_VFNPTR_NORMAL
|
2007-10-08 00:45:22 +02:00
|
|
|
return SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp, vfnptr, shptr);
|
2005-04-29 22:29:46 +02:00
|
|
|
}
|
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
|
2007-10-08 00:45:22 +02:00
|
|
|
SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>
|
|
|
|
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@])const, SourceHook::ISourceHook *shptr)
|
2005-04-30 21:09:51 +02:00
|
|
|
{
|
2007-05-12 10:08:01 +02:00
|
|
|
SH__CALL_GET_VFNPTR_NORMAL
|
2007-10-08 00:45:22 +02:00
|
|
|
return SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp, vfnptr, shptr);
|
2005-04-30 21:09:51 +02:00
|
|
|
}
|
|
|
|
|
2007-05-12 10:08:01 +02:00
|
|
|
template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
|
|
|
|
SourceHook::ExecutableClass$1<SourceHook::EmptyClass, MFP, RetType@[$2,1,$1:, Param$2@]>
|
2007-10-08 00:45:22 +02:00
|
|
|
SH_MCALL3(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]), int vtblidx, int vtbloffs, int thisptroffs, SourceHook::ISourceHook *shptr)
|
2006-05-14 20:29:35 +02:00
|
|
|
{
|
2007-05-12 10:08:01 +02:00
|
|
|
SH__CALL_GET_VFNPTR_MANUAL
|
|
|
|
return SourceHook::ExecutableClass$1<EmptyClass, MFP, RetType@[$2,1,$1:, Param$2@]>(
|
2007-10-08 00:45:22 +02:00
|
|
|
reinterpret_cast<SourceHook::EmptyClass*>(ptr), mfp, vfnptr, shptr);
|
2006-05-14 20:29:35 +02:00
|
|
|
}
|
2006-05-13 19:57:35 +02:00
|
|
|
@]
|
2005-05-05 12:40:47 +02:00
|
|
|
|
2005-05-05 23:02:31 +02:00
|
|
|
#if SH_COMP != SH_COMP_MSVC || _MSC_VER > 1300
|
|
|
|
// GCC & MSVC 7.1 need this, MSVC 7.0 doesn't like it
|
2005-05-05 12:40:47 +02:00
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
@[$1,0,$a:
|
|
|
|
// Support for $1 arguments
|
|
|
|
template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
|
2007-10-08 00:45:22 +02:00
|
|
|
SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>
|
|
|
|
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...), SourceHook::ISourceHook *shptr)
|
2005-05-01 20:04:18 +02:00
|
|
|
{
|
2007-05-12 10:08:01 +02:00
|
|
|
SH__CALL_GET_VFNPTR_NORMAL
|
2007-10-08 00:45:22 +02:00
|
|
|
return SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp, vfnptr, shptr);
|
2005-05-01 20:04:18 +02:00
|
|
|
}
|
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
template <class X, class Y, class MFP, class RetType@[$2,1,$1:, class Param$2@]>
|
2007-10-08 00:45:22 +02:00
|
|
|
SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>
|
|
|
|
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(@[$2,1,$1|, :Param$2@]@[$1!=0:, @]...)const, SourceHook::ISourceHook *shptr)
|
2005-05-01 20:04:18 +02:00
|
|
|
{
|
2007-05-12 10:08:01 +02:00
|
|
|
SH__CALL_GET_VFNPTR_NORMAL
|
2007-10-08 00:45:22 +02:00
|
|
|
return SourceHook::ExecutableClass$1<Y, MFP, RetType@[$2,1,$1:, Param$2@]>(ptr, mfp, vfnptr, shptr);
|
2005-05-01 20:04:18 +02:00
|
|
|
}
|
2006-05-14 20:29:35 +02:00
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
@]
|
2005-04-29 22:29:46 +02:00
|
|
|
|
2005-05-05 12:40:47 +02:00
|
|
|
#endif
|
|
|
|
|
2007-10-08 00:45:22 +02:00
|
|
|
#define SH_CALL(ptr, mfp) SH_CALL2((ptr), (mfp), (mfp), SH_GLOB_SHPTR)
|
|
|
|
#define SH_MCALL2(ptr, mfp, vtblidx, vtbloffs, thisptroffs) SH_MCALL3((ptr), (mfp), (mfp), (vtblidx), (vtbloffs), (thisptroffs), SH_GLOB_SHPTR)
|
2007-11-02 15:36:47 +01:00
|
|
|
#define SH_MCALL(ptr, mhookname) __SoureceHook_FHM_SHCall##mhookname(ptr)
|
2005-05-05 12:40:47 +02:00
|
|
|
|
2005-10-03 19:20:22 +02:00
|
|
|
#undef SH_MAKE_EXECUTABLECLASS_OB
|
2007-10-08 00:45:22 +02:00
|
|
|
#undef SH_MAKE_EXECUTABLECLASS_OB_void
|
2005-04-14 14:54:13 +02:00
|
|
|
|
2005-12-23 12:58:11 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2005-12-24 00:00:55 +01:00
|
|
|
// SetOverrideRet and RecallGetIface for recalls
|
2005-12-23 12:58:11 +01:00
|
|
|
// These take a ISourceHook pointer instead of using SH_GLOB_SHPTR directly
|
|
|
|
// The reason is that the user may want to redefine SH_GLOB_SHPTR - then the macros
|
|
|
|
// (META_RETURN_VALUE_NEWPARAMS) should obey the new pointer.
|
|
|
|
|
|
|
|
namespace SourceHook
|
|
|
|
{
|
2006-06-08 20:34:18 +02:00
|
|
|
template <class RetType>
|
|
|
|
void SetOverrideResult(ISourceHook *shptr, const RetType res)
|
|
|
|
{
|
|
|
|
*reinterpret_cast<RetType*>(shptr->GetOverrideRetPtr()) = res;
|
|
|
|
}
|
|
|
|
|
2006-08-09 08:46:11 +02:00
|
|
|
// SetOverrideResult used to be implemented like this:
|
|
|
|
// SetOverrideResult(shptr, memfuncptr, return);
|
|
|
|
// normally the compiler can deduce the return type from memfuncptr, but (at least msvc8) failed when it was a reference
|
|
|
|
// (it thought it was ambigous - the ref and non-ref type)
|
|
|
|
// so now SetOverrideResult(memfuncptr) deduces the ret type, and returns a functor which does the work
|
|
|
|
// new syntax: SetOverrideResult(memfuncptr)(shptr, return)
|
|
|
|
// This also allows us to create a special version for references which respects ReferenceCarrier.
|
|
|
|
|
|
|
|
template <class T> struct OverrideFunctor
|
|
|
|
{
|
|
|
|
void operator()(ISourceHook *shptr, T res)
|
|
|
|
{
|
|
|
|
*reinterpret_cast<T*>(shptr->GetOverrideRetPtr()) = res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template <class T> struct OverrideFunctor<T&>
|
|
|
|
{
|
|
|
|
void operator()(ISourceHook *shptr, T &res)
|
|
|
|
{
|
|
|
|
// overrideretptr points to ReferenceCarrier<T&>
|
2006-08-09 09:25:48 +02:00
|
|
|
*reinterpret_cast<typename ReferenceCarrier<T&>::type *>(shptr->GetOverrideRetPtr()) = res;
|
2006-08-09 08:46:11 +02:00
|
|
|
}
|
|
|
|
};
|
2006-05-13 19:57:35 +02:00
|
|
|
@[$1,0,$a:
|
|
|
|
template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
|
2006-08-09 08:46:11 +02:00
|
|
|
OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(@[$2,1,$1|, :Param$2@]))
|
2005-12-23 12:58:11 +01:00
|
|
|
{
|
2006-08-09 08:46:11 +02:00
|
|
|
return OverrideFunctor<RetType>();
|
2005-12-23 12:58:11 +01:00
|
|
|
}
|
2005-12-24 00:00:55 +01:00
|
|
|
|
2006-05-13 19:57:35 +02:00
|
|
|
template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
|
|
|
|
Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(@[$2,1,$1|, :Param$2@]))
|
2005-12-24 00:00:55 +01:00
|
|
|
{
|
|
|
|
return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
|
|
|
|
}
|
2006-05-13 19:57:35 +02:00
|
|
|
@]
|
2005-12-23 12:58:11 +01:00
|
|
|
}
|
|
|
|
|
2005-04-14 14:54:13 +02:00
|
|
|
#endif
|
2005-05-01 14:36:48 +02:00
|
|
|
// The pope is dead. -> :(
|