View Single Post
Author Message
talkingmelon
Junior Member
Join Date: Dec 2014
Old 07-26-2015 , 14:12   Hooking CBasePlayer::PlayerRunCommand in TF2
Reply With Quote #1

I've been trying to hook this function for a while now. I've gotten to the point where it will work once but the game will crash with RETURN_META_MNEWPARAMS. I've since changed to a method that uses CBasePlayer because I'm going to have to eventually (I think). Anyways, here is the code that I'm working with at the moment:

Code:
#define CLIENT_DLL
//#define TF_CLIENT_DLL
//#define GAME_DLL
//#define TF_DLL

#include "cbase.h"
#include "player.h"

//#include "c_baseplayer.h"
//#include "player.h"
//#include "c_sdk_player.h"

#include <stdio.h>
#include "stub_mm.h"
#include "usercmd.h"
#include <in_buttons.h>

#include "tier0\memdbgon.h"

int offset = 417;

SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, char const *);
SH_DECL_MANUALHOOK2_void(MHook_PlayerRunCommand, 0, 0, 0, CUserCmd *, IMoveHelper *);

void StartHooks(){
	SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientPutInServer, svrGameClients, Hook_ClientPutInServer, true);
	SH_MANUALHOOK_RECONFIGURE(MHook_PlayerRunCommand, offset, 0, 0);
}

void Hook_ClientPutInServer(edict_t *pEntity, char const *playername){


	CBasePlayer *pEnt = dynamic_cast<CBasePlayer *>(CBaseEntity::Instance(pEntity));


//By uncommenting this line and commenting the one above as well as #include player.h I've gotten the hook to work once but crash at RETURN_META_MNEWPARAMS
	//CBaseEntity *pEnt = pEntity->GetUnknown()->GetBaseEntity();

	if(pEnt){

		SH_ADD_MANUALDVPHOOK(MHook_PlayerRunCommand, pEnt, Hook_PlayerRunCommand, false);

	}
	
}

void Hook_PlayerRunCommand(CUserCmd *ucmd, IMoveHelper *moveHelper){
	Msg("Hooked Client Cmd\n");
	Msg("H %i %i %f %f %f %f %i\n", ucmd->command_number, ucmd->tick_count, ucmd->viewangles.x, ucmd->viewangles.y, ucmd->viewangles.z, ucmd->forwardmove, ucmd->buttons);

	//RETURN_META_MNEWPARAMS(MRES_IGNORED, MHook_PlayerRunCommand, (ucmd, moveHelper));
	RETURN_META(MRES_IGNORED);

}
Now, the problem I've been running into is with CBasePlayer. Before, I use to have this line commented out:
Code:
CBasePlayer *pEnt = dynamic_cast<CBasePlayer *>(CBaseEntity::Instance(pEntity));
commented out and didn't use CBasePlayer at all. When I did that, it would do the hook once and then crash the game with a memory access error. Since Ive started trying to use CBasePlayer to do it instead I get a whole slew of errors when I try to compile:

