From f064966ec0b0f6495c3bd53cac366f379af90bf9 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 18 Aug 2016 01:57:56 +0200 Subject: [PATCH] Add noclip and ufo commands --- src/Components/Modules/Command.cpp | 69 ++++++++++++++++++++++++++- src/Components/Modules/QuickPatch.cpp | 1 - src/Game/Functions.cpp | 2 + src/Game/Functions.hpp | 3 ++ src/Game/Structs.hpp | 11 ++++- 5 files changed, 83 insertions(+), 3 deletions(-) diff --git a/src/Components/Modules/Command.cpp b/src/Components/Modules/Command.cpp index 350a43ad..2a50877b 100644 --- a/src/Components/Modules/Command.cpp +++ b/src/Components/Modules/Command.cpp @@ -134,7 +134,74 @@ namespace Components Command::Command() { - // TODO: Add commands here? + // Disable native noclip command + Utils::Hook::Nop(0x474846, 5); + + Command::Add("noclip", [] (Command::Params params) + { + if (!Game::CL_IsCgameInitialized()) + { + Logger::Print("No game running!\n"); + return; + } + if (!Dvar::Var("sv_cheats").Get()) + { + Logger::Print("Cheats disabled!\n"); + return; + } + + int clientNum = Game::CG_GetClientNum(); + if (clientNum >= 18) + { + Logger::Print("Unable to lookup our clientnum!\n"); + return; + } + + Game::gentity_t* entity = &Game::g_entities[clientNum]; + + if (!entity->client) + { + Logger::Print("Unable to find our client info!\n"); + return; + } + + entity->client->flags ^= Game::PLAYER_FLAG_NOCLIP; + + Logger::Print("Noclip toggled\n"); + }); + + Command::Add("ufo", [] (Command::Params params) + { + if (!Game::CL_IsCgameInitialized()) + { + Logger::Print("No game running!\n"); + return; + } + if (!Dvar::Var("sv_cheats").Get()) + { + Logger::Print("Cheats disabled!\n"); + return; + } + + int clientNum = Game::CG_GetClientNum(); + if (clientNum >= 18) + { + Logger::Print("Unable to lookup our clientnum!\n"); + return; + } + + Game::gentity_t* entity = &Game::g_entities[clientNum]; + + if (!entity->client) + { + Logger::Print("Unable to find our client info!\n"); + return; + } + + entity->client->flags ^= Game::PLAYER_FLAG_UFO; + + Logger::Print("UFO toggled\n"); + }); } Command::~Command() diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index fc6d724c..d560af08 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -372,7 +372,6 @@ namespace Components throw new std::exception(); }); - // Debug patches #ifdef DEBUG // ui_debugMode 1 diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index d11a4067..e35b1b6b 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -8,6 +8,8 @@ namespace Game Cbuf_AddServerText_t Cbuf_AddServerText = (Cbuf_AddServerText_t)0x4BB9B0; Cbuf_AddText_t Cbuf_AddText = (Cbuf_AddText_t)0x404B20; + CG_GetClientNum_t CG_GetClientNum = (CG_GetClientNum_t)0x433700; + CL_GetClientName_t CL_GetClientName = (CL_GetClientName_t)0x4563D0; CL_IsCgameInitialized_t CL_IsCgameInitialized = (CL_IsCgameInitialized_t)0x43EB20; CL_ConnectFromParty_t CL_ConnectFromParty = (CL_ConnectFromParty_t)0x433D30; diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 2b9eff32..c3f29b05 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -9,6 +9,9 @@ namespace Game typedef void(__cdecl * Cbuf_AddText_t)(int localClientNum, const char *text); extern Cbuf_AddText_t Cbuf_AddText; + typedef int(__cdecl * CG_GetClientNum_t)(); + extern CG_GetClientNum_t CG_GetClientNum; + typedef char*(__cdecl * CL_GetClientName_t)(int localClientNum, int index, char *buf, size_t size); extern CL_GetClientName_t CL_GetClientName; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 29904325..fb163030 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -868,11 +868,20 @@ namespace Game int lastEntityRef; } msg_t; + enum playerFlag + { + PLAYER_FLAG_NOCLIP = 1, + PLAYER_FLAG_UFO = 2, + PLAYER_FLAG_FROZEN = 4, + }; + typedef struct gclient_s { unsigned char pad[12764]; unsigned int team; - char pad2[1164]; + char pad2[436]; + int flags; + char pad3[724]; } gclient_t; typedef struct gentity_s