From 4661b261274cdbe0340afab0c78b8cf7a9efb882 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 7 Apr 2023 14:51:16 +0200 Subject: [PATCH 1/4] Revert "Temporarily diable new protocol to merge changes" This reverts commit 6d0d3510646121acf41f3164e283b60201fa2d81. --- src/client/component/auth.cpp | 8 +++----- src/client/game/structs.hpp | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp index 45405af4..d5e2d4f6 100644 --- a/src/client/component/auth.cpp +++ b/src/client/component/auth.cpp @@ -172,9 +172,8 @@ namespace auth void post_unpack() override { // Skip connect handler - //utils::hook::set(game::select(0x142253EFA, 0x14053714A), 0xEB); - //network::on("connect", handle_connect_packet); - (void)&handle_connect_packet; + utils::hook::set(game::select(0x142253EFA, 0x14053714A), 0xEB); + network::on("connect", handle_connect_packet); // Patch steam id bit check std::vector> patches{}; @@ -221,8 +220,7 @@ namespace auth p(0x141EB5992_g, 0x141EB59D5_g); p(0x141EB74D2_g, 0x141EB7515_g); // ? - //utils::hook::call(0x14134BF7D_g, send_connect_data_stub); - (void)&send_connect_data_stub; + utils::hook::call(0x14134BF7D_g, send_connect_data_stub); } for (const auto& patch : patches) diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index a54fddbf..1e852b6c 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1,6 +1,6 @@ #pragma once -#define PROTOCOL 1 +#define PROTOCOL 2 #ifdef __cplusplus namespace game From f019f7f30a644da94694ecd4b4d643cf89c308ea Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 7 Apr 2023 14:52:08 +0200 Subject: [PATCH 2/4] Remove debug print --- src/client/component/profile_infos.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/client/component/profile_infos.cpp b/src/client/component/profile_infos.cpp index b72d192f..2badc361 100644 --- a/src/client/component/profile_infos.cpp +++ b/src/client/component/profile_infos.cpp @@ -201,8 +201,6 @@ namespace profile_infos std::optional get_profile_info(const uint64_t user_id) { - printf("Requesting profile info: %llX\n", user_id); - if (user_id == steam::SteamUser()->GetSteamID().bits) { return get_profile_info(); From 54519cdc0aba1ce1db050014a0e4975d7e8a148b Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 7 Apr 2023 14:52:39 +0200 Subject: [PATCH 3/4] Fix static assert --- src/client/game/structs.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index 1e852b6c..54dde0c0 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1556,7 +1556,7 @@ namespace game char __pad4[0x29DAC]; }; - static_assert(sizeof(client_s) <= 0xE5110); + static_assert(sizeof(client_s) == 0xE5110); static_assert(offsetof(game::client_s, address) == 0x2C); static_assert(offsetof(game::client_s, xuid) == 0x55C8); From fb57f0d55fb7e38d9db74a622d014c0ac60cfca5 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 7 Apr 2023 20:25:43 +0200 Subject: [PATCH 4/4] Fix profile info distribution --- src/client/component/auth.cpp | 10 +++++++++ src/client/component/profile_infos.cpp | 30 ++++++++------------------ src/client/component/profile_infos.hpp | 1 + src/common/utils/concurrency.hpp | 5 +++++ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp index d5e2d4f6..e870dfc5 100644 --- a/src/client/component/auth.cpp +++ b/src/client/component/auth.cpp @@ -143,12 +143,22 @@ namespace auth return; } + const auto _ = profile_infos::acquire_profile_lock(); + const utils::info_string info_string(params[1]); const auto xuid = strtoull(info_string.get("xuid").data(), nullptr, 16); profile_infos::add_and_distribute_profile_info(target, xuid, info); game::SV_DirectConnect(target); + + game::foreach_connected_client([&](game::client_s& client) + { + if (client.address == target) + { + client.xuid = xuid; + } + }); } } diff --git a/src/client/component/profile_infos.cpp b/src/client/component/profile_infos.cpp index 2badc361..597be96a 100644 --- a/src/client/component/profile_infos.cpp +++ b/src/client/component/profile_infos.cpp @@ -20,7 +20,7 @@ namespace profile_infos namespace { using profile_map = std::unordered_map; - utils::concurrency::container profile_mapping{}; + utils::concurrency::container profile_mapping{}; std::optional load_profile_info() { @@ -68,21 +68,6 @@ namespace profile_infos }); } - void schedule_pcache_update() - { - static std::atomic_bool update_triggered{false}; - if (game::is_server() || update_triggered.exchange(true)) - { - return; - } - - scheduler::once([] - { - game::PCache_DeleteEntries(game::CONTROLLER_INDEX_FIRST); - update_triggered = false; - }, scheduler::main, 5s); - } - std::unordered_set get_connected_client_xuids() { std::unordered_set connected_clients{}; @@ -103,10 +88,10 @@ namespace profile_infos return; } - const auto xuids = get_connected_client_xuids(); - - profile_mapping.access([&](profile_map& profiles) + profile_mapping.access([](profile_map& profiles) { + const auto xuids = get_connected_client_xuids(); + for (auto i = profiles.begin(); i != profiles.end();) { if (xuids.contains(i->first)) @@ -145,8 +130,6 @@ namespace profile_infos { profiles[user_id] = info; }); - - schedule_pcache_update(); } void distribute_profile_info_to_user(const game::netadr_t& addr, const uint64_t user_id, const profile_info& info) @@ -194,6 +177,11 @@ namespace profile_infos }); } + std::unique_lock acquire_profile_lock() + { + return profile_mapping.acquire_lock(); + } + std::optional get_profile_info() { return load_profile_info(); diff --git a/src/client/component/profile_infos.hpp b/src/client/component/profile_infos.hpp index c1cfd1f8..611ba422 100644 --- a/src/client/component/profile_infos.hpp +++ b/src/client/component/profile_infos.hpp @@ -19,6 +19,7 @@ namespace profile_infos void add_and_distribute_profile_info(const game::netadr_t& addr, uint64_t user_id, const profile_info& info); void clear_profile_infos(); + std::unique_lock acquire_profile_lock(); std::optional get_profile_info(); std::optional get_profile_info(uint64_t user_id); diff --git a/src/common/utils/concurrency.hpp b/src/common/utils/concurrency.hpp index 75967525..e8be0db0 100644 --- a/src/common/utils/concurrency.hpp +++ b/src/common/utils/concurrency.hpp @@ -45,6 +45,11 @@ namespace utils::concurrency return object_; } + std::unique_lock acquire_lock() + { + return std::unique_lock{mutex_}; + } + private: mutable MutexType mutex_{}; T object_{};