From 363f8cb01a070795101ac07fdae43e26aec9d885 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 7 Apr 2023 12:12:19 +0200 Subject: [PATCH] Trigger pcache updates --- src/client/component/auth.cpp | 7 +++- src/client/component/profile_infos.cpp | 55 ++++++++++++++++++++------ src/client/game/symbols.hpp | 3 ++ 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/client/component/auth.cpp b/src/client/component/auth.cpp index a8bfd8eb..7385be95 100644 --- a/src/client/component/auth.cpp +++ b/src/client/component/auth.cpp @@ -7,6 +7,7 @@ #include "profile_infos.hpp" #include +#include #include #include @@ -16,7 +17,6 @@ #include #include - namespace auth { namespace @@ -127,7 +127,10 @@ namespace auth void handle_connect_packet(const game::netadr_t& target, const network::data_view& data) { - // TODO: SV running? + if (!game::get_dvar_bool("sv_running")) + { + return; + } utils::byte_buffer buffer(data); const profile_infos::profile_info info(buffer); diff --git a/src/client/component/profile_infos.cpp b/src/client/component/profile_infos.cpp index 24c9ba68..46fa2c6d 100644 --- a/src/client/component/profile_infos.cpp +++ b/src/client/component/profile_infos.cpp @@ -4,6 +4,7 @@ #include "profile_infos.hpp" #include "network.hpp" #include "party.hpp" +#include "scheduler.hpp" #include #include @@ -90,6 +91,31 @@ namespace profile_infos distribute_profile_info(*game::svs_clients_cl, buffer.get_buffer()); } } + + 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); + } + + void clean_cached_profile_infos() + { + if (!game::get_dvar_bool("sv_running")) + { + return; + } + + // TODO + } } profile_info::profile_info(utils::byte_buffer& buffer) @@ -111,12 +137,12 @@ namespace profile_infos return; } - printf("Adding profile info: %llX\n", user_id); - profile_mapping.access([&](profile_map& profiles) { 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) @@ -203,23 +229,28 @@ namespace profile_infos utils::io::write_file("players/user/profile_info", data); } - struct component final : client_component + struct component final : generic_component { void post_unpack() override { - network::on("profileInfo", [](const game::netadr_t& server, const network::data_view& data) + scheduler::loop(clean_cached_profile_infos, scheduler::main, 5s); + + if (game::is_client()) { - if (!party::is_host(server)) + network::on("profileInfo", [](const game::netadr_t& server, const network::data_view& data) { - return; - } + if (!party::is_host(server)) + { + return; + } - utils::byte_buffer buffer(data); - const auto user_id = buffer.read(); - const profile_info info(buffer); + utils::byte_buffer buffer(data); + const auto user_id = buffer.read(); + const profile_info info(buffer); - add_profile_info(user_id, info); - }); + add_profile_info(user_id, info); + }); + } } }; } diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index 6abf5b32..4f666024 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -157,6 +157,9 @@ namespace game 0x141CD98D0 }; + // PCache + WEAK symbol PCache_DeleteEntries{0x141E8D710}; + // SV WEAK symbol SV_Loaded{0x142252250, 0x140535460}; WEAK symbol SV_AddTestClient{0x142248F40, 0x14052E3E0};