Skip to content

Commit

Permalink
Read enabled .mod files from ini file (#285)
Browse files Browse the repository at this point in the history
* Read enabled modvdf files from ini
  • Loading branch information
matthiakl authored Aug 22, 2022
1 parent 9dbb4f2 commit 2af6279
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
10 changes: 10 additions & 0 deletions game/gothic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,23 @@ Gothic::Gothic() {
modFile.reset(new IniFile(mod));
}

std::vector<std::u16string> 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)
Expand Down
20 changes: 17 additions & 3 deletions game/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::u16string>& modvdfs) {
std::vector<Archive> 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){
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions game/resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Resources final {

static Tempest::Device& device() { return inst->dev; }
static const char* renderer();
static void loadVdfs(const std::vector<std::u16string> &modvdfs);

static const Tempest::Sampler2d& shadowSampler();

Expand Down

0 comments on commit 2af6279

Please sign in to comment.