diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index d9ea8b16..a5b1ce7d 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -223,7 +223,7 @@ namespace Components DownloadProgress(&fDownload, bytes - fDownload.receivedBytes); }); - bool result = false; + auto result = false; fDownload.buffer = webIO.get(url, &result); if (!result) fDownload.buffer.clear(); diff --git a/src/Components/Modules/GSC/String.cpp b/src/Components/Modules/GSC/String.cpp index 0ee3b029..ebfb5bed 100644 --- a/src/Components/Modules/GSC/String.cpp +++ b/src/Components/Modules/GSC/String.cpp @@ -12,7 +12,7 @@ namespace Components::GSC const auto scriptValue = Game::Scr_GetConstString(0); const auto* string = Game::SL_ConvertToString(scriptValue); - char out[1024] = {0}; // 1024 is the max for a string in this SL system + char out[1024]{}; // 1024 is the max for a string in this SL system bool changed = false; size_t i = 0; diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index e29ae2c9..1418e6aa 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -349,10 +349,18 @@ namespace Components { for (int i = 0; i < maxClientCount; ++i) { - if (Game::svs_clients[i].header.state >= Game::CS_CONNECTED) + if (Game::svs_clients[i].header.state < Game::CS_ACTIVE) continue; + if (!Game::svs_clients[i].gentity || !Game::svs_clients[i].gentity->client) continue; + + const auto* client = Game::svs_clients[i].gentity->client; + const auto team = client->sess.cs.team; + if (Game::svs_clients[i].bIsTestClient || team == Game::TEAM_SPECTATOR) { - if (Game::svs_clients[i].bIsTestClient) ++botCount; - else ++clientCount; + ++botCount; + } + else + { + ++clientCount; } } } @@ -543,7 +551,7 @@ namespace Components if (clients >= maxClients) { - Party::ConnectError("@EXE_SERVERISFULL"); + ConnectError("@EXE_SERVERISFULL"); } else { diff --git a/src/Components/Modules/ServerInfo.cpp b/src/Components/Modules/ServerInfo.cpp index b929497f..0172f4a5 100644 --- a/src/Components/Modules/ServerInfo.cpp +++ b/src/Components/Modules/ServerInfo.cpp @@ -14,28 +14,25 @@ namespace Components { ServerInfo::Container ServerInfo::PlayerContainer; - Game::dvar_t** ServerInfo::CGScoreboardHeight; - Game::dvar_t** ServerInfo::CGScoreboardWidth; - unsigned int ServerInfo::GetPlayerCount() { - return ServerInfo::PlayerContainer.playerList.size(); + return PlayerContainer.playerList.size(); } const char* ServerInfo::GetPlayerText(unsigned int index, int column) { - if (index < ServerInfo::PlayerContainer.playerList.size()) + if (index < PlayerContainer.playerList.size()) { switch (column) { case 0: return Utils::String::VA("%d", index); case 1: - return ServerInfo::PlayerContainer.playerList[index].name.data(); + return PlayerContainer.playerList[index].name.data(); case 2: - return Utils::String::VA("%d", ServerInfo::PlayerContainer.playerList[index].score); + return Utils::String::VA("%d", PlayerContainer.playerList[index].score); case 3: - return Utils::String::VA("%d", ServerInfo::PlayerContainer.playerList[index].ping); + return Utils::String::VA("%d", PlayerContainer.playerList[index].ping); default: break; } @@ -46,13 +43,13 @@ namespace Components void ServerInfo::SelectPlayer(unsigned int index) { - ServerInfo::PlayerContainer.currentPlayer = index; + PlayerContainer.currentPlayer = index; } void ServerInfo::ServerStatus([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info) { - ServerInfo::PlayerContainer.currentPlayer = 0; - ServerInfo::PlayerContainer.playerList.clear(); + PlayerContainer.currentPlayer = 0; + PlayerContainer.playerList.clear(); auto* serverInfo = ServerList::GetCurrentServer(); @@ -78,8 +75,8 @@ namespace Components Dvar::Var("uiSi_ModName").set(serverInfo->mod.data() + 5); } - ServerInfo::PlayerContainer.target = serverInfo->addr; - Network::SendCommand(ServerInfo::PlayerContainer.target, "getstatus"); + PlayerContainer.target = serverInfo->addr; + Network::SendCommand(PlayerContainer.target, "getstatus"); } } @@ -90,22 +87,24 @@ namespace Components auto addressText = Network::Address(*Game::connectedHost).getString(); - if (addressText == "0.0.0.0:0" || addressText == "loopback") - addressText = "Listen Server"; + if (addressText == "0.0.0.0:0"s || addressText == "loopback"s) + { + addressText = "Listen Server"s; + } // Get x positions - auto y = (480.0f - (*ServerInfo::CGScoreboardHeight)->current.value) * 0.5f; - y += (*ServerInfo::CGScoreboardHeight)->current.value + 6.0f; + auto y = (480.0f - (*Game::cg_scoreboardHeight)->current.value) * 0.5f; + y += (*Game::cg_scoreboardHeight)->current.value + 6.0f; - const auto x = 320.0f - (*ServerInfo::CGScoreboardWidth)->current.value * 0.5f; - const auto x2 = 320.0f + (*ServerInfo::CGScoreboardWidth)->current.value * 0.5f; + const auto x = 320.0f - (*Game::cg_scoreboardWidth)->current.value * 0.5f; + const auto x2 = 320.0f + (*Game::cg_scoreboardWidth)->current.value * 0.5f; // Draw only when stream friendly ui is not enabled if (!Friends::UIStreamFriendly.get()) { constexpr auto fontSize = 0.35f; - Game::UI_DrawText(cxt, reinterpret_cast(0x7ED3F8), 0x7FFFFFFF, font, x, y, 0, 0, fontSize, reinterpret_cast(0x747F34), 3); - Game::UI_DrawText(cxt, addressText.data(), 0x7FFFFFFF, font, x2 - Game::UI_TextWidth(addressText.data(), 0, font, fontSize), y, 0, 0, fontSize, reinterpret_cast(0x747F34), 3); + Game::UI_DrawText(cxt, reinterpret_cast(0x7ED3F8), std::numeric_limits::max(), font, x, y, 0, 0, fontSize, reinterpret_cast(0x747F34), 3); + Game::UI_DrawText(cxt, addressText.data(), std::numeric_limits::max(), font, x2 - Game::UI_TextWidth(addressText.data(), 0, font, fontSize), y, 0, 0, fontSize, reinterpret_cast(0x747F34), 3); } } @@ -115,7 +114,7 @@ namespace Components { pushad push eax - call ServerInfo::DrawScoreboardInfo + call DrawScoreboardInfo pop eax popad @@ -187,28 +186,25 @@ namespace Components ServerInfo::ServerInfo() { - ServerInfo::PlayerContainer.currentPlayer = 0; - - ServerInfo::CGScoreboardHeight = reinterpret_cast(0x9FD070); - ServerInfo::CGScoreboardWidth = reinterpret_cast(0x9FD0AC); + PlayerContainer.currentPlayer = 0; // Draw IP and hostname on the scoreboard - Utils::Hook(0x4FC6EA, ServerInfo::DrawScoreboardStub, HOOK_CALL).install()->quick(); + Utils::Hook(0x4FC6EA, DrawScoreboardStub, HOOK_CALL).install()->quick(); // Ignore native getStatus implementation Utils::Hook::Nop(0x62654E, 6); // Add uiscript - UIScript::Add("ServerStatus", ServerInfo::ServerStatus); + UIScript::Add("ServerStatus", ServerStatus); // Add uifeeder - UIFeeder::Add(13.0f, ServerInfo::GetPlayerCount, ServerInfo::GetPlayerText, ServerInfo::SelectPlayer); + UIFeeder::Add(13.0f, GetPlayerCount, GetPlayerText, SelectPlayer); Network::OnClientPacket("getStatus", [](const Network::Address& address, [[maybe_unused]] const std::string& data) { std::string playerList; - Utils::InfoString info = ServerInfo::GetInfo(); + Utils::InfoString info = GetInfo(); info.set("challenge", Utils::ParseChallenge(data)); for (std::size_t i = 0; i < Game::MAX_CLIENTS; ++i) @@ -219,7 +215,15 @@ namespace Components if (Dedicated::IsRunning()) { - if (Game::svs_clients[i].header.state < Game::CS_CONNECTED) continue; + if (Game::svs_clients[i].header.state < Game::CS_ACTIVE) continue; + if (!Game::svs_clients[i].gentity || !Game::svs_clients[i].gentity->client) continue; + + const auto* client = Game::svs_clients[i].gentity->client; + const auto team = client->sess.cs.team; + if (team == Game::TEAM_SPECTATOR) + { + continue; + } score = Game::SV_GameClientNum_Score(static_cast(i)); ping = Game::svs_clients[i].ping; @@ -242,12 +246,12 @@ namespace Components Network::OnClientPacket("statusResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data) { - if (ServerInfo::PlayerContainer.target != address) + if (PlayerContainer.target != address) { return; } - const Utils::InfoString info(data.substr(0, data.find_first_of("\n"))); + const Utils::InfoString info(data.substr(0, data.find_first_of('\n'))); Dvar::Var("uiSi_ServerName").set(info.get("sv_hostname")); Dvar::Var("uiSi_MaxClients").set(info.get("sv_maxclients")); @@ -281,7 +285,7 @@ namespace Components if (Utils::String::StartsWith(info.get("fs_game"), "mods/")) { - auto mod = info.get("fs_game"); + const auto mod = info.get("fs_game"); Dvar::Var("uiSi_ModName").set(mod.substr(5)); } @@ -291,23 +295,23 @@ namespace Components for (std::size_t i = 1; i < lines.size(); ++i) { - ServerInfo::Container::Player player; + Container::Player player; std::string currentData = lines[i]; if (currentData.size() < 3) continue; // Insert score - player.score = atoi(currentData.substr(0, currentData.find_first_of(" ")).data()); + player.score = atoi(currentData.substr(0, currentData.find_first_of(' ')).data()); // Remove score - currentData = currentData.substr(currentData.find_first_of(" ") + 1); + currentData = currentData.substr(currentData.find_first_of(' ') + 1); // Insert ping - player.ping = atoi(currentData.substr(0, currentData.find_first_of(" ")).data()); + player.ping = atoi(currentData.substr(0, currentData.find_first_of(' ')).data()); // Remove ping - currentData = currentData.substr(currentData.find_first_of(" ") + 1); + currentData = currentData.substr(currentData.find_first_of(' ') + 1); if (currentData[0] == '\"') { @@ -321,13 +325,13 @@ namespace Components player.name = currentData; - ServerInfo::PlayerContainer.playerList.push_back(player); + PlayerContainer.playerList.push_back(player); } }); } ServerInfo::~ServerInfo() { - ServerInfo::PlayerContainer.playerList.clear(); + PlayerContainer.playerList.clear(); } } diff --git a/src/Components/Modules/ServerInfo.hpp b/src/Components/Modules/ServerInfo.hpp index f09d87b6..336e035f 100644 --- a/src/Components/Modules/ServerInfo.hpp +++ b/src/Components/Modules/ServerInfo.hpp @@ -28,9 +28,6 @@ namespace Components Network::Address target; }; - static Game::dvar_t** CGScoreboardHeight; - static Game::dvar_t** CGScoreboardWidth; - static Container PlayerContainer; static void ServerStatus([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info); diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index ea3b42c3..b66c9811 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -821,8 +821,10 @@ namespace Components bool ServerList::IsServerListOpen() { auto* menu = Game::Menus_FindByName(Game::uiContext, "pc_join_unranked"); - if (!menu) + if (!menu) + { return false; + } return Game::Menu_IsVisible(Game::uiContext, menu); } diff --git a/src/Components/Modules/Stats.cpp b/src/Components/Modules/Stats.cpp index d46fdbef..8e9580b2 100644 --- a/src/Components/Modules/Stats.cpp +++ b/src/Components/Modules/Stats.cpp @@ -179,7 +179,7 @@ namespace Components return; } - const auto index = std::atoi(params->get(1)); + const auto index = std::strtol(params->get(1), nullptr, 0); const auto stat = Game::LiveStorage_GetStat(0, index); Logger::Print(Game::CON_CHANNEL_SYSTEM, "Stat {}: {}\n", index, stat); }); diff --git a/src/Game/Dvars.cpp b/src/Game/Dvars.cpp index 827ad8d6..cae637d4 100644 --- a/src/Game/Dvars.cpp +++ b/src/Game/Dvars.cpp @@ -74,6 +74,8 @@ namespace Game const dvar_t** cg_chatHeight = reinterpret_cast(0x7ED398); const dvar_t** cg_chatTime = reinterpret_cast(0x9F5DE8); + const dvar_t** cg_scoreboardHeight = reinterpret_cast(0x9FD070); + const dvar_t** cg_scoreboardWidth = reinterpret_cast(0x9FD0AC); const dvar_t** version = reinterpret_cast(0x1AD7930); diff --git a/src/Game/Dvars.hpp b/src/Game/Dvars.hpp index 95e78d08..02cde645 100644 --- a/src/Game/Dvars.hpp +++ b/src/Game/Dvars.hpp @@ -126,6 +126,8 @@ namespace Game extern const dvar_t** cg_chatHeight; extern const dvar_t** cg_chatTime; + extern const dvar_t** cg_scoreboardHeight; + extern const dvar_t** cg_scoreboardWidth; extern const dvar_t** version; diff --git a/src/Utils/WebIO.cpp b/src/Utils/WebIO.cpp index fba8fcc3..852971c4 100644 --- a/src/Utils/WebIO.cpp +++ b/src/Utils/WebIO.cpp @@ -411,6 +411,13 @@ namespace Utils } } + std::string WebIO::GetCacheBuster() + { + return "?" + std::to_string( + std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count()); + } + bool WebIO::createDirectory(const std::string& directory) const { return (FtpCreateDirectoryA(this->hConnect_, directory.data()) == TRUE); diff --git a/src/Utils/WebIO.hpp b/src/Utils/WebIO.hpp index d6eed98a..52db1c42 100644 --- a/src/Utils/WebIO.hpp +++ b/src/Utils/WebIO.hpp @@ -65,6 +65,8 @@ namespace Utils void setProgressCallback(const Slot& callback); void cancelDownload(); + static std::string GetCacheBuster(); + private: enum Command {