From 852b9aac50ea1771b4cca6985a35a3e812e6cbdc Mon Sep 17 00:00:00 2001 From: GuglioIsStupid Date: Mon, 2 Mar 2026 12:27:32 -0500 Subject: [PATCH] Allow for loading of WAVE Audio files (#148) * Allow for loading of WAVE Audio files * Remove usage of strcpy and use _s versions of file opening * Update SoundEngine.cpp --------- Co-authored-by: void_17 <61356189+void2012@users.noreply.github.com> --- Minecraft.Client/Common/Audio/SoundEngine.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Minecraft.Client/Common/Audio/SoundEngine.cpp b/Minecraft.Client/Common/Audio/SoundEngine.cpp index 43d2059d..dfed0de7 100644 --- a/Minecraft.Client/Common/Audio/SoundEngine.cpp +++ b/Minecraft.Client/Common/Audio/SoundEngine.cpp @@ -1318,6 +1318,38 @@ void SoundEngine::playMusicUpdate() // char *SoundName = (char *)ConvertSoundPathToName(name); // strcat((char *)szStreamName,SoundName); + const bool isCD = (m_musicID >= m_iStream_CD_1); + const char* folder = isCD ? "cds/" : "music/"; + + FILE* pFile = nullptr; + if (fopen_s(&pFile, reinterpret_cast(m_szStreamName), "rb") == 0 && pFile) + { + fclose(pFile); + } + else + { + const char* extensions[] = { ".wav" }; // only wav works outside of binka files to my knowledge, i've only tested ogg, wav, mp3 and only wav worked out of the bunch + size_t count = sizeof(extensions) / sizeof(extensions[0]); + bool found = false; + + for (size_t i = 0; i < count; i++) + { + int n = sprintf_s(reinterpret_cast(m_szStreamName), 512, "%s%s%s%s", m_szMusicPath, folder, m_szStreamFileA[m_musicID], extensions[i]); + if (n < 0) continue; + + if (fopen_s(&pFile, reinterpret_cast(m_szStreamName), "rb") == 0 && pFile) + { + fclose(pFile); + found = true; + break; + } + } + + if (!found) + { + return; + } + } app.DebugPrintf("Starting streaming - %s\n",m_szStreamName);