From 94b19177964c8cfb3c1c5b4e766ce8a4ce2cd76a Mon Sep 17 00:00:00 2001 From: Johann <76482511+Primexz@users.noreply.github.com> Date: Thu, 9 Feb 2023 19:17:10 +0100 Subject: [PATCH] feat(self): add superman mode (#924) --- src/backend/looped/self/superman.cpp | 41 +++++++++++++++++++++ src/backend/looped/vehicle/turn_signals.cpp | 8 +--- src/core/globals.hpp | 3 +- src/util/is_key_pressed.hpp | 17 +++++++++ src/views/self/view_self.cpp | 1 + 5 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 src/backend/looped/self/superman.cpp create mode 100644 src/util/is_key_pressed.hpp diff --git a/src/backend/looped/self/superman.cpp b/src/backend/looped/self/superman.cpp new file mode 100644 index 00000000..9e329fd7 --- /dev/null +++ b/src/backend/looped/self/superman.cpp @@ -0,0 +1,41 @@ +#include "natives.hpp" +#include "backend/looped_command.hpp" +#include "gta/enums.hpp" +namespace big +{ + class superman : looped_command + { + using looped_command::looped_command; + + void apply_force(float x, float y, float z) + { + ENTITY::APPLY_FORCE_TO_ENTITY(self::ped, 1, x, y, z, 0, 0, 0, 0, true, true, true, false, true); + } + + virtual void on_tick() override + { + if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_JUMP)) + apply_force(0, 0, 10); + + WEAPON::GIVE_DELAYED_WEAPON_TO_PED(self::ped, rage::joaat("GADGET_PARACHUTE"), 1, 1); + if (!ENTITY::IS_ENTITY_IN_AIR(self::ped) || PED::IS_PED_RAGDOLL(self::ped)) + return; + + if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_UP_ONLY)) + apply_force(3, 0, 0); + + if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_DOWN_ONLY)) + apply_force(3, 6, 0); + + if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_SPRINT)) + apply_force(6, 0, 0); + } + + virtual void on_enable() override + { + g_notification_service->push("Superman Controls", "Use the following keys to control the Superman mode:\n'W' / 'S' / 'SPACE' / 'SHIFT'."); + } + }; + + superman g_superman("superman", "Superman", "Fly like a superman..", g.self.superman); +} diff --git a/src/backend/looped/vehicle/turn_signals.cpp b/src/backend/looped/vehicle/turn_signals.cpp index d27bcdf8..309e00e7 100644 --- a/src/backend/looped/vehicle/turn_signals.cpp +++ b/src/backend/looped/vehicle/turn_signals.cpp @@ -4,6 +4,7 @@ #include "natives.hpp" #include "script.hpp" #include "windows.h" +#include "util/is_key_pressed.hpp" struct key_state { @@ -25,14 +26,9 @@ inline key_state right_signal_key{ 'L' }; inline key_state left_signal_key{ 'J' }; inline key_state hazzards_key{ 'K' }; -bool is_key_pressed(int const v_key) -{ - return GetAsyncKeyState(v_key) & 0x8000; -} - void update_key_state(key_state& key_last_tick) { - if (is_key_pressed(key_last_tick.v_key)) + if (big::is_key_pressed(key_last_tick.v_key)) { switch (key_last_tick.state) { diff --git a/src/core/globals.hpp b/src/core/globals.hpp index e24122fd..45dd6b79 100644 --- a/src/core/globals.hpp +++ b/src/core/globals.hpp @@ -286,6 +286,7 @@ namespace big bool auto_tp = false; bool super_jump = false; bool beast_jump = false; + bool superman = false; // do not save below entries bool dance_mode = false; @@ -295,7 +296,7 @@ namespace big noclip, off_radar, super_run, no_collision, unlimited_oxygen, no_water_collision, wanted_level, god_mode, part_water, proof_bullet, proof_fire, proof_collision, proof_melee, proof_explosion, proof_steam, proof_drown, proof_water, proof_mask, hide_radar, hide_ammo, selected_hud_component, hud_components_states, force_show_hud_element, - force_show_hud, mobile_radio, fast_respawn, auto_tp, super_jump, beast_jump) + force_show_hud, mobile_radio, fast_respawn, auto_tp, super_jump, beast_jump, superman) } self{}; struct session diff --git a/src/util/is_key_pressed.hpp b/src/util/is_key_pressed.hpp new file mode 100644 index 00000000..e1e400d1 --- /dev/null +++ b/src/util/is_key_pressed.hpp @@ -0,0 +1,17 @@ +#pragma once +#include "../pointers.hpp" + +namespace big +{ + inline bool is_key_pressed(std::uint16_t key) + { + if (GetForegroundWindow() == g_pointers->m_hwnd) + { + if (GetAsyncKeyState(key) & 0x8000) + { + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/src/views/self/view_self.cpp b/src/views/self/view_self.cpp index 5d9104bc..5b9e9c51 100644 --- a/src/views/self/view_self.cpp +++ b/src/views/self/view_self.cpp @@ -56,6 +56,7 @@ namespace big components::command_checkbox<"cleanloop">(); components::command_checkbox<"nocollision">(); components::command_checkbox<"mobileradio">(); + components::command_checkbox<"superman">(); // TODO: fix this, causes a crash // ImGui::Checkbox("DANCE_MODE"_T.data(), &g.self.dance_mode);