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... |
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. |
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.
|
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 :) |
Re: Hooking OnTakeDamage
c0ldfly3: i would love to see the example..
thx |
Re: Hooking OnTakeDamage
This works for CS:S.
Code:
int ZombiePlugin::OnTakeDamage( const CTakeDamageInfo &info ) |
Re: Hooking OnTakeDamage
well i figured it out, thx to LDuke here is what i used
Code:
edict_t *Attacker= serverents->BaseEntityToEdict(info.GetAttacker()); |
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()
|
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.
|
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.