Raised This Month: $51 Target: $400
 12% 

Detour macros for static functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 08-31-2014 , 11:30   Detour macros for static functions
Reply With Quote #1

CEntity.cpp

PHP Code:
DECLARE_DETOUR(SetAbsOriginCEntity);
DECLARE_DEFAULTHANDLER_DETOUR_void(CEntitySetAbsOrigin, (const VectorabsOrigin), (absOrigin)); 
CEntity.h
PHP Code:
void SetAbsOrigin(const VectorabsOrigin);
DECLARE_DEFAULTHEADER_DETOUR(SetAbsOriginvoid, (const VectorabsOrigin)); 
-----------------------------------------------------------------------------------------------
DECLARE_DETOUR:
PHP Code:
#define DECLARE_DETOUR(name, cl) \
class name##cl##DetourTracker : public IDetourTracker \
{ \
public: \
    
void AddHook() \
    { \
        
void *callback = (void *)GetCodeAddress(&cl::Internal##name); \
        
void **trampoline = (void **)(&cl::name##_Actual); \
        
m_Detour CDetourManager::CreateDetour(callbacktrampoline#name); \
        
if (m_Detour) \
        { \
            
m_Detour->EnableDetour(); \
        } \
    } \
    
void RemoveHook() \
    { \
        if (
m_Detour) \
        { \
            
m_Detour->Destroy(); \
            
m_Detour NULL; \
        } \
    } \
}; \
name##cl##DetourTracker name##cl##DetourTrackerObj; 
DECLARE_DEFAULTHANDLER_DETOUR_void:
PHP Code:
#define DECLARE_DEFAULTHANDLER_DETOUR_void(type, name, params, paramscall) \
void type::name params \
{ \
    (((
type *)BaseEntity())->*name##_Actual) paramscall; \
} \
void type::Internal##name params \
{ \
    
type *pEnt = (type *)CEntity::Instance((CBaseEntity *)this); \
    if (
pEnt) \
        
pEnt->name paramscall; \
    else \
        
DETOUR_MEMBER_CALL(nameparamscall; \
} \
void (type::* type::name##_Actual) params = NULL; \ 
DECLARE_DEFAULTHEADER_DETOUR:
PHP Code:
#define DECLARE_DEFAULTHEADER_DETOUR(name, ret, params) \
    
ret Internal##name params; \
    
static ret (ThisClass::* name##_Actual) params; 
I'm looking for implementation of this macroses for static functions, like:
PHP Code:
static int PrecacheModel( const char *name ); 

Last edited by kadet.89; 09-01-2014 at 11:33.
kadet.89 is offline
Send a message via Skype™ to kadet.89
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode