Skip to content

Commit bdb8013

Browse files
Add client setting to toggle internet sound streams (#834)
* Add new client audio function isSoundStopped Helps to determine whether a sound is actually created. * Add new client setting allow_internet_sound_streams - When disabled, it disables creation of internet sound streams, and destroys existing streams, keeps sound elements, and triggers "onClientSoundStopped" with "disabled" reason - When enabled, it enables creation of internet sound streams, and creates missing streams and triggers "onClientSoundStarted" with "enabled" reason - Adds new reason to "onClientSoundStarted": "enabled", which is returned if setting is changed to true - Adds new reason to "onClientSoundStopped": "disabled", which is returned if setting is changed to false * Remove test tip text that was meant to be for the Advanced tab * Rename internet sound streams setting to external sounds * Update make_uname.bat * Remove isSoundStopped Let's rather make a generic client config getter function. * Fix crash on stream in if sound was not created due to client setting
1 parent 4dc2335 commit bdb8013

File tree

8 files changed

+89
-16
lines changed

8 files changed

+89
-16
lines changed

Client/core/CClientVariables.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: core/CClientVariables.cpp
66
* PURPOSE: Managed storage of client variables (cvars)
@@ -331,6 +331,7 @@ void CClientVariables::LoadDefaults()
331331
DEFAULT("high_detail_peds", 0); // Disable rendering high detail peds all the time
332332
DEFAULT("fast_clothes_loading", 1); // 0-off 1-auto 2-on
333333
DEFAULT("allow_screen_upload", 1); // 0-off 1-on
334+
DEFAULT("allow_external_sounds", 1); // 0-off 1-on
334335
DEFAULT("max_clientscript_log_kb", 5000); // Max size in KB (0-No limit)
335336
DEFAULT("display_fullscreen_style", 0); // 0-standard 1-borderless 2-borderless keep res 3-borderless stretch
336337
DEFAULT("display_windowed", 0); // 0-off 1-on

Client/core/CSettings.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ void CSettings::CreateGUI()
376376
m_pCheckBoxAllowScreenUpload->GetPosition(vecTemp, false);
377377
m_pCheckBoxAllowScreenUpload->AutoSize(NULL, 20.0f);
378378

379+
m_pCheckBoxAllowExternalSounds = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabMultiplayer, _("Allow external sounds"), true));
380+
m_pCheckBoxAllowExternalSounds->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f));
381+
m_pCheckBoxAllowExternalSounds->GetPosition(vecTemp, false);
382+
m_pCheckBoxAllowExternalSounds->AutoSize(NULL, 20.0f);
383+
379384
m_pCheckBoxCustomizedSAFiles = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabMultiplayer, _("Use customized GTA:SA files"), true));
380385
m_pCheckBoxCustomizedSAFiles->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f));
381386
m_pCheckBoxCustomizedSAFiles->GetPosition(vecTemp, false);
@@ -1213,6 +1218,7 @@ void CSettings::CreateGUI()
12131218
m_pComboFxQuality->SetSelectionHandler(GUI_CALLBACK(&CSettings::OnFxQualityChanged, this));
12141219
m_pCheckBoxVolumetricShadows->SetClickHandler(GUI_CALLBACK(&CSettings::OnVolumetricShadowsClick, this));
12151220
m_pCheckBoxAllowScreenUpload->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowScreenUploadClick, this));
1221+
m_pCheckBoxAllowExternalSounds->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowExternalSoundsClick, this));
12161222
m_pCheckBoxCustomizedSAFiles->SetClickHandler(GUI_CALLBACK(&CSettings::OnCustomizedSAFilesClick, this));
12171223
m_pCheckBoxWindowed->SetClickHandler(GUI_CALLBACK(&CSettings::OnWindowedClick, this));
12181224
m_pCheckBoxDPIAware->SetClickHandler(GUI_CALLBACK(&CSettings::OnDPIAwareClick, this));
@@ -1506,6 +1512,11 @@ void CSettings::UpdateVideoTab()
15061512
CVARS_GET("allow_screen_upload", bAllowScreenUploadEnabled);
15071513
m_pCheckBoxAllowScreenUpload->SetSelected(bAllowScreenUploadEnabled);
15081514

