Skip to content

Implement CBaseEntity::Fire<Bullets[3]|Buckshots> hooks.#202

Merged
s1lentq merged 15 commits intorehlds:masterfrom
FEDERICOMB96:Implement-CBaseEntity-Fire-Bullets-3]-Buckshots-hooks-
Aug 1, 2021
Merged

Implement CBaseEntity::Fire<Bullets[3]|Buckshots> hooks.#202
s1lentq merged 15 commits intorehlds:masterfrom
FEDERICOMB96:Implement-CBaseEntity-Fire-Bullets-3]-Buckshots-hooks-

Conversation

@FEDERICOMB96
Copy link
Contributor

  • Implement "CBaseEntity::Fire<Bullets[3]|Buckshots>" hooks.
  • Added new hook table "GamedllFunc_CBaseEntity".
  • Added new hookchain argument type "ATYPE_VECTOR"

@FEDERICOMB96
Copy link
Contributor Author

Apparently there is a strange bug with Get/SetHookChainReturn, basically GetHookChainReturn is not returning the correct values and SetHookChainReturn is not applying values correctly, not sure if I would call this a bug but more than a implementation typo on my end, so if someone can check it that would be good

@s1lentq
Copy link
Member

s1lentq commented Jun 22, 2021

@FEDERICOMB96 Done. Can you test it?

@FEDERICOMB96
Copy link
Contributor Author

@FEDERICOMB96 Done. Can you test it?

Works fine now. I forgot to add ATYPE_VECTOR in SetHookChainArg native

@FEDERICOMB96
Copy link
Contributor Author

FEDERICOMB96 commented Jun 22, 2021

I tried this

#include <amxmodx>
#include <reapi>
#include <xs>

public plugin_init()
{
	RegisterHookChain(RG_CBaseEntity_FireBullets3, "RG_CBaseEntity_FireBullets3_pre", 0);
	RegisterHookChain(RG_CBaseEntity_FireBullets3, "RG_CBaseEntity_FireBullets3_Post", 1);
}

public RG_CBaseEntity_FireBullets3_pre(pEntity, Float:vecSrc[3], Float:vecDirShooting[3], Float:vecSpread, Float:flDistance, iPenetration, iBulletType, iDamage, Float:flRangeModifier, pevAttacker, bool:bPistol, shared_rand)
{
	server_print("RG_CBaseEntity_FireBullets3_pre: pEntity %i, Float:vecSrc[3] {%f, %f, %f}, Float:vecDirShooting[3] {%f, %f, %f}, Float:vecSpread %f, ",
		pEntity, vecSrc[0], vecSrc[1], vecSrc[2], vecDirShooting[0], vecDirShooting[1], vecDirShooting[2], vecSpread);

	server_print("Float:flDistance %f, iPenetration %i, iBulletType %i, iDamage %i, Float:flRangeModifier %f, pevAttacker %i, bool:bPistol %i, shared_rand %i",
		flDistance, iPenetration, iBulletType, iDamage, flRangeModifier, pevAttacker, bPistol, shared_rand);

	new Float:vecRet[3];
	xs_vec_set(vecRet, 50.0, 50.0, 50.0);
	SetHookChainArg(3, ATYPE_VECTOR, vecRet);

	//SetHookChainReturn(ATYPE_VECTOR, vecRet);	
}

public RG_CBaseEntity_FireBullets3_Post(pEntity, Float:vecSrc[3], Float:vecDirShooting[3], Float:vecSpread, Float:flDistance, iPenetration, iBulletType, iDamage, Float:flRangeModifier, pevAttacker, bool:bPistol, shared_rand)
{
	server_print("RG_CBaseEntity_FireBullets3_post: pEntity %i, Float:vecSrc[3] {%f, %f, %f}, Float:vecDirShooting[3] {%f, %f, %f}, Float:vecSpread %f, ",
		pEntity, vecSrc[0], vecSrc[1], vecSrc[2], vecDirShooting[0], vecDirShooting[1], vecDirShooting[2], vecSpread);

	server_print("Float:flDistance %f, iPenetration %i, iBulletType %i, iDamage %i, Float:flRangeModifier %f, pevAttacker %i, bool:bPistol %i, shared_rand %i",
		flDistance, iPenetration, iBulletType, iDamage, flRangeModifier, pevAttacker, bPistol, shared_rand);

	new Float:vecRet[3];
	GetHookChainReturn(ATYPE_VECTOR, vecRet);

	client_print(0, print_chat, "Float:vecRet[3] {%f, %f, %f}", vecRet[0], vecRet[1], vecRet[2]);
}

but SetHookChainArg throws an error
[ReAPI] SetHookChainArg: invalid argument type provided, expected 'ATYPE_INTEGER'; got 'ATYPE_VECTOR'

I think the problem is here (hook_callback.h):

inline AType getApiType(Vector)         { return ATYPE_VECTOR; }
inline AType getApiType(Vector&)        { return ATYPE_VECTOR; }

@s1lentq
Copy link
Member

s1lentq commented Jun 22, 2021

@FEDERICOMB96 yes, SetHookChainArg not able yet handle with ATYPE_VECTOR, but anyway you can do it directly

vecDirShooting[0] = vecRet[0];
vecDirShooting[1] = vecRet[1];
vecDirShooting[2] = vecRet[2];

@FEDERICOMB96
Copy link
Contributor Author

FEDERICOMB96 commented Jun 22, 2021

@FEDERICOMB96 yes, SetHookChainArg not able yet handle with ATYPE_VECTOR, but anyway you can do it directly

vecDirShooting[0] = vecRet[0];
vecDirShooting[1] = vecRet[1];
vecDirShooting[2] = vecRet[2];

Oh i didn't know this, it works 😮
So, should I revert the changes in my last commit?

@s1lentq
Copy link
Member

s1lentq commented Jun 22, 2021

So, should I revert the changes in my last commit?

yes

@wopox1337 wopox1337 requested a review from s1lentq June 22, 2021 17:43
@wopox1337 wopox1337 added the Type: 🚀 enhancement Improvement or addition of a new feature. label Jun 22, 2021
@wopox1337 wopox1337 changed the title Implement "CBaseEntity::Fire<Bullets[3]|Buckshots>" hooks. Implement CBaseEntity::Fire<Bullets[3]|Buckshots> hooks. Jun 22, 2021
@FEDERICOMB96
Copy link
Contributor Author

So, should I revert the changes in my last commit?

yes

Done.

@s1lentq s1lentq merged commit 97aea0f into rehlds:master Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: 🚀 enhancement Improvement or addition of a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants