AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   Hooking OnTakeDamage (https://forums.alliedmods.net/showthread.php?t=62785)

ardiem 11-04-2007 20:19

Hooking OnTakeDamage
 
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...

BAILOPAN 11-04-2007 23:47

Re: Hooking OnTakeDamage
 
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.

ardiem 11-05-2007 00:04

Re: Hooking OnTakeDamage
 
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.

c0ldfyr3 04-05-2008 08:37

Re: Hooking OnTakeDamage
 
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 :)

Fredd 04-08-2008 21:25

Re: Hooking OnTakeDamage
 
c0ldfly3: i would love to see the example..
thx

c0ldfyr3 04-15-2008 20:21

Re: Hooking OnTakeDamage
 
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  );
                }
        }
}


Fredd 04-15-2008 21:28

Re: Hooking OnTakeDamage
 
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..

BAILOPAN 04-15-2008 21:31

Re: Hooking OnTakeDamage
 
You can use GetEntryIndex() and GetEntrySerial() to decide whether the handle points to a valid entity. See the source code for SourceMod's GetEntDataEnt2()

Fredd 04-15-2008 22:07

Re: Hooking OnTakeDamage
 
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.

BAILOPAN 04-16-2008 13:11

Re: Hooking OnTakeDamage
 
GetEntryIndex() tells you the index, you need the serial number to verify that it's still valid.


All times are GMT -4. The time now is 19:07.

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