1515+
// Allow external sounds
1516+
bool bAllowExternalSoundsEnabled;
1517+
CVARS_GET("allow_external_sounds", bAllowExternalSoundsEnabled);
1518+
m_pCheckBoxAllowExternalSounds->SetSelected(bAllowExternalSoundsEnabled);
1519+
15091520
// Customized sa files
15101521
m_pCheckBoxCustomizedSAFiles->SetSelected(GetApplicationSettingInt("customized-sa-files-request") != 0);
15111522
m_pCheckBoxCustomizedSAFiles->SetVisible(GetApplicationSettingInt("customized-sa-files-show") != 0);
@@ -3333,6 +3344,10 @@ void CSettings::SaveData()
33333344
bool bAllowScreenUploadEnabled = m_pCheckBoxAllowScreenUpload->GetSelected();
33343345
CVARS_SET("allow_screen_upload", bAllowScreenUploadEnabled);
33353346

3347+
// Allow external sounds
3348+
bool bAllowExternalSoundsEnabled = m_pCheckBoxAllowExternalSounds->GetSelected();
3349+
CVARS_SET("allow_external_sounds", bAllowExternalSoundsEnabled);
3350+
33363351
// Grass
33373352
bool bGrassEnabled = m_pCheckBoxGrass->GetSelected();
33383353
CVARS_SET("grass", bGrassEnabled);
@@ -4336,6 +4351,24 @@ bool CSettings::OnAllowScreenUploadClick(CGUIElement* pElement)
43364351
return true;
43374352
}
43384353

4354+
//
4355+
// AllowExternalSounds
4356+
//
4357+
bool CSettings::OnAllowExternalSoundsClick(CGUIElement* pElement)
4358+
{
4359+
if (!m_pCheckBoxAllowExternalSounds->GetSelected() && !m_bShownAllowExternalSoundsMessage)
4360+
{
4361+
m_bShownAllowExternalSoundsMessage = true;
4362+
SString strMessage;
4363+
strMessage +=
4364+
_("Some scripts may play sounds, such as radio, from the internet."
4365+
"\n\nDisabling this setting may decrease network"
4366+
"\nbandwidth consumption.\n");
4367+
CCore::GetSingleton().ShowMessageBox(_("EXTERNAL SOUNDS"), strMessage, MB_BUTTON_OK | MB_ICON_INFO);
4368+
}
4369+
return true;
4370+
}
4371+
43394372
//
43404373
// CustomizedSAFiles
43414374
//

Client/core/CSettings.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: core/CSettings.h
66
* PURPOSE: Header file for in-game settings window class
@@ -152,6 +152,7 @@ class CSettings
152152
CGUICheckBox* m_pCheckBoxDeviceSelectionDialog;
153153
CGUICheckBox* m_pCheckBoxShowUnsafeResolutions;
154154
CGUICheckBox* m_pCheckBoxAllowScreenUpload;
155+
CGUICheckBox* m_pCheckBoxAllowExternalSounds;
155156
CGUICheckBox* m_pCheckBoxCustomizedSAFiles;
156157
CGUICheckBox* m_pCheckBoxGrass;
157158
CGUICheckBox* m_pCheckBoxHeatHaze;
@@ -377,6 +378,7 @@ class CSettings
377378
bool OnFxQualityChanged(CGUIElement* pElement);
378379
bool OnVolumetricShadowsClick(CGUIElement* pElement);
379380
bool OnAllowScreenUploadClick(CGUIElement* pElement);
381+
bool OnAllowExternalSoundsClick(CGUIElement* pElement);
380382
bool OnCustomizedSAFilesClick(CGUIElement* pElement);
381383
bool ShowUnsafeResolutionsClick(CGUIElement* pElement);
382384
bool OnWindowedClick(CGUIElement* pElement);
@@ -443,6 +445,7 @@ class CSettings
443445
DWORD m_dwFrameCount;
444446
bool m_bShownVolumetricShadowsWarning;
445447
bool m_bShownAllowScreenUploadMessage;
448+
bool m_bShownAllowExternalSoundsMessage;
446449
int m_iMaxAnisotropic;
447450

