AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Dhooks passing int reference to detour (https://forums.alliedmods.net/showthread.php?t=338951)

xerox8521 08-05-2022 08:29

Dhooks passing int reference to detour
 
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?

Zynda 08-05-2022 13:47

Re: Dhooks passing int reference to detour
 
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 :)

xerox8521 08-05-2022 14:23

Re: Dhooks passing int reference to detour
 
Well, LoadFromAddress requires the address and param.GetAddress from dhooks only works on ptr param types.
So how would I get the address?

Zynda 08-06-2022 05:08

Re: Dhooks passing int reference to detour
 
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;




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

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