Skip to content

Commit

Permalink
Add CAESoundManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Necktrox committed Feb 20, 2018
1 parent 4484459 commit 4230804
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 24 deletions.
28 changes: 28 additions & 0 deletions Client/game_sa/CAESoundManagerSA.cpp
@@ -0,0 +1,28 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CAESoundManagerSA.cpp
* PURPOSE: Audio engine sound manager
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"

#define FUNC_CAESoundManager__CancelSoundsInBankSlot 0x4EFC60

CAESoundManagerSA* g_pAESoundManagerSA = nullptr;

CAESoundManagerSA::CAESoundManagerSA ( CAESoundManagerSAInterface * pInterface )
: m_pInterface { pInterface }
{
g_pAESoundManagerSA = this;
}

void CAESoundManagerSA::CancelSoundsInBankSlot ( uint uiGroup, uint uiIndex )
{
using CAESoundManager__CancelSoundsInBankSlot = CAESound * ( __thiscall * ) ( CAESoundManagerSAInterface *, uint, uint );
static auto pCancelSoundsInBankSlot = reinterpret_cast < CAESoundManager__CancelSoundsInBankSlot > ( FUNC_CAESoundManager__CancelSoundsInBankSlot );
pCancelSoundsInBankSlot ( m_pInterface, uiGroup, uiIndex );
}
32 changes: 32 additions & 0 deletions Client/game_sa/CAESoundManagerSA.h
@@ -0,0 +1,32 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CAESoundManagerSA.h
* PURPOSE: Header file for audio engine sound manager class
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
#pragma once

#include <game/CAESoundManager.h>

#define CLASS_CAESoundManager 0xB62CB0

class CAESoundManagerSAInterface
{

};

class CAESoundManagerSA : public CAESoundManager
{
public:
CAESoundManagerSA ( CAESoundManagerSAInterface * pInterface );

public:
virtual void CancelSoundsInBankSlot ( uint uiGroup, uint uiIndex ) override;

private:
CAESoundManagerSAInterface * m_pInterface;
};
20 changes: 4 additions & 16 deletions Client/game_sa/CAudioEngineSA.cpp
Expand Up @@ -21,12 +21,8 @@ void HOOK_CAEAmbienceTrackManager_CheckForPause ();
DWORD RETURN_CAESoundManager_RequestNewSound = 0x4EFB15;
void HOOK_CAESoundManager_RequestNewSound();

#define FUNC_CAESoundManager__CancelSoundsInBankSlot 0x4EFC60
#define VAR_pAESoundManager 0xB62CB0

class CAESoundManager;

CAudioEngineSA* g_pAudioSA = NULL;
extern CAESoundManagerSA* g_pAESoundManagerSA;

