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

Hooking functions in CBasePlayer


Post New Thread Reply   
 
Thread Tools Display Modes
TommyV
Member
Join Date: Nov 2005
Old 04-06-2006 , 02:45  
Reply With Quote #11

Quote:
Originally Posted by L. Duke
Not sure, but ClientConnect() may be too early. I record the client info on "player_connect" event and then wait to hook them until they have spawned in game and are alive (i.e. I don't hook them in spectator mode, I wait until they join a team and spawn.)

Looks like showdax is using ClientActive() succesfully, so maybe I should have tried that.

EDIT: Read BAILOPAN's post (about the third one down) in this thread.
Well that explains my error, it worked when I moved it to ClientPutInServer, even without the manual hooks.

Thanks for all the help.
TommyV is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-06-2006 , 03:04  
Reply With Quote #12

Code:
SH_DECL_HOOK1_void(CBasePlayer, Touch, SH_NOATTRIB, 0, CBaseEntity *); 

SH_ADD_HOOK_MEMFUNC(CBasePlayer, Touch, pPlayer, &g_TouchCatcher, &TouchCatcher::Touch_handler, false);
You can't use it like that, you have to use manual hooking.
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
TommyV
Member
Join Date: Nov 2005
Old 04-06-2006 , 11:02  
Reply With Quote #13

Quote:
Originally Posted by c0ldfyr3
You can't use it like that, you have to use manual hooking.
Why? It says you can in the SourceMM docs, and it works.
TommyV is offline
showdax
Senior Member
Join Date: Dec 2004
Old 04-06-2006 , 12:13  
Reply With Quote #14

Quote:
Originally Posted by TommyV
Quote:
Originally Posted by c0ldfyr3
You can't use it like that, you have to use manual hooking.
Why? It says you can in the SourceMM docs, and it works.
You shouldn't try to hook something that you don't have valid header for, in that fashion. The player.h in the SDK differs from what's used in CS:S, DoD:S, et cetera, so the offsets derived from the class definition could be wrong.
showdax is offline
Send a message via MSN to showdax
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-06-2006 , 14:07  
Reply With Quote #15

Quote:
Originally Posted by TommyV
Quote:
Originally Posted by c0ldfyr3
You can't use it like that, you have to use manual hooking.
Why? It says you can in the SourceMM docs, and it works.
Yes, the docs are older than the headers.
If you had been reading what we said earlier, they physically MOVED the functions around in the .h file.

So, when you hook Touch, it might work on YOUR windows machine, but try testing it on linux or even another windows machine and watch crash city from the front row.

The functions around Touch are as follows..
Code:
_ZNK11CBaseEntity8GetEnemyEv
_ZN11CBaseEntity3UseEPS_S0_8USE_TYPEf
_ZN11CBaseEntity10StartTouchEPS_
_ZN11CBasePlayer5TouchEP11CBaseEntity
_ZN11CBaseEntity8EndTouchEPS_
_ZN11CBaseEntity12StartBlockedEPS_
_ZN11CBaseEntity7BlockedEPS_
_ZN11CBaseEntity10EndBlockedEv
So, when you hook Touch, you could be hooking any one of the above, depending on where they moved each function from.
If you are hooking StartTouch but think you are hooking Touch, of course its going to fire everytime Touch does, but with a param of god only knows what.

Do yourself a favour and avoid the headaches, and start your project using manual hooks.
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
TommyV
Member
Join Date: Nov 2005
Old 04-06-2006 , 15:13  
Reply With Quote #16

Ok, I'll use manual hooks.

I'm only asking because it is very difficult to know what's what if you haven't been involved with plugins much and had to deal with fixing them when hl2 is updated. How do I know what is a valid header, why is it is ok to hook IServerGameDLL functions but not CBasePlayer functions? I guess the answer is you just have to know.

I was hoping that using sourcemm would bring some elegance and certainty to function hooking which is something I'm not experienced or comfortable with, but if valve are going to make sure the sdk doesn't match the real code then I guess there's nothing anyone can do about it

I'll stick to manual hooks and hope that someone is always good enough to update the offset lists for any classes I use because I wouldn't know where to start trying to get vtable offsets.
TommyV is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-06-2006 , 17:32  
Reply With Quote #17

There are enough of us that know how to get the vtable to post it if it changes.

As for questions #1, well, IServerGameDLL isnt a hacked include. Its a valid interface which Valve provided for your usage. CBaseEntity is not.
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
BAILOPAN
Join Date: Jan 2004
Old 04-06-2006 , 19:07  
Reply With Quote #18

Quote:
Originally Posted by TommyV
I was hoping that using sourcemm would bring some elegance and certainty to function hooking which is something I'm not experienced or comfortable with
For interfaces you definitively know about, it does. Unfortunately some of more savory stuff in the HL2SDK is mod specific and you have no choice but to get into disassembling/reverse engineering.

Making virtual function hooking "easy" is only one goal of SourceHook. The other goal, of course, is to make it flexible and not crash ;) (i.e. letting many plugins hook the same thing cleanly).
__________________
egg
BAILOPAN 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 23:53.


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