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 8 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;
}

Copy link
Member

@Kenzzer Kenzzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work, especially given the situation that surround Address. The less we mess with memory directly in plugin, the better !
I just have a few request changes, but otherwise I think this is a good addition to dhooks.

extensions/dhooks/natives.cpp Outdated Show resolved Hide resolved
extensions/dhooks/natives.cpp Outdated Show resolved Hide resolved
extensions/dhooks/natives.cpp Outdated Show resolved Hide resolved
extensions/dhooks/natives.cpp Outdated Show resolved Hide resolved
extensions/dhooks/natives.cpp Outdated Show resolved Hide resolved
extensions/dhooks/natives.cpp Outdated Show resolved Hide resolved
extensions/dhooks/natives.cpp Outdated Show resolved Hide resolved
@A1mDev
Copy link
Contributor Author

A1mDev commented Dec 30, 2024

I think I've finished this PR, I just need to check

@A1mDev
Copy link
Contributor Author

A1mDev commented Dec 30, 2024

I tested it with this type address, everything works fine!

Copy link
Member

@Kenzzer Kenzzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for seeing this through, it looks great! I'm going to let this sit a for little while longer, so others may review it as well. Otherwise I think this is ready to be taken in, thanks again!

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.

2 participants