From d1ab2ce916d4b491c7a90a0804672d287a893c80 Mon Sep 17 00:00:00 2001 From: Liko Date: Sun, 10 Jul 2022 16:30:02 +0200 Subject: [PATCH] Added AutoRun feature --- cheat-library/cheat-library.vcxproj | 2 + cheat-library/cheat-library.vcxproj.filters | 6 ++ cheat-library/src/user/cheat/cheat.cpp | 2 + .../src/user/cheat/player/AutoRun.cpp | 93 +++++++++++++++++++ cheat-library/src/user/cheat/player/AutoRun.h | 28 ++++++ 5 files changed, 131 insertions(+) create mode 100644 cheat-library/src/user/cheat/player/AutoRun.cpp create mode 100644 cheat-library/src/user/cheat/player/AutoRun.h diff --git a/cheat-library/cheat-library.vcxproj b/cheat-library/cheat-library.vcxproj index fa7f177..2ada415 100644 --- a/cheat-library/cheat-library.vcxproj +++ b/cheat-library/cheat-library.vcxproj @@ -20,6 +20,7 @@ + @@ -110,6 +111,7 @@ + diff --git a/cheat-library/cheat-library.vcxproj.filters b/cheat-library/cheat-library.vcxproj.filters index 91bba0d..de81a31 100644 --- a/cheat-library/cheat-library.vcxproj.filters +++ b/cheat-library/cheat-library.vcxproj.filters @@ -246,6 +246,9 @@ Header Files + + Header Files + @@ -450,6 +453,9 @@ Source Files + + Source Files + diff --git a/cheat-library/src/user/cheat/cheat.cpp b/cheat-library/src/user/cheat/cheat.cpp index 40d90bc..9cad842 100644 --- a/cheat-library/src/user/cheat/cheat.cpp +++ b/cheat-library/src/user/cheat/cheat.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -82,6 +83,7 @@ namespace cheat FEAT_INST(NoCD), FEAT_INST(NoClip), FEAT_INST(RapidFire), + FEAT_INST(AutoRun), FEAT_INST(AutoLoot), FEAT_INST(AutoTreeFarm), diff --git a/cheat-library/src/user/cheat/player/AutoRun.cpp b/cheat-library/src/user/cheat/player/AutoRun.cpp new file mode 100644 index 0000000..c01cac4 --- /dev/null +++ b/cheat-library/src/user/cheat/player/AutoRun.cpp @@ -0,0 +1,93 @@ +#include "pch-il2cpp.h" +#include "AutoRun.h" + +#include +#include +#include +#include +#include + +namespace cheat::feature +{ + //bool isAutoRunEnabled = false; + + AutoRun::AutoRun() : Feature(), + NF(f_Enabled, "Auto Run", "Player::AutoRun", false), + NF(f_Speed, "Speed", "Player::AutoRun",1.0f), + NF(f_CameraRelative, "Relative to camera", "Player::AutoRun" , false) + { + events::GameUpdateEvent += MY_METHOD_HANDLER(AutoRun::OnGameUpdate); + } + + const FeatureGUIInfo& AutoRun::GetGUIInfo() const + { + static const FeatureGUIInfo info{ "Auto Run", "Player", true }; + return info; + } + + void AutoRun::DrawMain() + { + ConfigWidget("Enable", f_Enabled); + ConfigWidget("Auto Run speed", f_Speed, 0.01f, 0.01f, 1000.0f, "Speed of character \n Not recommended going above 5"); + ConfigWidget("Movement relative to camera", f_CameraRelative); + } + + bool AutoRun::NeedStatusDraw() const + { + return f_Enabled; + } + void AutoRun::DrawStatus() + { + ImGui::Text("Auto Run[%.01f]",f_Speed.value()); + } + + AutoRun& AutoRun::GetInstance() + { + static AutoRun instance; + return instance; + } + + void enableAutoRun(float speed, bool cameraRelative) { + + auto& manager = game::EntityManager::instance(); + auto avatarEntity = manager.avatar(); + + auto baseMove = avatarEntity->moveComponent(); + auto rigidBody = avatarEntity->rigidbody(); + + app::Rigidbody_set_detectCollisions(rigidBody, true, nullptr); + + auto cameraEntity = game::Entity(reinterpret_cast(manager.mainCamera())); + auto relativeEntity = cameraRelative ? &cameraEntity : avatarEntity; + + if (baseMove == nullptr) + return; + + if (rigidBody == nullptr) + return; + + if (renderer::IsInputLocked()) + return; + + app::Vector3 dir = {}; + dir = dir + relativeEntity->forward(); + + app::Vector3 prevPos = avatarEntity->relativePosition(); + if (IsVectorZero(prevPos)) + return; + + float deltaTime = app::Time_get_deltaTime(nullptr); + + app::Vector3 newPos = prevPos + dir * speed * deltaTime; + + avatarEntity->setRelativePosition(newPos); + } + + void AutoRun::OnGameUpdate() { + if (f_Enabled) { + float speed = f_Speed.value(); + bool cameraRelative = f_CameraRelative.value(); + enableAutoRun(speed, cameraRelative); + } + } +} \ No newline at end of file diff --git a/cheat-library/src/user/cheat/player/AutoRun.h b/cheat-library/src/user/cheat/player/AutoRun.h new file mode 100644 index 0000000..fb78efb --- /dev/null +++ b/cheat-library/src/user/cheat/player/AutoRun.h @@ -0,0 +1,28 @@ +#pragma once +#include +#include + + +namespace cheat::feature +{ + class AutoRun : public Feature + { + public: + config::Field> f_Enabled; + config::Field f_Speed; + config::Field f_CameraRelative; + + static AutoRun& GetInstance(); + + const FeatureGUIInfo& GetGUIInfo() const override; + void DrawMain() override; + + bool NeedStatusDraw() const override; + void DrawStatus() override; + + void OnGameUpdate(); + + private: + AutoRun(); + }; +} \ No newline at end of file