From 949d6ad9d56b3d8e8657ffc05660a82dd5955f9d Mon Sep 17 00:00:00 2001 From: FutureRave Date: Thu, 12 May 2022 14:14:59 +0100 Subject: [PATCH] [ClientCommand] Add kill --- src/game/game.cpp | 4 +++ src/game/game.hpp | 3 ++ src/game/structs.hpp | 68 ++++++++++++++++++++++++++++++++--- src/module/client_command.cpp | 18 +++++++++- src/std_include.hpp | 10 +++--- 5 files changed, 93 insertions(+), 10 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 09e1c59..9356f5a 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -81,6 +81,8 @@ namespace game Com_Quit_f_t Com_Quit_f; + player_die_t player_die; + decltype(longjmp)* _longjmp; CmdArgs* sv_cmd_args; @@ -701,6 +703,8 @@ namespace game native::Com_Quit_f = native::Com_Quit_f_t(SELECT_VALUE(0x4F48B0, 0x5556B0, 0x4D95B0)); + native::player_die = native::player_die_t(SELECT_VALUE(0x0, 0x503460, 0x47F4D0)); + native::_longjmp = reinterpret_cast(SELECT_VALUE(0x73AC20, 0x7363BC, 0x655558)); native::sv_cmd_args = reinterpret_cast(SELECT_VALUE(0x1757218, 0x1CAA998, 0x1B5E7D8)); diff --git a/src/game/game.hpp b/src/game/game.hpp index 4559c75..1d80191 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -133,6 +133,9 @@ namespace game typedef void (*Com_Quit_f_t)(); extern Com_Quit_f_t Com_Quit_f; + typedef void (*player_die_t)(gentity_s* self, const gentity_s* inflictor, gentity_s* attacker, int damage, int meansOfDeath, const Weapon* iWeapon, bool isAlternate, const float* vDir, const hitLocation_t hitLoc, int psTimeOffset); + extern player_die_t player_die; + extern decltype(longjmp)* _longjmp; constexpr auto CMD_MAX_NESTING = 8; diff --git a/src/game/structs.hpp b/src/game/structs.hpp index f7b0125..0800859 100644 --- a/src/game/structs.hpp +++ b/src/game/structs.hpp @@ -736,6 +736,32 @@ namespace game static_assert(sizeof(weaponParms) == 0x4C); + enum hitLocation_t + { + HITLOC_NONE = 0x0, + HITLOC_HELMET = 0x1, + HITLOC_HEAD = 0x2, + HITLOC_NECK = 0x3, + HITLOC_TORSO_UPR = 0x4, + HITLOC_TORSO_LWR = 0x5, + HITLOC_R_ARM_UPR = 0x6, + HITLOC_L_ARM_UPR = 0x7, + HITLOC_R_ARM_LWR = 0x8, + HITLOC_L_ARM_LWR = 0x9, + HITLOC_R_HAND = 0xA, + HITLOC_L_HAND = 0xB, + HITLOC_R_LEG_UPR = 0xC, + HITLOC_L_LEG_UPR = 0xD, + HITLOC_R_LEG_LWR = 0xE, + HITLOC_L_LEG_LWR = 0xF, + HITLOC_R_FOOT = 0x10, + HITLOC_L_FOOT = 0x11, + HITLOC_GUN = 0x12, + HITLOC_SHIELD = 0x13, + + HITLOC_NUM = 0x14, + }; + enum ViewLockTypes { PLAYERVIEWLOCK_NONE = 0x0, @@ -800,10 +826,10 @@ namespace game unsigned char __pad0[0x470]; unsigned int perks[0x2]; unsigned int perkSlots[0x9]; - unsigned char __pad1[0x2DE8]; + unsigned char __pad1[0x2DF4]; }; - static_assert(sizeof(playerState_s) == 0x3300); + static_assert(sizeof(playerState_s) == 0x330C); struct pmove_t { @@ -831,12 +857,46 @@ namespace game static_assert(sizeof(pmove_t) == 0x138); + enum sessionState_t + { + SESS_STATE_PLAYING = 0x0, + SESS_STATE_DEAD = 0x1, + SESS_STATE_SPECTATOR = 0x2, + SESS_STATE_INTERMISSION = 0x3, + }; + + enum clientConnected_t + { + CON_DISCONNECTED = 0x0, + CON_CONNECTING = 0x1, + CON_CONNECTED = 0x2, + }; + + struct clientSession_t + { + sessionState_t sessionState; + int forceSpectatorClient; + int killCamEntity; + int killCamLookAtEntity; + int status_icon; + int archiveTime; + int score; + int deaths; + int kills; + int assists; + unsigned __int16 scriptPersId; + clientConnected_t connected; + unsigned char __pad0[0x290]; + }; + + static_assert(sizeof(clientSession_t) == 0x2C0); + struct gclient_s { playerState_s ps; - unsigned char __pad0[0x2CC]; + clientSession_t sess; int flags; - unsigned char __pad1[0x3B0]; + unsigned char __pad0[0x3B0]; }; static_assert(sizeof(gclient_s) == 0x3980); diff --git a/src/module/client_command.cpp b/src/module/client_command.cpp index cb30cdc..fb9aa3a 100644 --- a/src/module/client_command.cpp +++ b/src/module/client_command.cpp @@ -4,6 +4,7 @@ #include "game/game.hpp" #include "command.hpp" +#include "scheduler.hpp" class client_command final : public module { @@ -127,13 +128,28 @@ private: angles[1] = std::strtof(params.get(4), nullptr); // Yaw } - if (params.size() == 6u) + if (params.size() == 6) { angles[0] = std::strtof(params.get(5), nullptr); // Pitch } game::native::TeleportPlayer(ent, origin, angles); }); + + command::add_sv("kill", [](game::native::gentity_s* ent, [[maybe_unused]] const command::params_sv& params) + { + assert(ent->client->sess.connected != game::native::CON_DISCONNECTED); + + if (ent->client->sess.sessionState != game::native::SESS_STATE_PLAYING || !cheats_ok(ent)) + return; + + scheduler::once([ent] + { + ent->flags &= ~(game::native::entityFlag::FL_GODMODE | game::native::entityFlag::FL_DEMI_GODMODE); + ent->health = 0; + game::native::player_die(ent, ent, ent, 100000, 12, nullptr, false, nullptr, game::native::hitLocation_t::HITLOC_NONE, 0); + }, scheduler::pipeline::server); + }); } }; diff --git a/src/std_include.hpp b/src/std_include.hpp index 3de9928..7342d87 100644 --- a/src/std_include.hpp +++ b/src/std_include.hpp @@ -18,12 +18,12 @@ #define WIN32_LEAN_AND_MEAN -#include -#include -#include +#include +#include +#include #include #include -#include +#include #include #include #include @@ -74,4 +74,4 @@ using namespace std::literals; -extern __declspec(thread) char tls_data[TLS_PAYLOAD_SIZE]; \ No newline at end of file +extern __declspec(thread) char tls_data[TLS_PAYLOAD_SIZE];