From 0829fa8b015d21baaca2be8e3b9c438d18047556 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto <58637860+fedddddd@users.noreply.github.com> Date: Sun, 11 Sep 2022 16:26:11 +0200 Subject: [PATCH] Some fixes --- src/client/component/download.cpp | 20 +++++++++++++------- src/client/component/party.cpp | 21 ++++++--------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/client/component/download.cpp b/src/client/component/download.cpp index aa83c10a..5605eee1 100644 --- a/src/client/component/download.cpp +++ b/src/client/component/download.cpp @@ -66,6 +66,14 @@ namespace download return 0; } + + void menu_error(const std::string& error) + { + scheduler::once([=]() + { + party::menu_error(error); + }, scheduler::pipeline::lui); + } } void start_download(const game::netadr_s& target, const utils::info_string& info) @@ -81,7 +89,7 @@ namespace download } return scheduler::cond_continue; - }); + }, scheduler::pipeline::main); return; } @@ -94,7 +102,7 @@ namespace download const auto base = info.get("sv_wwwBaseUrl"); if (base.empty()) { - party::menu_error("Download failed: Server doesn't have 'sv_wwwBaseUrl' dvar set."); + menu_error("Download failed: Server doesn't have 'sv_wwwBaseUrl' dvar set."); return; } @@ -129,7 +137,7 @@ namespace download const auto data = utils::http::get_data(url, {}, {}, &progress_callback); if (!data.has_value()) { - party::menu_error("Download failed: An unknown error occurred, please try again."); + menu_error("Download failed: An unknown error occurred, please try again."); return; } @@ -141,7 +149,7 @@ namespace download const auto& result = data.value(); if (result.code != CURLE_OK) { - party::menu_error(utils::string::va("Download failed: %s (%i)\n", result.code, curl_easy_strerror(result.code))); + menu_error(utils::string::va("Download failed: %s (%i)\n", result.code, curl_easy_strerror(result.code))); return; } @@ -153,7 +161,6 @@ namespace download ui_scripting::notify("mod_download_done", {}); }, scheduler::pipeline::lui); - // reconnect back to target after download of mod is finished scheduler::once([=]() { party::connect(target); @@ -176,9 +183,8 @@ namespace download scheduler::once([]() { ui_scripting::notify("mod_download_done", {}); + party::menu_error("Download for server mod has been cancelled."); }, scheduler::pipeline::lui); - - party::menu_error("Download for server mod has been cancelled."); } } diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index 16cbabe7..df5abc11 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -155,7 +155,7 @@ namespace party const auto server_fs_game = utils::string::to_lower(info.get("fs_game")); if (!server_fs_game.starts_with("mods/") || server_fs_game.contains('.')) { - console::info("Invalid server fs_game value %s\n", server_fs_game.data()); + menu_error(utils::string::va("Invalid server fs_game value %s\n", server_fs_game.data())); return true; } @@ -218,21 +218,14 @@ namespace party void menu_error(const std::string& error) { - // print error to console console::error("%s\n", error.data()); - - scheduler::once([&]() + if (game::Menu_IsMenuOpenAndVisible(0, "popup_acceptinginvite")) { - // check if popup_acceptinginvite is open and close if so - if (game::Menu_IsMenuOpenAndVisible(0, "popup_acceptinginvite")) - { - utils::hook::invoke(0x26BE80_b, 0, "popup_acceptinginvite", 0, *game::hks::lua_state); // LUI_LeaveMenuByName - } + utils::hook::invoke(0x26BE80_b, 0, "popup_acceptinginvite", 0, *game::hks::lua_state); // LUI_LeaveMenuByName + } - // set ui error information - utils::hook::invoke(0x17D770_b, error.data(), "MENU_NOTICE"); // Com_SetLocalizedErrorMessage - utils::hook::set(0x2ED2F78_b, 1); - }, scheduler::pipeline::lui); + utils::hook::invoke(0x17D770_b, error.data(), "MENU_NOTICE"); // Com_SetLocalizedErrorMessage + *reinterpret_cast(0x2ED2F78_b) = 1; } void clear_sv_motd() @@ -745,8 +738,6 @@ namespace party return; } - // returning true doesn't exactly mean there is a error, but more or less means that we are cancelling the connection for more than one different reason. - // if there is a genuine error that occurs, menu_error is called within the function. if (download_mod(target, info)) { return;