Fix ping value

This commit is contained in:
Federico Cecchetto 2022-05-28 19:08:51 +02:00
parent 93a0d730a4
commit aebf58c667
4 changed files with 14 additions and 6 deletions

View File

@ -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);

View File

@ -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&)

View File

@ -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,

View File

@ -269,8 +269,6 @@ namespace game
WEAK symbol<int> svs_numclients{0x0, 0x2DC338C};
WEAK symbol<int> gameTime{0x0, 0x0};
WEAK symbol<int> ping{0x0, 0x2ECCF40};
WEAK symbol<int> sv_serverId_value{0x0, 0x0};
WEAK symbol<bool> virtualLobby_loaded{0x0, 0x2E6EC9D};