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

PlayerRunCmd Hook


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 01-10-2015 , 14:46   PlayerRunCmd Hook
Reply With Quote #1

I'm trying to hook PlayerRunCmd. I use this example as a base for my plugin:
extensions\sdktools\hooks.cpp

here is my code:
PHP Code:
    SH_ADD_MANUALHOOK_MEMFUNC(PlayerRunCmdHookservertools->GetBaseEntityByEntIndex(1), &g_hook, &Hook::PlayerRunCmd,  false);
}
void Hook::PlayerRunCmd(CUserCmd *ucmdIMoveHelper *moveHelper)
{
    
g_pSM->LogMessage(myself"H %i %i %f %f %f %f %i"ucmd->command_numberucmd->tick_countucmd->viewangles.xucmd->viewangles.yucmd->viewangles.zucmd->forwardmoveucmd->buttons);
    
RETURN_META(MRES_IGNORED);

Code:
L 01/10/2015 - 22:37:38: [HOOKS] H 534801936 103623936 0.000000 0.000000 0.015059 0.007772 537626765
This function only fires when the player does something. And all the values never change, they are all always incorrect.
kadet.89 is offline
Send a message via Skype™ to kadet.89
rcbotCheeseh
Junior Member
Join Date: May 2013
Old 02-15-2015 , 05:36   Re: PlayerRunCmd Hook
Reply With Quote #2

since I'm not really an expert on Sourcemod but I've hooked this function manually without needed sourcemod, I can noticed that you are trying to hook a claass function.

In the sourcemod docuemtnation there is an example to hook a class function like this:
Code:
SH_DECL_MANUALHOOK1_void(MHook_TakeDamage, 0, 0, 0, int);   

extern void *player_vtable; int takedamage_hook = 0;   

void StartHooks() 
{    
takedamage_hook = SH_ADD_MANUALDVPHOOK(MHook_TakeDamage, player_vtable, SH_STATIC(Hook_TakeDamage), false); 
}  

 void StopHooks() 
{    
if (takedamage_hook)    
{       
SH_REMOVE_HOOK_ID(takedamage_hook);   
 } 
}


void Hook_TakeDamage(int damage)
{
//...
}

changing this to player run cmd

Code:
SH_DECL_MANUALHOOK1_void(MHook_PlayerRunCmd, 0, 0, 0, CUserCmd*, IMoveHelper*);   

extern void *player_vtable; 

int playerruncmd_hook = 0;   

void StartHooks() 
{    
playerruncmd_hook = SH_ADD_MANUALDVPHOOK(MHook_PlayerRunCmd, player_vtable, SH_STATIC(Hook_PlayerRunCmd), false); 
}  

void StopHooks() 
{    
if (playerruncmd_hook)    
{
SH_REMOVE_HOOK_ID(playerruncmd_hook);   
 } 
}


void Hook_PlayerRunCmd(CUserCmd *ucmd, IMoveHelper *moveHelper)
{

Player *pPlayer = META_IFACEPTR(Player);

g_pSM->LogMessage(myself, "H %i %i %f %f %f %f %i", ucmd->command_number, ucmd->tick_count, ucmd->viewangles.x, ucmd->viewangles.y, ucmd->viewangles.z, ucmd->forwardmove, ucmd->buttons); 

RETURN_META(MRES_IGNORED); 
}


__________________
rcbotCheeseh is offline
rcbotCheeseh
Junior Member
Join Date: May 2013
Old 03-02-2015 , 06:00   Re: PlayerRunCmd Hook
Reply With Quote #3

I had a look as I want to try this myself and this seems to work

Code:
// global scope
SH_DECL_MANUALHOOK2_void(MHook_PlayerRunCmd, 0, 0, 0, CUserCmd*, IMoveHelper*); 

void setupHooks()
{
int offset = readOffset("CBasePlayer::RunPlayerCmd"); // this should be your own way of reading the offset value

SH_MANUALHOOK_RECONFIGURE(MHook_PlayerRunCmd,offset,0,0);
}

void CPlugin::Hook_ClientPutInServer(edict_t *pEntity, char const *playername)
{
    CBaseEntity *pEnt = servergameents->EdictToBaseEntity(pEntity);

    if ( pEnt )
    {
        SH_ADD_MANUALHOOK_MEMFUNC(MHook_PlayerRunCmd, pEnt, this, &CPlugin::Hook_PlayerRunCmd, false);
    }
}

void CPlugin::Hook_ClientDisconnect(edict_t *pEntity)
{
    CBaseEntity *pEnt = servergameents->EdictToBaseEntity(pEntity);

    if ( pEnt )
    {
        SH_REMOVE_MANUALHOOK_MEMFUNC(MHook_PlayerRunCmd, pEnt, this, &CPlugin::Hook_PlayerRunCmd, false); 
    }
    META_LOG(g_PLAPI, "Hook_ClientDisconnect(%d)", IndexOfEdict(pEntity));
}


void CPlugin::Hook_PlayerRunCmd(CUserCmd *ucmd, IMoveHelper *moveHelper)
{
    CBaseEntity *pPlayer = META_IFACEPTR(CBaseEntity);

   g_pSM->LogMessage(NULL, "H %i %i %f %f %f %f %i", ucmd->command_number, ucmd->tick_count, ucmd->viewangles.x, ucmd->viewangles.y, ucmd->viewangles.z, ucmd->forwardmove, ucmd->buttons); 

RETURN_META(MRES_IGNORED); 
}
the offset can be found at www.sourcemodplugins.org
__________________
rcbotCheeseh is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 03-06-2015 , 13:32   Re: PlayerRunCmd Hook
Reply With Quote #4

I just want to thx you to post the answer even after no respond, those sections are dying and it hard to get into it with little activity in here.

Your a warrior! Warrior Hug for you my friend!
Mathias. is offline
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 00:00.


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