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

Hooking OnTakeDamage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ardiem
New Member
Join Date: Nov 2007
Old 11-04-2007 , 20:19   Hooking OnTakeDamage
Reply With Quote #1

For a MM plugin, I'm trying to hook into OnTakeDamage(CTakeDamageInfo). CTakeDamageInfo is defined in hl2sdk-ob/game_shared/takedamageinfo.h, which isn't in any of the paths included in the default Makefile in the MM SDK. Is hooking into OnTakeDamage a no-no or is there an obvious fix here i'm missing?

I'm trying to hook OnTakeDamage as opposed to the player_hurt event due to the extra information available in CTakeDamageInfo before it's "summarized" as a player_hurt event, as well as for being able to apply the solution to this problem towards other hooks (if needed).

Are there any other pitfalls I should be aware of?

Thanks in advance...
ardiem is offline
BAILOPAN
Join Date: Jan 2004
Old 11-04-2007 , 23:47   Re: Hooking OnTakeDamage
Reply With Quote #2

Well, hooking anything not in public generally means it's mod specific. Thus, CTakeDamageInfo can be changed by a mod, and the header may not match. Since the Orange Box SDK is not fully released, that takedamage info structure might be out of date as well.

That said, you can simply include the file and try it. If it doesn't work, you may have to reverse engineer why and modify the file locally such that it's compatible.

For example, SourceMod does tricks with AcceptEntityInput, which takes in a private structure called variant_t. We know that it may change based on the SDK/mod version, so we make member offsets configurable and don't use the structure as the compiler sees it. But if you only need to work against one mod, you can hardcode structure changes as you see fit.
__________________
egg
BAILOPAN is offline
ardiem
New Member
Join Date: Nov 2007
Old 11-05-2007 , 00:04   Re: Hooking OnTakeDamage
Reply With Quote #3

Thanks for the reply. I was planning on just brute forcing it as you suggested, but I'm glad to hear from you that I'm not missing out on a more elegant solution.
ardiem is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-05-2008 , 08:37   Re: Hooking OnTakeDamage
Reply With Quote #4

Hey,

Sorry to bump an old thread but I hook this without problems, I also get the Attacker from the type passed in, if you want an example I can go dig one out
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
Fredd
Veteran Member
Join Date: Jul 2007
Old 04-08-2008 , 21:25   Re: Hooking OnTakeDamage
Reply With Quote #5

c0ldfly3: i would love to see the example..
thx
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!
Fredd is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 04-15-2008 , 20:21   Re: Hooking OnTakeDamage
Reply With Quote #6

This works for CS:S.
Code:
int ZombiePlugin::OnTakeDamage( const CTakeDamageInfo &info )
{
	CBasePlayer *pVictim =  META_IFACEPTR( CBasePlayer );
	edict_t *pEdict = m_GameEnts->BaseEntityToEdict( pVictim );
	if ( pVictim && pEdict && !pEdict->IsFree() )
	{
		int nIndex = m_Engine->IndexOfEdict( pEdict );
		int AIndex = info.m_hAttacker.GetEntryIndex();

		if ( AIndex > 0 && AIndex <= MAX_CLIENTS ) 
		{
			pAEdict = m_Engine->PEntityOfEntIndex( AIndex  );
		}
	}
}
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
Fredd
Veteran Member
Join Date: Jul 2007
Old 04-15-2008 , 21:28   Re: Hooking OnTakeDamage
Reply With Quote #7

well i figured it out, thx to LDuke here is what i used
Code:
edict_t *Attacker=  serverents->BaseEntityToEdict(info.GetAttacker());
then using "IndexOfEdict" to get me the index..the problem is that "info.m_hAttacker" wont work unless if you change the sdk files..
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!
Fredd is offline
BAILOPAN
Join Date: Jan 2004
Old 04-15-2008 , 21:31   Re: Hooking OnTakeDamage
Reply With Quote #8

You can use GetEntryIndex() and GetEntrySerial() to decide whether the handle points to a valid entity. See the source code for SourceMod's GetEntDataEnt2()
__________________
egg
BAILOPAN is offline
Fredd
Veteran Member
Join Date: Jul 2007
Old 04-15-2008 , 22:07   Re: Hooking OnTakeDamage
Reply With Quote #9

aight, its just that in order for "info.m_hAttacker" to work i would need to get to the CTakeDamageInfo.h and change the m_hAttacker to public, thats why i used GetAttack() but ill defiantly use GetEntryIndex() to see if its a valid entity.
__________________
Need a private coder? AMXX, SourceMOD, MMS? PM me!
Fredd is offline
BAILOPAN
Join Date: Jan 2004
Old 04-16-2008 , 13:11   Re: Hooking OnTakeDamage
Reply With Quote #10

GetEntryIndex() tells you the index, you need the serial number to verify that it's still valid.
__________________
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 05:59.


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