diff --git a/game/gothic.cpp b/game/gothic.cpp index e7584bd13..bd1ec38df 100644 --- a/game/gothic.cpp +++ b/game/gothic.cpp @@ -100,13 +100,23 @@ Gothic::Gothic() { modFile.reset(new IniFile(mod)); } + std::vector modvdfs; if(modFile!=nullptr) { wrldDef = modFile->getS("SETTINGS","WORLD"); size_t split = wrldDef.rfind('\\'); if(split!=std::string::npos) wrldDef = wrldDef.substr(split+1); plDef = modFile->getS("SETTINGS","PLAYER"); + + std::u16string vdf = TextCodec::toUtf16(std::string(modFile->getS("FILES","VDF"))); + for (size_t start = 0, split = 0; split != std::string::npos; start = split+1) { + split = vdf.find(' ', start); + std::u16string mod = vdf.substr(start, split-start); + if (!mod.empty()) + modvdfs.push_back(mod); + } } + Resources::loadVdfs(modvdfs); if(wrldDef.empty()) { if(version().game==2) diff --git a/game/resources.cpp b/game/resources.cpp index 7c2cd9508..6e7cc3eea 100644 --- a/game/resources.cpp +++ b/game/resources.cpp @@ -102,9 +102,23 @@ Resources::Resources(Tempest::Device &device) Pixmap pm(1,1,Pixmap::Format::RGBA); fbZero = device.texture(pm); } + } +void Resources::loadVdfs(const std::vector& modvdfs) { std::vector archives; - detectVdf(archives,Gothic::inst().nestedPath({u"Data"},Dir::FT_Dir)); + inst->detectVdf(archives,Gothic::inst().nestedPath({u"Data"},Dir::FT_Dir)); + + // Remove all mod files, that are not listed in modvdfs + archives.erase(std::remove_if(archives.begin(), archives.end(), + [&modvdfs](const Archive& a){ + return a.isMod && modvdfs.end() == std::find_if(modvdfs.begin(), modvdfs.end(), + [&a](const std::u16string& modname) { + const std::u16string_view& full_path = a.name; + const std::u16string_view& file_name = modname; + return (0 == full_path.compare(full_path.length() - file_name.length(), + file_name.length(), file_name)); + }); + }), archives.end()); // addon archives first! std::stable_sort(archives.begin(),archives.end(),[](const Archive& a,const Archive& b){ @@ -115,8 +129,8 @@ Resources::Resources(Tempest::Device &device) }); for(auto& i:archives) - gothicAssets.loadVDF(i.name); - gothicAssets.finalizeLoad(); + inst->gothicAssets.loadVDF(i.name); + inst->gothicAssets.finalizeLoad(); //for(auto& i:gothicAssets.getKnownFiles()) // Log::i(i); diff --git a/game/resources.h b/game/resources.h index d6c0251d2..39b104eea 100644 --- a/game/resources.h +++ b/game/resources.h @@ -81,6 +81,7 @@ class Resources final { static Tempest::Device& device() { return inst->dev; } static const char* renderer(); + static void loadVdfs(const std::vector &modvdfs); static const Tempest::Sampler2d& shadowSampler();