From de26138f5b3a03d3caf0bfc79862d3b3a58ceb94 Mon Sep 17 00:00:00 2001 From: m Date: Thu, 27 Oct 2022 21:48:00 -0500 Subject: [PATCH] yes/no popup before download --- src/client/component/party.cpp | 74 ++++++++++++++++++---- src/client/component/ui_scripting.cpp | 12 ++-- src/client/component/ui_scripting.hpp | 2 + src/client/game/ui_scripting/execution.cpp | 3 +- 4 files changed, 71 insertions(+), 20 deletions(-) diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index cb033e50..615c516d 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -11,6 +11,7 @@ #include "fastfiles.hpp" #include "game/game.hpp" +#include "game/ui_scripting/execution.hpp" #include "steam/steam.hpp" @@ -48,6 +49,9 @@ namespace party {".arena", "usermaparenahash", true}, }; + game::netadr_s saved_target; + utils::info_string saved_info_string; + void perform_game_initialization() { command::execute("onlinegame 1", true); @@ -288,9 +292,51 @@ namespace party return false; } + void close_joining_popups() + { + if (game::Menu_IsMenuOpenAndVisible(0, "popup_acceptinginvite")) + { + command::execute("lui_close popup_acceptinginvite", false); + } + + if (game::Menu_IsMenuOpenAndVisible(0, "generic_waiting_popup_")) + { + command::execute("lui_close generic_waiting_popup_", false); + } + } + + bool download_files(const game::netadr_s& target, const utils::info_string& info, bool should_download); + + int confirm_user_download_cb(game::hks::lua_State* state) + { + const auto response = state->m_apistack.base[0].v.boolean; + if (!response) + { + return 0; + } + + download_files(saved_target, saved_info_string, true); + return 1; + } + + void confirm_user_download(const game::netadr_s& target, const utils::info_string& info) + { + const auto LUI = ui_scripting::get_globals().get("LUI").as(); + const auto yes_no_popup_func = LUI.get("yesnopopup").as(); + + const ui_scripting::table data_table{}; + data_table.set("title", game::UI_SafeTranslateString("MENU_NOTICE")); + data_table.set("text", std::format("Would you like to install required 3rd-party content for this server? (from {})", info.get("sv_wwwBaseUrl"))); + data_table.set("callback", confirm_user_download_cb); + + close_joining_popups(); + + yes_no_popup_func(data_table); + } + bool needs_vid_restart = false; - bool download_files(const game::netadr_s& target, const utils::info_string& info) + bool download_files(const game::netadr_s& target, const utils::info_string& info, bool should_download) { try { @@ -302,8 +348,16 @@ namespace party if (files.size() > 0) { - download::stop_download(); - download::start_download(target, info, files); + if (should_download) + { + download::stop_download(); + download::start_download(target, info, files); + } + else + { + confirm_user_download(target, info); + } + return true; } else if (needs_restart || needs_vid_restart) @@ -428,15 +482,8 @@ namespace party void menu_error(const std::string& error) { console::error("%s\n", error.data()); - if (game::Menu_IsMenuOpenAndVisible(0, "popup_acceptinginvite")) - { - command::execute("lui_close popup_acceptinginvite", false); - } - if (game::Menu_IsMenuOpenAndVisible(0, "generic_waiting_popup_")) - { - command::execute("lui_close generic_waiting_popup_", false); - } + close_joining_popups(); utils::hook::invoke(0x17D770_b, error.data(), "MENU_NOTICE"); // Com_SetLocalizedErrorMessage *reinterpret_cast(0x2ED2F78_b) = 1; @@ -918,6 +965,9 @@ namespace party return; } + saved_target = target; + saved_info_string = info; + if (info.get("challenge") != connect_state.challenge) { menu_error("Connection failed: Invalid challenge."); @@ -959,7 +1009,7 @@ namespace party return; } - if (download_files(target, info)) + if (download_files(target, info, false)) { return; } diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index 2089a5ac..7db9c820 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -69,12 +69,6 @@ namespace ui_scripting return itr == globals.loaded_scripts.end() ? std::string() : itr->second; } - table get_globals() - { - const auto state = *game::hks::lua_state; - return state->globals.v.table; - } - void print_error(const std::string& error) { console::error("************** LUI script execution error **************\n"); @@ -523,6 +517,12 @@ namespace ui_scripting } } + table get_globals() + { + const auto state = *game::hks::lua_state; + return state->globals.v.table; + } + template game::hks::cclosure* convert_function(F f) { diff --git a/src/client/component/ui_scripting.hpp b/src/client/component/ui_scripting.hpp index 804c8a14..2d01867b 100644 --- a/src/client/component/ui_scripting.hpp +++ b/src/client/component/ui_scripting.hpp @@ -42,6 +42,8 @@ namespace ui_scripting return wrap_function(std::function(f)); } + table get_globals(); + template game::hks::cclosure* convert_function(F f); diff --git a/src/client/game/ui_scripting/execution.cpp b/src/client/game/ui_scripting/execution.cpp index efce4474..acf281c5 100644 --- a/src/client/game/ui_scripting/execution.cpp +++ b/src/client/game/ui_scripting/execution.cpp @@ -111,8 +111,7 @@ namespace ui_scripting try { - const auto globals = table((*::game::hks::lua_state)->globals.v.table); - const auto engine = globals.get("Engine").as(); + const auto engine = get_globals().get("Engine").as
(); const auto root = engine.get("GetLuiRoot")()[0].as(); const auto process_event = root.get("processEvent");