From b04f3606120fbdf6b15afcaae2c07c2b7d70c15b Mon Sep 17 00:00:00 2001 From: rtw1x1 Date: Wed, 21 Jan 2026 12:39:38 +0000 Subject: [PATCH] fix: BGM failed to load --- src/PackLib/PackManager.cpp | 42 ++++++++++++++++------------- src/UserInterface/UserInterface.cpp | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/PackLib/PackManager.cpp b/src/PackLib/PackManager.cpp index bb2b6a8..b8ecf29 100644 --- a/src/PackLib/PackManager.cpp +++ b/src/PackLib/PackManager.cpp @@ -48,29 +48,30 @@ bool CPackManager::GetFileWithPool(std::string_view path, TPackFile& result, CBu thread_local std::string buf; NormalizePath(path, buf); + // First try to load from pack if (m_load_from_pack) { auto it = m_entries.find(buf); if (it != m_entries.end()) { return it->second.first->GetFileWithPool(it->second.second, result, pPool); } } - else { - std::ifstream ifs(buf, std::ios::binary); - if (ifs.is_open()) { - ifs.seekg(0, std::ios::end); - size_t size = ifs.tellg(); - ifs.seekg(0, std::ios::beg); - if (pPool) { - result = pPool->Acquire(size); - result.resize(size); - } else { - result.resize(size); - } + // Fallback to disk (for files not in packs, like bgm folder) + std::ifstream ifs(buf, std::ios::binary); + if (ifs.is_open()) { + ifs.seekg(0, std::ios::end); + size_t size = ifs.tellg(); + ifs.seekg(0, std::ios::beg); - if (ifs.read((char*)result.data(), size)) { - return true; - } + if (pPool) { + result = pPool->Acquire(size); + result.resize(size); + } else { + result.resize(size); + } + + if (ifs.read((char*)result.data(), size)) { + return true; } } @@ -82,13 +83,16 @@ bool CPackManager::IsExist(std::string_view path) const thread_local std::string buf; NormalizePath(path, buf); + // First check in pack entries if (m_load_from_pack) { auto it = m_entries.find(buf); - return it != m_entries.end(); - } - else { - return std::filesystem::exists(buf); + if (it != m_entries.end()) { + return true; + } } + + // Fallback to disk (for files not in packs, like bgm folder) + return std::filesystem::exists(buf); } void CPackManager::NormalizePath(std::string_view in, std::string& out) const diff --git a/src/UserInterface/UserInterface.cpp b/src/UserInterface/UserInterface.cpp index 9670490..63b0199 100644 --- a/src/UserInterface/UserInterface.cpp +++ b/src/UserInterface/UserInterface.cpp @@ -162,7 +162,7 @@ bool PackInitialize(const char * c_pszFolder) "sound", "sound_m", "sound2", - "bgm", + // "bgm", // BGM files are loaded directly from disk, not from pack "locale", "uiscript", "ETC",