From 16af5a0d0bce17a994ee9fbe9e8d4e8d1bb2fb5e Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 29 May 2022 23:16:10 +0200 Subject: [PATCH] Noclip, ufo, etc... commands --- src/client/component/command.cpp | 10 +++--- src/client/component/gameplay.cpp | 55 +++++++++++++++++++++++++++++++ src/client/game/structs.hpp | 11 +++++-- src/client/game/symbols.hpp | 10 +++--- 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index 456c1283..458ed522 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -635,7 +635,7 @@ namespace command static void add_commands_sp() { - /*add("god", []() + add("god", []() { if (!game::SV_Loaded()) { @@ -723,14 +723,14 @@ namespace command } cmd_give_weapon(0, params.get_all()); - });*/ + }); } static void add_commands_mp() { client_command_hook.create(0x4132E0_b, &client_command); - /*add_sv("god", [](const int client_num, const params_sv&) + add_sv("god", [](const int client_num, const params_sv&) { if (!check_cheats(client_num)) { @@ -777,8 +777,8 @@ namespace command return; } - toggle_client_flag(client_num, 2, "noclip"); - });*/ + toggle_client_flag(client_num, 2, "ufo"); + }); add_sv("give", [](const int client_num, const params_sv& params) { diff --git a/src/client/component/gameplay.cpp b/src/client/component/gameplay.cpp index 464d04b4..724a5adb 100644 --- a/src/client/component/gameplay.cpp +++ b/src/client/component/gameplay.cpp @@ -21,6 +21,10 @@ namespace gameplay utils::hook::detour stuck_in_client_hook; utils::hook::detour cm_transformed_capsule_trace_hook; + utils::hook::detour client_end_frame_hook; + utils::hook::detour g_damage_client_hook; + utils::hook::detour g_damage_hook; + game::dvar_t* jump_slowDownEnable; game::dvar_t* jump_enableFallDamage; @@ -168,6 +172,52 @@ namespace gameplay a.bind(allsolid); a.jmp(0x2C9F9F_b); }; + + void client_end_frame_stub2(game::mp::gentity_s* entity) + { + client_end_frame_hook.invoke(entity); + + if ((entity->client->flags & 1)) // noclip + { + entity->client->pm_type = 2; + } + else if ((entity->client->flags & 2)) // ufo + { + entity->client->pm_type = 3; + } + } + + void g_damage_client_stub(game::mp::gentity_s* targ, const game::mp::gentity_s* inflictor, game::mp::gentity_s* attacker, + const float* dir, const float* point, int damage, int dflags, int mod, + const unsigned int weapon, bool is_alternate, unsigned int hit_loc, int time_offset) + { + if ((targ->client->flags & 1) || (targ->client->flags & 2)) // noclip, ufo + { + return; + } + + g_damage_client_hook.invoke(targ, inflictor, attacker, dir, point, damage, dflags, mod, + weapon, is_alternate, hit_loc, time_offset); + } + + void g_damage_stub(game::mp::gentity_s* targ, const game::mp::gentity_s* inflictor, game::mp::gentity_s* attacker, + const float* dir, const float* point, int damage, int dflags, int mod, + const unsigned int weapon, bool is_alternate, unsigned int hit_loc, + unsigned int model_index, unsigned int part_name, int time_offset) + { + if (targ->flags & 1) // godmode + { + return; + } + + if (targ->flags & 2) // demigod + { + damage = 1; + } + + g_damage_hook.invoke(targ, inflictor, attacker, dir, point, damage, dflags, mod, weapon, + is_alternate, hit_loc, model_index, part_name, time_offset); + } } class component final : public component_interface @@ -230,6 +280,11 @@ namespace gameplay dvars::g_playerCollision = dvars::register_bool("g_playerCollision", true, game::DVAR_FLAG_REPLICATED, "Flag whether player collision is on or off"); cm_transformed_capsule_trace_hook.create(0x4D63C0_b, cm_transformed_capsule_trace_stub); + + // Make noclip work + client_end_frame_hook.create(0x3FF7D0_b, client_end_frame_stub2); + g_damage_client_hook.create(0x414F10_b, g_damage_client_stub); + g_damage_hook.create(0x414A10_b, g_damage_stub); } }; } diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index 3fe30fe9..8c4c5432 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1501,12 +1501,17 @@ namespace game struct gclient_s { - char __pad0[18834]; - char name[32]; // 18720 - char __pad1[622]; + char __pad0[2]; + char pm_type; // 2 + char __pad1[18831]; + char name[32]; // 18834 + char __pad2[622]; int flags; // 19488 }; // size = ? + static_assert(offsetof(gclient_s, name) == 18834); + static_assert(offsetof(gclient_s, flags) == 19488); + struct EntityState { uint16_t entityNum; diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index d23b7555..b6b00474 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -59,8 +59,8 @@ namespace game WEAK symbol Quit{0x3A5A20, 0x17CF50}; - WEAK symbol CG_GameMessage{0x0, 0x316210}; - WEAK symbol CG_GameMessageBold{0x0, 0x3122F0}; + WEAK symbol CG_GameMessage{0x15B3B0, 0x316210}; + WEAK symbol CG_GameMessageBold{0x15B110, 0x3122F0}; WEAK symbol CG_SetClientDvarFromServer{0x0, 0x0}; WEAK symbol G_GetWeaponForName{0x2F20F0, 0x461180}; WEAK symbol G_GivePlayerWeapon{0x2F24F0, 0x461600}; - WEAK symbol G_InitializeAmmo{0x0, 0x41C170}; - WEAK symbol G_SelectWeapon{0x0, 0x462560}; + WEAK symbol G_InitializeAmmo{0x29D9E0, 0x41C170}; + WEAK symbol G_SelectWeapon{0x2F2EA0, 0x462560}; WEAK symbol G_TakePlayerWeapon{0x2F3050, 0x462770}; WEAK symbol I_CleanStr{0x4293E0, 0x5AF2E0}; @@ -196,7 +196,7 @@ namespace game WEAK symbol SV_GetGuid{0x0, 0x551D90}; WEAK symbol SV_GetClientPing{0x0, 0x551D70}; - WEAK symbol SV_GetPlayerstateForClientNum{0x0, 0x551E10}; + WEAK symbol SV_GetPlayerstateForClientNum{0x4C3F10, 0x551E10}; WEAK symbol SV_SetConfigstring{0x0, 0x553E60}; WEAK symbol SV_Loaded{0x4C4810, 0x553970}; WEAK symbol SV_KickClientNum{0x0, 0x54C060};