static cell_t sm_AddToForward(IPluginContext *pContext, const cell_t *params)
{
	Handle_t fwdHandle = static_cast<Handle_t>(params[1]);
	Handle_t plHandle = static_cast<Handle_t>(params[2]);
	HandleError err;
	IChangeableForward *pForward;
	IPlugin *pPlugin;

	if ((err=g_HandleSys.ReadHandle(fwdHandle, g_PrivateFwdType, NULL, (void **)&pForward))
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid private forward handle %x (error %d)", fwdHandle, err);
	}

	if (plHandle == 0)
	{
		pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext());
	} else {
		pPlugin = g_PluginSys.PluginFromHandle(plHandle, &err);

		if (!pPlugin)
		{
			return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", plHandle, err);
		}
	}

	IPluginFunction *pFunction = pPlugin->GetBaseContext()->GetFunctionById(params[3]);

	if (!pFunction)
	{
		return pContext->ThrowNativeError("Invalid function id (%X)", params[3]);
	}

	return pForward->AddFunction(pFunction);
}
示例#2
0
void ConVarManager::HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction)
{
	ConVarInfo *pInfo;
	IChangeableForward *pForward;

	/* Find the convar in the lookup trie */
	if (convar_cache_lookup(pConVar->GetName(), &pInfo))
	{
		/* Get the forward */
		pForward = pInfo->pChangeForward;

		/* If forward does not exist, create it */
		if (!pForward)
		{
			pForward = forwardsys->CreateForwardEx(NULL, ET_Ignore, 3, CONVARCHANGE_PARAMS);
			pInfo->pChangeForward = pForward;
		}

		/* Add function to forward's list */
		pForward->AddFunction(pFunction);
	}
}
示例#3
0
static cell_t sm_AddFrameAction(IPluginContext *pContext, const cell_t *params)
{
	IPlugin *pPlugin = pluginsys->FindPluginByContext(pContext->GetContext());
	IPluginFunction *pFunction = pPlugin->GetBaseContext()->GetFunctionById(params[1]);
	if (!pFunction)
	{
		return pContext->ThrowNativeError("Invalid function id (%X)", params[1]);
	}

	IChangeableForward *pForward = forwardsys->CreateForwardEx(NULL, ET_Ignore, 1, NULL, Param_Cell);
	IdentityToken_t *pIdentity = pContext->GetIdentity();
	Handle_t Handle = handlesys->CreateHandle(g_PrivateFwdType, pForward, pIdentity, g_pCoreIdent, NULL);
	if (Handle == BAD_HANDLE)
	{
		forwardsys->ReleaseForward(pForward);
		return 0;
	}

	pForward->AddFunction(pFunction);

	SMFrameActionData *pData = new SMFrameActionData(Handle, pPlugin->GetMyHandle(), params[2]);
	g_pSM->AddFrameAction(PawnFrameAction, pData);
	return 1;
}