Code:
1>d:\Programs\Visual C++\VC\include\stddef.h(60): warning C4005: 'offsetof' : macro redefinition
1>          D:\Programming\Source\hl2sdk\public\tier0/platform.h(293) : see previous definition of 'offsetof'
1>D:\Programming\Source\hl2sdk\game\client\cdll_client_int.h(61): error C2371: 'engine' : redefinition; different basic types
1>          d:\programming\source\hl2sdk\game\server\enginecallback.h(36) : see declaration of 'engine'
1>D:\Programming\Source\hl2sdk\game\client\cdll_client_int.h(71): error C2371: 'modelinfo' : redefinition; different basic types
1>          d:\programming\source\hl2sdk\game\server\enginecallback.h(43) : see declaration of 'modelinfo'
1>D:\Programming\Source\hl2sdk\game\client\cdll_client_int.h(76): error C2371: 'staticpropmgr' : redefinition; different basic types
1>          d:\programming\source\hl2sdk\game\server\enginecallback.h(39) : see declaration of 'staticpropmgr'
1>d:\programming\source\hl2sdk\game\server\util.h(171): error C2371: 'gpGlobals' : redefinition; different basic types
1>          D:\Programming\Source\hl2sdk\game\client\cdll_client_int.h(86) : see declaration of 'gpGlobals'
1>D:\Programming\Source\hl2sdk\game\shared\predictable_entity.h(160): warning C4005: 'LINK_ENTITY_TO_CLASS' : macro redefinition
1>          d:\programming\source\hl2sdk\game\server\util.h(138) : see previous definition of 'LINK_ENTITY_TO_CLASS'
1>d:\programming\source\hl2sdk\game\client\particle_util.h(428): error C2039: 'GetLightForPoint' : is not a member of 'IVEngineServer'
1>          D:\Programming\Source\hl2sdk\public\eiface.h(111) : see declaration of 'IVEngineServer'
1>d:\programming\source\hl2sdk\game\server\entitylist.h(211): error C2440: 'return' : cannot convert from 'CBaseEntity *' to 'C_BaseEntity *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>d:\programming\source\hl2sdk\game\server\ServerNetworkProperty.h(128): error C2555: 'CServerNetworkProperty::GetBaseEntity': overriding virtual function return type differs and is not covariant from 'IServerNetworkable::GetBaseEntity'
1>          d:\programming\source\hl2sdk\public\iservernetworkable.h(105) : see declaration of 'IServerNetworkable::GetBaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(321): error C2011: 'thinkfunc_t' : 'struct' type redefinition
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(152) : see declaration of 'thinkfunc_t'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(334): warning C4005: 'CREATE_PREDICTED_ENTITY' : macro redefinition
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(160) : see previous definition of 'CREATE_PREDICTED_ENTITY'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(339): error C2011: 'C_BaseEntity' : 'class' type redefinition
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1752): warning C4005: 'SetTouch' : macro redefinition
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(1649) : see previous definition of 'SetTouch'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1763): error C2440: 'return' : cannot convert from 'CBaseEntity *' to 'C_BaseEntity *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1774): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1776): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1776): error C2065: 'm_bDebugPause' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1783): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1785): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1785): error C2065: 'm_bDebugPause' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1794): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1796): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1796): error C2065: 'm_nDebugSteps' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1798): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1798): error C2065: 'm_nDebugSteps' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1800): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1800): error C2065: 'm_nDebugSteps' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1809): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1811): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1811): error C2065: 'm_nDebugSteps' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1818): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1820): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1820): error C2065: 'm_bDebugPause' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1820): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1820): error C2065: 'm_nDebugSteps' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1826): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1828): error C2065: 'm_hMoveParent' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1828): error C2228: left of '.Get' must have class/struct/union
1>          type is ''unknown-type''
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1831): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1833): error C2065: 'm_hMoveChild' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1833): error C2228: left of '.Get' must have class/struct/union
1>          type is ''unknown-type''
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1836): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1838): error C2065: 'm_hMovePeer' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1838): error C2228: left of '.Get' must have class/struct/union
1>          type is ''unknown-type''
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1842): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1844): error C2065: 'm_pParent' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1844): error C2228: left of '.Get' must have class/struct/union
1>          type is ''unknown-type''
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1847): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1849): error C2065: 'm_iParentAttachment' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1855): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1857): error C2065: 'm_iName' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1860): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1862): error C2065: 'm_iName' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1866): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1868): error C2065: 'm_iName' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1870): error C3861: 'NameMatchesComplex': identifier not found
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1873): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1875): error C2065: 'm_iName' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1877): error C3861: 'NameMatchesComplex': identifier not found
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1880): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1882): error C2065: 'm_iClassname' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1884): error C3861: 'ClassMatchesComplex': identifier not found
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1887): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1889): error C2065: 'm_iClassname' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1889): error C2228: left of '.ToCStr' must have class/struct/union
1>          type is ''unknown-type''
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1893): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1895): error C2065: 'm_iClassname' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1897): error C3861: 'ClassMatchesComplex': identifier not found
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1900): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1901): error C2270: 'GetSpawnFlags' : modifiers not allowed on nonmember functions
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1902): error C2065: 'm_spawnflags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1905): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1907): error C2065: 'm_spawnflags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1909): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1911): error C2065: 'm_spawnflags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1914): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1916): error C2065: 'm_spawnflags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1919): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1920): error C2270: 'HasSpawnFlags' : modifiers not allowed on nonmember functions
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1921): error C2065: 'm_spawnflags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1927): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1929): error C2065: 'm_iEFlags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1935): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1936): error C2270: 'GetEFlags' : modifiers not allowed on nonmember functions
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1937): error C2065: 'm_iEFlags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1940): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1942): error C2065: 'm_iEFlags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1946): error C3861: 'DispatchUpdateTransmitState': identifier not found
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1950): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1952): error C2065: 'm_iEFlags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1956): error C3861: 'DispatchUpdateTransmitState': identifier not found
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1960): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1962): error C2065: 'm_iEFlags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1965): error C3861: 'DispatchUpdateTransmitState': identifier not found
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1968): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1969): error C2270: 'IsEFlagSet' : modifiers not allowed on nonmember functions
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1970): error C2065: 'm_iEFlags' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1973): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1976): error C2065: 'm_flNavIgnoreUntilTime' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1977): error C2065: 'm_flNavIgnoreUntilTime' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1980): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1982): error C2065: 'm_flNavIgnoreUntilTime' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1985): error C2027: use of undefined type 'C_BaseEntity'
1>          D:\Programming\Source\hl2sdk\game\client\c_baseentity.h(173) : see declaration of 'C_BaseEntity'
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1986): error C2270: 'IsNavIgnored' : modifiers not allowed on nonmember functions
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1987): error C2065: 'm_flNavIgnoreUntilTime' : undeclared identifier
1>d:\programming\source\hl2sdk\game\server\baseentity.h(1987): fatal error C1003: error count exceeds 100; stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I would appreciate any help even if it involves scrapping anything or everything I've done, I'm kinda new to this.

Thanks!

Last edited by talkingmelon; 07-26-2015 at 16:36.
talkingmelon is offline