Raised This Month: $248 Target: $400
 62% 

Solved Hook m_pfnThink


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kadet.89
Veteran Member
Join Date: Nov 2012
Old 03-28-2020 , 14:10   Hook m_pfnThink
Reply With Quote #1

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?

Last edited by kadet.89; 04-01-2020 at 17:16. Reason: Solved, found a solution in CEntity from CSS NPC extension
kadet.89 is offline
Send a message via Skype™ to kadet.89
Reply


Thread Tools
Display Modes

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 14:25.


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