From 4079334179d77eae8c05c936194c24add9e481c9 Mon Sep 17 00:00:00 2001 From: m Date: Mon, 14 Apr 2025 18:27:30 -0500 Subject: [PATCH 1/8] add -noupdate flag [skip ci] --- src/client/component/updater.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client/component/updater.cpp b/src/client/component/updater.cpp index 61ec0041..8f72c80e 100644 --- a/src/client/component/updater.cpp +++ b/src/client/component/updater.cpp @@ -475,7 +475,11 @@ namespace updater void post_start() override { delete_old_file(); - run_update(); + + if (!utils::flags::has_flag("noupdate")) + { + run_update(); + } } component_priority priority() override From b05d9dadb9ced583af8fccbc6cc6e0e80d88ce74 Mon Sep 17 00:00:00 2001 From: m Date: Mon, 14 Apr 2025 18:29:56 -0500 Subject: [PATCH 2/8] update resource.rc [skip ci] --- src/client/resource.rc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/client/resource.rc b/src/client/resource.rc index e657525c..717f2be0 100644 --- a/src/client/resource.rc +++ b/src/client/resource.rc @@ -70,13 +70,13 @@ BEGIN BEGIN BLOCK "040904b0" BEGIN - VALUE "CompanyName", "XLabs" + VALUE "CompanyName", "Aurora" VALUE "FileDescription", "IW7-Mod" VALUE "FileVersion", VERSION_FILE VALUE "InternalName", "IW7-Mod" - VALUE "LegalCopyright", "Copyright (C) 2022 X Labs Project. All rights reserved." + VALUE "LegalCopyright", "Copyright (C) 2025 Aurora. All rights reserved." VALUE "Licence", "GPLv3" - VALUE "Info", "https://github.com/Joelrau/iw7-mod/" + VALUE "Info", "https://github.com/auroramod/iw7-mod/" VALUE "OriginalFilename", "iw7-mod.exe" VALUE "ProductName", "iw7-mod" VALUE "ProductVersion", VERSION_PRODUCT @@ -123,4 +123,3 @@ ICON_IMAGE RCDATA "resources/icon.png" ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED - From 39f2452c603ce0be54b28d0d0745554df9c407c3 Mon Sep 17 00:00:00 2001 From: m Date: Mon, 14 Apr 2025 20:01:49 -0500 Subject: [PATCH 3/8] add sv_sayName & say[raw] + tell[raw] --- src/client/component/party.cpp | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index 89dca6ae..f032acc9 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -85,6 +85,8 @@ namespace party std::unordered_map hash_cache; + const game::dvar_t* sv_say_name = nullptr; + std::string get_file_hash(const std::string& file) { const auto iter = hash_cache.find(file); @@ -915,6 +917,71 @@ namespace party }, scheduler::pipeline::server); }); + scheduler::once([]() + { + sv_say_name = game::Dvar_RegisterString("sv_sayName", "console", game::DvarFlags::DVAR_FLAG_NONE, "Custom name for RCON console"); + }, scheduler::pipeline::main); + + command::add("tell", [](const command::params& params) + { + if (params.size() < 3) + { + return; + } + + const auto client_num = atoi(params.get(1)); + const auto message = params.join(2); + const auto* const name = sv_say_name->current.string; + + game::SV_GameSendServerCommand(client_num, game::SV_CMD_CAN_IGNORE, + utils::string::va("%c \"%s: %s\"", 84, name, message.data())); + console::info("%s -> %i: %s\n", name, client_num, message.data()); + }); + + command::add("tellraw", [](const command::params& params) + { + if (params.size() < 3) + { + return; + } + + const auto client_num = atoi(params.get(1)); + const auto message = params.join(2); + + game::SV_GameSendServerCommand(client_num, game::SV_CMD_CAN_IGNORE, + utils::string::va("%c \"%s\"", 84, message.data())); + console::info("%i: %s\n", client_num, message.data()); + }); + + command::add("say", [](const command::params& params) + { + if (params.size() < 2) + { + return; + } + + const auto message = params.join(1); + const auto* const name = sv_say_name->current.string; + + game::SV_GameSendServerCommand( + -1, game::SV_CMD_CAN_IGNORE, utils::string::va("%c \"%s: %s\"", 84, name, message.data())); + console::info("%s: %s\n", name, message.data()); + }); + + command::add("sayraw", [](const command::params& params) + { + if (params.size() < 2) + { + return; + } + + const auto message = params.join(1); + + game::SV_GameSendServerCommand(-1, game::SV_CMD_CAN_IGNORE, + utils::string::va("%c \"%s\"", 84, message.data())); + console::info("%s\n", message.data()); + }); + network::on("getInfo", [](const game::netadr_s& target, const std::string_view& data) { utils::info_string info{}; From f6648523b76a2a2e871242c995e30bc19f0d395b Mon Sep 17 00:00:00 2001 From: m Date: Mon, 14 Apr 2025 20:53:43 -0500 Subject: [PATCH 4/8] fix GSC include paths closes #277 --- src/client/component/gsc/script_loading.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/component/gsc/script_loading.cpp b/src/client/component/gsc/script_loading.cpp index c88ab19b..407d7ee4 100644 --- a/src/client/component/gsc/script_loading.cpp +++ b/src/client/component/gsc/script_loading.cpp @@ -335,7 +335,7 @@ namespace gsc const auto script_name = std::filesystem::path(included_path).replace_extension().string(); std::string file_buffer; - if (!read_raw_script_file(script_name, &file_buffer) || file_buffer.empty()) + if (!read_raw_script_file(included_path, &file_buffer) || file_buffer.empty()) { const auto name = get_script_file_name(script_name); if (game::DB_XAssetExists(game::ASSET_TYPE_SCRIPTFILE, name.data())) @@ -349,7 +349,7 @@ namespace gsc std::vector script_data; script_data.assign(file_buffer.begin(), file_buffer.end()); - return { {}, script_data }; + return {{}, script_data}; }); } From 7264a995c1f6136dc417781de7025304260278f8 Mon Sep 17 00:00:00 2001 From: m Date: Mon, 14 Apr 2025 21:27:41 -0500 Subject: [PATCH 5/8] rework auth to save & load GUID correctly from h1-mod https://github.com/auroramod/h1-mod/commit/371c967a9fb4f17438110881883706eb3ceef386?diff=unified --- src/client/component/auth.cpp | 80 +++++++++++++++++++++++++++++++++-- src/common/utils/string.cpp | 2 +- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp index 5a852dff..5925640d 100644 --- a/src/client/component/auth.cpp +++ b/src/client/component/auth.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include namespace auth { @@ -31,13 +33,20 @@ namespace auth std::string get_hw_profile_guid() { + auto hw_profile_path = (utils::properties::get_appdata_path() / "iw7-guid.dat").generic_string(); + if (utils::io::file_exists(hw_profile_path)) + { + utils::io::remove_file(hw_profile_path); + } + HW_PROFILE_INFO info; if (!GetCurrentHwProfileA(&info)) { return {}; } - return std::string{ info.szHwProfileGuid, sizeof(info.szHwProfileGuid) }; + auto hw_profile_info = std::string{ info.szHwProfileGuid, sizeof(info.szHwProfileGuid) }; + return hw_profile_info; } std::string get_protected_data() @@ -52,7 +61,7 @@ namespace auth return {}; } - const auto size = std::min(data_out.cbData, 52ul); + const auto size = std::min(data_out.cbData, 52); std::string result{ reinterpret_cast(data_out.pbData), size }; LocalFree(data_out.pbData); @@ -76,9 +85,72 @@ namespace auth return entropy; } + bool load_key(utils::cryptography::ecc::key& key) + { + std::string data{}; + + auto key_path = (utils::properties::get_appdata_path() / "iw7-private.key").generic_string(); + if (!utils::io::read_file(key_path, &data)) + { + return false; + } + + key.deserialize(data); + if (!key.is_valid()) + { + console::error("Loaded key is invalid!\n"); + return false; + } + + return true; + } + + utils::cryptography::ecc::key generate_key() + { + auto key = utils::cryptography::ecc::generate_key(512, get_key_entropy()); + if (!key.is_valid()) + { + throw std::runtime_error("Failed to generate cryptographic key!"); + } + + auto key_path = (utils::properties::get_appdata_path() / "iw7-private.key").generic_string(); + if (!utils::io::write_file(key_path, key.serialize())) + { + console::error("Failed to write cryptographic key!\n"); + } + + console::info("Generated cryptographic key: %llX\n", key.get_hash()); + return key; + } + + utils::cryptography::ecc::key load_or_generate_key() + { + utils::cryptography::ecc::key key{}; + if (load_key(key)) + { + console::info("Loaded cryptographic key: %llX\n", key.get_hash()); + return key; + } + + return generate_key(); + } + + utils::cryptography::ecc::key get_key_internal() + { + auto key = load_or_generate_key(); + + auto key_path = (utils::properties::get_appdata_path() / "iw7-public.key").generic_string(); + if (!utils::io::write_file(key_path, key.get_public_key())) + { + console::error("Failed to write public key!\n"); + } + + return key; + } + utils::cryptography::ecc::key& get_key() { - static auto key = utils::cryptography::ecc::generate_key(512, get_key_entropy()); + static auto key = get_key_internal(); return key; } } @@ -132,7 +204,7 @@ namespace auth utils::hook::jump(patch.first, patch.second); } - command::add("guid", []() + command::add("guid", []() -> void { console::info("Your guid: %llX\n", steam::SteamUser()->GetSteamID().bits); }); diff --git a/src/common/utils/string.cpp b/src/common/utils/string.cpp index 93ba3df4..b5dcd45d 100644 --- a/src/common/utils/string.cpp +++ b/src/common/utils/string.cpp @@ -112,7 +112,7 @@ namespace utils::string void strip(const char* in, char* out, int max) { - if (!in || !out) return; + if (!in || !out || !max) return; max--; auto current = 0; From 64dbdba3f253f7e005651ba0dfc83e0687b7f969 Mon Sep 17 00:00:00 2001 From: m Date: Mon, 14 Apr 2025 22:29:39 -0500 Subject: [PATCH 6/8] add missing return --- src/client/component/rcon.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/component/rcon.cpp b/src/client/component/rcon.cpp index 728f36d5..602c9361 100644 --- a/src/client/component/rcon.cpp +++ b/src/client/component/rcon.cpp @@ -219,6 +219,7 @@ namespace rcon if (!has_redirected_) { network::send(redirect_target_, "print", "", '\n'); + return; } clear_redirect(); From 36bd1df1cdd2508b8acfeced2d53aa956ff00ac9 Mon Sep 17 00:00:00 2001 From: m Date: Mon, 14 Apr 2025 22:50:24 -0500 Subject: [PATCH 7/8] fix Sys_SendPacket dying? --- src/client/component/network.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/component/network.cpp b/src/client/component/network.cpp index da0717cf..36974bf3 100644 --- a/src/client/component/network.cpp +++ b/src/client/component/network.cpp @@ -250,14 +250,14 @@ namespace network void send_data(const game::netadr_s& address, const std::string& data) { auto size = static_cast(data.size()); - if (size > 1280) - { - console::error("Packet was too long. Truncated!\n"); - size = 1280; - } - if (address.type == game::NA_LOOPBACK) { + if (size > 1280) + { + console::error("Packet was too long. Truncated!\n"); + size = 1280; + } + game::NET_SendLoopPacket(game::NS_CLIENT1, size, data.data(), &address); } else @@ -387,4 +387,4 @@ namespace network }; } -REGISTER_COMPONENT(network::component) \ No newline at end of file +REGISTER_COMPONENT(network::component) From 71ef00d29c76abafd00769860c8dbcb6f91cd8af Mon Sep 17 00:00:00 2001 From: quaK Date: Fri, 25 Apr 2025 21:47:52 +0300 Subject: [PATCH 8/8] Faster bootup Co-Authored-By: m <64374267+mjkzy@users.noreply.github.com> --- src/client/component/wmi.cpp | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/client/component/wmi.cpp diff --git a/src/client/component/wmi.cpp b/src/client/component/wmi.cpp new file mode 100644 index 00000000..37135a66 --- /dev/null +++ b/src/client/component/wmi.cpp @@ -0,0 +1,49 @@ +#include +#include "loader/component_loader.hpp" + +#include "game/game.hpp" + +#include "console/console.hpp" + +#include + +// Speeds up startup by disabling WMI + +namespace wmi +{ + namespace + { + HRESULT WINAPI co_initialize_ex_stub(LPVOID pvReserved, DWORD dwCoInit) + { + if ((uint64_t)_ReturnAddress() == 0x1412B36F2) + { + return E_FAIL; + } + + return CoInitializeEx(pvReserved, dwCoInit); + } + } + + class component final : public component_interface + { + public: + void* load_import(const std::string& library, const std::string& function) override + { + if (function == "CoInitializeEx") + { + return co_initialize_ex_stub; + } + + return nullptr; + } + + void post_unpack() override + { + // disable WMI and remove Hardware query(uses WMI) + utils::hook::set(0x140110260, 0xC3); // WMI + utils::hook::set(0x14002D808, 0xC3); // Hardware query + } + }; +} + +REGISTER_COMPONENT(wmi::component) \ No newline at end of file