From a7dcdcaec38bfdeb5cc7304e3d0600c8fb2aae60 Mon Sep 17 00:00:00 2001 From: "Marco Antonio J. Costa" Date: Wed, 22 Jul 2026 12:15:55 -0300 Subject: [PATCH] let PlayJA2SampleFromFile take a filename it will not write to The parameter was STR8, a mutable char*, for a filename the function only reads: it runs strstr over it and hands it to SoundPlay. environment.cpp picks between two of them at runtime, PlayJA2SampleFromFile( Chance( 50 ) ? "Sounds\\WATERSNAKE_ATTACK_01.WAV" : "Sounds\\WATERSNAKE_ATTACK_02.WAV", ... ); and the conditional is a const char*, which STR8 has no room for. Literals passed on their own are still accepted under the MSVC rules, which is why only these two calls ever failed. The cast at the call to SoundPlay was already written as (STR) and is left as it is. SoundPlay, SoundPlayStreamed and SoundLoadSample below it all still take STR, so making them const is a separate piece of work and a much larger one; until then that cast is where const stops. No call site changes. The (char*) cast at LuaInitNPCs.cpp:11640 is now unnecessary but still valid, and is left for whoever next edits that line. Verification: ninja -C build parse # both environment.cpp sites gone ninja -C build -k 0 # Release, four applications, green ninja -C build-debug -k 0 # Debug, four applications, green Co-Authored-By: Claude Opus 4.8 --- Utils/Sound Control.cpp | 2 +- Utils/Sound Control.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Utils/Sound Control.cpp b/Utils/Sound Control.cpp index a25e66fbd..08b61d036 100644 --- a/Utils/Sound Control.cpp +++ b/Utils/Sound Control.cpp @@ -496,7 +496,7 @@ UINT32 PlayWeaponSound(STR8 szFileName, UINT32 ubVolume, UINT32 uiPan) return(SoundPlay((STR)szFileName, &spParms)); } -UINT32 PlayJA2SampleFromFile( STR8 szFileName, UINT32 usRate, UINT32 ubVolume, UINT32 ubLoops, UINT32 uiPan ) +UINT32 PlayJA2SampleFromFile( const CHAR8* szFileName, UINT32 usRate, UINT32 ubVolume, UINT32 ubLoops, UINT32 uiPan ) { //SoundLog((CHAR8 *)String(" Play sound %s on volume %d", szFileName, ubVolume)); // does the same thing as PlayJA2Sound, but one only has to pass the filename, not the index of the sound array diff --git a/Utils/Sound Control.h b/Utils/Sound Control.h index 655357938..1506508bc 100644 --- a/Utils/Sound Control.h +++ b/Utils/Sound Control.h @@ -420,7 +420,7 @@ BOOLEAN ShutdownJA2Sound( ); UINT32 PlayJA2Sample( UINT32 usNum, UINT32 usRate, UINT32 ubVolume, UINT32 ubLoops, UINT32 uiPan ); UINT32 PlayJA2StreamingSample( UINT32 usNum, UINT32 usRate, UINT32 ubVolume, UINT32 ubLoops, UINT32 uiPan ); -UINT32 PlayJA2SampleFromFile( STR8 szFileName, UINT32 usRate, UINT32 ubVolume, UINT32 ubLoops, UINT32 uiPan ); +UINT32 PlayJA2SampleFromFile( const CHAR8* szFileName, UINT32 usRate, UINT32 ubVolume, UINT32 ubLoops, UINT32 uiPan ); UINT32 PlayWeaponSound(STR8 szFileName, UINT32 ubVolume, UINT32 uiPan); UINT32 PlayJA2StreamingSampleFromFile( STR8 szFileName, UINT32 usRate, UINT32 ubVolume, UINT32 ubLoops, UINT32 uiPan, SOUND_STOP_CALLBACK EndsCallback );