From 2cb6b652ddb65da84aaef058be6703eaaa899c21 Mon Sep 17 00:00:00 2001 From: eXhumer <62310242+eXhumer@users.noreply.github.com> Date: Sun, 25 May 2025 18:01:23 +0300 Subject: [PATCH] feat(self): improve SuperRun (#337) Co-authored-by: Deadlineem --- src/game/features/self/SuperRun.cpp | 40 ++++++++++++++++++++++++++--- src/game/frontend/submenus/Self.cpp | 2 ++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/game/features/self/SuperRun.cpp b/src/game/features/self/SuperRun.cpp index 2b05b02..5b1a044 100644 --- a/src/game/features/self/SuperRun.cpp +++ b/src/game/features/self/SuperRun.cpp @@ -1,9 +1,14 @@ #include "core/commands/LoopedCommand.hpp" +#include "core/commands/FloatCommand.hpp" +#include "core/util/Math.hpp" #include "game/backend/Self.hpp" #include "game/gta/Natives.hpp" namespace YimMenu::Features { + static FloatCommand _SuperRunRunSpeed{"superrunrunspeed", "Run Speed", "Run speed (in m/s)", 0.0f, std::nullopt, 10.0f}; + static FloatCommand _SuperRunSprintSpeed{"superrunsprintspeed", "Sprint Speed", "Sprint speed (in m/s)", 0.0f, std::nullopt, 30.0f}; + class SuperRun : public LoopedCommand { using LoopedCommand::LoopedCommand; @@ -12,11 +17,40 @@ namespace YimMenu::Features { if (auto ped = Self::GetPed()) { - if (PED::IS_PED_RAGDOLL(ped.GetHandle())) + auto pedHandle = ped.GetHandle(); + + if (PED::IS_PED_RAGDOLL(pedHandle)) return; - if (TASK::IS_PED_RUNNING(ped.GetHandle()) || TASK::IS_PED_SPRINTING(ped.GetHandle())) - ENTITY::APPLY_FORCE_TO_ENTITY(ped.GetHandle(), 1, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1, 1, 1, true, false, true); + // don't set speed if in 1st person camera and moving backwards due to it not working properly + if (ENTITY::GET_ENTITY_SPEED_VECTOR(pedHandle, 1).y < 0.0f && CAM::GET_FOLLOW_PED_CAM_VIEW_MODE() == 4) + return; + + if (TASK::IS_PED_RUNNING(pedHandle) || TASK::IS_PED_SPRINTING(pedHandle)) { + const float run_speed = TASK::IS_PED_SPRINTING(pedHandle) ? + _SuperRunSprintSpeed.GetState() : + _SuperRunRunSpeed.GetState(); + + if (ENTITY::GET_ENTITY_SPEED(pedHandle) < run_speed) { + Vector3 location = ENTITY::GET_ENTITY_COORDS(pedHandle, false /*Unused*/); + Vector3 rot = ENTITY::GET_ENTITY_ROTATION(pedHandle, 2); + float yaw = Math::DegToRad(rot.z + 90); + + Vector3 offset; + offset.x = location.x + (run_speed * cos(yaw)); + offset.y = location.y + (run_speed * sin(yaw)); + offset.z = location.z; + + float groundZ; + MISC::GET_GROUND_Z_FOR_3D_COORD(offset.x, offset.y, 1000.f, &groundZ, false, false); + if (groundZ < location.z) + offset.z = groundZ; + + Vector3 vel = offset - location; + + ENTITY::SET_ENTITY_VELOCITY(ped.GetHandle(), vel.x, vel.y, vel.z); + } + } } } }; diff --git a/src/game/frontend/submenus/Self.cpp b/src/game/frontend/submenus/Self.cpp index 122a7b7..3ef7ed8 100644 --- a/src/game/frontend/submenus/Self.cpp +++ b/src/game/frontend/submenus/Self.cpp @@ -47,6 +47,8 @@ namespace YimMenu::Submenus movementGroup->AddItem(std::make_shared("standonvehicles"_J)); movementGroup->AddItem(std::make_shared("disableactionmode"_J)); movementGroup->AddItem(std::make_shared("superrun"_J)); + movementGroup->AddItem(std::make_shared("superrun"_J, std::make_shared("superrunrunspeed"_J))); + movementGroup->AddItem(std::make_shared("superrun"_J, std::make_shared("superrunsprintspeed"_J))); movementGroup->AddItem(std::make_shared("superjump"_J)); movementGroup->AddItem(std::make_shared("noclip"_J)); movementGroup->AddItem(std::make_shared("noclip"_J, std::make_shared("noclipspeed"_J)));