Skip to content

Commit

Permalink
fix(Vfs): write the current date to created VDF files
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Jun 9, 2024
1 parent 748962d commit 5e60a3a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Vfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ namespace zenkit {
return count;
}

static std::uint32_t vfs_unix_to_dos_time(std::time_t unix_) noexcept {
tm t = *gmtime(&unix_);

uint32_t dos = 0;
dos |= (t.tm_year - 80) << 25;
dos |= (t.tm_mon + 1) << 21;
dos |= (t.tm_mday) << 16;
dos |= (t.tm_hour) << 11;
dos |= (t.tm_min) << 5;
dos |= (t.tm_sec / 2);

return dos;
}

void Vfs::save(Write* w, GameVersion version) const {
std::vector<std::byte> catalog;
auto write_catalog = Write::to(&catalog);
Expand Down Expand Up @@ -346,7 +360,7 @@ namespace zenkit {
w->write_string(version == GameVersion::GOTHIC_1 ? VFS_DISK_SIGNATURE_G1 : VFS_DISK_SIGNATURE_G2);
w->write_uint(files);
w->write_uint(index);
w->write_uint(0);
w->write_uint(vfs_unix_to_dos_time(time(nullptr)));
w->write_uint(off + catalog.size());
w->write_uint(header_size);
w->write_uint(80);
Expand Down

0 comments on commit 5e60a3a

Please sign in to comment.