448451
std::list<SKeyBindSection*> m_pKeyBindSections;

Client/mods/deathmatch/logic/CClientSound.cpp

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
4-
* (Shared logic for modifications)
3+
* PROJECT: Multi Theft Auto
54
* LICENSE: See LICENSE in the top level directory
6-
* FILE: mods/shared_logic/CClientSound.cpp
5+
* FILE: mods/deathmatch/logic/CClientSound.cpp
76
* PURPOSE: Sound entity class
87
*
98
*****************************************************************************/
@@ -63,12 +62,15 @@ void CClientSound::DistanceStreamIn()
6362
{
6463
if (!m_pAudio)
6564
{
66-
Create();
67-
m_pSoundManager->OnDistanceStreamIn(this);
65+
// If the sound was successfully created, we stream it in
66+
if (Create())
67+
{
68+
m_pSoundManager->OnDistanceStreamIn(this);
6869

69-
// Call Stream In event
70-
CLuaArguments Arguments;
71-
CallEvent("onClientElementStreamIn", Arguments, true);
70+
// Call Stream In event
71+
CLuaArguments Arguments;
72+
CallEvent("onClientElementStreamIn", Arguments, true);
73+
}
7274
}
7375
}
7476

@@ -104,6 +106,11 @@ bool CClientSound::Create()
104106
if (m_pAudio)
105107
return false;
106108

109+
// If we're not allowed to play a stream, stop here
110+
if (m_bStream)
111+
if (!g_pCore->GetCVars()->GetValue("allow_external_sounds", true))
112+
return false;
113+
107114
// Initial state
108115
if (!m_pBuffer)
109116
m_pAudio = new CBassAudio(m_bStream, m_strPath, m_bLoop, m_bThrottle, m_b3D);
@@ -626,6 +633,35 @@ bool CClientSound::IsFxEffectEnabled(uint uiFxEffect)
626633
////////////////////////////////////////////////////////////
627634
void CClientSound::Process3D(const CVector& vecPlayerPosition, const CVector& vecCameraPosition, const CVector& vecLookAt)
628635
{
636+
// If this is a stream
637+
if (m_bStream)
638+
{
639+
// Check if we're allowed to play streams, otherwise just destroy the stream
640+
// This way we can start the stream without the need to handle this edge case in scripting
641+
if (g_pCore->GetCVars()->GetValue("allow_external_sounds", true))
642+
{
643+
if (!m_pAudio)
644+
{
645+
// call onClientSoundStarted
646+
CLuaArguments Arguments;
647+
Arguments.PushString("enabled"); // Reason
648+
CallEvent("onClientSoundStarted", Arguments, false);
649+
Create();
650+
}
651+
}
652+
else
653+
{
654+
if (m_pAudio)
655+
{
656+
// call onClientSoundStopped
657+
CLuaArguments Arguments;
658+
Arguments.PushString("disabled"); // Reason
659+
CallEvent("onClientSoundStopped", Arguments, false);
660+
Destroy();
661+
}
662+
}
663+
}
664+
629665
// Update 3D things if required
630666
if (m_b3D)
631667
{

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
66
* PURPOSE: Scripting function processing

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: mods/deathmatch/logic/CStaticFunctionDefinitions.h
66
* PURPOSE: Header for static function definitions class

Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.x
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
5-
* FILE: mods/shared_logic/luadefs/CLuaAudioDefs.cpp
5+
* FILE: mods/deathmatch/logic/luadefs/CLuaAudioDefs.cpp
66
* PURPOSE: Lua audio definitions class
77
*
88
* Multi Theft Auto is available from http://www.multitheftauto.com/

Client/mods/deathmatch/logic/luadefs/CLuaAudioDefs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.x
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
5-
* FILE: mods/shared_logic/luadefs/CLuaAudioDefs.h
5+
* FILE: mods/deathmatch/logic/luadefs/CLuaAudioDefs.h
66
* PURPOSE: Lua audio definitions class header
77
*
88
* Multi Theft Auto is available from http://www.multitheftauto.com/

0 commit comments

Comments
 (0)