View Single Post
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 03-27-2020 , 18:37   Re: Call a function by the pointer from FunctionTable
Reply With Quote #2

Here is my solution:

PHP Code:
#define EXTRACT_VOID_FUNCTIONPTR(x)        (*(void **)(&(x)))

void *UTIL_FunctionFromNamedatamap_t *pMap, const char *pName )
{
    while ( 
pMap )
    {
        for ( 
int i 0pMap->dataNumFieldsi++ )
        {
            
Assertsizeof(pMap->dataDesc[i].inputFunc) == sizeof(void *) );

            if ( 
pMap->dataDesc[i].flags FTYPEDESC_FUNCTIONTABLE )
            {
                if ( 
FStrEqpNamepMap->dataDesc[i].fieldName ) )
                {
                    return 
EXTRACT_VOID_FUNCTIONPTR(pMap->dataDesc[i].inputFunc);
                }
            }
        }
        
pMap pMap->baseMap;
    }

    
Msg"Failed to find function %s\n"pName );

    return 
NULL;
}

typedef void (CBaseEntity::*VALVE_BASEPTR)(void);
typedef void (CBaseEntity::*VALVE_ENTITYFUNCPTR)(CBaseEntity *pOther);

VALVE_BASEPTR CBaseGrenade::func_Detonate nullptr;
VALVE_ENTITYFUNCPTR CBaseGrenade::func_ExplodeTouch nullptr;

void CBaseGrenade::detonate()
{
    if(
func_Detonate != nullptr)
        return;

    
void *ptr UTIL_FunctionFromNameGetDataDescMap_Real(), "CBaseGrenadeDetonate");
    if(!
ptr)
        return;

    
memcpy(&func_Detonate, &ptrsizeof(void *));
    (
getBaseEntity()->*func_Detonate)(); //getBaseEntity() returns CBaseEntity*

For GetDataDescMap_Real use standard offset from core.games "GetDataDescMap"
It seams to be the only way to detonate grenades without delays and dealing with signatures.

Last edited by kadet.89; 03-27-2020 at 18:40.
kadet.89 is offline
Send a message via Skype™ to kadet.89