From 5dc75c505ee66d5368e9b787f5e03df0cab5048d Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 11 Sep 2022 02:21:38 +0200 Subject: [PATCH] Close fastfiles handles during update + fixes --- data/cdata/ui_scripts/mods/__init__.lua | 4 ---- data/cdata/ui_scripts/patches/__init__.lua | 2 +- src/client/component/fastfiles.cpp | 18 +++++++++++++++++- src/client/component/fastfiles.hpp | 2 ++ src/client/component/updater.cpp | 9 +++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/data/cdata/ui_scripts/mods/__init__.lua b/data/cdata/ui_scripts/mods/__init__.lua index 5c75897c..ca2d3da9 100644 --- a/data/cdata/ui_scripts/mods/__init__.lua +++ b/data/cdata/ui_scripts/mods/__init__.lua @@ -1,5 +1 @@ require("loading") - -if (Engine.InFrontend()) then - require("download") -end diff --git a/data/cdata/ui_scripts/patches/__init__.lua b/data/cdata/ui_scripts/patches/__init__.lua index b5a19097..edc0f5b2 100644 --- a/data/cdata/ui_scripts/patches/__init__.lua +++ b/data/cdata/ui_scripts/patches/__init__.lua @@ -3,7 +3,7 @@ if (game:issingleplayer()) then end if (Engine.InFrontend()) then - require("shaderdialog") + require("shader_dialog") require("gamemodes") require("no_mode_switch") require("disable_useless_things") diff --git a/src/client/component/fastfiles.cpp b/src/client/component/fastfiles.cpp index a5ae2c0b..563cad87 100644 --- a/src/client/component/fastfiles.cpp +++ b/src/client/component/fastfiles.cpp @@ -23,6 +23,8 @@ namespace fastfiles utils::hook::detour db_find_xasset_header_hook; game::dvar_t* g_dump_scripts; + std::vector fastfile_handles; + void db_try_load_x_file_internal(const char* zone_name, const int flags) { console::info("Loading fastfile %s\n", zone_name); @@ -189,7 +191,13 @@ namespace fastfiles } } - return CreateFileA(path.data(), 0x80000000, 1u, 0, 3u, 0x60000000u, 0); + const auto handle = CreateFileA(path.data(), 0x80000000, 1u, 0, 3u, 0x60000000u, 0); + if (handle != reinterpret_cast(-1)) + { + fastfile_handles.push_back(handle); + } + + return handle; } utils::hook::detour sys_createfile_hook; @@ -321,6 +329,14 @@ namespace fastfiles }), &callback, includeOverride); } + void close_fastfile_handles() + { + for (const auto& handle : fastfile_handles) + { + CloseHandle(handle); + } + } + class component final : public component_interface { public: diff --git a/src/client/component/fastfiles.hpp b/src/client/component/fastfiles.hpp index dbda02c7..154f57df 100644 --- a/src/client/component/fastfiles.hpp +++ b/src/client/component/fastfiles.hpp @@ -10,4 +10,6 @@ namespace fastfiles void enum_assets(const game::XAssetType type, const std::function& callback, const bool includeOverride); + + void close_fastfile_handles(); } diff --git a/src/client/component/updater.cpp b/src/client/component/updater.cpp index 6d765dfd..d19cdc8a 100644 --- a/src/client/component/updater.cpp +++ b/src/client/component/updater.cpp @@ -5,6 +5,7 @@ #include "scheduler.hpp" #include "dvars.hpp" #include "updater.hpp" +#include "fastfiles.hpp" #include "game/ui_scripting/execution.hpp" #include "version.h" @@ -508,6 +509,14 @@ namespace updater return data_.garbage_files; }); + update_data.access([](update_data_t& data_) + { + if (data_.restart_required) + { + fastfiles::close_fastfile_handles(); + } + }); + for (const auto& file : garbage_files) { try