From 7c17c66b1535ddd90511b1d0a3d4f341e610b192 Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Wed, 12 Oct 2022 23:40:17 +0200 Subject: [PATCH] More usermap fixes --- src/client/component/fastfiles.cpp | 32 +++++++++++++++--------------- src/client/component/fastfiles.hpp | 2 +- src/client/component/party.cpp | 20 ++++++++++++------- src/common/utils/string.cpp | 5 +++++ src/common/utils/string.hpp | 2 ++ 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/client/component/fastfiles.cpp b/src/client/component/fastfiles.cpp index 1e704fc6..28454cff 100644 --- a/src/client/component/fastfiles.cpp +++ b/src/client/component/fastfiles.cpp @@ -232,7 +232,7 @@ namespace fastfiles } utils::hook::detour sys_createfile_hook; - HANDLE sys_create_file_stub(game::Sys_Folder folder, const char* base_filename) + HANDLE sys_create_file(game::Sys_Folder folder, const char* base_filename, bool ignore_usermap) { const auto* fs_basepath = game::Dvar_FindVar("fs_basepath"); const auto* fs_game = game::Dvar_FindVar("fs_game"); @@ -264,10 +264,13 @@ namespace fastfiles return handle; } - const auto usermap = find_usermap(name); - if (usermap != INVALID_HANDLE_VALUE) + if (!ignore_usermap) { - return usermap; + const auto usermap = find_usermap(name); + if (usermap != INVALID_HANDLE_VALUE) + { + return usermap; + } } if (name.ends_with(".ff")) @@ -278,6 +281,11 @@ namespace fastfiles return handle; } + HANDLE sys_create_file_stub(game::Sys_Folder folder, const char* base_filename) + { + return sys_create_file(folder, base_filename, false); + } + utils::hook::detour db_file_exists_hook; bool db_file_exists_stub(const char* file, int a2) { @@ -396,11 +404,11 @@ namespace fastfiles } } - bool exists(const std::string& zone) + bool exists(const std::string& zone, bool ignore_usermap) { const auto is_localized = game::DB_IsLocalized(zone.data()); - const auto handle = game::Sys_CreateFile((is_localized ? game::SF_ZONE_LOC : game::SF_ZONE), - utils::string::va("%s.ff", zone.data())); + const auto handle = sys_create_file((is_localized ? game::SF_ZONE_LOC : game::SF_ZONE), + utils::string::va("%s.ff", zone.data()), ignore_usermap); if (handle != INVALID_HANDLE_VALUE) { @@ -474,15 +482,7 @@ namespace fastfiles bool is_stock_map(const std::string& name) { - for (auto map = &game::maps[0]; map->unk; ++map) - { - if (map->name == name) - { - return true; - } - } - - return false; + return fastfiles::exists(name, true); } class component final : public component_interface diff --git a/src/client/component/fastfiles.hpp b/src/client/component/fastfiles.hpp index 608983be..319d3e25 100644 --- a/src/client/component/fastfiles.hpp +++ b/src/client/component/fastfiles.hpp @@ -4,7 +4,7 @@ namespace fastfiles { - bool exists(const std::string& zone); + bool exists(const std::string& zone, bool ignore_usermap = false); std::string get_current_fastfile(); diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index d0e6d9f4..6e9e67b4 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -151,10 +151,14 @@ namespace party utils::hook::detour cl_disconnect_hook; - void cl_disconnect_stub(int showMainMenu) // possibly bool + void cl_disconnect_stub(int show_main_menu) // possibly bool { party::clear_sv_motd(); - cl_disconnect_hook.invoke(showMainMenu); + if (!game::VirtualLobby_Loaded()) + { + fastfiles::clear_usermap(); + } + cl_disconnect_hook.invoke(show_main_menu); } std::optional get_file_hash(const std::string& file) @@ -288,7 +292,7 @@ namespace party catch (const std::exception& e) { menu_error(e.what()); - return false; + return true; } return false; @@ -301,11 +305,11 @@ namespace party const std::string usermap_hash = game::MSG_ReadStringLine(msg, buffer, static_cast(sizeof(buffer))); - if (!fastfiles::is_stock_map(mapname)) + if (!game::SV_Loaded() && !fastfiles::is_stock_map(mapname)) { const auto filename = utils::string::va("usermaps\\%s\\%s.ff", mapname, mapname); const auto hash = get_file_hash(filename); - if (!hash.has_value() || hash.value() != usermap_hash) + if (!hash.has_value() || (usermap_hash.empty() || hash.value() != usermap_hash)) { command::execute("disconnect"); scheduler::once([] @@ -837,13 +841,15 @@ namespace party if (!fastfiles::is_stock_map(mapname)) { - const auto hash = get_file_hash(utils::string::va("usermaps/%s/%s.ff", mapname.data(), mapname.data())); + const auto hash = get_file_hash( + utils::string::va("usermaps\\%s\\%s.ff", mapname.data(), mapname.data())); if (hash.has_value()) { info.set("usermaphash", hash.value()); } - const auto load_file_hash = get_file_hash(utils::string::va("usermaps/%s/%s_load.ff", mapname.data(), mapname.data())); + const auto load_file_hash = get_file_hash( + utils::string::va("usermaps\\%s\\%s_load.ff", mapname.data(), mapname.data())); if (load_file_hash.has_value()) { info.set("usermaploadhash", load_file_hash.value()); diff --git a/src/common/utils/string.cpp b/src/common/utils/string.cpp index 422adc76..30e35e9d 100644 --- a/src/common/utils/string.cpp +++ b/src/common/utils/string.cpp @@ -180,4 +180,9 @@ namespace utils::string if (!exact && text.find(input) != std::string::npos) return true; return false; } + + bool is_numeric(const std::string& text) + { + return std::to_string(atoi(text.data())) == text; + } } diff --git a/src/common/utils/string.hpp b/src/common/utils/string.hpp index 322ce9ce..13bcbbf8 100644 --- a/src/common/utils/string.hpp +++ b/src/common/utils/string.hpp @@ -99,4 +99,6 @@ namespace utils::string std::string replace(std::string str, const std::string& from, const std::string& to); bool match_compare(const std::string& input, const std::string& text, const bool exact); + + bool is_numeric(const std::string& text); }