AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   Solved Hook m_pfnThink (https://forums.alliedmods.net/showthread.php?t=322501)

kadet.89 03-28-2020 14:10

Hook m_pfnThink
 
I need to hook think function of "dronegun" entity. Inside it's just a prop_phusics with some extra stuff.

PHP Code:

typedef void (CBaseEntity::*VALVE_BASEPTR)(void);
VALVE_BASEPTR srcThinkFunc_;

void CDroneGun::onSpawnPost(void)
{
    
srcThinkFunc_ m_pfnThink// m_pfnThink is from CBaseEntity datamap
    
*(m_pfnThink) = reinterpret_cast<VALVE_BASEPTR>(&CDroneGun::Think);
}

void CDroneGun::Think()
{
    
LogMessage("CDroneGun::Think");
    if(
srcThinkFunc_)
        (
getBaseEntity()->*srcThinkFunc_)(); // call the original Think function

    
if(*(m_pfnThink) != reinterpret_cast<VALVE_BASEPTR>(&CDroneGun::Think)) //If the Think function has changed, set up a new "hook"
    
{
        
srcThinkFunc_ m_pfnThink;

        *(
m_pfnThink) = reinterpret_cast<VALVE_BASEPTR>(&CDroneGun::Think);
    }


The drone moves and attacks, but "CDroneGun::Think" is never shown, what am I doing wrong?


All times are GMT -4. The time now is 14:00.

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