AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   Solved Hooking IServerTools finctions leads to compile-time errors (https://forums.alliedmods.net/showthread.php?t=320694)

kadet.89 01-04-2020 10:20

Hooking IServerTools finctions leads to compile-time errors
 
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 &  ); 


Fyren 01-04-2020 16:30

Re: Hooking IServerTools finctions leads to compile-time errors
 
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).

kadet.89 01-08-2020 15:17

Re: Hooking IServerTools finctions leads to compile-time errors
 
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)


Fyren 01-09-2020 18:32

Re: Hooking IServerTools finctions leads to compile-time errors
 
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)

TheDS1337 01-10-2020 04:00

Re: Hooking IServerTools finctions leads to compile-time errors
 
I agree with what Fyren said.

EmitSound methods are overloaded too and they use something similar in SDKTools.


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

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