Raised This Month: $13 Target: $400
 3% 

Solved Hooking IServerTools finctions leads to compile-time errors


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kadet.89
Veteran Member
Join Date: Nov 2012
Old 01-04-2020 , 10:20   Hooking IServerTools finctions leads to compile-time errors
Reply With Quote #1

I'm trying to hook SetKeyValue functions from IServerTools:

PHP Code:
    virtual bool SetKeyValueCBaseEntity *pEntity, const char *szField, const char *szValue ) = 0;
    
virtual bool SetKeyValueCBaseEntity *pEntity, const char *szFieldfloat flValue ) = 0;
    
virtual bool SetKeyValueCBaseEntity *pEntity, const char *szField, const Vector &vecValue ) = 0
If I hook only the first one, it goes fine, but for the second and third I get errors:
error: redefinition of '__SourceHook_FHCls_IServerToolsSetKeyValue0'
Though the functions are not the same and have different parameters.
What is the proper way to define them?

Here my corrent definitions:
PHP Code:
SH_DECL_HOOK3(IServerToolsSetKeyValueSH_NOATTRIB0boolvoid *, const char *, const char *  );
SH_DECL_HOOK3(IServerToolsSetKeyValueSH_NOATTRIB0boolvoid *, const char *, float  );
SH_DECL_HOOK3(IServerToolsSetKeyValueSH_NOATTRIB0boolvoid *, const char *, const Vector &  ); 

Last edited by kadet.89; 01-14-2020 at 08:41.
kadet.89 is offline
Send a message via Skype™ to kadet.89
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 01-04-2020 , 16:30   Re: Hooking IServerTools finctions leads to compile-time errors
Reply With Quote #2

As the docs say, you need to use the fourth parameter to the macro for overloads. Make them 0, 1, and 2 (or whatever as long as they're different).

Last edited by Fyren; 01-04-2020 at 16:31.
Fyren is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Old 01-08-2020 , 15:17   Re: Hooking IServerTools finctions leads to compile-time errors
Reply With Quote #3

Thanks, I managed to hook them. I have one last question, how can I bypass the hooks?

That's how I try to do it:
PHP Code:
    void p1 nullptr;
    const 
char *p2 nullptr;
    const 
char p3 nullptr;
    
bool value SH_CALL(servertools, &IServerTools::SetKeyValue)(p1 p2 p3 ); 
And get this error:
Code:
error: no matching function for call to 'SH_CALL2'
        bool value = SH_CALL(servertools, &IServerTools::SetKeyValue)(pEntity, szField, szValue);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:8315:27: note: expanded from macro 'SH_CALL'
#define SH_CALL(ptr, mfp) SH_CALL2((ptr), (mfp), (mfp), SH_GLOB_SHPTR)
                          ^~~~~~~~
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:7386:1: note: candidate template ignored: couldn't infer template argument 'X'
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(), SourceHook::ISourceHook *shptr)
^
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:7394:1: note: candidate template ignored: couldn't infer template argument 'X'
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)()const, SourceHook::ISourceHook *shptr)
^
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:7412:1: note: candidate template ignored: couldn't infer template argument 'X'
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(Param1), SourceHook::ISourceHook *shptr)
^
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:7420:1: note: candidate template ignored: couldn't infer template argument 'X'
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(Param1)const, SourceHook::ISourceHook *shptr)
^
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:7438:1: note: candidate template ignored: couldn't infer template argument 'X'
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(Param1, Param2), SourceHook::ISourceHook *shptr)
^
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:7446:1: note: candidate template ignored: couldn't infer template argument 'X'
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(Param1, Param2)const, SourceHook::ISourceHook *shptr)
^
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:7464:1: note: candidate template ignored: couldn't infer template argument 'X'
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(Param1, Param2, Param3), SourceHook::ISourceHook *shptr)
^
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:7472:1: note: candidate template ignored: couldn't infer template argument 'X'
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(Param1, Param2, Param3)const, SourceHook::ISourceHook *shptr)
^
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:7490:1: note: candidate template ignored: couldn't infer template argument 'X'
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(Param1, Param2, Param3, Param4), SourceHook::ISourceHook *shptr)
^
/home/d/alliedmodders/mmsource-1.10/core/sourcehook/sourcehook.h:7498:1: note: candidate template ignored: couldn't infer template argument 'X'
SH_CALL2(Y *ptr, MFP mfp, RetType(X::*mfp2)(Param1, Param2, Param3, Param4)const, SourceHook::ISourceHook *shptr)

Last edited by kadet.89; 01-08-2020 at 15:23.
kadet.89 is offline
Send a message via Skype™ to kadet.89
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 01-09-2020 , 18:32   Re: Hooking IServerTools finctions leads to compile-time errors
Reply With Quote #4

Off the top of my head, I'm not sure. If the reason it can't infer the template parameters is because the function is an overload, you could try casting the MFP and do something like this:

Code:
SH_CALL(servertools, static_cast<bool (IServerTools::*)(void *, const char *, const char *)>(&IServerTools::SetKeyValue))(p1, p2, p3)
Fyren is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 01-10-2020 , 04:00   Re: Hooking IServerTools finctions leads to compile-time errors
Reply With Quote #5

I agree with what Fyren said.

EmitSound methods are overloaded too and they use something similar in SDKTools.
__________________
TheDS1337 is offline
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 10:41.


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