diff --git a/client/CMusicHandler.cpp b/client/CMusicHandler.cpp index 9dc57d8d2..84ee69c57 100644 --- a/client/CMusicHandler.cpp +++ b/client/CMusicHandler.cpp @@ -106,9 +106,6 @@ void CSoundHandler::init() if (initialized) { // Load sounds - sndh.add_file(std::string(GameConstants::DATA_DIR + "/Data/Heroes3.snd")); - sndh.add_file(std::string(GameConstants::DATA_DIR + "/Data/Heroes3-cd2.snd"), false); - sndh.add_file(std::string(GameConstants::DATA_DIR + "/Data/H3ab_ahd.snd")); Mix_ChannelFinished(soundFinishedCallbackC); } } @@ -140,12 +137,9 @@ Mix_Chunk *CSoundHandler::GetSoundChunk(soundBase::soundID soundID) return NULL; // Load and insert - int size; - const char *data = sndh.extract(it->second, size); - if (!data) - return NULL; + auto data = CResourceHandler::get()->loadData(ResourceID(std::string("SOUNDS/") + it->second, EResType::SOUND)); - SDL_RWops *ops = SDL_RWFromConstMem(data, size); + SDL_RWops *ops = SDL_RWFromMem(data.first.release(), data.second); Mix_Chunk *chunk; chunk = Mix_LoadWAV_RW(ops, 1); // will free ops diff --git a/client/CMusicHandler.h b/client/CMusicHandler.h index 11f3d7b22..fc4d6f83a 100644 --- a/client/CMusicHandler.h +++ b/client/CMusicHandler.h @@ -3,7 +3,6 @@ #include "CConfigHandler.h" #include "CSoundBase.h" #include "../lib/CCreatureHandler.h" -#include "CSndHandler.h" /* * CMusicHandler.h, part of VCMI engine @@ -63,7 +62,6 @@ public: class CSoundHandler: public CAudioBase { private: - CSndHandler sndh; soundBase::soundID getSoundID(const std::string &fileName); //update volume on configuration change SettingsListener listener; diff --git a/client/CSndHandler.cpp b/client/CSndHandler.cpp index a4dc7b8f1..a1341b8ba 100644 --- a/client/CSndHandler.cpp +++ b/client/CSndHandler.cpp @@ -89,31 +89,6 @@ void CMediaHandler::extract(std::string srcfile, std::string dstfile, bool caseS } } -#if 0 -// unused and not sure what it's supposed to do -MemberFile CMediaHandler::getFile(std::string name) -{ - MemberFile ret; - std::transform(name.begin(),name.end(),name.begin(),tolower); - for (size_t i=0;idata(); - ui32 numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]); - struct soundEntry *se = (struct soundEntry *)&data[4]; - - for (ui32 i=0; ifilename; - entry.offset = SDL_SwapLE32(se->offset); - entry.size = SDL_SwapLE32(se->size); - entry.data = mfile->data() + entry.offset; - - entries.push_back(entry); - fimap[entry.name] = i; - } -} - void CVidHandler::add_file(std::string fname) { boost::iostreams::mapped_file_source *mfile = NULL; diff --git a/client/CSndHandler.h b/client/CSndHandler.h index f617c34ac..940192603 100644 --- a/client/CSndHandler.h +++ b/client/CSndHandler.h @@ -28,14 +28,6 @@ struct MemberFile int length; }; -// sound entry structure in catalog -struct soundEntry -{ - char filename[40]; - Uint32 offset; /* little endian */ - Uint32 size; /* little endian */ -}; - // video entry structure in catalog struct videoEntry { @@ -64,16 +56,9 @@ public: void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file const char * extract (std::string srcfile, int & size); //return selecte file data, NULL if file doesn't exist void extract(int index, std::string dstfile); //saves selected file - MemberFile getFile(std::string name);//nie testowane - sprawdzic const char * extract (int index, int & size); //return selecte file - NIE TESTOWANE }; -class CSndHandler: public CMediaHandler -{ -public: - void add_file(std::string fname, bool important = true); //if not important, then we don't print warning when the file is missing -}; - class CVidHandler: public CMediaHandler { public: diff --git a/lib/Filesystem/CLodArchiveLoader.cpp b/lib/Filesystem/CLodArchiveLoader.cpp index e45f83e79..f211d3ad4 100644 --- a/lib/Filesystem/CLodArchiveLoader.cpp +++ b/lib/Filesystem/CLodArchiveLoader.cpp @@ -124,7 +124,8 @@ void CLodArchiveLoader::initVIDArchive(CFileInputStream & fileStream) else { VideoEntryBlock nextVidEntry = vidEntries[i + 1]; - entry.size = SDL_SwapLE32(nextVidEntry.offset) - entry.offset; + entry.realSize = SDL_SwapLE32(nextVidEntry.offset) - entry.offset; + entry.size = 0; } entries[entry.name] = entry; @@ -160,10 +161,15 @@ void CLodArchiveLoader::initSNDArchive(CFileInputStream & fileStream) SoundEntryBlock sndEntry = sndEntries[i]; ArchiveEntry entry; - entry.name = sndEntry.filename; - entry.offset = SDL_SwapLE32(sndEntry.offset); - entry.size = SDL_SwapLE32(sndEntry.size); + //for some reason entries in snd have format NAME\0WAV\0\0\0.... + //we need to replace first \0 with dot and trim line + entry.name = std::string(sndEntry.filename, 40); + entry.name[entry.name.find_first_of('\0')] = '.'; + entry.name.resize(entry.name.find_first_of('\0')); + entry.offset = SDL_SwapLE32(sndEntry.offset); + entry.realSize = SDL_SwapLE32(sndEntry.size); + entry.size = 0; entries[entry.name] = entry; } diff --git a/lib/Filesystem/CResourceLoader.cpp b/lib/Filesystem/CResourceLoader.cpp index 16274fd9b..c03fff92a 100644 --- a/lib/Filesystem/CResourceLoader.cpp +++ b/lib/Filesystem/CResourceLoader.cpp @@ -374,7 +374,6 @@ void CResourceHandler::loadFileSystem(const std::string fsConfigURI) void CResourceHandler::loadModsFilesystems() { - auto iterator = initialLoader->getIterator([](const ResourceID & ident) -> bool { std::string name = ident.getName();