Raised This Month: $51 Target: $400
 12% 

Hooking ConVar::SetValue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 07-04-2009 , 13:42   Hooking ConVar::SetValue
Reply With Quote #1

Hi.
I'm currently trying to hook ConVar::SetValue.
All worked well, but RETURN_META_NEWPARAMS causes 82 errors: http://nopaste.org/p/aw6ORRr8C

Here's my declaration:
Code:
SH_DECL_HOOK1_void(ConVar, SetValue, SH_NOATTRIB, 0, int);
SH_DECL_HOOK1_void(ConVar, SetValue, SH_NOATTRIB, 1, float);
SH_DECL_HOOK1_void(ConVar, SetValue, SH_NOATTRIB, 2, const char*);
Here's the code to register the hook:
Code:
SH_ADD_HOOK_MEMFUNC(ConVar, SetValue, pConVar, &gConVar, &cConVar::SetValue, false);
And here's the hook function:
Code:
void cConVar::SetValue(int value)
{
    ConVar *pConVar = META_IFACEPTR(ConVar);

    if (!strcmp(pConVar->GetName(), "mp_timelimit"))
        RETURN_META_NEWPARAMS(MRES_IGNORED, &ConVar::SetValue, 0);
    
    RETURN_META(MRES_IGNORED);
}
I think it's caused by the 3 overloads that this function has.
But I can't understand why that code causes 82 errors :/
I hope someone can help me

Greetz.
Chrisber is offline
BAILOPAN
Join Date: Jan 2004
Old 07-04-2009 , 15:01   Re: Hooking ConVar::SetValue
Reply With Quote #2

Code:
RETURN_META_NEWPARAMS(MRES_IGNORED, &ConVar::SetValue, 0);
Should look like:

Code:
RETURN_META_NEWPARAMS(MRES_IGNORED, &ConVar::SetValue, (0));
__________________
egg
BAILOPAN is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 07-04-2009 , 19:11   Re: Hooking ConVar::SetValue
Reply With Quote #3

Hi.
Causes the same errors.

Greetz.
Chrisber is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 07-05-2009 , 05:41   Re: Hooking ConVar::SetValue
Reply With Quote #4

Hello,

1) BAIL is right, don't forget the ()

2) SourceHook can't deduce which one of the overloaded functions you want. I suppose a static_cast would work, but the clean way to slove this would probably be a temporary member function pointer variable:

Code:
void (ConVar::*  mfp) (int) = &ConVar::SetValue;
RETURN_META_NEWPARAMS(MRES_IGNORED, mfp, (0));
I suppose I could add a way to ask for the overload number in SH_DECL_HOOK ( 0 here ) but that would be only more confusing.

BTW: It gives you 82 errors because it lists every deduction function that doesn't fit twice, there are two deduction functions per parameter count and the allowed parameter counts are 0, 1, 2, ... 20. This gives us 2 * 2 * 21 = 84, but the exception is param count 1, where it finds a fitting deduction function but can't deduce the ambigous parameter type, which leads to only one error or something.

Hope this works,
PM


EDIT: or maybe some kind of template thing:
Code:
template <class TYPE>
inline static TYPE MFP_Chooser(TYPE a)
{
   return a;
}

RETURN_META_NEWPARAMS(MRES_IGNORED, MFP_Chooser< void (ConVar::*)(int) > (&ConVar::SetValue) , (0));
__________________
hello, i am pm

Last edited by PM; 07-05-2009 at 05:47.
PM is offline
Chrisber
AlliedModders Donor
Join Date: Jul 2007
Location: localhost
Old 07-06-2009 , 09:50   Re: Hooking ConVar::SetValue
Reply With Quote #5

Hi.
Wow - that works perfectly now - big thx to you!!!

~ Chris
Chrisber is offline
Reply



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 06:25.


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