From 28b089f0707b1f21ab20ce8b667779326e92e8f8 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sat, 20 Aug 2022 12:09:41 +0200 Subject: [PATCH] [Structs] use clientheader --- src/Components/Modules/Bans.cpp | 4 +-- src/Components/Modules/CardTitles.cpp | 2 +- src/Components/Modules/Console.cpp | 2 +- src/Components/Modules/Dedicated.cpp | 4 +-- src/Components/Modules/Download.cpp | 6 ++-- .../Modules/GSC/ScriptExtension.cpp | 2 +- src/Components/Modules/Network.cpp | 2 +- src/Components/Modules/Party.cpp | 2 +- src/Components/Modules/ServerInfo.cpp | 2 +- src/Components/Modules/Voice.cpp | 12 ++++---- src/Game/Functions.cpp | 4 +-- src/Game/Structs.hpp | 29 +++++++++++++------ 12 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/Components/Modules/Bans.cpp b/src/Components/Modules/Bans.cpp index f1cac387..dd7e0bec 100644 --- a/src/Components/Modules/Bans.cpp +++ b/src/Components/Modules/Bans.cpp @@ -180,7 +180,7 @@ namespace Components SteamID guid; guid.bits = cl->steamID; - InsertBan({guid, cl->netchan.remoteAddress.ip}); + InsertBan({guid, cl->header.netchan.remoteAddress.ip}); Game::SV_DropClient(cl, reason.data(), true); } @@ -257,7 +257,7 @@ namespace Components } const auto* cl = &Game::svs_clients[num]; - if (cl->state == Game::CS_FREE) + if (cl->header.state == Game::CS_FREE) { Logger::Print("Client {} is not active\n", num); return; diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index 7f5d6164..da34aa24 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -160,7 +160,7 @@ namespace Components { char playerTitle[18]; - if (Game::svs_clients[i].state >= Game::CS_CONNECTED) + if (Game::svs_clients[i].header.state >= Game::CS_CONNECTED) { strncpy_s(playerTitle, Game::Info_ValueForKey(Game::svs_clients[i].userinfo, "customTitle"), _TRUNCATE); } diff --git a/src/Components/Modules/Console.cpp b/src/Components/Modules/Console.cpp index 9fc90446..bcb5995d 100644 --- a/src/Components/Modules/Console.cpp +++ b/src/Components/Modules/Console.cpp @@ -46,7 +46,7 @@ namespace Components { for (int i = 0; i < maxclientCount; ++i) { - if (Game::svs_clients[i].state >= 3) + if (Game::svs_clients[i].header.state >= Game::CS_CONNECTED) { ++clientCount; } diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index cb1bb132..b8bc3e11 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -81,9 +81,9 @@ namespace Components { std::string list = Utils::String::VA("%c", 20); - for (int i = 0; i < 18; ++i) + for (std::size_t i = 0; i < Game::MAX_CLIENTS; ++i) { - if (Game::svs_clients[i].state >= 3) + if (Game::svs_clients[i].header.state >= 3) { list.append(Utils::String::VA(" %llX", Game::svs_clients[i].steamID)); diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index b51d073c..d48b1cda 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -388,9 +388,9 @@ namespace Components { Game::client_t* client = &Game::svs_clients[i]; - if (client->state >= 3) + if (client->header.state >= Game::CS_CONNECTED) { - if (address.getIP().full == Network::Address(client->netchan.remoteAddress).getIP().full) + if (address.getIP().full == Network::Address(client->header.netchan.remoteAddress).getIP().full) { return client; } @@ -752,7 +752,7 @@ namespace Components if ((*Game::com_sv_running)->current.enabled) { - if (Game::svs_clients[i].state < 3) continue; + if (Game::svs_clients[i].header.state < Game::CS_CONNECTED) continue; playerInfo["score"] = Game::SV_GameClientNum_Score(i); playerInfo["ping"] = Game::svs_clients[i].ping; diff --git a/src/Components/Modules/GSC/ScriptExtension.cpp b/src/Components/Modules/GSC/ScriptExtension.cpp index efbe790b..3953bc47 100644 --- a/src/Components/Modules/GSC/ScriptExtension.cpp +++ b/src/Components/Modules/GSC/ScriptExtension.cpp @@ -251,7 +251,7 @@ namespace Components const auto* ent = Game::GetPlayerEntity(entref); const auto* client = Script::GetClient(ent); - std::string ip = Game::NET_AdrToString(client->netchan.remoteAddress); + std::string ip = Game::NET_AdrToString(client->header.netchan.remoteAddress); if (const auto pos = ip.find_first_of(":"); pos != std::string::npos) ip.erase(ip.begin() + pos, ip.end()); // Erase port diff --git a/src/Components/Modules/Network.cpp b/src/Components/Modules/Network.cpp index 04e453f1..06f08b12 100644 --- a/src/Components/Modules/Network.cpp +++ b/src/Components/Modules/Network.cpp @@ -270,7 +270,7 @@ namespace Components Logger::Print(Game::conChannel_t::CON_CHANNEL_NETWORK, "Negative reliableAcknowledge from {} - cl->reliableSequence is {}, reliableAcknowledge is {}\n", client->name, client->reliableSequence, client->reliableAcknowledge); client->reliableAcknowledge = client->reliableSequence; - SendCommand(Game::NS_SERVER, client->netchan.remoteAddress, "error", "EXE_LOSTRELIABLECOMMANDS"); + SendCommand(Game::NS_SERVER, client->header.netchan.remoteAddress, "error", "EXE_LOSTRELIABLECOMMANDS"); return; } diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index db2331a8..cb402a2a 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -322,7 +322,7 @@ namespace Components { for (int i = 0; i < maxclientCount; ++i) { - if (Game::svs_clients[i].state >= 3) + if (Game::svs_clients[i].header.state >= Game::CS_CONNECTED) { if (Game::svs_clients[i].bIsTestClient) ++botCount; else ++clientCount; diff --git a/src/Components/Modules/ServerInfo.cpp b/src/Components/Modules/ServerInfo.cpp index 0992e4df..f497e7d7 100644 --- a/src/Components/Modules/ServerInfo.cpp +++ b/src/Components/Modules/ServerInfo.cpp @@ -208,7 +208,7 @@ namespace Components if ((*Game::com_sv_running)->current.enabled) { - if (Game::svs_clients[i].state < 3) continue; + if (Game::svs_clients[i].header.state < Game::CS_CONNECTED) continue; score = Game::SV_GameClientNum_Score(i); ping = Game::svs_clients[i].ping; diff --git a/src/Components/Modules/Voice.cpp b/src/Components/Modules/Voice.cpp index 6871d863..c334d33b 100644 --- a/src/Components/Modules/Voice.cpp +++ b/src/Components/Modules/Voice.cpp @@ -42,7 +42,7 @@ namespace Components assert(VoicePacketCount[clientNum] >= 0); - if (client->state == Game::CS_ACTIVE && VoicePacketCount[clientNum]) + if (client->header.state == Game::CS_ACTIVE && VoicePacketCount[clientNum]) { Game::MSG_Init(&msg, msg_buf.get(), 0x10000); @@ -58,7 +58,7 @@ namespace Components } else { - Game::NET_OutOfBandVoiceData(Game::NS_SERVER, client->netchan.remoteAddress, msg.data, msg.cursize, true); + Game::NET_OutOfBandVoiceData(Game::NS_SERVER, client->header.netchan.remoteAddress, msg.data, msg.cursize, true); VoicePacketCount[clientNum] = 0; } } @@ -203,7 +203,7 @@ namespace Components Game::MSG_ReadData(msg, voicePacket.data, voicePacket.dataSize); for (auto otherPlayer = 0; otherPlayer < (*Game::sv_maxclients)->current.integer; ++otherPlayer) { - if (otherPlayer != talker && Game::svs_clients[otherPlayer].state >= Game::CS_CONNECTED && !SV_ServerHasClientMuted(talker)) + if (otherPlayer != talker && Game::svs_clients[otherPlayer].header.state >= Game::CS_CONNECTED && !SV_ServerHasClientMuted(talker)) { SV_QueueVoicePacket(talker, otherPlayer, &voicePacket); } @@ -213,15 +213,15 @@ namespace Components void Voice::SV_VoicePacket(Game::netadr_t from, Game::msg_t* msg) { - auto qport = Game::MSG_ReadShort(msg); + const auto qport = Game::MSG_ReadShort(msg); auto* cl = Game::SV_FindClientByAddress(from, qport, 0); - if (!cl || cl->state == Game::CS_ZOMBIE) + if (!cl || cl->header.state == Game::CS_ZOMBIE) { return; } cl->lastPacketTime = *Game::svs_time; - if (cl->state < Game::CS_ACTIVE) + if (cl->header.state < Game::CS_ACTIVE) { SV_PreGameUserVoice(cl, msg); } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 32a75199..c9ddab80 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -884,8 +884,8 @@ namespace Game { for (auto i = 0; i < *svs_clientCount; ++i) { - if (svs_clients[i].state != CS_FREE - && svs_clients[i].netchan.remoteAddress.type == NA_BOT) + if (svs_clients[i].header.state != CS_FREE + && svs_clients[i].header.netchan.remoteAddress.type == NA_BOT) { SV_GameDropClient(i, "GAME_GET_TO_COVER"); } diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 1387aa13..85c6305b 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -235,7 +235,7 @@ namespace Game DVAR_TYPE_COUNT = 0xA, } dvar_type; - typedef enum + enum clientState_t { CS_FREE = 0x0, CS_ZOMBIE = 0x1, @@ -243,7 +243,7 @@ namespace Game CS_CONNECTED = 0x3, CS_CLIENTLOADING = 0x4, CS_ACTIVE = 0x5, - } clientState_t; + }; enum serverState_t { @@ -6301,17 +6301,28 @@ namespace Game bool topFire; }; + struct clientHeader_t + { + int state; + int sendAsActive; + int deltaMessage; + int rateDelayed; + int hasAckedBaselineData; + int hugeSnapshotSent; + netchan_t netchan; + float predictedOrigin[3]; + int predictedOriginServerTime; + int migrationState; + }; + + static_assert(sizeof(clientHeader_t) == 1624); + #pragma pack(push, 1) typedef struct client_s { - clientState_t state; // 0 - int sendAsActive; // 4 - int deltaMessage; // 8 - char __pad1[12]; // 12 - netchan_t netchan; // 24 - char __pad2[20]; // 1604 - const char* delayDropReason; // 1624 + clientHeader_t header; + const char* dropReason; // 1624 char userinfo[1024]; // 1628 char __pad3[132096]; // 2652 int reliableSequence; // 134748