From 8b1a99fcac0c6a4da5cb826ca7b87de08fe26ab0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Mar 2022 22:22:29 +0000 Subject: [PATCH 01/26] Bump deps/zlib from `cacf7f1` to `21767c6` Bumps [deps/zlib](https://github.com/madler/zlib) from `cacf7f1` to `21767c6`. - [Release notes](https://github.com/madler/zlib/releases) - [Commits](https://github.com/madler/zlib/compare/cacf7f1d4e3d44d871b605da3b647f07d718623f...21767c654d31d2dccdde4330529775c6c5fd5389) --- updated-dependencies: - dependency-name: deps/zlib dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- deps/zlib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/zlib b/deps/zlib index cacf7f1d..21767c65 160000 --- a/deps/zlib +++ b/deps/zlib @@ -1 +1 @@ -Subproject commit cacf7f1d4e3d44d871b605da3b647f07d718623f +Subproject commit 21767c654d31d2dccdde4330529775c6c5fd5389 From f93477f809c18138b37b97024e4bda65c37611d1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Mar 2022 22:22:40 +0000 Subject: [PATCH 02/26] Bump deps/libtommath from `66de864` to `5108f12` Bumps [deps/libtommath](https://github.com/libtom/libtommath) from `66de864` to `5108f12`. - [Release notes](https://github.com/libtom/libtommath/releases) - [Commits](https://github.com/libtom/libtommath/compare/66de86426e9cdb88526974c765108f01554af2b0...5108f12350b6daa4aa5dbc846517ad1db2f8388a) --- updated-dependencies: - dependency-name: deps/libtommath dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- deps/libtommath | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/libtommath b/deps/libtommath index 66de8642..5108f123 160000 --- a/deps/libtommath +++ b/deps/libtommath @@ -1 +1 @@ -Subproject commit 66de86426e9cdb88526974c765108f01554af2b0 +Subproject commit 5108f12350b6daa4aa5dbc846517ad1db2f8388a From ff9f403a351f99c94f4edb187040ed20ab445c5e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Apr 2022 22:19:29 +0000 Subject: [PATCH 03/26] Bump deps/curl from `47048e0` to `854ec76` Bumps [deps/curl](https://github.com/curl/curl) from `47048e0` to `854ec76`. - [Release notes](https://github.com/curl/curl/releases) - [Commits](https://github.com/curl/curl/compare/47048e02878c59367db1d42813f32dcce543eed3...854ec765515ce900cd1440603cc3a1d611ce92e0) --- updated-dependencies: - dependency-name: deps/curl dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- deps/curl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/curl b/deps/curl index 47048e02..854ec765 160000 --- a/deps/curl +++ b/deps/curl @@ -1 +1 @@ -Subproject commit 47048e02878c59367db1d42813f32dcce543eed3 +Subproject commit 854ec765515ce900cd1440603cc3a1d611ce92e0 From 45f6695efc0f4b0f9b4a75a2af492ac870fe7a5c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Apr 2022 22:36:55 +0000 Subject: [PATCH 04/26] Bump deps/asmjit from `21a31b8` to `a876e4d` Bumps [deps/asmjit](https://github.com/asmjit/asmjit) from `21a31b8` to `a876e4d`. - [Release notes](https://github.com/asmjit/asmjit/releases) - [Commits](https://github.com/asmjit/asmjit/compare/21a31b8a338da3341d2b423f85913597b8ec3d63...a876e4d1cd17468ed3cf4305f0e701967601fd34) --- updated-dependencies: - dependency-name: deps/asmjit dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- deps/asmjit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/asmjit b/deps/asmjit index 21a31b8a..a876e4d1 160000 --- a/deps/asmjit +++ b/deps/asmjit @@ -1 +1 @@ -Subproject commit 21a31b8a338da3341d2b423f85913597b8ec3d63 +Subproject commit a876e4d1cd17468ed3cf4305f0e701967601fd34 From f47a0ce7d9de4ddcbb72abad4d29860f9e6b02e8 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 3 Apr 2022 22:01:50 +0200 Subject: [PATCH 05/26] Small fix --- src/client/component/gui_console.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/component/gui_console.cpp b/src/client/component/gui_console.cpp index 13943c7a..60b425cb 100644 --- a/src/client/component/gui_console.cpp +++ b/src/client/component/gui_console.cpp @@ -106,7 +106,7 @@ namespace gui::console } } - if (text[text.size() - 1] == '\n') + if (!text.empty() && text[text.size() - 1] == '\n') { text.pop_back(); } From 9e86a0b7b046f16815adc7edf5eaaff1cc397863 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Apr 2022 22:51:26 +0000 Subject: [PATCH 06/26] Bump deps/rapidjson from `8261c1d` to `fcb23c2` Bumps [deps/rapidjson](https://github.com/Tencent/rapidjson) from `8261c1d` to `fcb23c2`. - [Release notes](https://github.com/Tencent/rapidjson/releases) - [Commits](https://github.com/Tencent/rapidjson/compare/8261c1ddf43f10de00fd8c9a67811d1486b2c784...fcb23c2dbf561ec0798529be4f66394d3e4996d8) --- updated-dependencies: - dependency-name: deps/rapidjson dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- deps/rapidjson | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/rapidjson b/deps/rapidjson index 8261c1dd..fcb23c2d 160000 --- a/deps/rapidjson +++ b/deps/rapidjson @@ -1 +1 @@ -Subproject commit 8261c1ddf43f10de00fd8c9a67811d1486b2c784 +Subproject commit fcb23c2dbf561ec0798529be4f66394d3e4996d8 From d1ea7a76ea9f211f34d2283cb2347505b3a62e50 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Fri, 8 Apr 2022 16:19:52 +0200 Subject: [PATCH 07/26] Small fix --- src/client/game/ui_scripting/lua/context.cpp | 54 +++++--------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/src/client/game/ui_scripting/lua/context.cpp b/src/client/game/ui_scripting/lua/context.cpp index 0e5d831c..f38dcc19 100644 --- a/src/client/game/ui_scripting/lua/context.cpp +++ b/src/client/game/ui_scripting/lua/context.cpp @@ -30,45 +30,6 @@ namespace ui_scripting::lua { const auto json_script = utils::nt::load_resource(LUA_JSON); - scripting::script_value script_convert(const sol::lua_value& value) - { - if (value.is()) - { - return {value.as()}; - } - - if (value.is()) - { - return {value.as()}; - } - - if (value.is()) - { - return {value.as()}; - } - - if (value.is()) - { - return {value.as()}; - } - - if (value.is()) - { - return {value.as()}; - } - if (value.is()) - { - return {value.as()}; - } - - if (value.is()) - { - return {value.as()}; - } - - return {}; - } - bool valid_dvar_name(const std::string& name) { for (const auto c : name) @@ -435,15 +396,24 @@ namespace ui_scripting::lua throw std::runtime_error("Not in game"); } - ::scheduler::once([s, name, args = std::vector(va.begin(), va.end())]() + const sol::state_view view{s}; + const auto to_string = view["tostring"].get(); + + std::vector args{}; + for (auto arg : va) + { + args.push_back(to_string.call(arg).get()); + } + + ::scheduler::once([s, name, args]() { try { std::vector arguments{}; - for (auto arg : args) + for (const auto& arg : args) { - arguments.push_back(script_convert({s, arg})); + arguments.push_back(arg); } const auto player = scripting::call("getentbynum", {0}).as(); From abcdb6ac5bfa7d23bee1872579958d880777eed0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 22:23:50 +0000 Subject: [PATCH 08/26] Bump deps/asmjit from `a876e4d` to `a4cb51b` Bumps [deps/asmjit](https://github.com/asmjit/asmjit) from `a876e4d` to `a4cb51b`. - [Release notes](https://github.com/asmjit/asmjit/releases) - [Commits](https://github.com/asmjit/asmjit/compare/a876e4d1cd17468ed3cf4305f0e701967601fd34...a4cb51b532af0f8137c4182914244c3b05d7745f) --- updated-dependencies: - dependency-name: deps/asmjit dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- deps/asmjit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/asmjit b/deps/asmjit index a876e4d1..a4cb51b5 160000 --- a/deps/asmjit +++ b/deps/asmjit @@ -1 +1 @@ -Subproject commit a876e4d1cd17468ed3cf4305f0e701967601fd34 +Subproject commit a4cb51b532af0f8137c4182914244c3b05d7745f From 15ad0d49be42cc72d9b84f328098d6b6ed7249a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 22:12:05 +0000 Subject: [PATCH 09/26] Bump deps/GSL from `3837236` to `2bfd495` Bumps [deps/GSL](https://github.com/Microsoft/GSL) from `3837236` to `2bfd495`. - [Release notes](https://github.com/Microsoft/GSL/releases) - [Commits](https://github.com/Microsoft/GSL/compare/383723676cd548d615159701ac3d050f8dd1e128...2bfd4950802a223dde37a08a205812b6dfdfeb61) --- updated-dependencies: - dependency-name: deps/GSL dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- deps/GSL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/GSL b/deps/GSL index 38372367..2bfd4950 160000 --- a/deps/GSL +++ b/deps/GSL @@ -1 +1 @@ -Subproject commit 383723676cd548d615159701ac3d050f8dd1e128 +Subproject commit 2bfd4950802a223dde37a08a205812b6dfdfeb61 From dd7595aa8358eb9ba40734321ce9341a2f3d32f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 22:12:08 +0000 Subject: [PATCH 10/26] Bump deps/sol2 from `50b62c9` to `6409634` Bumps [deps/sol2](https://github.com/ThePhD/sol2) from `50b62c9` to `6409634`. - [Release notes](https://github.com/ThePhD/sol2/releases) - [Commits](https://github.com/ThePhD/sol2/compare/50b62c9346750b7c2c406c9e4c546f96b0bf021d...64096348465b980e2f1d0e5ba9cbeea8782e8f27) --- updated-dependencies: - dependency-name: deps/sol2 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- deps/sol2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/sol2 b/deps/sol2 index 50b62c93..64096348 160000 --- a/deps/sol2 +++ b/deps/sol2 @@ -1 +1 @@ -Subproject commit 50b62c9346750b7c2c406c9e4c546f96b0bf021d +Subproject commit 64096348465b980e2f1d0e5ba9cbeea8782e8f27 From 0dbe5c3a6e4f55bdddd5e8f21885bf671af2418b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 22:12:10 +0000 Subject: [PATCH 11/26] Bump deps/curl from `854ec76` to `af2dac8` Bumps [deps/curl](https://github.com/curl/curl) from `854ec76` to `af2dac8`. - [Release notes](https://github.com/curl/curl/releases) - [Commits](https://github.com/curl/curl/compare/854ec765515ce900cd1440603cc3a1d611ce92e0...af2dac82988f95e10351d13af8d4693ea4175183) --- updated-dependencies: - dependency-name: deps/curl dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- deps/curl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/curl b/deps/curl index 854ec765..af2dac82 160000 --- a/deps/curl +++ b/deps/curl @@ -1 +1 @@ -Subproject commit 854ec765515ce900cd1440603cc3a1d611ce92e0 +Subproject commit af2dac82988f95e10351d13af8d4693ea4175183 From a8537ed67bd236c2b31059d0023b6dce2bf34ca2 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 18 Apr 2022 20:01:23 +0200 Subject: [PATCH 12/26] Some fixes --- src/client/component/command.cpp | 155 +++++++++++---------- src/client/component/gui.cpp | 11 +- src/client/component/input.cpp | 29 ++-- src/client/game/ui_scripting/execution.cpp | 1 + 4 files changed, 110 insertions(+), 86 deletions(-) diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index 6fba69f6..4acdef6a 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -303,70 +303,77 @@ namespace command return; } - try + const std::string arg = params.get(1); + const std::string arg2 = params.get(2); + const auto count = params.size(); + + scheduler::once([=]() { - const auto arg = params.get(1); - const scripting::entity player = scripting::call("getentbynum", {0}).as(); - auto ps = game::g_entities[0].client; + printf("%i\n", game::Sys_IsMainThread()); - if (arg == "ammo"s) + try { - const auto weapon = player.call("getcurrentweapon").as(); - player.call("givemaxammo", {weapon}); - } - else if (arg == "allammo"s) - { - const auto weapons = player.call("getweaponslist").as(); - for (auto i = 0; i < weapons.size(); i++) - { - player.call("givemaxammo", {weapons[i]}); - } - } - else if (arg == "health"s) - { - if (params.size() > 2) - { - const auto amount = atoi(params.get(2)); - const auto health = player.get("health").as(); - player.set("health", {health + amount}); - } - else - { - const auto amount = game::Dvar_FindVar("g_player_maxhealth")->current.integer; - player.set("health", {amount}); - } - } - else if (arg == "all"s) - { - const auto type = game::XAssetType::ASSET_TYPE_WEAPON; - fastfiles::enum_assets(type, [&player, type](const game::XAssetHeader header) - { - const auto asset = game::XAsset{type, header}; - const auto* const asset_name = game::DB_GetXAssetName(&asset); + const scripting::entity player = scripting::call("getentbynum", {0}).as(); + auto ps = game::g_entities[0].client; - player.call("giveweapon", {asset_name}); - }, true); - } - else - { - const auto wp = game::G_GetWeaponForName(arg); - if (wp) + if (arg == "ammo") { - if (game::G_GivePlayerWeapon(ps, wp, 0, 0, 0, 0)) + const auto weapon = player.call("getcurrentweapon").as(); + player.call("givemaxammo", {weapon}); + } + else if (arg == "allammo") + { + const auto weapons = player.call("getweaponslist").as(); + for (auto i = 0; i < weapons.size(); i++) { - game::G_InitializeAmmo(ps, wp, 0); - game::G_SelectWeapon(0, wp); + player.call("givemaxammo", {weapons[i]}); } } + else if (arg == "health") + { + if (count > 2) + { + const auto amount = atoi(arg2.data()); + const auto health = player.get("health").as(); + player.set("health", {health + amount}); + } + else + { + const auto amount = game::Dvar_FindVar("g_player_maxhealth")->current.integer; + player.set("health", {amount}); + } + } + else if (arg == "all") + { + const auto type = game::XAssetType::ASSET_TYPE_WEAPON; + fastfiles::enum_assets(type, [&player, type](const game::XAssetHeader header) + { + const auto asset = game::XAsset{type, header}; + const auto* const asset_name = game::DB_GetXAssetName(&asset); + player.call("giveweapon", {asset_name}); + }, true); + } else { - game::CG_GameMessage(0, "Weapon does not exist"); + const auto wp = game::G_GetWeaponForName(arg.data()); + if (wp) + { + if (game::G_GivePlayerWeapon(ps, wp, 0, 0, 0, 0)) + { + game::G_InitializeAmmo(ps, wp, 0); + game::G_SelectWeapon(0, wp); + } + } + else + { + game::CG_GameMessage(0, "Weapon does not exist"); + } } } - } - catch (...) - { - } + catch (...) + { + } + }, scheduler::pipeline::server); }); add("dropweapon", [](const params& params) @@ -376,15 +383,18 @@ namespace command return; } - try + scheduler::once([]() { - const scripting::entity player = scripting::call("getentbynum", {0}).as(); - const auto weapon = player.call("getcurrentweapon"); - player.call("dropitem", {weapon}); - } - catch (...) - { - } + try + { + const scripting::entity player = scripting::call("getentbynum", {0}).as(); + const auto weapon = player.call("getcurrentweapon"); + player.call("dropitem", {weapon}); + } + catch (...) + { + } + }, scheduler::pipeline::server); }); add("take", [](const params& params) @@ -400,23 +410,26 @@ namespace command return; } - const auto weapon = params.get(1); + const std::string weapon = params.get(1); - try + scheduler::once([=]() { - const auto player = scripting::call("getentbynum", {0}).as(); - if (weapon == "all"s) + try { - player.call("takeallweapons"); + const auto player = scripting::call("getentbynum", {0}).as(); + if (weapon == "all"s) + { + player.call("takeallweapons"); + } + else + { + player.call("takeweapon", {weapon}); + } } - else + catch (...) { - player.call("takeweapon", {weapon}); } - } - catch (...) - { - } + }, scheduler::pipeline::server); }); add("kill", [](const params& params) diff --git a/src/client/component/gui.cpp b/src/client/component/gui.cpp index f8187cbe..1cba1a67 100644 --- a/src/client/component/gui.cpp +++ b/src/client/component/gui.cpp @@ -68,8 +68,15 @@ namespace gui void new_gui_frame() { - ImGui::GetIO().MouseDrawCursor = toggled || *game::keyCatchers & 0x1; - *game::keyCatchers |= 0x10 * toggled; + ImGui::GetIO().MouseDrawCursor = toggled; + if (toggled) + { + *game::keyCatchers |= 0x10; + } + else + { + *game::keyCatchers &= ~0x10; + } ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); diff --git a/src/client/component/input.cpp b/src/client/component/input.cpp index 7b14cc46..027cd685 100644 --- a/src/client/component/input.cpp +++ b/src/client/component/input.cpp @@ -26,41 +26,44 @@ namespace input void cl_char_event_stub(const int local_client_num, const int key) { - ui_scripting::notify("keypress", + if (!gui::gui_char_event(local_client_num, key)) { - {"keynum", key}, - {"key", game::Key_KeynumToString(key, 0, 1)}, - }); + return; + } if (!game_console::console_char_event(local_client_num, key)) { return; } - if (!gui::gui_char_event(local_client_num, key)) + ui_scripting::notify("keypress", { - return; - } + {"keynum", key}, + {"key", game::Key_KeynumToString(key, 0, 1)}, + }); cl_char_event_hook.invoke(local_client_num, key); } void cl_key_event_stub(const int local_client_num, const int key, const int down) { - ui_scripting::notify(down ? "keydown" : "keyup", + if (!gui::gui_key_event(local_client_num, key, down)) { - {"keynum", key}, - {"key", game::Key_KeynumToString(key, 0, 1)}, - }); + return; + } if (!game_console::console_key_event(local_client_num, key, down)) { return; } - if (!gui::gui_key_event(local_client_num, key, down)) + if (!(*game::keyCatchers & 1) && !(*game::keyCatchers & 0x10)) { - return; + ui_scripting::notify(down ? "keydown" : "keyup", + { + {"keynum", key}, + {"key", game::Key_KeynumToString(key, 0, 1)}, + }); } cl_key_event_hook.invoke(local_client_num, key, down); diff --git a/src/client/game/ui_scripting/execution.cpp b/src/client/game/ui_scripting/execution.cpp index fe6e3f7a..e6c8c115 100644 --- a/src/client/game/ui_scripting/execution.cpp +++ b/src/client/game/ui_scripting/execution.cpp @@ -57,6 +57,7 @@ namespace ui_scripting table event{}; event.set("name", name); + event.set("dispatchChildren", true); for (const auto& arg : arguments) { From bb018bc76b2739f28f16f37dd3037dbab91a0670 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Tue, 19 Apr 2022 02:22:59 +0200 Subject: [PATCH 13/26] Small fix --- src/client/component/input.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client/component/input.cpp b/src/client/component/input.cpp index 027cd685..2fb43498 100644 --- a/src/client/component/input.cpp +++ b/src/client/component/input.cpp @@ -26,12 +26,12 @@ namespace input void cl_char_event_stub(const int local_client_num, const int key) { - if (!gui::gui_char_event(local_client_num, key)) + if (!game_console::console_char_event(local_client_num, key)) { return; } - if (!game_console::console_char_event(local_client_num, key)) + if (!gui::gui_char_event(local_client_num, key)) { return; } @@ -47,12 +47,12 @@ namespace input void cl_key_event_stub(const int local_client_num, const int key, const int down) { - if (!gui::gui_key_event(local_client_num, key, down)) + if (!game_console::console_key_event(local_client_num, key, down)) { return; } - if (!game_console::console_key_event(local_client_num, key, down)) + if (!gui::gui_key_event(local_client_num, key, down)) { return; } From 30a8ee8d9f31613d125c200fd0aa77a91d214155 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Thu, 21 Apr 2022 00:06:10 +0200 Subject: [PATCH 14/26] Fix main menu freezing --- data/ui_scripts/mods/loading.lua | 10 ++++++++-- data/ui_scripts/patches/__init__.lua | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 data/ui_scripts/patches/__init__.lua diff --git a/data/ui_scripts/mods/loading.lua b/data/ui_scripts/mods/loading.lua index c83ea272..2dfe9081 100644 --- a/data/ui_scripts/mods/loading.lua +++ b/data/ui_scripts/mods/loading.lua @@ -48,11 +48,16 @@ LUI.addmenubutton("main_campaign", { function getmodname(path) local name = path - local desc = Engine.Localize("@LUA_MENU_MOD_DESC_DEFAULT", name) + game:addlocalizedstring(name, name) + game:addlocalizedstring("LUA_MENU_MOD_DESC_DEFAULT", "Load &&1.") + local desc = Engine.Localize("LUA_MENU_MOD_DESC_DEFAULT", name) local infofile = path .. "/info.json" if (io.fileexists(infofile)) then pcall(function() + game:addlocalizedstring(data.description) + game:addlocalizedstring(data.author) + game:addlocalizedstring(data.version) local data = json.decode(io.readfile(infofile)) desc = Engine.Localize("@LUA_MENU_MOD_DESC", data.description, data.author, data.version) @@ -82,7 +87,8 @@ LUI.MenuBuilder.m_types_build["mods_menu"] = function(a1) local modfolder = game:getloadedmod() if (modfolder ~= "") then - createdivider(menu, Engine.Localize("@LUA_MENU_LOADED_MOD", getmodname(modfolder):truncate(24))) + local name = getmodname(modfolder) + createdivider(menu, Engine.Localize("@LUA_MENU_LOADED_MOD", name:truncate(24))) menu:AddButton("@LUA_MENU_UNLOAD", function() game:executecommand("unloadmod") diff --git a/data/ui_scripts/patches/__init__.lua b/data/ui_scripts/patches/__init__.lua new file mode 100644 index 00000000..9002be83 --- /dev/null +++ b/data/ui_scripts/patches/__init__.lua @@ -0,0 +1,27 @@ +local maps = { + "af_caves", + "af_chase", + "airport", + "arcadia", + "boneyard", + "cliffhanger", + "contingency", + "dc_whitehouse", + "dcburning", + "dcemp", + "ending", + "estate", + "favela", + "favela_escape", + "gulag", + "invasion", + "oilrig", + "roadkill", + "trainer", + "museum", +} + +for i = 1, #maps do + local string = "LUA_MENU_SP_LOCATION_" .. maps[i]:upper() + game:addlocalizedstring(string, string) +end From b117d4b787de74e2d6a0616d4cf440221e3fb5f0 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sat, 23 Apr 2022 01:59:38 +0200 Subject: [PATCH 15/26] Some fixes --- data/ui_scripts/mods/loading.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/data/ui_scripts/mods/loading.lua b/data/ui_scripts/mods/loading.lua index 2dfe9081..a71fc4d7 100644 --- a/data/ui_scripts/mods/loading.lua +++ b/data/ui_scripts/mods/loading.lua @@ -2,7 +2,7 @@ game:addlocalizedstring("MENU_MODS", "MODS") game:addlocalizedstring("MENU_MODS_DESC", "Load installed mods.") game:addlocalizedstring("LUA_MENU_MOD_DESC_DEFAULT", "Load &&1.") game:addlocalizedstring("LUA_MENU_MOD_DESC", "&&1\nAuthor: &&2\nVersion: &&3") -game:addlocalizedstring("LUA_MENU_OPEN_STORE", "Open store") +game:addlocalizedstring("LUA_MENU_OPEN_STORE", "Store") game:addlocalizedstring("LUA_MENU_OPEN_STORE_DESC", "Download and install mods.") game:addlocalizedstring("LUA_MENU_LOADED_MOD", "Loaded mod: ^3&&1") game:addlocalizedstring("LUA_MENU_AVAILABLE_MODS", "Available mods") @@ -27,6 +27,7 @@ function createdivider(menu, text) })) menu.list:addElement(element) + return element end function string:truncate(length) @@ -55,10 +56,10 @@ function getmodname(path) if (io.fileexists(infofile)) then pcall(function() - game:addlocalizedstring(data.description) - game:addlocalizedstring(data.author) - game:addlocalizedstring(data.version) local data = json.decode(io.readfile(infofile)) + game:addlocalizedstring(data.description, data.description) + game:addlocalizedstring(data.author, data.author) + game:addlocalizedstring(data.version, data.version) desc = Engine.Localize("@LUA_MENU_MOD_DESC", data.description, data.author, data.version) name = data.name @@ -68,7 +69,7 @@ function getmodname(path) return name, desc end -LUI.MenuBuilder.m_types_build["mods_menu"] = function(a1) +LUI.MenuBuilder.registerType("mods_menu", function(a1) local menu = LUI.MenuTemplate.new(a1, { menu_title = "@MENU_MODS", exclusiveController = 0, @@ -78,8 +79,8 @@ LUI.MenuBuilder.m_types_build["mods_menu"] = function(a1) }) menu:AddButton("@LUA_MENU_OPEN_STORE", function() - if (LUI.MenuBuilder.m_types_build["mod_store_menu"]) then - LUI.FlowManager.RequestAddMenu(nil, "mod_store_menu") + if (LUI.MenuBuilder.m_types_build["mods_store_menu"]) then + LUI.FlowManager.RequestAddMenu(nil, "mods_store_menu") end end, nil, true, nil, { desc_text = Engine.Localize("@LUA_MENU_OPEN_STORE_DESC") @@ -127,4 +128,4 @@ LUI.MenuBuilder.m_types_build["mods_menu"] = function(a1) menu.optionTextInfo = LUI.Options.AddOptionTextInfo(menu) return menu -end +end) From 29b95f3625466698a3fccb020eec84c79fb5f8ed Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 25 Apr 2022 22:41:02 +0200 Subject: [PATCH 16/26] Cleanup --- src/client/component/ui_scripting.hpp | 1 - src/client/game/structs.hpp | 10 +- src/client/game/ui_scripting/event.hpp | 11 -- src/client/game/ui_scripting/execution.cpp | 2 +- src/client/game/ui_scripting/lua/context.hpp | 4 - src/client/game/ui_scripting/lua/engine.hpp | 2 - .../game/ui_scripting/lua/event_handler.cpp | 175 ------------------ .../game/ui_scripting/lua/event_handler.hpp | 58 ------ .../game/ui_scripting/lua/scheduler.cpp | 49 ----- .../game/ui_scripting/lua/scheduler.hpp | 4 - src/client/game/ui_scripting/script_value.cpp | 12 +- 11 files changed, 16 insertions(+), 312 deletions(-) delete mode 100644 src/client/game/ui_scripting/event.hpp delete mode 100644 src/client/game/ui_scripting/lua/event_handler.cpp delete mode 100644 src/client/game/ui_scripting/lua/event_handler.hpp diff --git a/src/client/component/ui_scripting.hpp b/src/client/component/ui_scripting.hpp index 417619fe..d00036f1 100644 --- a/src/client/component/ui_scripting.hpp +++ b/src/client/component/ui_scripting.hpp @@ -1,6 +1,5 @@ #pragma once #include "game/ui_scripting/lua/value_conversion.hpp" -#include "game/ui_scripting/event.hpp" namespace ui_scripting { diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index 8c3017c2..c76c760d 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1206,11 +1206,11 @@ namespace game enum HksError { HKS_NO_ERROR = 0x0, - LUA_ERRSYNTAX = 0xFFFFFFFC, - LUA_ERRFILE = 0xFFFFFFFB, - LUA_ERRRUN = 0xFFFFFF9C, - LUA_ERRMEM = 0xFFFFFF38, - LUA_ERRERR = 0xFFFFFED4, + HKS_ERRSYNTAX = 0xFFFFFFFC, + HKS_ERRFILE = 0xFFFFFFFB, + HKS_ERRRUN = 0xFFFFFF9C, + HKS_ERRMEM = 0xFFFFFF38, + HKS_ERRERR = 0xFFFFFED4, HKS_THROWING_ERROR = 0xFFFFFE0C, HKS_GC_YIELD = 0x1, }; diff --git a/src/client/game/ui_scripting/event.hpp b/src/client/game/ui_scripting/event.hpp deleted file mode 100644 index f82c8a79..00000000 --- a/src/client/game/ui_scripting/event.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include "script_value.hpp" - -namespace ui_scripting -{ - struct event - { - std::string name; - arguments arguments; - }; -} diff --git a/src/client/game/ui_scripting/execution.cpp b/src/client/game/ui_scripting/execution.cpp index e6c8c115..a0b0de13 100644 --- a/src/client/game/ui_scripting/execution.cpp +++ b/src/client/game/ui_scripting/execution.cpp @@ -40,7 +40,7 @@ namespace ui_scripting bool notify(const std::string& name, const event_arguments& arguments) { const auto state = *game::hks::lua_state; - if (!state) + if (state == nullptr) { return false; } diff --git a/src/client/game/ui_scripting/lua/context.hpp b/src/client/game/ui_scripting/lua/context.hpp index 5ad4fb7c..585d70e3 100644 --- a/src/client/game/ui_scripting/lua/context.hpp +++ b/src/client/game/ui_scripting/lua/context.hpp @@ -1,7 +1,5 @@ #pragma once -#include "../event.hpp" - #pragma warning(push) #pragma warning(disable: 4702) @@ -10,7 +8,6 @@ #include #include "scheduler.hpp" -#include "event_handler.hpp" namespace ui_scripting::lua { @@ -33,7 +30,6 @@ namespace ui_scripting::lua context& operator=(const context&) = delete; void run_frame(); - void notify(const event& e); private: sol::state state_{}; diff --git a/src/client/game/ui_scripting/lua/engine.hpp b/src/client/game/ui_scripting/lua/engine.hpp index e098f192..bbcf427c 100644 --- a/src/client/game/ui_scripting/lua/engine.hpp +++ b/src/client/game/ui_scripting/lua/engine.hpp @@ -1,7 +1,5 @@ #pragma once -#include "../event.hpp" - namespace ui_scripting::lua::engine { void start(); diff --git a/src/client/game/ui_scripting/lua/event_handler.cpp b/src/client/game/ui_scripting/lua/event_handler.cpp deleted file mode 100644 index 8d123f29..00000000 --- a/src/client/game/ui_scripting/lua/event_handler.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include "std_include.hpp" -#include "context.hpp" -#include "error.hpp" - -#include "event_handler.hpp" -#include "value_conversion.hpp" - -namespace ui_scripting::lua -{ - event_handler::event_handler(sol::state& state) - : state_(state) - { - auto event_listener_handle_type = state.new_usertype("event_listener_handle"); - - event_listener_handle_type["clear"] = [this](const event_listener_handle& handle) - { - this->remove(handle); - }; - - event_listener_handle_type["endon"] = [this](const event_listener_handle& handle, const std::string& event) - { - this->add_endon_condition(handle, event); - }; - } - - void event_handler::dispatch(const event& event) - { - bool has_built_arguments = false; - event_arguments arguments{}; - - callbacks_.access([&](task_list& tasks) - { - this->merge_callbacks(); - this->handle_endon_conditions(event); - - for (auto i = tasks.begin(); i != tasks.end();) - { - if (i->event != event.name) - { - ++i; - continue; - } - - if (!i->is_deleted) - { - if (!has_built_arguments) - { - has_built_arguments = true; - arguments = this->build_arguments(event); - } - - handle_error(i->callback(sol::as_args(arguments))); - } - - if (i->is_volatile || i->is_deleted) - { - i = tasks.erase(i); - } - else - { - ++i; - } - } - }); - } - - event_listener_handle event_handler::add_event_listener(event_listener&& listener) - { - const uint64_t id = ++this->current_listener_id_; - listener.id = id; - listener.is_deleted = false; - - new_callbacks_.access([&listener](task_list& tasks) - { - tasks.emplace_back(std::move(listener)); - }); - - return {id}; - } - - void event_handler::add_endon_condition(const event_listener_handle& handle, const std::string& event) - { - auto merger = [&](task_list& tasks) - { - for (auto& task : tasks) - { - if (task.id == handle.id) - { - task.endon_conditions.emplace_back(event); - } - } - }; - - callbacks_.access([&](task_list& tasks) - { - merger(tasks); - new_callbacks_.access(merger); - }); - } - - void event_handler::clear() - { - callbacks_.access([&](task_list& tasks) - { - new_callbacks_.access([&](task_list& new_tasks) - { - new_tasks.clear(); - tasks.clear(); - }); - }); - } - - void event_handler::remove(const event_listener_handle& handle) - { - auto mask_as_deleted = [&](task_list& tasks) - { - for (auto& task : tasks) - { - if (task.id == handle.id) - { - task.is_deleted = true; - break; - } - } - }; - - callbacks_.access(mask_as_deleted); - new_callbacks_.access(mask_as_deleted); - } - - void event_handler::merge_callbacks() - { - callbacks_.access([&](task_list& tasks) - { - new_callbacks_.access([&](task_list& new_tasks) - { - tasks.insert(tasks.end(), std::move_iterator(new_tasks.begin()), - std::move_iterator(new_tasks.end())); - new_tasks = {}; - }); - }); - } - - void event_handler::handle_endon_conditions(const event& event) - { - auto deleter = [&](task_list& tasks) - { - for (auto& task : tasks) - { - for (auto& condition : task.endon_conditions) - { - if (condition == event.name) - { - task.is_deleted = true; - break; - } - } - } - }; - - callbacks_.access(deleter); - } - - event_arguments event_handler::build_arguments(const event& event) const - { - event_arguments arguments; - - for (const auto& argument : event.arguments) - { - arguments.emplace_back(convert(this->state_, argument)); - } - - return arguments; - } -} diff --git a/src/client/game/ui_scripting/lua/event_handler.hpp b/src/client/game/ui_scripting/lua/event_handler.hpp deleted file mode 100644 index abf1415e..00000000 --- a/src/client/game/ui_scripting/lua/event_handler.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once -#include - -namespace ui_scripting::lua -{ - using event_arguments = std::vector; - using event_callback = sol::protected_function; - - class event_listener_handle - { - public: - uint64_t id = 0; - }; - - class event_listener final : public event_listener_handle - { - public: - std::string event = {}; - event_callback callback = {}; - bool is_volatile = false; - bool is_deleted = false; - std::vector endon_conditions{}; - }; - - class event_handler final - { - public: - event_handler(sol::state& state); - - event_handler(event_handler&&) noexcept = delete; - event_handler& operator=(event_handler&&) noexcept = delete; - - event_handler(const scheduler&) = delete; - event_handler& operator=(const event_handler&) = delete; - - void dispatch(const event& event); - - event_listener_handle add_event_listener(event_listener&& listener); - - void clear(); - - private: - sol::state& state_; - std::atomic_int64_t current_listener_id_ = 0; - - using task_list = std::vector; - utils::concurrency::container new_callbacks_; - utils::concurrency::container callbacks_; - - void remove(const event_listener_handle& handle); - void merge_callbacks(); - void handle_endon_conditions(const event& event); - - void add_endon_condition(const event_listener_handle& handle, const std::string& event); - - event_arguments build_arguments(const event& event) const; - }; -} diff --git a/src/client/game/ui_scripting/lua/scheduler.cpp b/src/client/game/ui_scripting/lua/scheduler.cpp index 99cac9a5..18e779b6 100644 --- a/src/client/game/ui_scripting/lua/scheduler.cpp +++ b/src/client/game/ui_scripting/lua/scheduler.cpp @@ -12,35 +12,6 @@ namespace ui_scripting::lua { this->remove(handle); }; - - task_handle_type["endon"] = [this](const task_handle& handle, const std::string& event) - { - this->add_endon_condition(handle, event); - }; - } - - void scheduler::dispatch(const event& event) - { - auto deleter = [&](task_list& tasks) - { - for (auto& task : tasks) - { - for (auto& condition : task.endon_conditions) - { - if (condition == event.name) - { - task.is_deleted = true; - break; - } - } - } - }; - - callbacks_.access([&](task_list& tasks) - { - deleter(tasks); - new_callbacks_.access(deleter); - }); } void scheduler::run_frame() @@ -118,26 +89,6 @@ namespace ui_scripting::lua return {id}; } - void scheduler::add_endon_condition(const task_handle& handle, const std::string& event) - { - auto merger = [&](task_list& tasks) - { - for (auto& task : tasks) - { - if (task.id == handle.id) - { - task.endon_conditions.emplace_back(event); - } - } - }; - - callbacks_.access([&](task_list& tasks) - { - merger(tasks); - new_callbacks_.access(merger); - }); - } - void scheduler::remove(const task_handle& handle) { auto mask_as_deleted = [&](task_list& tasks) diff --git a/src/client/game/ui_scripting/lua/scheduler.hpp b/src/client/game/ui_scripting/lua/scheduler.hpp index 26ab9c32..1935e25e 100644 --- a/src/client/game/ui_scripting/lua/scheduler.hpp +++ b/src/client/game/ui_scripting/lua/scheduler.hpp @@ -19,7 +19,6 @@ namespace ui_scripting::lua std::chrono::milliseconds delay{}; bool is_volatile = false; bool is_deleted = false; - std::vector endon_conditions{}; }; class scheduler final @@ -33,7 +32,6 @@ namespace ui_scripting::lua scheduler(const scheduler&) = delete; scheduler& operator=(const scheduler&) = delete; - void dispatch(const event& event); void run_frame(); void clear(); @@ -46,8 +44,6 @@ namespace ui_scripting::lua utils::concurrency::container callbacks_; std::atomic_int64_t current_task_id_ = 0; - void add_endon_condition(const task_handle& handle, const std::string& event); - void remove(const task_handle& handle); void merge_callbacks(); }; diff --git a/src/client/game/ui_scripting/script_value.cpp b/src/client/game/ui_scripting/script_value.cpp index faf66202..fcde49c3 100644 --- a/src/client/game/ui_scripting/script_value.cpp +++ b/src/client/game/ui_scripting/script_value.cpp @@ -60,8 +60,12 @@ namespace ui_scripting game::hks::HksObject obj{}; const auto state = *game::hks::lua_state; - state->m_apistack.top = state->m_apistack.base; + if (state == nullptr) + { + return; + } + state->m_apistack.top = state->m_apistack.base; game::hks::hksi_lua_pushlstring(state, value, static_cast(strlen(value))); obj = state->m_apistack.top[-1]; @@ -73,8 +77,12 @@ namespace ui_scripting game::hks::HksObject obj{}; const auto state = *game::hks::lua_state; - state->m_apistack.top = state->m_apistack.base; + if (state == nullptr) + { + return; + } + state->m_apistack.top = state->m_apistack.base; game::hks::hksi_lua_pushlstring(state, value, len); obj = state->m_apistack.top[-1]; From 4cc12bf653bd7672fde21c6f45271124114b1b9d Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Tue, 26 Apr 2022 17:09:00 +0200 Subject: [PATCH 17/26] Update README.md --- README.md | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9a5b352c..76427a62 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,28 @@
-## Download +## Installation -**NOTE**: Cracked/Pirated versions of the game are NOT compatible with this mod, if you run such a version and have issues/crashes launching the client refer to [this issue](https://github.com/fedddddd/h2-mod/issues/111). +**NOTE**: Cracked/Pirated versions of the game are **NOT** compatible with this mod, if you run such a version and have issues/crashes when running the client read **Step 2**. -- **[Click here to get the latest release](https://ci.appveyor.com/api/projects/fedddddd/h2-mod/artifacts/build%2Fbin%2Fx64%2FRelease%2Fh2-mod.exe?branch=develop&job=Environment%3A%20APPVEYOR_BUILD_WORKER_IMAGE%3DVisual%20Studio%202022%2C%20PREMAKE_ACTION%3Dvs2022%2C%20CI%3D1%3B%20Configuration%3A%20Release)** -- **You will need to drop this in your Call of Duty: Modern Warfare 2 Campaign Remastered installation folder. If you don't have Call of Duty: Modern Warfare 2 Campaign Remastered, get those game files first.** +1. Download the latest **[release](https://github.com/fedddddd/h2-mod/releases/latest/download/h2-mod.exe)** or **[develop ](https://ci.appveyor.com/api/projects/fedddddd/h2-mod/artifacts/build%2Fbin%2Fx64%2FRelease%2Fh2-mod.exe?branch=develop&job=Environment%3A%20APPVEYOR_BUILD_WORKER_IMAGE%3DVisual%20Studio%202022%2C%20PREMAKE_ACTION%3Dvs2022%2C%20CI%3D1%3B%20Configuration%3A%20Release)** build +2. Drop the file in your **Call of Duty: Modern Warfare 2 Campaign Remastered** installation folder. + If you don't have the game installed (or own a cracked/pirated copy of it) you can download it for free from the official **Battle.Net** servers using [Battle.Net Installer](https://github.com/barncastle/Battle.Net-Installer) and executing this command: + + ``` + .\bnetinstaller.exe --prod lazr --uid lazarus --lang enUS --dir "YOUR INSTALL PATH" + ``` + + **Make sure to replace "YOUR INSTALL PATH" with an actual installation path of your choice.** +3. Run **h2-mod.exe** and make sure you press **"YES"** when asked whether to install updates. + +## Common issues + +- If you get crashes that show errors like **"Create2DTexture(...) failed ..."** or **"IDXGISwapChain::Present failed: ..."** when loading certain maps try: + * Disabling shader preloading + * Lowering graphics settings + * Freeing up RAM (close programs) + * Updating your GPU drivers ## Compile from source @@ -24,14 +40,12 @@ - Update the submodules and run `premake5 vs2019` or simply use the delivered `generate.bat`. - Build via solution file in `build\h2-mod.sln`. -### Premake arguments + ### Premake arguments -| Argument | Description | -|:----------------------------|:-----------------------------------------------| -| `--copy-to=PATH` | Optional, copy the EXE to a custom folder after build, define the path here if wanted. | -| `--dev-build` | Enable development builds of the client. | - -
+ | Argument | Description | + |:----------------------------|:-----------------------------------------------| + | `--copy-to=PATH` | Optional, copy the EXE to a custom folder after build, define the path here if wanted. | + | `--dev-build` | Enable development builds of the client. | ## Disclaimer From 7c93b1b041e8496f91ad0f2840c879cc8da984bc Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Tue, 26 Apr 2022 17:19:33 +0200 Subject: [PATCH 18/26] Fix #261 --- src/client/game/scripting/lua/event_handler.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/client/game/scripting/lua/event_handler.cpp b/src/client/game/scripting/lua/event_handler.cpp index d433fd18..b0f8f876 100644 --- a/src/client/game/scripting/lua/event_handler.cpp +++ b/src/client/game/scripting/lua/event_handler.cpp @@ -35,12 +35,6 @@ namespace scripting::lua for (auto i = tasks.begin(); i != tasks.end();) { - if (i->is_deleted) - { - i = tasks.erase(i); - continue; - } - if (i->event != event.name || i->entity != event.entity) { ++i; From 3be2ae0ed9a4b8b587ada9b31628d0f1aa5fca31 Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Tue, 26 Apr 2022 20:41:32 +0200 Subject: [PATCH 19/26] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 76427a62..b805c1f7 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ **NOTE**: Cracked/Pirated versions of the game are **NOT** compatible with this mod, if you run such a version and have issues/crashes when running the client read **Step 2**. -1. Download the latest **[release](https://github.com/fedddddd/h2-mod/releases/latest/download/h2-mod.exe)** or **[develop ](https://ci.appveyor.com/api/projects/fedddddd/h2-mod/artifacts/build%2Fbin%2Fx64%2FRelease%2Fh2-mod.exe?branch=develop&job=Environment%3A%20APPVEYOR_BUILD_WORKER_IMAGE%3DVisual%20Studio%202022%2C%20PREMAKE_ACTION%3Dvs2022%2C%20CI%3D1%3B%20Configuration%3A%20Release)** build +1. Download the latest **[release](https://github.com/fedddddd/h2-mod/releases/latest/download/h2-mod.exe)** or **[develop](https://ci.appveyor.com/api/projects/fedddddd/h2-mod/artifacts/build%2Fbin%2Fx64%2FRelease%2Fh2-mod.exe?branch=develop&job=Environment%3A%20APPVEYOR_BUILD_WORKER_IMAGE%3DVisual%20Studio%202022%2C%20PREMAKE_ACTION%3Dvs2022%2C%20CI%3D1%3B%20Configuration%3A%20Release)** build 2. Drop the file in your **Call of Duty: Modern Warfare 2 Campaign Remastered** installation folder. If you don't have the game installed (or own a cracked/pirated copy of it) you can download it for free from the official **Battle.Net** servers using [Battle.Net Installer](https://github.com/barncastle/Battle.Net-Installer) and executing this command: From 35cdd3927e8acdfe1628ce4862efedc52fb925a0 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Thu, 28 Apr 2022 22:41:29 +0200 Subject: [PATCH 20/26] Big LUI scripting changes --- data/ui_scripts/mods/loading.lua | 18 +- data/ui_scripts/settings/__init__.lua | 4 +- src/client/component/filesystem.cpp | 7 +- src/client/component/filesystem.hpp | 2 +- src/client/component/game_console.cpp | 4 +- src/client/component/input.cpp | 1 - src/client/component/scheduler.cpp | 17 +- src/client/component/ui_scripting.cpp | 502 +++++++++++--- src/client/component/ui_scripting.hpp | 48 +- src/client/component/updater.cpp | 14 + src/client/game/structs.hpp | 255 +++++++- src/client/game/symbols.hpp | 6 + src/client/game/ui_scripting/execution.cpp | 142 ++-- src/client/game/ui_scripting/execution.hpp | 4 +- src/client/game/ui_scripting/lua/context.cpp | 618 ------------------ src/client/game/ui_scripting/lua/context.hpp | 43 -- src/client/game/ui_scripting/lua/engine.cpp | 77 --- src/client/game/ui_scripting/lua/engine.hpp | 8 - src/client/game/ui_scripting/lua/error.cpp | 24 - src/client/game/ui_scripting/lua/error.hpp | 8 - .../game/ui_scripting/lua/scheduler.cpp | 122 ---- .../game/ui_scripting/lua/scheduler.hpp | 50 -- .../ui_scripting/lua/value_conversion.cpp | 144 ---- .../ui_scripting/lua/value_conversion.hpp | 9 - src/client/game/ui_scripting/script_value.cpp | 197 +++++- src/client/game/ui_scripting/script_value.hpp | 208 +++++- src/client/game/ui_scripting/types.cpp | 86 ++- src/client/game/ui_scripting/types.hpp | 51 ++ src/client/resources/json.lua | 2 +- src/client/resources/ui_scripts/common.lua | 54 +- src/client/resources/ui_scripts/updater.lua | 57 +- 31 files changed, 1334 insertions(+), 1448 deletions(-) delete mode 100644 src/client/game/ui_scripting/lua/context.cpp delete mode 100644 src/client/game/ui_scripting/lua/context.hpp delete mode 100644 src/client/game/ui_scripting/lua/engine.cpp delete mode 100644 src/client/game/ui_scripting/lua/engine.hpp delete mode 100644 src/client/game/ui_scripting/lua/error.cpp delete mode 100644 src/client/game/ui_scripting/lua/error.hpp delete mode 100644 src/client/game/ui_scripting/lua/scheduler.cpp delete mode 100644 src/client/game/ui_scripting/lua/scheduler.hpp delete mode 100644 src/client/game/ui_scripting/lua/value_conversion.cpp delete mode 100644 src/client/game/ui_scripting/lua/value_conversion.hpp diff --git a/data/ui_scripts/mods/loading.lua b/data/ui_scripts/mods/loading.lua index a71fc4d7..7918d7f0 100644 --- a/data/ui_scripts/mods/loading.lua +++ b/data/ui_scripts/mods/loading.lua @@ -2,12 +2,12 @@ game:addlocalizedstring("MENU_MODS", "MODS") game:addlocalizedstring("MENU_MODS_DESC", "Load installed mods.") game:addlocalizedstring("LUA_MENU_MOD_DESC_DEFAULT", "Load &&1.") game:addlocalizedstring("LUA_MENU_MOD_DESC", "&&1\nAuthor: &&2\nVersion: &&3") -game:addlocalizedstring("LUA_MENU_OPEN_STORE", "Store") -game:addlocalizedstring("LUA_MENU_OPEN_STORE_DESC", "Download and install mods.") game:addlocalizedstring("LUA_MENU_LOADED_MOD", "Loaded mod: ^3&&1") game:addlocalizedstring("LUA_MENU_AVAILABLE_MODS", "Available mods") game:addlocalizedstring("LUA_MENU_UNLOAD", "Unload") game:addlocalizedstring("LUA_MENU_UNLOAD_DESC", "Unload the currently loaded mod.") +game:addlocalizedstring("LUA_MENU_WORKSHOP", "Workshop") +game:addlocalizedstring("LUA_MENU_WORKSHOP_DESC", "Download and install mods.") function createdivider(menu, text) local element = LUI.UIElement.new( { @@ -26,6 +26,8 @@ function createdivider(menu, text) title_bar_text = Engine.ToUpperCase(text) })) + element.text = element:getFirstChild():getFirstChild():getNextSibling() + menu.list:addElement(element) return element end @@ -78,12 +80,12 @@ LUI.MenuBuilder.registerType("mods_menu", function(a1) showTopRightSmallBar = true }) - menu:AddButton("@LUA_MENU_OPEN_STORE", function() - if (LUI.MenuBuilder.m_types_build["mods_store_menu"]) then - LUI.FlowManager.RequestAddMenu(nil, "mods_store_menu") + menu:AddButton("@LUA_MENU_WORKSHOP", function() + if (LUI.MenuBuilder.m_types_build["mods_workshop_menu"]) then + LUI.FlowManager.RequestAddMenu(nil, "mods_workshop_menu") end end, nil, true, nil, { - desc_text = Engine.Localize("@LUA_MENU_OPEN_STORE_DESC") + desc_text = Engine.Localize("@LUA_MENU_WORKSHOP_DESC") }) local modfolder = game:getloadedmod() @@ -92,7 +94,7 @@ LUI.MenuBuilder.registerType("mods_menu", function(a1) createdivider(menu, Engine.Localize("@LUA_MENU_LOADED_MOD", name:truncate(24))) menu:AddButton("@LUA_MENU_UNLOAD", function() - game:executecommand("unloadmod") + Engine.Exec("unloadmod") end, nil, true, nil, { desc_text = Engine.Localize("@LUA_MENU_UNLOAD_DESC") }) @@ -109,7 +111,7 @@ LUI.MenuBuilder.registerType("mods_menu", function(a1) if (mods[i] ~= modfolder) then game:addlocalizedstring(name, name) menu:AddButton(name, function() - game:executecommand("loadmod " .. mods[i]) + Engine.Exec("loadmod " .. mods[i]) end, nil, true, nil, { desc_text = desc }) diff --git a/data/ui_scripts/settings/__init__.lua b/data/ui_scripts/settings/__init__.lua index 00cd8125..26b798ac 100644 --- a/data/ui_scripts/settings/__init__.lua +++ b/data/ui_scripts/settings/__init__.lua @@ -55,8 +55,8 @@ LUI.addmenubutton("pc_controls", { LUI.MenuBuilder.m_types_build["settings_menu"] = function(a1) local menu = LUI.MenuTemplate.new(a1, { menu_title = "@MENU_GENERAL", - menu_list_divider_top_offset = -(LUI.H1MenuTab.tabChangeHoldingElementHeight + luiglobals.H1MenuDims.spacing), - menu_width = luiglobals.GenericMenuDims.OptionMenuWidth + menu_list_divider_top_offset = -(LUI.H1MenuTab.tabChangeHoldingElementHeight + H1MenuDims.spacing), + menu_width = GenericMenuDims.OptionMenuWidth }) createdivider(menu, "@LUA_MENU_UPDATES") diff --git a/src/client/component/filesystem.cpp b/src/client/component/filesystem.cpp index cba191cc..321364a5 100644 --- a/src/client/component/filesystem.cpp +++ b/src/client/component/filesystem.cpp @@ -27,13 +27,18 @@ namespace filesystem return {}; } - bool read_file(const std::string& path, std::string* data) + bool read_file(const std::string& path, std::string* data, std::string* real_path) { for (const auto& search_path : get_search_paths()) { const auto path_ = search_path + "/" + path; if (utils::io::read_file(path_, data)) { + if (real_path != nullptr) + { + *real_path = path_; + } + return true; } } diff --git a/src/client/component/filesystem.hpp b/src/client/component/filesystem.hpp index 718e5377..3e9c5b02 100644 --- a/src/client/component/filesystem.hpp +++ b/src/client/component/filesystem.hpp @@ -4,5 +4,5 @@ namespace filesystem { std::unordered_set& get_search_paths(); std::string read_file(const std::string& path); - bool read_file(const std::string& path, std::string* data); + bool read_file(const std::string& path, std::string* data, std::string* real_path = nullptr); } \ No newline at end of file diff --git a/src/client/component/game_console.cpp b/src/client/component/game_console.cpp index 78d8f401..3e1a6a6c 100644 --- a/src/client/component/game_console.cpp +++ b/src/client/component/game_console.cpp @@ -386,11 +386,13 @@ namespace game_console va_end(ap); const auto formatted = std::string(va_buffer); + printf(va_buffer); + const auto lines = utils::string::split(formatted, '\n'); for (auto& line : lines) { - print(type == con_type_info ? line : "^"s.append(std::to_string(type)).append(line)); + print(type == con_type_info ? line : "^"s.append(std::to_string(type)).append(line), false); } } diff --git a/src/client/component/input.cpp b/src/client/component/input.cpp index 2fb43498..3f34bf2e 100644 --- a/src/client/component/input.cpp +++ b/src/client/component/input.cpp @@ -5,7 +5,6 @@ #include "game_console.hpp" #include "gui.hpp" -#include "game/ui_scripting/lua/engine.hpp" #include "game/ui_scripting/execution.hpp" #include diff --git a/src/client/component/scheduler.cpp b/src/client/component/scheduler.cpp index ed0301b8..07ae3b07 100644 --- a/src/client/component/scheduler.cpp +++ b/src/client/component/scheduler.cpp @@ -87,6 +87,7 @@ namespace scheduler utils::hook::detour r_end_frame_hook; utils::hook::detour g_run_frame_hook; utils::hook::detour main_frame_hook; + utils::hook::detour hks_frame_hook; void execute(const pipeline type) { @@ -97,11 +98,6 @@ namespace scheduler void r_end_frame_stub() { execute(pipeline::renderer); - if (game::Sys_IsMainThread()) - { - execute(pipeline::lui); - } - r_end_frame_hook.invoke(); } @@ -116,6 +112,16 @@ namespace scheduler main_frame_hook.invoke(); execute(pipeline::main); } + + void hks_frame_stub() + { + const auto state = *game::hks::lua_state; + if (state) + { + execute(pipeline::lui); + } + hks_frame_hook.invoke(); + } } void schedule(const std::function& callback, const pipeline type, @@ -186,6 +192,7 @@ namespace scheduler r_end_frame_hook.create(0x14076D7B0, scheduler::r_end_frame_stub); g_run_frame_hook.create(0x1404CB030, scheduler::server_frame_stub); main_frame_hook.create(0x140417FA0, scheduler::main_frame_stub); + hks_frame_hook.create(0x140327880, scheduler::hks_frame_stub); } void pre_destroy() override diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index ee6d4831..cfa93990 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -7,172 +7,461 @@ #include "scheduler.hpp" #include "command.hpp" -#include "ui_scripting.hpp" +#include "filesystem.hpp" +#include "localized_strings.hpp" +#include "scripting.hpp" +#include "fastfiles.hpp" +#include "mods.hpp" +#include "updater.hpp" -#include "game/ui_scripting/lua/engine.hpp" #include "game/ui_scripting/execution.hpp" -#include "game/ui_scripting/lua/error.hpp" +#include "game/scripting/execution.hpp" + +#include "ui_scripting.hpp" #include #include +#include namespace ui_scripting { namespace { - std::unordered_map converted_functions; + const auto lui_common = utils::nt::load_resource(LUI_COMMON); + const auto lui_updater = utils::nt::load_resource(LUI_UPDATER); + const auto lua_json = utils::nt::load_resource(LUA_JSON); + + std::unordered_map> converted_functions; - utils::hook::detour hksi_lual_error_hook; - utils::hook::detour hksi_lual_error_hook2; utils::hook::detour hks_start_hook; utils::hook::detour hks_shutdown_hook; - utils::hook::detour hks_allocator_hook; - utils::hook::detour lui_error_hook; - utils::hook::detour hksi_hks_error_hook; - utils::hook::detour hks_frame_hook; + utils::hook::detour hks_package_require_hook; - int error_hook_enabled = 0; - - void hksi_lual_error_stub(game::hks::lua_State* s, const char* fmt, ...) + struct script { - char va_buffer[2048] = {0}; + std::string name; + std::string root; + }; - va_list ap; - va_start(ap, fmt); - vsprintf_s(va_buffer, fmt, ap); - va_end(ap); + struct globals_t + { + std::string in_require_script; + std::vector