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/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}; }); } 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) 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{}; 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(); 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 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 diff --git a/src/client/resource.rc b/src/client/resource.rc index a82b333e..e0d134e1 100644 --- a/src/client/resource.rc +++ b/src/client/resource.rc @@ -123,4 +123,3 @@ ICON_IMAGE RCDATA "resources/icon.png" ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED - 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;