From 3ebd7536db2fd797f4d4ee5fdb7610d2f71e945e Mon Sep 17 00:00:00 2001 From: Night Owl Date: Sat, 11 Nov 2017 10:49:43 +0500 Subject: [PATCH] Add ambient_fmodstream implementation. --- cl_dll/hud.cpp | 17 ++++++++++++++++ dlls/client.cpp | 7 +++++++ dlls/player.cpp | 2 ++ dlls/triggers.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/cl_dll/hud.cpp b/cl_dll/hud.cpp index 05bda284..9e3ed4dd 100644 --- a/cl_dll/hud.cpp +++ b/cl_dll/hud.cpp @@ -78,6 +78,20 @@ int __MsgFunc_GameMode( const char *pszName, int iSize, void *pbuf ) return gHUD.MsgFunc_GameMode( pszName, iSize, pbuf ); } +int __MsgFunc_PlayMP3( const char *pszName, int iSize, void *pbuf ) +{ + BEGIN_READ( pbuf, iSize ); + + gEngfuncs.pfnPrimeMusicStream( READ_STRING(), 1 ); + + return 1; +} + +void __CmdFunc_StopMP3( void ) +{ + gEngfuncs.pfnPrimeMusicStream( 0, 0 ); +} + // TFFree Command Menu void __CmdFunc_OpenCommandMenu( void ) { @@ -183,6 +197,9 @@ void CHud::Init( void ) // VGUI Menus HOOK_MESSAGE( VGUIMenu ); + HOOK_MESSAGE( PlayMP3 ); + HOOK_COMMAND( "stopaudio", StopMP3 ); + CVAR_CREATE( "hud_classautokill", "1", FCVAR_ARCHIVE | FCVAR_USERINFO ); // controls whether or not to suicide immediately on TF class switch CVAR_CREATE( "hud_takesshots", "0", FCVAR_ARCHIVE ); // controls whether or not to automatically take screenshots at the end of a round hud_textmode = CVAR_CREATE ( "hud_textmode", "0", FCVAR_ARCHIVE ); diff --git a/dlls/client.cpp b/dlls/client.cpp index 578534e3..06a00a2c 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -49,6 +49,7 @@ extern void CopyToBodyQue( entvars_t* pev ); extern int giPrecacheGrunt; extern int gmsgSayText; extern int gmsgBhopcap; +extern int gmsgPlayMP3; extern cvar_t allow_spectators; @@ -487,6 +488,12 @@ void ClientCommand( edict_t *pEntity ) { GetClassPtr( (CBasePlayer *)pev )->ForceClientDllUpdate(); } + else if( FStrEq(pcmd, "playaudio" ) ) + { + MESSAGE_BEGIN( MSG_ONE, gmsgPlayMP3, NULL, ENT( pev ) ); + WRITE_STRING( (char *)CMD_ARGV( 1 ) ); + MESSAGE_END(); + } else if( FStrEq(pcmd, "give" ) ) { if( g_flWeaponCheat != 0.0 ) diff --git a/dlls/player.cpp b/dlls/player.cpp index ea803ecf..26b62abc 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -185,6 +185,7 @@ int gmsgShowMenu = 0; int gmsgGeigerRange = 0; int gmsgTeamNames = 0; int gmsgBhopcap = 0; +int gmsgPlayMP3 = 0; int gmsgStatusText = 0; int gmsgStatusValue = 0; @@ -232,6 +233,7 @@ void LinkUserMessages( void ) gmsgAmmoX = REG_USER_MSG( "AmmoX", 2 ); gmsgTeamNames = REG_USER_MSG( "TeamNames", -1 ); gmsgBhopcap = REG_USER_MSG( "Bhopcap", 1 ); + gmsgPlayMP3 = REG_USER_MSG( "PlayMP3", -1 ); gmsgStatusText = REG_USER_MSG( "StatusText", -1 ); gmsgStatusValue = REG_USER_MSG( "StatusValue", 3 ); diff --git a/dlls/triggers.cpp b/dlls/triggers.cpp index 8171a195..1a152518 100644 --- a/dlls/triggers.cpp +++ b/dlls/triggers.cpp @@ -771,6 +771,57 @@ void CTargetCDAudio::Play( void ) UTIL_Remove( this ); } +#define SF_REMOVE_ON_FIRE 1 + +class CTargetFMODAudio : public CPointEntity +{ +public: + void Spawn( void ); + void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); + + BOOL m_bPlaying; +}; + +LINK_ENTITY_TO_CLASS( ambient_fmodstream, CTargetFMODAudio ) +LINK_ENTITY_TO_CLASS( trigger_mp3audio, CTargetFMODAudio ) + +void CTargetFMODAudio::Spawn( void ) +{ + pev->solid = SOLID_NOT; + pev->movetype = MOVETYPE_NONE; + + m_bPlaying = FALSE; // start out not playing +} + +void CTargetFMODAudio::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) +{ + char command[64]; + + if( !pActivator->IsPlayer()) // activator should be a player + return; + + if( !m_bPlaying ) // if we're not playing, start playing! + { + m_bPlaying = TRUE; + } + else + { + // if we're already playing, stop the mp3 + m_bPlaying = FALSE; + CLIENT_COMMAND( pActivator->edict(), "stopaudio\n" ); + return; + } + + // issue the play/loop command + sprintf( command, "playaudio %s\n", STRING( pev->message ) ); + + CLIENT_COMMAND( pActivator->edict(), command ); + + // remove if set + if( FBitSet( pev->spawnflags, SF_REMOVE_ON_FIRE ) ) + UTIL_Remove( this ); +} + //===================================== // // trigger_hurt - hurts anything that touches it. if the trigger has a targetname, firing it will toggle state