Raised This Month: $32 Target: $400
 8% 

Solved Virtual hooks, bypass only current hook


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 03-10-2020 , 10:37   Virtual hooks, bypass only current hook
Reply With Quote #1

I hook a custom virtual function in two extensions:
CBaseEntity* CreateEntityByName(const char * className);

So that control is passed to B function of extension B, then to A from extension A then back to the original CreateEntityByName. It works fine if I use RETURN_META_VALUE_MNEWPARAMS in both A and B. I get this sequence:

O -> B -> A -> CreateEntityByName -> back to O

But I need to know the result CBaseEntity pointer in both A and B. So I replace the RETURN_META_VALUE_MNEWPARAMS with:

SH_CALL and RETURN_META_VALUE(MRES_SUPERCEDE , false);

The problem here is that SH_CALL bypasses both hooks and the original CreateEntityByName is called twice, so 2 entities are created. I get this sequence:

O -> B, SH_CALL-> CreateEntityByName -> back to B -> A, SH_CALL-> CreateEntityByName -> back to A -> back to O

Is there a way to bypass only current hook to get correct sequence?

O -> B, SH_CALL-> A, SH_CALL-> CreateEntityByName -> back to A -> back to B -> back to O

Last edited by kadet.89; 03-11-2020 at 16:57.
kadet.89 is offline
Send a message via Skype™ to kadet.89
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-10-2020 , 16:12   Re: Virtual hooks, bypass only current hook
Reply With Quote #2

You should split your hooks into separate pre and post hooks rather than using SH_CALL.
__________________
asherkin is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 03-11-2020 , 16:29   Re: Virtual hooks, bypass only current hook
Reply With Quote #3

That could be a way, how can I get the result CBaseEntity pointer in the posthook ?
kadet.89 is offline
Send a message via Skype™ to kadet.89
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-11-2020 , 16:37   Re: Virtual hooks, bypass only current hook
Reply With Quote #4

Code:
META_RESULT_ORIG_RET
(the dumb anti-shouting feature won't let me post that as all caps without writing more text.)
__________________

Last edited by asherkin; 03-11-2020 at 16:38.
asherkin is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 03-11-2020 , 16:54   Re: Virtual hooks, bypass only current hook
Reply With Quote #5

Thanks, it works.

Code:
CBaseEntity* pEntity = META_RESULT_ORIG_RET(CBaseEntity*);
I have to keep a variable to pass some data from pre to post hook, but anyway it's much better than checking and processing double calls inside the original function.

Last edited by kadet.89; 03-11-2020 at 16:57.
kadet.89 is offline
Send a message via Skype™ to kadet.89
Reply


Thread Tools
Display Modes

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 07:01.


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