Пример #1
0
static cell_t smn_TESend(IPluginContext *pContext, const cell_t *params)
{
	if (!g_TEManager.IsAvailable())
	{
		return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
	}
	if (!g_CurrentTE)
	{
		return pContext->ThrowNativeError("No TempEntity call is in progress");
	}

	cell_t *cl_array;
	unsigned int numClients;
	int client;
	IGamePlayer *pPlayer = NULL;

	pContext->LocalToPhysAddr(params[1], &cl_array);
	numClients = params[2];

	/* Client validation */
	for (unsigned int i = 0; i < numClients; i++)
	{
		client = cl_array[i];
		pPlayer = playerhelpers->GetGamePlayer(client);

		if (!pPlayer)
		{
			return pContext->ThrowNativeError("Client index %d is invalid", client);
		} else if (!pPlayer->IsInGame()) {
			return pContext->ThrowNativeError("Client %d is not connected", client);
		}
	}

	g_TERecFilter.Reset();
	g_TERecFilter.Initialize(cl_array, numClients);

	g_CurrentTE->Send(g_TERecFilter, sp_ctof(params[3]));
	g_CurrentTE = NULL;

	return 1;
}
Пример #2
0
static cell_t EmitSound(IPluginContext *pContext, const cell_t *params)
{
	cell_t *addr, *cl_array;
	CellRecipientFilter crf;
	unsigned int numClients;
	int client;
	IGamePlayer *pPlayer = NULL;

	pContext->LocalToPhysAddr(params[1], &cl_array);
	numClients = params[2];

	/* Client validation */
	for (unsigned int i = 0; i < numClients; i++)
	{
		client = cl_array[i];
		pPlayer = playerhelpers->GetGamePlayer(client);

		if (!pPlayer)
		{
			return pContext->ThrowNativeError("Client index %d is invalid", client);
		} else if (!pPlayer->IsInGame()) {
			return pContext->ThrowNativeError("Client %d is not connected", client);
		}
	}

	crf.Initialize(cl_array, numClients);

	char *sample;
	pContext->LocalToString(params[3], &sample);
	
	int entity = SoundReferenceToIndex(params[4]);
	int channel = params[5];
	int level = params[6];
	int flags = params[7];
	float vol = sp_ctof(params[8]);
	int pitch = params[9];
	int speakerentity = params[10];

	Vector *pOrigin = NULL, origin;
	Vector *pDir = NULL, dir;

	pContext->LocalToPhysAddr(params[11], &addr);
	if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
	{
		pOrigin = &origin;
		origin.x = sp_ctof(addr[0]);
		origin.y = sp_ctof(addr[1]);
		origin.z = sp_ctof(addr[2]);
	}

	pContext->LocalToPhysAddr(params[12], &addr);
	if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
	{
		pDir = &dir;
		dir.x = sp_ctof(addr[0]);
		dir.y = sp_ctof(addr[1]);
		dir.z = sp_ctof(addr[2]);
	}

	bool updatePos = params[13] ? true : false;
	float soundtime = sp_ctof(params[14]);

	CUtlVector<Vector> *pOrigVec = NULL;
	CUtlVector<Vector> origvec;
	if (params[0] > 14)
	{
		pOrigVec = &origvec;
		for (cell_t i = 15; i <= params[0]; i++)
		{
			Vector vec;
			pContext->LocalToPhysAddr(params[i], &addr);
			vec.x = sp_ctof(addr[0]);
			vec.y = sp_ctof(addr[1]);
			vec.z = sp_ctof(addr[2]);
			origvec.AddToTail(vec);
		}
	}

	/* If we're going to a "local player" and this is a dedicated server,
	 * intelligently redirect each sound.
	 */

	if (entity == -2 && engine->IsDedicatedServer())
	{
		for (unsigned int i = 0; i < numClients; i++)
		{
			cell_t player[1];
			player[0] = cl_array[i];
			crf.Reset();
			crf.Initialize(player, 1);
#if SOURCE_ENGINE >= SE_PORTAL2
			if (g_InSoundHook)
			{
				SH_CALL(enginesoundPatch, 
					static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float, 
					soundlevel_t, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>

					(&IEngineSound::EmitSound))
					(crf, 
					player[0], 
					channel, 
					sample, 
					-1, 
					sample, 
					vol, 
					(soundlevel_t)level, 
					0, 
					flags, 
					pitch, 
					pOrigin,
					pDir,
					pOrigVec,
					updatePos,
					soundtime,
					speakerentity);
			}
			else
			{
				engsound->EmitSound(crf, 
					player[0], 
					channel, 
					sample, 
					-1, 
					sample, 
					vol, 
					(soundlevel_t)level, 
					0, 
					flags, 
					pitch, 
					pOrigin,
					pDir,
					pOrigVec,
					updatePos,
					soundtime,
					speakerentity);
			}
#elif SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_SDK2013 \
	|| SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_TF2
			if (g_InSoundHook)
			{
				SH_CALL(enginesoundPatch, 
					static_cast<void (IEngineSound::*)(IRecipientFilter &, int, int, const char*, float, 
					soundlevel_t, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
					(&IEngineSound::EmitSound))
					(crf, 
					player[0], 
					channel, 
					sample, 
					vol, 
					(soundlevel_t)level, 
					flags, 
					pitch, 
					0, 
					pOrigin,
					pDir,
					pOrigVec,
					updatePos,
					soundtime,
					speakerentity);
			}
			else
			{
				engsound->EmitSound(crf, 
					player[0], 
					channel, 
					sample, 
					vol, 
					(soundlevel_t)level, 
					flags, 
					pitch, 
					0, 
					pOrigin,
					pDir,
					pOrigVec,
					updatePos,
					soundtime,
					speakerentity);
			}
#else
			if (g_InSoundHook)
			{
				SH_CALL(enginesoundPatch, 
					static_cast<void (IEngineSound::*)(IRecipientFilter &, int, int, const char*, float, 
					soundlevel_t, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
					(&IEngineSound::EmitSound))
					(crf, 
					player[0], 
					channel, 
					sample, 
					vol, 
					(soundlevel_t)level, 
					flags, 
					pitch, 
					pOrigin,
					pDir,
					pOrigVec,
					updatePos,
					soundtime,
					speakerentity);
			}
			else
			{
				engsound->EmitSound(crf, 
					player[0], 
					channel, 
					sample, 
					vol, 
					(soundlevel_t)level, 
					flags, 
					pitch, 
					pOrigin,
					pDir,
					pOrigVec,
					updatePos,
					soundtime,
					speakerentity);
			}
#endif
		}
	} else {
#if SOURCE_ENGINE >= SE_PORTAL2
		if (g_InSoundHook)
		{
			SH_CALL(enginesoundPatch, 
				static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float, 
				soundlevel_t, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
				(&IEngineSound::EmitSound))
				(crf, 
				entity, 
				channel, 
				sample, 
				-1, 
				sample, 
				vol, 
				(soundlevel_t)level, 
				0, 
				flags, 
				pitch, 
				pOrigin,
				pDir,
				pOrigVec,
				updatePos,
				soundtime,
				speakerentity);
		}
		else
		{
			engsound->EmitSound(crf, 
				entity, 
				channel, 
				sample, 
				-1, 
				sample, 
				vol, 
				(soundlevel_t)level, 
				0, 
				flags, 
				pitch, 
				pOrigin,
				pDir,
				pOrigVec,
				updatePos,
				soundtime,
				speakerentity);
		}
#elif SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_SDK2013 \
	|| SOURCE_ENGINE == SE_BMS || SOURCE_ENGINE == SE_TF2
		if (g_InSoundHook)
		{
			SH_CALL(enginesoundPatch, 
				static_cast<void (IEngineSound::*)(IRecipientFilter &, int, int, const char*, float, 
				soundlevel_t, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
				(&IEngineSound::EmitSound))
				(crf, 
				entity, 
				channel, 
				sample, 
				vol, 
				(soundlevel_t)level, 
				flags, 
				pitch, 
				0, 
				pOrigin,
				pDir,
				pOrigVec,
				updatePos,
				soundtime,
				speakerentity);
		}
		else
		{
			engsound->EmitSound(crf, 
				entity, 
				channel, 
				sample, 
				vol, 
				(soundlevel_t)level, 
				flags, 
				pitch, 
				0, 
				pOrigin,
				pDir,
				pOrigVec,
				updatePos,
				soundtime,
				speakerentity);
		}
#else
		if (g_InSoundHook)
		{
			SH_CALL(enginesoundPatch, 
				static_cast<void (IEngineSound::*)(IRecipientFilter &, int, int, const char*, float, 
				soundlevel_t, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
				(&IEngineSound::EmitSound))
				(crf, 
				entity, 
				channel, 
				sample, 
				vol, 
				(soundlevel_t)level, 
				flags, 
				pitch, 
				pOrigin,
				pDir,
				pOrigVec,
				updatePos,
				soundtime,
				speakerentity);
		}
		else
		{
			engsound->EmitSound(crf, 
				entity, 
				channel, 
				sample, 
				vol, 
				(soundlevel_t)level, 
				flags, 
				pitch, 
				pOrigin,
				pDir,
				pOrigVec,
				updatePos,
				soundtime,
				speakerentity);
		}
#endif
	}

	return 1;
}
Пример #3
0
static cell_t EmitSoundEntry(IPluginContext *pContext, const cell_t *params)
{
#if SOURCE_ENGINE < SE_PORTAL2
	return pContext->ThrowNativeError("EmitSoundEntry is not available in this game.");
#else
	cell_t *addr, *cl_array;
	CellRecipientFilter crf;
	unsigned int numClients;
	int client;
	IGamePlayer *pPlayer = NULL;

	pContext->LocalToPhysAddr(params[1], &cl_array);
	numClients = params[2];

	/* Client validation */
	for (unsigned int i = 0; i < numClients; i++)
	{
		client = cl_array[i];
		pPlayer = playerhelpers->GetGamePlayer(client);

		if (!pPlayer)
		{
			return pContext->ThrowNativeError("Client index %d is invalid", client);
		}
		else if (!pPlayer->IsInGame()) {
			return pContext->ThrowNativeError("Client %d is not connected", client);
		}
	}

	crf.Initialize(cl_array, numClients);

	char *soundEntry;
	pContext->LocalToString(params[3], &soundEntry);

	char *sample;
	pContext->LocalToString(params[4], &sample);

	// By default, we want the hash to equal maxint
	unsigned int soundEntryHash = -1;

	// We only generate a hash if the sample is not the same as the sound entry and the sound entry is not empty.
	if (strcmp(soundEntry, sample) != 0 && strcmp(soundEntry, "") != 0)
		soundEntryHash = GenerateSoundEntryHash(soundEntry);

	int entity = SoundReferenceToIndex(params[5]);
	int channel = params[6];
	int level = params[7];
	int seed = params[8];
	int flags = params[9];
	float vol = sp_ctof(params[10]);
	int pitch = params[11];
	int speakerentity = params[12];

	Vector *pOrigin = NULL, origin;
	Vector *pDir = NULL, dir;

	pContext->LocalToPhysAddr(params[13], &addr);
	if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
	{
		pOrigin = &origin;
		origin.x = sp_ctof(addr[0]);
		origin.y = sp_ctof(addr[1]);
		origin.z = sp_ctof(addr[2]);
	}

	pContext->LocalToPhysAddr(params[14], &addr);
	if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
	{
		pDir = &dir;
		dir.x = sp_ctof(addr[0]);
		dir.y = sp_ctof(addr[1]);
		dir.z = sp_ctof(addr[2]);
	}

	bool updatePos = params[15] ? true : false;
	float soundtime = sp_ctof(params[16]);

	CUtlVector<Vector> *pOrigVec = NULL;
	CUtlVector<Vector> origvec;
	if (params[0] > 16)
	{
		pOrigVec = &origvec;
		for (cell_t i = 17; i <= params[0]; i++)
		{
			Vector vec;
			pContext->LocalToPhysAddr(params[i], &addr);
			vec.x = sp_ctof(addr[0]);
			vec.y = sp_ctof(addr[1]);
			vec.z = sp_ctof(addr[2]);
			origvec.AddToTail(vec);
		}
	}

	/* If we're going to a "local player" and this is a dedicated server,
	* intelligently redirect each sound.
	*/

	if (entity == -2 && engine->IsDedicatedServer())
	{
		for (unsigned int i = 0; i < numClients; i++)
		{
			cell_t player[1];
			player[0] = cl_array[i];
			crf.Reset();
			crf.Initialize(player, 1);

			if (g_InSoundHook)
			{
				SH_CALL(enginesoundPatch,
					static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float,
					soundlevel_t, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
					(&IEngineSound::EmitSound))(crf, player[0], channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level, seed,
					flags, pitch, pOrigin, pDir, pOrigVec, updatePos, soundtime, speakerentity);
			}
			else
			{
				engsound->EmitSound(crf, player[0], channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level, seed,
					flags, pitch, pOrigin, pDir, pOrigVec, updatePos, soundtime, speakerentity);
			}
		}
	}
	else {
		if (g_InSoundHook)
		{
			SH_CALL(enginesoundPatch,
				static_cast<int (IEngineSound::*)(IRecipientFilter &, int, int, const char*, unsigned int, const char*, float,
				soundlevel_t, int, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
				(&IEngineSound::EmitSound))(crf, entity, channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level,
				seed, flags, pitch, pOrigin, pDir, pOrigVec, updatePos, soundtime, speakerentity);
		}
		else
		{
			engsound->EmitSound(crf, entity, channel, soundEntry, soundEntryHash, sample, vol, (soundlevel_t)level, seed,
				flags, pitch, pOrigin, pDir, pOrigVec, updatePos, soundtime, speakerentity);
		}
	}

	return 1;
#endif
}
Пример #4
0
static cell_t EmitSound(IPluginContext *pContext, const cell_t *params)
{
	cell_t *addr, *pl_addr;

	CellRecipientFilter crf;
	pContext->LocalToPhysAddr(params[1], &pl_addr);
	crf.Initialize(pl_addr, params[2]);

	char *sample;
	pContext->LocalToString(params[3], &sample);
	
	int entity = params[4];
	int channel = params[5];
	int level = params[6];
	int flags = params[7];
	float vol = sp_ctof(params[8]);
	int pitch = params[9];
	int speakerentity = params[10];

	Vector *pOrigin = NULL, origin;
	Vector *pDir = NULL, dir;

	pContext->LocalToPhysAddr(params[11], &addr);
	if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
	{
		pOrigin = &origin;
		origin.x = sp_ctof(addr[0]);
		origin.y = sp_ctof(addr[1]);
		origin.z = sp_ctof(addr[2]);
	}

	pContext->LocalToPhysAddr(params[12], &addr);
	if (addr != pContext->GetNullRef(SP_NULL_VECTOR))
	{
		pDir = &dir;
		dir.x = sp_ctof(addr[0]);
		dir.y = sp_ctof(addr[1]);
		dir.z = sp_ctof(addr[2]);
	}

	bool updatePos = params[13] ? true : false;
	float soundtime = sp_ctof(params[14]);

	CUtlVector<Vector> *pOrigVec = NULL;
	CUtlVector<Vector> origvec;
	if (params[0] > 14)
	{
		pOrigVec = &origvec;
		for (cell_t i = 15; i <= params[0]; i++)
		{
			Vector vec;
			pContext->LocalToPhysAddr(params[i], &addr);
			vec.x = sp_ctof(addr[0]);
			vec.y = sp_ctof(addr[1]);
			vec.z = sp_ctof(addr[2]);
			origvec.AddToTail(vec);
		}
	}

	/* If we're going to a "local player" and this is a dedicated server,
	 * intelligently redirect each sound.
	 */

	if (entity == -2 && engine->IsDedicatedServer())
	{
		for (cell_t i=0; i<params[2]; i++)
		{
			cell_t player[1];
			player[0] = pl_addr[i];
			crf.Reset();
			crf.Initialize(player, 1);
			if (g_InSoundHook)
			{
				SH_CALL(enginesoundPatch, 
					static_cast<void (IEngineSound::*)(IRecipientFilter &, int, int, const char*, float, 
					soundlevel_t, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
					(&IEngineSound::EmitSound))
					(crf, 
					player[0], 
					channel, 
					sample, 
					vol, 
					(soundlevel_t)level, 
					flags, 
					pitch, 
					pOrigin,
					pDir,
					pOrigVec,
					updatePos,
					soundtime,
					speakerentity);
			}
			else
			{
				engsound->EmitSound(crf, 
					player[0], 
					channel, 
					sample, 
					vol, 
					(soundlevel_t)level, 
					flags, 
					pitch, 
					pOrigin,
					pDir,
					pOrigVec,
					updatePos,
					soundtime,
					speakerentity);
			}
		}
	} else {
		if (g_InSoundHook)
		{
			SH_CALL(enginesoundPatch, 
				static_cast<void (IEngineSound::*)(IRecipientFilter &, int, int, const char*, float, 
				soundlevel_t, int, int, const Vector *, const Vector *, CUtlVector<Vector> *, bool, float, int)>
				(&IEngineSound::EmitSound))
				(crf, 
				entity, 
				channel, 
				sample, 
				vol, 
				(soundlevel_t)level, 
				flags, 
				pitch, 
				pOrigin,
				pDir,
				pOrigVec,
				updatePos,
				soundtime,
				speakerentity);
		}
		else
		{
			engsound->EmitSound(crf, 
				entity, 
				channel, 
				sample, 
				vol, 
				(soundlevel_t)level, 
				flags, 
				pitch, 
				pOrigin,
				pDir,
				pOrigVec,
				updatePos,
				soundtime,
				speakerentity);
		}
	}

	return 1;
}