From 4047857317db8a111b7eaf2c62f625b592f49e75 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sat, 28 May 2022 19:08:51 +0200 Subject: [PATCH] Fix ping value --- src/client/component/fps.cpp | 4 ++-- src/client/component/ui_scripting.cpp | 7 ++++++- src/client/game/structs.hpp | 7 ++++++- src/client/game/symbols.hpp | 2 -- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/client/component/fps.cpp b/src/client/component/fps.cpp index a2523ca3..dc721c3b 100644 --- a/src/client/component/fps.cpp +++ b/src/client/component/fps.cpp @@ -115,10 +115,10 @@ namespace fps void cg_draw_ping() { - if (cg_drawping->current.integer > 0 && game::CL_IsCgameInitialized() && !game::VirtualLobby_Loaded()) + if (cg_drawping->current.integer > 0 && game::CL_IsCgameInitialized() && !game::VirtualLobby_Loaded() && *game::mp::client_state) { const auto font = game::R_RegisterFont("fonts/consolefont", 20); - const auto ping_string = utils::string::va("Ping: %i", *game::mp::ping); + const auto ping_string = utils::string::va("Ping: %i", (*game::mp::client_state)->ping); const auto x = (game::ScrPlace_GetViewPlacement()->realViewportSize[0] - 375.0f) - game::R_TextWidth( ping_string, 0x7FFFFFFF, font); diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index a4bc3cf2..9c5bf61b 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -188,7 +188,12 @@ namespace ui_scripting game_type["getping"] = [](const game&) { - return *::game::mp::ping; + if ((*::game::mp::client_state) == nullptr) + { + return 0; + } + + return (*::game::mp::client_state)->ping; }; game_type["issingleplayer"] = [](const game&) diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index a5954baf..78c56f1e 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1460,10 +1460,15 @@ namespace game // made up struct client_state_t { - char __pad0[0x4A5C]; + char __pad0[0x4A50]; + int ping; + char __pad1[0x8]; int num_players; }; + static_assert(offsetof(client_state_t, ping) == 0x4A50); + static_assert(offsetof(client_state_t, num_players) == 0x4A5C); + enum PlayerHandIndex { WEAPON_HAND_DEFAULT = 0x0, diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index 099d3e46..6f83e41e 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -269,8 +269,6 @@ namespace game WEAK symbol svs_numclients{0x0, 0x2DC338C}; WEAK symbol gameTime{0x0, 0x0}; - WEAK symbol ping{0x0, 0x2ECCF40}; - WEAK symbol sv_serverId_value{0x0, 0x0}; WEAK symbol virtualLobby_loaded{0x0, 0x2E6EC9D};