Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dhooks] Add the ability to work with the this parameter, which is an object #2219

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

A1mDev
Copy link
Contributor

@A1mDev A1mDev commented Nov 11, 2024

Sometimes we have to work with this parameter which is a class but dhooks doesn't have this feature, this PR solves this problem. This code has been tested on both post and pre hooks. Below is an example code for working with the new functionality.

/*class CBaseEntity : public IServerEntity
{
	...
protected:
	EHANDLE m_pParent;  // for movement hierarchy	
	...
};*/

MRESReturn Handler_CBaseEntity__OnTakeDamage(Address pThis, Handle hReturn, Handle hParams)
{
	// If EHANDLE type or entity returns entity index.
	// Index num 0, for working with this parameter

	int iParent = DHookGetParamObjectPtrVar(hParams, 0, 384, ObjectValueType_Ehandle);
	if (iParent < 1 || !IsValidEntity(iParent)) {
		return MRES_Ignored;
	}

	char sEntityName[64];
	GetEntityClassname(iParent, sEntityName, sizeof(sEntityName));
	
	PrintToChatAll("[Handler_CBaseEntity__OnTakeDamage] iParent: %s (%d)", sEntityName, iParent);
	
	return MRES_Ignored;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant