From 116b747be2da6f4562234b8c59de2176b50a752b Mon Sep 17 00:00:00 2001 From: quaK Date: Tue, 6 Aug 2024 09:59:48 +0300 Subject: [PATCH] fastdl progress --- data/cdata/ui_scripts/Mods/ModDownload.lua | 40 +++++++++++ data/cdata/ui_scripts/Mods/__init__.lua | 2 +- src/client/component/download.cpp | 7 +- src/client/component/party.cpp | 12 +++- src/client/component/scripting.cpp | 2 - src/client/component/scripting.hpp | 4 -- src/client/component/ui_scripting.cpp | 80 +++++++--------------- 7 files changed, 78 insertions(+), 69 deletions(-) create mode 100644 data/cdata/ui_scripts/Mods/ModDownload.lua diff --git a/data/cdata/ui_scripts/Mods/ModDownload.lua b/data/cdata/ui_scripts/Mods/ModDownload.lua new file mode 100644 index 0000000..a7a490f --- /dev/null +++ b/data/cdata/ui_scripts/Mods/ModDownload.lua @@ -0,0 +1,40 @@ +function ModDownloadCancel( arg0, arg1 ) + download.abort() + LUI.FlowManager.RequestLeaveMenu( arg0 ) +end + +function ModDownloadPopup( arg0, arg1 ) + local popup = MenuBuilder.BuildRegisteredType( "FenceDialogPopup", { + message = "Downloading files...", + controllerIndex = arg1.controllerIndex, + onCancel = ModDownloadCancel + } ) + popup.id = "ModDownloadPopup" + + local file = "" + + popup:registerEventHandler("mod_download_set_file", function(element, event) + file = event.request.name + popup.Message:setText(string.format("Downloading %s...", file)) + end) + + popup:registerEventHandler("mod_download_progress", function(element, event) + popup.Message:setText(string.format("Downloading %s (%i%%)...", file, math.floor(event.fraction * 100))) + end) + + popup:registerEventHandler("mod_download_done", function() + LUI.FlowManager.RequestLeaveMenu(popup) + end) + + return popup +end + +MenuBuilder.registerType( "ModDownloadPopup", ModDownloadPopup ) + +local function reg_func() + Engine.GetLuiRoot():registerEventHandler("mod_download_start", function(element, event) + LUI.FlowManager.RequestPopupMenu( element, "ModDownloadPopup", true, event.controller, false ) + end) +end + +scheduler.once(reg_func) \ No newline at end of file diff --git a/data/cdata/ui_scripts/Mods/__init__.lua b/data/cdata/ui_scripts/Mods/__init__.lua index bb4daf5..495f7c5 100644 --- a/data/cdata/ui_scripts/Mods/__init__.lua +++ b/data/cdata/ui_scripts/Mods/__init__.lua @@ -2,5 +2,5 @@ require( "ModSelectButton" ) require( "ModSelectMenu" ) if (Engine.InFrontend()) then - --require("download") + require("ModDownload") end \ No newline at end of file diff --git a/src/client/component/download.cpp b/src/client/component/download.cpp index eeb1ca6..0d5bb01 100644 --- a/src/client/component/download.cpp +++ b/src/client/component/download.cpp @@ -88,7 +88,7 @@ namespace download }, scheduler::pipeline::lui); } - //console::debug("Download progress: %lli/%lli\n", progress, total); + console::debug("Download progress: %lli/%lli\n", progress, total); if (download_aborted()) { return -1; @@ -99,10 +99,7 @@ namespace download void menu_error(const std::string& error) { - scheduler::once([=] - { - game::shared::menu_error(error); - }, scheduler::pipeline::lui); + throw std::runtime_error(error); } } diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index 519cb8d..bdb61c8 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -280,6 +280,7 @@ namespace party } catch (const std::exception& e) { + command::execute("luiLeaveMenu AcceptingInvite", true); game::shared::menu_error(e.what()); return true; } @@ -399,6 +400,13 @@ namespace party { profile_infos::xuid::clear_xuids(); + hash_cache.clear(); + + if (game::environment::is_dedi()) + { + generate_hashes(map); + } + preloaded_map = map_is_preloaded; sv_start_map_for_party_hook.invoke(map, game_type, client_count, agent_count, hardcore, map_is_preloaded, migrate); } @@ -851,7 +859,7 @@ namespace party info.set("sv_discordImageUrl", get_dvar_string("sv_discordImageUrl")); info.set("sv_discordImageText", get_dvar_string("sv_discordImageText")); - /*const auto fs_game = get_dvar_string("fs_game"); + const auto fs_game = get_dvar_string("fs_game"); info.set("fs_game", fs_game); if (!fs_game.empty()) @@ -862,7 +870,7 @@ namespace party fs_game.data(), file.extension.data())); info.set(file.name, hash); } - }*/ + } network::send(target, "infoResponse", info.build(), '\n'); }); diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index d657068..f059ff7 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -24,8 +24,6 @@ namespace scripting std::unordered_map>> script_function_table_sort; std::unordered_map> script_function_table_rev; - utils::concurrency::container shared_table; - std::string current_file; namespace diff --git a/src/client/component/scripting.hpp b/src/client/component/scripting.hpp index 12598b9..4604821 100644 --- a/src/client/component/scripting.hpp +++ b/src/client/component/scripting.hpp @@ -3,15 +3,11 @@ namespace scripting { - using shared_table_t = std::unordered_map; - extern std::unordered_map> fields_table; extern std::unordered_map> script_function_table; extern std::unordered_map>> script_function_table_sort; extern std::unordered_map> script_function_table_rev; - extern utils::concurrency::container shared_table; - extern std::string current_file; void on_shutdown(const std::function& callback); diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index ead7fde..b801fc9 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -4,7 +4,6 @@ #include "game/game.hpp" #include "game/dvars.hpp" - #include "command.hpp" #include "console/console.hpp" #include "fastfiles.hpp" @@ -15,6 +14,7 @@ #include "scheduler.hpp" #include "scripting.hpp" #include "server_list.hpp" +#include "download.hpp" #include "game/ui_scripting/execution.hpp" //#include "game/scripting/execution.hpp" @@ -183,60 +183,6 @@ namespace ui_scripting }; */ - game_type["sharedset"] = [](const game&, const std::string& key, const std::string& value) - { - scripting::shared_table.access([key, value](scripting::shared_table_t& table) - { - table[key] = value; - }); - }; - - game_type["sharedget"] = [](const game&, const std::string& key) - { - std::string result; - scripting::shared_table.access([key, &result](scripting::shared_table_t& table) - { - result = table[key]; - }); - return result; - }; - - game_type["sharedclear"] = [](const game&) - { - scripting::shared_table.access([](scripting::shared_table_t& table) - { - table.clear(); - }); - }; - - /* - game_type["assetlist"] = [](const game&, const std::string& type_string) - { - auto table_ = table(); - auto index = 1; - auto type_index = -1; - for (auto i = 0; i < ::game::XAssetType::ASSET_TYPE_COUNT; i++) - { - if (type_string == ::game::g_assetNames[i]) - { - type_index = i; - } - } - if (type_index == -1) - { - throw std::runtime_error("Asset type does not exist"); - } - const auto type = static_cast<::game::XAssetType>(type_index); - fastfiles::enum_assets(type, [type, &table_, &index](const ::game::XAssetHeader header) - { - const auto asset = ::game::XAsset{type, header}; - const std::string asset_name = ::game::DB_GetXAssetName(&asset); - table_[index++] = asset_name; - }, true); - return table_; - }; - */ - game_type["getcurrentgamelanguage"] = [](const game&) { return steam::SteamApps()->GetCurrentGameLanguage(); @@ -248,11 +194,35 @@ namespace ui_scripting material.data())); }; + auto scheduler = table(); + lua["scheduler"] = scheduler; + + scheduler["once"] = [](const function_argument& args) + { + scheduler::once([args]() + { + auto func = args.as(); + func(); + }, scheduler::lui); + }; + auto server_list_table = table(); lua["serverlist"] = server_list_table; server_list_table["getplayercount"] = server_list::get_player_count; server_list_table["getservercount"] = server_list::get_server_count; + + auto download_table = table(); + lua["download"] = download_table; + + download_table["abort"] = download::stop_download; + + //download_table["userdownloadresponse"] = party::user_download_response; + //download_table["getwwwurl"] = [] + //{ + // const auto state = party::get_server_connection_state(); + // return state.base_url; + //}; } void enable_globals()