CAudioEngineSA::CAudioEngineSA ( CAudioEngineSAInterface * pInterface )
{
Expand Down Expand Up @@ -468,29 +464,21 @@ void _declspec(naked) HOOK_CAEAmbienceTrackManager_CheckForPause ()
//

// uiIndex = -1 for all in group
void CAudioEngineSA::SetWorldSoundEnabled ( uint uiGroup, uint uiIndex, bool bEnabled, bool bForceCancel )
void CAudioEngineSA::SetWorldSoundEnabled ( uint uiGroup, uint uiIndex, bool bEnabled, bool bImmediate )
{
uint uiFirst = ( uiGroup << 8 ) + ( uiIndex != -1 ? uiIndex : 0 );
uint uiLast = ( uiGroup << 8 ) + ( uiIndex != -1 ? uiIndex : 255 );
if ( !bEnabled )
{
m_DisabledWorldSounds.SetRange ( uiFirst, uiLast - uiFirst + 1 );

if ( bForceCancel )
CancelSoundsInBankSlot ( uiGroup, uiIndex );
if ( bImmediate )
g_pAESoundManagerSA->CancelSoundsInBankSlot ( uiGroup, uiIndex );
}
else
m_DisabledWorldSounds.UnsetRange ( uiFirst, uiLast - uiFirst + 1 );
}

static auto CancelSoundsInBankSlot ( uint uiGroup, uint uiIndex )
{
using CAESoundManager__CancelSoundsInBankSlot = CAESound * ( __thiscall * ) ( CAESoundManager *, uint, uint );
static auto pAESoundManager = reinterpret_cast < CAESoundManager * > ( VAR_pAESoundManager );
static auto pCancelSoundsInBankSlot = reinterpret_cast < CAESoundManager__CancelSoundsInBankSlot > ( FUNC_CAESoundManager__CancelSoundsInBankSlot );
return pCancelSoundsInBankSlot ( pAESoundManager, uiGroup, uiIndex );
}

// uiIndex = -1 for all in group
bool CAudioEngineSA::IsWorldSoundEnabled ( uint uiGroup, uint uiIndex )
{
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CAudioEngineSA.h
Expand Up @@ -142,7 +142,7 @@ class CAudioEngineSA : public CAudioEngine
VOID SetAmbientSoundEnabled ( eAmbientSoundType eType, bool bEnabled );
bool IsAmbientSoundEnabled ( eAmbientSoundType eType );
void ResetAmbientSounds ( void );
VOID SetWorldSoundEnabled ( uint uiGroup, uint uiIndex, bool bEnabled, bool bForceCancel );
VOID SetWorldSoundEnabled ( uint uiGroup, uint uiIndex, bool bEnabled, bool bImmediate );
bool IsWorldSoundEnabled ( uint uiGroup, uint uiIndex );
void ResetWorldSounds ( void );
void SetWorldSoundHandler ( WorldSoundHandler * pHandler );
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CGameSA.cpp
Expand Up @@ -67,6 +67,7 @@ CGameSA::CGameSA()
DEBUG_TRACE("CGameSA::CGameSA()");
this->m_pAudioEngine = new CAudioEngineSA((CAudioEngineSAInterface*)CLASS_CAudioEngine);
this->m_pAEAudioHardware = new CAEAudioHardwareSA((CAEAudioHardwareSAInterface*)CLASS_CAEAudioHardware);
this->m_pAESoundManager = new CAESoundManagerSA((CAESoundManagerSAInterface*)CLASS_CAESoundManager);
this->m_pAudioContainer = new CAudioContainerSA();
this->m_pWorld = new CWorldSA();
this->m_pPools = new CPoolsSA();
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CGameSA.h
Expand Up @@ -136,6 +136,7 @@ class CGameSA : public CGame
inline CAERadioTrackManager * GetAERadioTrackManager() { DEBUG_TRACE("CAERadioTrackManager * GetAERadioTrackManager()");return m_pCAERadioTrackManager; };
inline CAudioEngine * GetAudioEngine() { DEBUG_TRACE("CAudio * GetAudioEngine()");return m_pAudioEngine; };
inline CAEAudioHardware * GetAEAudioHardware() { DEBUG_TRACE("CAEAudioHardware * GetAEAudioHardware()");return m_pAEAudioHardware; };
inline CAESoundManager * GetAESoundManager ( ) override { return m_pAESoundManager; }
inline CAudioEngine * GetAudio() { DEBUG_TRACE("CAudio * GetAudioEngine()");return m_pAudioEngine; };
inline CAudioContainer * GetAudioContainer() { DEBUG_TRACE("CAudio * GetAudioContainer()");return m_pAudioContainer; };
inline CMenuManager * GetMenuManager() { DEBUG_TRACE("CMenuManager * GetMenuManager()");return m_pMenuManager; };
Expand Down Expand Up @@ -298,6 +299,7 @@ class CGameSA : public CGame
CAERadioTrackManager * m_pCAERadioTrackManager;
CAudioEngine * m_pAudioEngine;
CAEAudioHardware * m_pAEAudioHardware;
CAESoundManager * m_pAESoundManager;
CAudioContainer * m_pAudioContainer;
CMenuManager * m_pMenuManager;
CText * m_pText;
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/StdInc.h
Expand Up @@ -61,6 +61,7 @@
#include "CAudioEngineSA.h"
#include "CAEAudioHardwareSA.h"
#include "CAEVehicleAudioEntitySA.h"
#include "CAESoundManagerSA.h"
#include "CAudioContainerSA.h"
#include "CPlayerInfoSA.h"
#include "CPopulationSA.h"
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -4276,9 +4276,9 @@ bool CStaticFunctionDefinitions::ResetAmbientSounds ( void )
}


bool CStaticFunctionDefinitions::SetWorldSoundEnabled ( uint uiGroup, uint uiIndex, bool bMute, bool bForceCancel )
bool CStaticFunctionDefinitions::SetWorldSoundEnabled ( uint uiGroup, uint uiIndex, bool bMute, bool bImmediate )
{
g_pGame->GetAudio ()->SetWorldSoundEnabled ( uiGroup, uiIndex, bMute, bForceCancel );
g_pGame->GetAudio ()->SetWorldSoundEnabled ( uiGroup, uiIndex, bMute, bImmediate );
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Expand Up @@ -334,7 +334,7 @@ class CStaticFunctionDefinitions
static bool SetAmbientSoundEnabled ( eAmbientSoundType eType, bool bMute );
static bool IsAmbientSoundEnabled ( eAmbientSoundType eType, bool& bOutMute );
static bool ResetAmbientSounds ( void );
static bool SetWorldSoundEnabled ( uint uiGroup, uint uiIndex, bool bMute, bool bForceCancel );
static bool SetWorldSoundEnabled ( uint uiGroup, uint uiIndex, bool bMute, bool bImmediate );
static bool IsWorldSoundEnabled ( uint uiGroup, uint uiIndex, bool& bOutMute );
static bool ResetWorldSounds ( void );
static bool PlaySFX ( CResource* pResource, eAudioLookupIndex containerIndex, int iBankIndex, int iAudioIndex, bool bLoop, CClientSound*& outSound );
Expand Down
8 changes: 4 additions & 4 deletions Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp
Expand Up @@ -1431,19 +1431,19 @@ int CLuaAudioDefs::ResetAmbientSounds ( lua_State* luaVM )

int CLuaAudioDefs::SetWorldSoundEnabled ( lua_State* luaVM )
{
// setWorldSoundEnabled ( int group, [int index, ], bool enable [, bool forceCancel = false ] )
int group; int index = -1; bool bEnabled; bool bForceCancel;
// setWorldSoundEnabled ( int group, [int index, ], bool enable [, bool immediate = false ] )
int group; int index = -1; bool bEnabled; bool bImmediate;

CScriptArgReader argStream ( luaVM );
argStream.ReadNumber ( group );
if ( !argStream.NextIsBool () )
argStream.ReadNumber ( index );
argStream.ReadBool ( bEnabled );
argStream.ReadBool ( bForceCancel, false );
argStream.ReadBool ( bImmediate, false );

if ( !argStream.HasErrors () )
{
if ( CStaticFunctionDefinitions::SetWorldSoundEnabled ( group, index, bEnabled, bForceCancel ) )
if ( CStaticFunctionDefinitions::SetWorldSoundEnabled ( group, index, bEnabled, bImmediate ) )
{
lua_pushboolean ( luaVM, true );
return 1;
Expand Down
17 changes: 17 additions & 0 deletions Client/sdk/game/CAESoundManager.h
@@ -0,0 +1,17 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: sdk/game/CAESoundManager.h
* PURPOSE: Game audio engine manager interface
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
#pragma once

class CAESoundManager
{
public:
virtual void CancelSoundsInBankSlot ( uint uiGroup, uint uiIndex ) = 0;
};
2 changes: 2 additions & 0 deletions Client/sdk/game/CGame.h
Expand Up @@ -26,6 +26,7 @@ typedef void ( InRenderer ) ( void );
#include "CAnimManager.h"
#include "CAudioEngine.h"
#include "CAEAudioHardware.h"
#include "CAESoundManager.h"
#include "CAEVehicleAudioEntity.h"
#include "CAudioContainer.h"
#include "CCam.h"
Expand Down Expand Up @@ -139,6 +140,7 @@ class __declspec(novtable) CGame
virtual CAERadioTrackManager* GetAERadioTrackManager()=0;
virtual CAudioEngine * GetAudioEngine()=0;
virtual CAEAudioHardware * GetAEAudioHardware()=0;
virtual CAESoundManager * GetAESoundManager ( ) = 0;
virtual CAudioEngine * GetAudio()=0;
virtual CAudioContainer * GetAudioContainer()=0;
virtual CMenuManager * GetMenuManager()=0;
Expand Down

0 comments on commit 4230804

Please sign in to comment.