Add better hud ping & fps counter
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
#include <std_include.hpp>
|
||||
#include "loader/component_loader.hpp"
|
||||
|
||||
#include "fps.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
#include "game/dvars.hpp"
|
||||
|
||||
@ -93,9 +95,7 @@ namespace fps
|
||||
{
|
||||
if (cg_drawfps->current.integer > 0)
|
||||
{
|
||||
const auto fps = static_cast<std::int32_t>(static_cast<float>(1000.0f / static_cast<float>(cg_perf.
|
||||
average))
|
||||
+ 9.313225746154785e-10);
|
||||
const auto fps = fps::get_fps();
|
||||
|
||||
const auto font = game::R_RegisterFont("fonts/fira_mono_regular.ttf", 25);
|
||||
const auto fps_string = utils::string::va("%i", fps);
|
||||
@ -113,10 +113,8 @@ namespace fps
|
||||
{
|
||||
if (cg_drawping->current.integer > 0 && game::CL_IsCgameInitialized() && !game::VirtualLobby_Loaded())
|
||||
{
|
||||
const auto ping = *reinterpret_cast<int*>(0x142D106F0);
|
||||
|
||||
const auto font = game::R_RegisterFont("fonts/consolefont", 20);
|
||||
const auto ping_string = utils::string::va("Ping: %i", ping);
|
||||
const auto ping_string = utils::string::va("Ping: %i", *game::mp::ping);
|
||||
|
||||
const auto x = (game::ScrPlace_GetViewPlacement()->realViewportSize[0] - 375.0f) - game::R_TextWidth(
|
||||
ping_string, 0x7FFFFFFF, font);
|
||||
@ -134,6 +132,13 @@ namespace fps
|
||||
}
|
||||
}
|
||||
|
||||
int get_fps()
|
||||
{
|
||||
return static_cast<std::int32_t>(static_cast<float>(1000.0f / static_cast<float>(cg_perf.
|
||||
average))
|
||||
+ 9.313225746154785e-10);
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
{
|
||||
public:
|
||||
@ -167,6 +172,9 @@ namespace fps
|
||||
|
||||
scheduler::loop(cg_draw_ping, scheduler::pipeline::renderer);
|
||||
}
|
||||
|
||||
dvars::register_bool("cg_infobar_fps", false, game::DVAR_FLAG_SAVED, true);
|
||||
dvars::register_bool("cg_infobar_ping", false, game::DVAR_FLAG_SAVED, true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
6
src/client/component/fps.hpp
Normal file
6
src/client/component/fps.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace fps
|
||||
{
|
||||
int get_fps();
|
||||
}
|
@ -266,7 +266,7 @@ namespace patches
|
||||
|
||||
dvars::register_int("scr_game_spectatetype", 1, 0, 99, game::DVAR_FLAG_REPLICATED);
|
||||
|
||||
dvars::override::register_int("com_maxfps", 0, 10, 1000, game::DVAR_FLAG_SAVED);
|
||||
dvars::override::register_int("com_maxfps", 0, 0, 1000, game::DVAR_FLAG_SAVED);
|
||||
|
||||
// Prevent clients from ending the game as non host by sending 'end_game' lui notification
|
||||
// cmd_lui_notify_server_hook.create(0x140335A70, cmd_lui_notify_server_stub); // H1(1.4)
|
||||
|
@ -220,6 +220,8 @@ namespace game
|
||||
WEAK symbol<int> svs_numclients{0, 0x14B204A0C};
|
||||
WEAK symbol<int> gameTime{0, 0x14621BDBC};
|
||||
|
||||
WEAK symbol<int> ping{0, 0x142D106F0};
|
||||
|
||||
WEAK symbol<int> sv_serverId_value{0, 0x14A3E99B8};
|
||||
|
||||
WEAK symbol<bool> virtualLobby_loaded{0, 0x142D077FD};
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "../../../component/ui_scripting.hpp"
|
||||
#include "../../../component/command.hpp"
|
||||
#include "../../../component/updater.hpp"
|
||||
#include "../../../component/fps.hpp"
|
||||
|
||||
#include "component/game_console.hpp"
|
||||
#include "component/scheduler.hpp"
|
||||
@ -40,6 +41,26 @@ namespace ui_scripting::lua
|
||||
return scheduler.add(callback, milliseconds, false);
|
||||
};
|
||||
|
||||
game_type["getfps"] = [](const game&)
|
||||
{
|
||||
return fps::get_fps();
|
||||
};
|
||||
|
||||
game_type["getping"] = [](const game&)
|
||||
{
|
||||
return *::game::mp::ping;
|
||||
};
|
||||
|
||||
game_type["issingleplayer"] = [](const game&)
|
||||
{
|
||||
return ::game::environment::is_sp();
|
||||
};
|
||||
|
||||
game_type["ismultiplayer"] = [](const game&)
|
||||
{
|
||||
return ::game::environment::is_mp();
|
||||
};
|
||||
|
||||
auto userdata_type = state.new_usertype<userdata>("userdata_");
|
||||
|
||||
userdata_type["new"] = sol::property(
|
||||
|
Reference in New Issue
Block a user