From 2785a60dc01808d01affa4845ceeddb47ea1d8fe Mon Sep 17 00:00:00 2001 From: Diavolo Date: Wed, 2 Feb 2022 12:45:07 +0100 Subject: [PATCH 1/3] Add function drop all bots --- src/component/gsc.cpp | 14 +++++++ src/game/game.cpp | 8 ++++ src/game/game.hpp | 2 + src/game/structs.hpp | 87 ++++++++++++++++++++++++++++++++++++++++++- src/game/symbols.hpp | 3 ++ 5 files changed, 113 insertions(+), 1 deletion(-) diff --git a/src/component/gsc.cpp b/src/component/gsc.cpp index 25ffa00..1430229 100644 --- a/src/component/gsc.cpp +++ b/src/component/gsc.cpp @@ -380,6 +380,20 @@ namespace gsc return {}; }); + function::add("dropallbots", [](const function_args& args) -> scripting::script_value + { + for (auto i = 0; i < *game::svs_clientCount; i++) + { + if (game::svs_clients[i].header.state !=game::CS_FREE + && game::svs_clients[i].header.netchan.remoteAddress.type == game::NA_BOT) + { + game::SV_GameDropClient(i, "GAME_GET_TO_COVER"); + } + } + + return {}; + }); + method::add("tell", [](const game::scr_entref_t ent, const function_args& args) -> scripting::script_value { if (ent.classnum != 0) diff --git a/src/game/game.cpp b/src/game/game.cpp index 931724d..e4ffe61 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -2,5 +2,13 @@ namespace game { + void SV_GameDropClient(int clientNum, const char* reason) + { + assert(sv_maxclients->current.integer >= 1 && sv_maxclients->current.integer <= 18); + if (clientNum >= 0 && clientNum < sv_maxclients->current.integer) + { + SV_DropClient(&svs_clients[clientNum], reason, true); + } + } } diff --git a/src/game/game.hpp b/src/game/game.hpp index e52eef9..a130d5a 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -29,6 +29,8 @@ namespace game private: T* dedi_; }; + + void SV_GameDropClient(int clientNum, const char* reason); } #include "symbols.hpp" \ No newline at end of file diff --git a/src/game/structs.hpp b/src/game/structs.hpp index a67cc97..fa7d28d 100644 --- a/src/game/structs.hpp +++ b/src/game/structs.hpp @@ -328,9 +328,94 @@ namespace game char __pad2[0xEC]; }; + enum netsrc_t + { + NS_CLIENT1 = 0x0, + NS_CLIENT2 = 0x1, + NS_CLIENT3 = 0x2, + NS_CLIENT4 = 0x3, + NS_MAXCLIENTS = 0x4, + NS_SERVER = 0x4, + NS_PACKET = 0x5, + NS_INVALID_NETSRC = 0x6 + }; + + enum netadrtype_t + { + NA_BOT = 0x0, + NA_BAD = 0x1, + NA_LOOPBACK = 0x2, + NA_BROADCAST = 0x3, + NA_IP = 0x4 + }; + + struct netadr_s + { + netadrtype_t type; + unsigned char ip[4]; + unsigned __int16 port; + unsigned char ipx[10]; + unsigned int addrHandleIndex; + }; + + static_assert(sizeof(netadr_s) == 24); + + struct netchan_t + { + int outgoingSequence; + netsrc_t sock; // 28 + int dropped; // 32 + int incomingSequence; // 36 + netadr_s remoteAddress; // 40 + int qport; + int fragmentSequence; + int fragmentLength; + unsigned char* fragmentBuffer; + int fragmentBufferSize; + int unsentFragments; + int unsentFragmentStart; + int unsentLength; + unsigned char* unsentBuffer; + int unsentBufferSize; + unsigned char __pad0[0x5E0]; + }; + + static_assert(sizeof(netchan_t) == 0x630); + + enum clientState_t + { + CS_FREE = 0, + CS_ZOMBIE = 1, + CS_RECONNECTING = 2, + CS_CONNECTED = 3, + CS_CLIENTLOADING = 4, + CS_ACTIVE = 5 + }; + + struct clientHeader_t + { + clientState_t state; // 0 + int sendAsActive; // 4 + int deltaMessage; // 8 + int rateDealyed; // 12 + int hasAckedBaselineData; // 16 + int hugeSnapshotSent; // 20 + netchan_t netchan; // 24 + vec3_t predictedOrigin; + int predictedOriginServerTime; + int migrationState; + vec3_t predictedVehicleOrigin; + int predictedVehicleServerTime; + }; + + static_assert(sizeof(clientHeader_t) == 0x66C); + struct client_s { - char __pad0[0x41CB2]; + clientHeader_t header; + const char* dropReason; + char userinfo[1024]; + char __pad0[0x41242]; unsigned __int16 scriptId; // 269490 int bIsTestClient; // 269492 int serverId; // 269496 diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index 83c7ada..4f02550 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -57,6 +57,7 @@ namespace game WEAK symbol SV_GameSendServerCommand{0x573220}; WEAK symbol SV_Cmd_ArgvBuffer{0x5459F0}; + WEAK symbol SV_DropClient{0x570980}; WEAK symbol VM_Notify{0x569720}; WEAK symbol VM_Execute{0x56DFE0}; @@ -79,6 +80,8 @@ namespace game WEAK symbol g_entities{0x1A66E28}; WEAK symbol levelEntityId{0x208E1A4}; + WEAK symbol sv_maxclients{0x1BA0E4C}; + WEAK symbol svs_clientCount{0x4B5CF8C}; WEAK symbol svs_clients{0x4B5CF90}; namespace plutonium From c230a1d9166d7369ebf6cf88d8eef198c6b7ae90 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Wed, 2 Feb 2022 12:47:46 +0100 Subject: [PATCH 2/3] Remove incorrect offset comments --- src/component/gsc.cpp | 2 +- src/game/structs.hpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/component/gsc.cpp b/src/component/gsc.cpp index 1430229..d01147d 100644 --- a/src/component/gsc.cpp +++ b/src/component/gsc.cpp @@ -384,7 +384,7 @@ namespace gsc { for (auto i = 0; i < *game::svs_clientCount; i++) { - if (game::svs_clients[i].header.state !=game::CS_FREE + if (game::svs_clients[i].header.state != game::CS_FREE && game::svs_clients[i].header.netchan.remoteAddress.type == game::NA_BOT) { game::SV_GameDropClient(i, "GAME_GET_TO_COVER"); diff --git a/src/game/structs.hpp b/src/game/structs.hpp index fa7d28d..ec63303 100644 --- a/src/game/structs.hpp +++ b/src/game/structs.hpp @@ -363,10 +363,10 @@ namespace game struct netchan_t { int outgoingSequence; - netsrc_t sock; // 28 - int dropped; // 32 - int incomingSequence; // 36 - netadr_s remoteAddress; // 40 + netsrc_t sock; + int dropped; + int incomingSequence; + netadr_s remoteAddress; int qport; int fragmentSequence; int fragmentLength; From ccd8176c2573d10719ba66789c31169b9afdaa74 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Wed, 2 Feb 2022 15:24:20 +0100 Subject: [PATCH 3/3] Remove assert --- src/game/game.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index e4ffe61..3bcba57 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -4,8 +4,6 @@ namespace game { void SV_GameDropClient(int clientNum, const char* reason) { - assert(sv_maxclients->current.integer >= 1 && sv_maxclients->current.integer <= 18); - if (clientNum >= 0 && clientNum < sv_maxclients->current.integer) { SV_DropClient(&svs_clients[clientNum], reason, true);