Skip to content

[DHooks] Cannot set CBaseEntity param to NULL #1751

@Ilusion9

Description

@Ilusion9
Handle g_DHook_AcceptInput;

public void OnPluginStart()
{
	int acceptInputOffset;
	// retrieve offset here ...
	
	g_DHook_AcceptInput = DHookCreate(acceptInputOffset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity);
	DHookAddParam(g_DHook_AcceptInput, HookParamType_CharPtr);
	DHookAddParam(g_DHook_AcceptInput, HookParamType_CBaseEntity);
	DHookAddParam(g_DHook_AcceptInput, HookParamType_CBaseEntity);
	DHookAddParam(g_DHook_AcceptInput, HookParamType_Object, 20, DHookPass_ByVal | DHookPass_ODTOR | DHookPass_OCTOR | DHookPass_OASSIGNOP);
	DHookAddParam(g_DHook_AcceptInput, HookParamType_Int);
}

public void OnEntityCreated(int entity, const char[] classname)
{
	DHookEntity(g_DHook_AcceptInput, false, entity, INVALID_FUNCTION, DHook_AcceptInput);
}

public MRESReturn DHook_AcceptInput(int pThis, Handle hReturn, Handle hParams)
{
	int activator = -1;
	if (!DHookIsNullParam(hParams, 2))
	{
		activator = DHookGetParam(hParams, 2);
	}
	
	int caller = -1;
	if (!DHookIsNullParam(hParams, 3))
	{
		caller = DHookGetParam(hParams, 3);
	}
	
	// here i want to set the caller or activator to NULL
	return MRES_ChangedHandled;
}

There is no option to set the activator or caller to null. Not in DHookSetParam, not even in DHookSetParamObjectPtrVar.
From dhooks/natives.cpp (Native_SetParam):

		case HookParamType_CBaseEntity:
		{
			CBaseEntity *pEnt = gamehelpers->ReferenceToEntity(params[2]);

			if(!pEnt)
			{
				return pContext->ThrowNativeError("Invalid entity index passed for param value");
			}

			*(CBaseEntity **)addr = pEnt;
			break;
		}

I'm trying to make a forward where other people can change inputs by their desire (maybe they want to remove the activator or the caller):

forward Action EntityIO_OnEntityInput(int entity, char input[256], int& activator, int& caller, EntityIO_ParamInfo paramInfo, int outputId);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature Requestuser requested featureGood First IssueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions