sourcemod icon indicating copy to clipboard operation
sourcemod copied to clipboard

[Dhooks Feature Request] Add more options to work with this parameter

Open A1mDev opened this issue 3 years ago • 0 comments

Description

Dhooks can work with function arguments, but it can't work with parameter 'this'. For example, we have a this parameter pointing to a class object, this class has a property of type EHANDLE. There is no way we can get the player or entity index from the EHANDLE type if we specify the this parameter as address. We have to pass this parameter as a function argument for this to work, but that's not correct.

Wrong code (which can work now?)

  • Gamedata:
"Functions"
{
	"DhooksCall"
	{
		"signature"		"..."
		"callconv"		"cdecl"
		"return"		"void"
		//"this"			"ignore"
		"arguments"
		{
			"this"
			{
				"type"	"objectptr"
			}
		}
	}
}
  • Code example:
int iEhandleOffset = 244;

public MRESReturn DhooksCall(Handle hParams)
{
	int iClient = hParams.GetObjectVar(1, iEhandleOffset, ObjectValueType_Ehandle);

	return MRES_Ignored;
}

Should be something like this:

  • Gamedata:
"Functions"
{
	"DhooksCall"
	{
		"signature"		"..."
		"callconv"		"thiscall"
		"return"		"void"
		"this"			"objectptr"
	}
}
  • Code example:
int iEhandleOffset = 244;

public MRESReturn DhooksCall(DHookThis hThis)
{
	int iClient = hThis.GetObjectVar(iEhandleOffset, ObjectValueType_Ehandle);

	return MRES_Ignored;
}

A1mDev avatar Jun 21 '22 20:06 A1mDev