2023-01-02 07:57:00 -05:00
|
|
|
#include <std_include.hpp>
|
|
|
|
#include "loader/component_loader.hpp"
|
|
|
|
|
|
|
|
#include "game/game.hpp"
|
|
|
|
#include "steam/steam.hpp"
|
|
|
|
|
|
|
|
#include "network.hpp"
|
|
|
|
|
2023-01-07 07:46:09 -05:00
|
|
|
#include <utils/hook.hpp>
|
2023-01-02 07:57:00 -05:00
|
|
|
#include <utils/string.hpp>
|
|
|
|
#include <utils/info_string.hpp>
|
|
|
|
|
|
|
|
#include <version.hpp>
|
|
|
|
|
2023-02-12 04:51:15 -05:00
|
|
|
#include "game/utils.hpp"
|
|
|
|
|
2023-01-02 07:57:00 -05:00
|
|
|
namespace getinfo
|
|
|
|
{
|
2023-02-17 14:45:19 -05:00
|
|
|
int get_max_client_count()
|
2023-01-02 07:57:00 -05:00
|
|
|
{
|
2023-02-17 14:45:19 -05:00
|
|
|
return game::get_dvar_int("com_maxclients");
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_client_count()
|
|
|
|
{
|
|
|
|
int count = 0;
|
2023-03-04 10:50:42 -05:00
|
|
|
const auto client_states = *reinterpret_cast<uint64_t*>(game::select(0x1576F9318, 0x14A178E98));
|
2023-02-22 13:53:42 -05:00
|
|
|
if (!client_states)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-17 14:45:19 -05:00
|
|
|
const auto object_length = game::is_server() ? 0xE5110 : 0xE5170;
|
|
|
|
|
|
|
|
for (int i = 0; i < get_max_client_count(); ++i)
|
2023-02-07 13:21:25 -05:00
|
|
|
{
|
2023-02-17 14:45:19 -05:00
|
|
|
const auto client_state = *reinterpret_cast<int*>(client_states + (i * object_length));
|
|
|
|
if (client_state > 0)
|
|
|
|
{
|
|
|
|
++count;
|
|
|
|
}
|
2023-02-07 13:21:25 -05:00
|
|
|
}
|
|
|
|
|
2023-02-17 14:45:19 -05:00
|
|
|
return count;
|
|
|
|
}
|
2023-02-07 13:21:25 -05:00
|
|
|
|
2023-02-17 14:45:19 -05:00
|
|
|
int get_bot_count()
|
|
|
|
{
|
2023-03-04 10:50:42 -05:00
|
|
|
const auto client_states = *reinterpret_cast<uint64_t*>(game::select(0x1576F9318, 0x14A178E98));
|
2023-02-22 13:53:42 -05:00
|
|
|
if (!client_states)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-17 14:45:19 -05:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < get_max_client_count(); ++i)
|
|
|
|
{
|
|
|
|
if (game::SV_IsTestClient(i))
|
2023-02-07 13:21:25 -05:00
|
|
|
{
|
2023-02-17 14:45:19 -05:00
|
|
|
++count;
|
2023-02-07 13:21:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-17 14:45:19 -05:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2023-02-04 09:53:54 -05:00
|
|
|
int Com_SessionMode_GetGameMode()
|
|
|
|
{
|
2023-03-04 10:50:42 -05:00
|
|
|
return *reinterpret_cast<int*>(game::select(0x1568ED7F4, 0x14948DB04)) << 14 >> 28;
|
2023-02-04 09:53:54 -05:00
|
|
|
}
|
2023-01-02 07:57:00 -05:00
|
|
|
}
|
|
|
|
|
2023-01-07 07:46:09 -05:00
|
|
|
int get_assigned_team()
|
|
|
|
{
|
|
|
|
return (rand() % 2) + 1;
|
|
|
|
}
|
2023-02-07 13:27:03 -05:00
|
|
|
|
2023-02-27 06:32:29 -05:00
|
|
|
bool is_host()
|
|
|
|
{
|
2023-02-28 01:35:12 -05:00
|
|
|
return game::SV_Loaded() && (game::is_server() || !game::Com_IsRunningUILevel());
|
2023-02-27 06:32:29 -05:00
|
|
|
}
|
|
|
|
|
2023-01-02 07:57:00 -05:00
|
|
|
struct component final : generic_component
|
|
|
|
{
|
|
|
|
void post_unpack() override
|
|
|
|
{
|
2023-01-07 07:46:09 -05:00
|
|
|
//utils::hook::jump(game::select(0x142254EF0, 0x140537730), get_assigned_team);
|
|
|
|
|
2023-01-02 07:57:00 -05:00
|
|
|
network::on("getInfo", [](const game::netadr_t& target, const network::data_view& data)
|
|
|
|
{
|
|
|
|
utils::info_string info{};
|
|
|
|
info.set("challenge", std::string(data.begin(), data.end()));
|
|
|
|
info.set("gamename", "T7");
|
2023-02-22 13:53:42 -05:00
|
|
|
info.set("hostname",
|
|
|
|
game::get_dvar_string(game::is_server() ? "live_steam_server_name" : "sv_hostname"));
|
2023-02-12 04:51:15 -05:00
|
|
|
info.set("gametype", game::get_dvar_string("g_gametype"));
|
2023-01-02 07:57:00 -05:00
|
|
|
//info.set("sv_motd", get_dvar_string("sv_motd"));
|
2023-02-22 13:53:42 -05:00
|
|
|
info.set("description",
|
|
|
|
game::is_server() ? game::get_dvar_string("live_steam_server_description") : "");
|
2023-01-02 07:57:00 -05:00
|
|
|
info.set("xuid", utils::string::va("%llX", steam::SteamUser()->GetSteamID().bits));
|
2023-02-12 04:51:15 -05:00
|
|
|
info.set("mapname", game::get_dvar_string("mapname"));
|
|
|
|
info.set("isPrivate", game::get_dvar_string("g_password").empty() ? "0" : "1");
|
2023-02-07 13:21:25 -05:00
|
|
|
info.set("clients", utils::string::va("%i", get_client_count()));
|
2023-02-18 16:07:45 -05:00
|
|
|
info.set("bots", utils::string::va("%i", get_bot_count()));
|
2023-02-07 13:21:25 -05:00
|
|
|
info.set("sv_maxclients", utils::string::va("%i", get_max_client_count()));
|
2023-02-05 10:15:29 -05:00
|
|
|
info.set("protocol", utils::string::va("%i", PROTOCOL));
|
2023-01-02 07:57:00 -05:00
|
|
|
info.set("playmode", utils::string::va("%i", game::Com_SessionMode_GetMode()));
|
2023-02-04 09:53:54 -05:00
|
|
|
info.set("gamemode", utils::string::va("%i", Com_SessionMode_GetGameMode()));
|
2023-01-02 07:57:00 -05:00
|
|
|
//info.set("sv_running", utils::string::va("%i", get_dvar_bool("sv_running")));
|
|
|
|
info.set("dedicated", utils::string::va("%i", game::is_server() ? 1 : 0));
|
|
|
|
info.set("shortversion", SHORTVERSION);
|
|
|
|
|
|
|
|
network::send(target, "infoResponse", info.build(), '\n');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-04 10:50:42 -05:00
|
|
|
REGISTER_COMPONENT_WORKING(getinfo::component)
|