From 58ff94c2f3b1cce57b02418a5262f9fe5a424563 Mon Sep 17 00:00:00 2001 From: Night Owl Date: Fri, 22 Dec 2017 12:13:11 +0500 Subject: [PATCH] Fix trigger_mp3audio. --- cl_dll/hud.cpp | 17 +++++++++++++++++ dlls/client.cpp | 7 +++++++ dlls/player.cpp | 2 ++ dlls/triggers.cpp | 42 ++++++++++++++++++++++++++++-------------- 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/cl_dll/hud.cpp b/cl_dll/hud.cpp index dfc1ae12..7a7069c8 100644 --- a/cl_dll/hud.cpp +++ b/cl_dll/hud.cpp @@ -100,6 +100,20 @@ void __CmdFunc_ToggleServerBrowser( void ) { } +int __MsgFunc_PlayMP3( const char *pszName, int iSize, void *pbuf ) +{ + BEGIN_READ( pbuf, iSize ); + + gEngfuncs.pfnPrimeMusicStream( READ_STRING(), 0 ); + + return 1; +} + +void __CmdFunc_StopMP3( void ) +{ + gEngfuncs.pfnPrimeMusicStream( 0, 0 ); +} + // TFFree Command Menu Message Handlers int __MsgFunc_ValClass( const char *pszName, int iSize, void *pbuf ) { @@ -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 bd2146c3..e0dc96d3 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 8996b687..f24a89c2 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -189,6 +189,7 @@ int gmsgStatusText = 0; int gmsgStatusValue = 0; int gmsgNightvision = 0; +int gmsgPlayMP3 = 0; void LinkUserMessages( void ) { @@ -238,6 +239,7 @@ void LinkUserMessages( void ) gmsgStatusValue = REG_USER_MSG( "StatusValue", 3 ); gmsgNightvision = REG_USER_MSG( "Nightvision", 1 ); + gmsgPlayMP3 = REG_USER_MSG( "PlayMP3", -1 ); } LINK_ENTITY_TO_CLASS( player, CBasePlayer ) diff --git a/dlls/triggers.cpp b/dlls/triggers.cpp index 3c63d682..577f1b16 100644 --- a/dlls/triggers.cpp +++ b/dlls/triggers.cpp @@ -2385,11 +2385,12 @@ void CTriggerCamera::Move() // // Adapted from TWHL - Using mp3s in Steam // +#define SF_REMOVE_ON_FIRE 1 class CTargetMP3Audio : public CBaseTrigger { public: - virtual int Save( CSave &save ); - virtual int Restore( CRestore &restore ); + int Save( CSave &save ); + int Restore( CRestore &restore ); static TYPEDESCRIPTION m_SaveData[]; void Spawn( void ); @@ -2397,15 +2398,16 @@ public: void Touch( CBaseEntity *pOther ); - int m_iszTrack; - BOOL m_bTriggered; + string_t m_iszTrack; + BOOL m_bPlaying; }; LINK_ENTITY_TO_CLASS( trigger_mp3audio, CTargetMP3Audio ); TYPEDESCRIPTION CTargetMP3Audio::m_SaveData[] = { - DEFINE_FIELD( CTargetMP3Audio, m_bTriggered, FIELD_BOOLEAN ), + DEFINE_FIELD( CTargetMP3Audio, m_iszTrack, FIELD_STRING ), + DEFINE_FIELD( CTargetMP3Audio, m_bPlaying, FIELD_BOOLEAN ), }; IMPLEMENT_SAVERESTORE( CTargetMP3Audio, CBaseTrigger ); @@ -2414,7 +2416,10 @@ void CTargetMP3Audio::KeyValue( KeyValueData *pkvd ) { if( FStrEq( pkvd->szKeyName, "track" ) ) { - m_iszTrack = ALLOC_STRING( pkvd->szValue ); + if( FStrEq( pkvd->szValue, "hl28.mp3" ) ) + m_iszTrack = MAKE_STRING( "Suspense07.mp3" ); + else + m_iszTrack = ALLOC_STRING( pkvd->szValue ); pkvd->fHandled = TRUE; } else @@ -2424,22 +2429,31 @@ void CTargetMP3Audio::KeyValue( KeyValueData *pkvd ) void CTargetMP3Audio::Spawn( void ) { InitTrigger(); - - m_bTriggered = FALSE; + m_bPlaying = FALSE; // start out not playing } void CTargetMP3Audio::Touch( CBaseEntity *pOther ) { - if( m_bTriggered ) - return; + char command[64]; if( !pOther || !pOther->IsPlayer() ) return; - m_bTriggered = TRUE; - - if( FStrEq( STRING( gpGlobals->mapname ), "ops_17th" ) ) + if( !m_bPlaying ) // if we're not playing, start playing! { - CLIENT_COMMAND( pOther->edict(), "play media/Suspense07.mp3\n" ); + m_bPlaying = TRUE; + // issue the play/loop command + sprintf( command, "playaudio %s\n", STRING( m_iszTrack ) ); + CLIENT_COMMAND( pOther->edict(), command ); } + /*else + { + // if we're already playing, stop the mp3 + m_bPlaying = FALSE; + CLIENT_COMMAND( pOther->edict(), "stopaudio\n" ); + return; + }*/ + + if( pev->spawnflags & SF_REMOVE_ON_FIRE ) + UTIL_Remove( this ); }