Include more data in console title

Console title contains the following data:
- Server name
- Current map name
- Total players on server / max players (bots)
This commit is contained in:
BrentVL-1952840 2023-02-17 20:45:19 +01:00
parent dfe4b43502
commit c7c10051fc
6 changed files with 104 additions and 37 deletions

View File

@ -1,4 +1,5 @@
#include <std_include.hpp> #include <std_include.hpp>
#include "console.hpp"
#include "loader/component_loader.hpp" #include "loader/component_loader.hpp"
#include "resource.hpp" #include "resource.hpp"
@ -15,6 +16,11 @@
namespace console namespace console
{ {
void set_title(const std::string& title)
{
SetWindowTextA(*game::s_wcd::hWnd, title.data());
}
namespace namespace
{ {
utils::image::object logo; utils::image::object logo;
@ -205,17 +211,6 @@ namespace console
{ {
utils::hook::set<uint8_t>(0x14133D2FE_g, 0xEB); // Always enable ingame console utils::hook::set<uint8_t>(0x14133D2FE_g, 0xEB); // Always enable ingame console
} }
else
{
scheduler::once([]()
{
const auto server_name_dvar = game::Dvar_FindVar("live_steam_server_name");
if (server_name_dvar)
{
SetWindowTextA(*game::s_wcd::hWnd, server_name_dvar->current.string);
}
}, scheduler::pipeline::main);
}
utils::hook::jump(game::select(0x1423337F0, 0x1405976B0), queue_message); utils::hook::jump(game::select(0x1423337F0, 0x1405976B0), queue_message);
utils::hook::nop(game::select(0x14233380A, 0x1405976CA), 2); // Print from every thread utils::hook::nop(game::select(0x14233380A, 0x1405976CA), 2); // Print from every thread

View File

@ -0,0 +1,6 @@
#pragma once
namespace console
{
void set_title(const std::string& title);
}

View File

@ -0,0 +1,42 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/utils.hpp"
#include "scheduler.hpp"
#include "getinfo.hpp"
#include "console.hpp"
#include <utils/string.hpp>
namespace dedicated_info
{
class component final : public server_component
{
public:
void post_unpack() override
{
scheduler::loop([]()
{
const auto sv_running = game::Dvar_FindVar("sv_running");
if (sv_running && sv_running->current.enabled)
{
const auto server_name = game::get_dvar_string("live_steam_server_name");
const auto mapname = game::get_dvar_string("mapname");
std::string window_text = utils::string::va("%s on %s [%d/%d] (%d)",
server_name.data(),
mapname.data(),
getinfo::get_client_count(),
getinfo::get_max_client_count(),
getinfo::get_bot_count());
console::set_title(window_text);
}
}, scheduler::pipeline::main, 1s);
}
};
}
REGISTER_COMPONENT(dedicated_info::component)

View File

@ -16,31 +16,46 @@
namespace getinfo namespace getinfo
{ {
int get_max_client_count()
{
return game::get_dvar_int("com_maxclients");
}
int get_client_count()
{
int count = 0;
const auto client_states = *reinterpret_cast<uint64_t*>(game::select(0x1576FB318, 0x14A178E98));
const auto object_length = game::is_server() ? 0xE5110 : 0xE5170;
for (int i = 0; i < get_max_client_count(); ++i)
{
const auto client_state = *reinterpret_cast<int*>(client_states + (i * object_length));
if (client_state > 0)
{
++count;
}
}
return count;
}
int get_bot_count()
{
int count = 0;
for (int i = 0; i < get_max_client_count(); ++i)
{
if (game::SV_IsTestClient(i))
{
++count;
}
}
return count;
}
namespace namespace
{ {
int get_max_client_count()
{
return game::get_dvar_int("com_maxclients");
}
int get_client_count()
{
int count = 0;
const auto client_states = *reinterpret_cast<uint64_t*>(game::select(0x1576FB318, 0x14A178E98));
const auto object_length = game::is_server() ? 0xE5110 : 0xE5170;
for (int i = 0; i < get_max_client_count(); ++i)
{
const auto client_state = *reinterpret_cast<int*>(client_states + (i * object_length));
if (client_state > 0)
{
++count;
}
}
return count;
}
int Com_SessionMode_GetGameMode() int Com_SessionMode_GetGameMode()
{ {
return *reinterpret_cast<int*>(game::select(0x1568EF7F4, 0x14948DB04)) << 14 >> 28; return *reinterpret_cast<int*>(game::select(0x1568EF7F4, 0x14948DB04)) << 14 >> 28;

View File

@ -0,0 +1,8 @@
#pragma once
namespace getinfo
{
int get_max_client_count();
int get_client_count();
int get_bot_count();
}

View File

@ -27,7 +27,7 @@ namespace game
}; };
WEAK symbol<void(uint32_t localClientNum, const char* text)> Cbuf_AddText{0x1420EC8B0, 0x1404F75B0}; WEAK symbol<void(uint32_t localClientNum, const char* text)> Cbuf_AddText{0x1420EC8B0, 0x1404F75B0};
WEAK symbol<void(int localClientNum, ControllerIndex_t controllerIndex, const char* buffer)> Cbuf_ExecuteBuffer{ WEAK symbol<void(uint32_t localClientNum, ControllerIndex_t controllerIndex, const char* buffer)> Cbuf_ExecuteBuffer{
0x14133BE10, 0x1404F78D0 0x14133BE10, 0x1404F78D0
}; };
WEAK symbol<void(const char* cmdName, xcommand_t function, cmd_function_s* allocedCmd)> Cmd_AddCommandInternal{ WEAK symbol<void(const char* cmdName, xcommand_t function, cmd_function_s* allocedCmd)> Cmd_AddCommandInternal{
@ -99,8 +99,8 @@ namespace game
WEAK symbol<void(const char*, const char*, int, game::hks::lua_State*)> UI_AddMenu{ 0x1427024B0, 0x0 }; WEAK symbol<void(const char*, const char*, int, game::hks::lua_State*)> UI_AddMenu{ 0x1427024B0, 0x0 };
WEAK symbol<const char* (int)> UI_CoD_GetRootNameForController{ 0x141F291E0, 0x0 }; WEAK symbol<const char* (int)> UI_CoD_GetRootNameForController{ 0x141F291E0, 0x0 };
WEAK symbol<void(game::hks::lua_State*, const char*)> Lua_CoD_LoadLuaFile{ 0x141F122C0, 0x0 }; WEAK symbol<void(game::hks::lua_State*, const char*)> Lua_CoD_LoadLuaFile{ 0x141F122C0, 0x0 };
WEAK symbol<void(int localClientNum)> CG_LUIHUDRestart{ 0x140F7E970 }; WEAK symbol<void(uint32_t localClientNum)> CG_LUIHUDRestart{ 0x140F7E970 };
WEAK symbol<void(int localClientNum)> CL_CheckKeepDrawingConnectScreen{ 0x1413CCAE0 }; WEAK symbol<void(uint32_t localClientNum)> CL_CheckKeepDrawingConnectScreen{ 0x1413CCAE0 };
// Scr // Scr
WEAK symbol<void(scriptInstance_t inst, int value)> Scr_AddInt{0x0, 0x14016F160}; WEAK symbol<void(scriptInstance_t inst, int value)> Scr_AddInt{0x0, 0x14016F160};
@ -125,6 +125,7 @@ namespace game
// SV // SV
WEAK symbol<void*()> SV_AddTestClient{0x1422499A0, 0x14052E3E0}; WEAK symbol<void*()> SV_AddTestClient{0x1422499A0, 0x14052E3E0};
WEAK symbol<void(client_s* cl_0, svscmd_type type, const char* fmt, ...)> SV_SendServerCommand{0x0, 0x140537F10}; WEAK symbol<void(client_s* cl_0, svscmd_type type, const char* fmt, ...)> SV_SendServerCommand{0x0, 0x140537F10};
WEAK symbol<bool(uint32_t clientNum)> SV_IsTestClient{0x14224B5C0, 0x14052FF40};
// Variables // Variables