Raised This Month: $ Target: $400
 0% 

Dhooks passing int reference to detour


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xerox8521
Senior Member
Join Date: Sep 2011
Old 08-05-2022 , 08:29   Dhooks passing int reference to detour
Reply With Quote #1

Hi,

It seems to me you cannot pass argument types to functions with dhooks that are passed by reference unless they are virtual.
Well problem is this function CServerGameClients::GetPlayerLimits I wouldn't know how to make this one virtual as you need to pass an instance of CServerGameClients which you don't have in the normal API.
So i set this up as detour but with this commit here I cannot tell dhooks that the parameters are to be passed as reference. If I just specify them as int I obviously just get garbage.

So what would be the right approach to do this?
xerox8521 is offline
Zynda
Member
Join Date: Jul 2011
Old 08-05-2022 , 13:47   Re: Dhooks passing int reference to detour
Reply With Quote #2

There's a global instance g_ServerGameClients (gameinterface.cpp) if you're on linux you can simply use the symbol name.
By the way the 'garbage' value is actually the underlying int *
nothing is stopping you from simply using LoadFromAddress/StoreToAddress on it :)

Last edited by Zynda; 08-05-2022 at 13:49.
Zynda is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 08-05-2022 , 14:23   Re: Dhooks passing int reference to detour
Reply With Quote #3

Well, LoadFromAddress requires the address and param.GetAddress from dhooks only works on ptr param types.
So how would I get the address?
xerox8521 is offline
Zynda
Member
Join Date: Jul 2011
Old 08-06-2022 , 05:08   Re: Dhooks passing int reference to detour
Reply With Quote #4

PHP Code:
public MRESReturn GetPlayerLimits(Address pThisDHookParam hParams)
{
    
Address a1 hParams.Get(1);
    
Address a2 hParams.Get(2);
    
Address a3 hParams.Get(3);

    
// dereference
    
int v1 LoadFromAddress(a1NumberType_Int32);
    
int v2 LoadFromAddress(a2NumberType_Int32);
    
int v3 LoadFromAddress(a3NumberType_Int32);
    
PrintToServer("Min [%d] Max [%d] Default [%d]"v1v2v3);

    
StoreToAddress(a11NumberType_Int32);
    
StoreToAddress(a24NumberType_Int32);
    
StoreToAddress(a31NumberType_Int32);

    
// Make sure the original does not get called
    
return MRES_Supercede;

Zynda 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 15:07.


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