From c108adf2e75b20a0b380da6fe8b04864482a2118 Mon Sep 17 00:00:00 2001 From: Andrei Abrudan Date: Sat, 9 Jul 2022 22:35:50 +0100 Subject: [PATCH 1/3] Added new option for fall control --- 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/FallControl.cpp | 122 ++++++++++++++++++ .../src/user/cheat/player/FallControl.h | 32 +++++ 5 files changed, 164 insertions(+) create mode 100644 cheat-library/src/user/cheat/player/FallControl.cpp create mode 100644 cheat-library/src/user/cheat/player/FallControl.h diff --git a/cheat-library/cheat-library.vcxproj b/cheat-library/cheat-library.vcxproj index fa7f177..df570f8 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..800889c 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..92947a5 100644 --- a/cheat-library/src/user/cheat/cheat.cpp +++ b/cheat-library/src/user/cheat/cheat.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include "GenshinCM.h" @@ -82,6 +83,7 @@ namespace cheat FEAT_INST(NoCD), FEAT_INST(NoClip), FEAT_INST(RapidFire), + FEAT_INST(FallControl), FEAT_INST(AutoLoot), FEAT_INST(AutoTreeFarm), diff --git a/cheat-library/src/user/cheat/player/FallControl.cpp b/cheat-library/src/user/cheat/player/FallControl.cpp new file mode 100644 index 0000000..1d1962a --- /dev/null +++ b/cheat-library/src/user/cheat/player/FallControl.cpp @@ -0,0 +1,122 @@ +#include "pch-il2cpp.h" +#include "FallControl.h" + +#include +#include + +namespace cheat::feature +{ + bool FallControl::isFalling = false; + + FallControl::FallControl() : Feature(), + NF(f_Enabled, "Fall Control", "FallControl", false), + NF(f_Speed, "Speed", "FallControl", 1.0f) + { + events::GameUpdateEvent += MY_METHOD_HANDLER(FallControl::OnGameUpdate); + events::MoveSyncEvent += MY_METHOD_HANDLER(FallControl::OnMoveSync); + } + + const FeatureGUIInfo& cheat::feature::FallControl::GetGUIInfo() const + { + static const FeatureGUIInfo info{ "Fall-Control", "Player", true }; + return info; + } + + void cheat::feature::FallControl::DrawMain() + { + ConfigWidget("Enabled", f_Enabled, "Enables fall control"); + ConfigWidget("Speed", f_Speed, 0.1f, 5.0f, 10.0f, "Movement speed when using fall control"); + } + + bool cheat::feature::FallControl::NeedStatusDraw() const + { + return f_Enabled; + } + + void cheat::feature::FallControl::DrawStatus() + { + ImGui::Text("Fall Control [%.1f]", f_Speed.value()); + } + + FallControl& cheat::feature::FallControl::GetInstance() + { + static FallControl instance; + return instance; + } + + // Fall control update function + // Detects and moves avatar when movement keys are pressed. + void FallControl::OnGameUpdate() + { + if (!f_Enabled || !isFalling) + return; + + auto& manager = game::EntityManager::instance(); + const auto avatarEntity = manager.avatar(); + + app::Vector3 direction = {}; + if (Hotkey('W').IsPressed()) + direction = direction + avatarEntity->forward(); + if (Hotkey('S').IsPressed()) + direction = direction + avatarEntity->back(); + if (Hotkey('D').IsPressed()) + direction = direction + avatarEntity->right(); + if (Hotkey('A').IsPressed()) + direction = direction + avatarEntity->left(); + if (IsVectorZero(direction)) + return; + + auto rigidBody = avatarEntity->rigidbody(); + if (rigidBody == nullptr) + return; + + // // Alternative, using set_velocity. Does not work while falling? + // const float speed = f_Speed.value(); + // const auto currentVelocity = app::Rigidbody_get_velocity(rigidBody, nullptr); + // const auto desiredvelocity = currentVelocity + direction * speed; + // LOG_DEBUG("Current velocity: [%.1f,%.1f,%.1f]", desiredvelocity.x, desiredvelocity.y, desiredvelocity.z); + // app::Rigidbody_set_velocity(rigidBody, desiredvelocity, nullptr); + + const app::Vector3 prevPos = avatarEntity->relativePosition(); + const auto currentVelocity = app::Rigidbody_get_velocity(rigidBody, nullptr); + const float speed = f_Speed.value(); + const float deltaTime = app::Time_get_deltaTime(nullptr); + const app::Vector3 newPos = prevPos + (currentVelocity + direction * speed) * deltaTime; + // const auto debugvel = (currentVelocity + direction * speed); + // LOG_DEBUG("PrevPos: [%.1f,%.1f,%.1f]", prevPos.x, prevPos.y, prevPos.z); + // LOG_DEBUG("delta time: %f", deltaTime); + // LOG_DEBUG("currentVelocity: [%.1f,%.1f,%.1f]", currentVelocity.x, currentVelocity.y, currentVelocity.z); + // LOG_DEBUG("direction: [%.1f,%.1f,%.1f]", direction.x, direction.y, direction.z); + // LOG_DEBUG("(currentVelocity + direction * speed): [%.1f,%.1f,%.1f]\n", debugvel.x, debugvel.y, debugvel.z); + avatarEntity->setRelativePosition(newPos); + } + + // Detects when player is falling and enables the FallControl cheat + void FallControl::OnMoveSync(uint32_t entityId, app::MotionInfo* syncInfo) + { + if (!f_Enabled) { + // Edgecase for when you turn off cheat while falling + isFalling = false; + return; + } + + const auto motionState = syncInfo->fields.motionState; + switch (motionState) + { + // These states tell us we are falling + case app::MotionState__Enum::MotionDrop: + isFalling = true; + return; + + // State that doesn't tell us anything + case app::MotionState__Enum::MotionStandby: + case app::MotionState__Enum::MotionNotify: + return; + + // We are not falling + default: + isFalling = false; + break; + } + } +} diff --git a/cheat-library/src/user/cheat/player/FallControl.h b/cheat-library/src/user/cheat/player/FallControl.h new file mode 100644 index 0000000..5979114 --- /dev/null +++ b/cheat-library/src/user/cheat/player/FallControl.h @@ -0,0 +1,32 @@ +#pragma once +#include +#include + +#include + +namespace cheat::feature +{ + class FallControl : public Feature + { + public: + config::Field> f_Enabled; + config::Field f_Speed; + + static FallControl& GetInstance(); + + // Inherited via Feature + virtual const FeatureGUIInfo& GetGUIInfo() const override; + virtual void DrawMain() override; + + virtual bool NeedStatusDraw() const override; + void DrawStatus() override; + + void OnGameUpdate(); + void OnMoveSync(uint32_t entityId, app::MotionInfo* syncInfo); + + private: + FallControl(); + + static bool isFalling; + }; +} From b99aef834c1f722e5a4fddc03591a5360ca773a8 Mon Sep 17 00:00:00 2001 From: Andrei Abrudan Date: Sat, 6 Aug 2022 13:48:43 +0100 Subject: [PATCH 2/3] Made Entity direction functions const --- cheat-library/src/user/cheat/game/Entity.cpp | 12 ++++++------ cheat-library/src/user/cheat/game/Entity.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cheat-library/src/user/cheat/game/Entity.cpp b/cheat-library/src/user/cheat/game/Entity.cpp index 37c3747..6e0fed3 100644 --- a/cheat-library/src/user/cheat/game/Entity.cpp +++ b/cheat-library/src/user/cheat/game/Entity.cpp @@ -229,7 +229,7 @@ namespace cheat::game SAFE_END(); } - app::Vector3 Entity::forward() + app::Vector3 Entity::forward() const { if (m_RawEntity == nullptr) return {}; @@ -237,12 +237,12 @@ namespace cheat::game return app::MoleMole_BaseEntity_GetForward(m_RawEntity, nullptr); } - app::Vector3 Entity::back() + app::Vector3 Entity::back() const { return -forward(); } - app::Vector3 Entity::right() + app::Vector3 Entity::right() const { if (m_RawEntity == nullptr) return {}; @@ -250,12 +250,12 @@ namespace cheat::game return app::MoleMole_BaseEntity_GetRight(m_RawEntity, nullptr); } - app::Vector3 Entity::left() + app::Vector3 Entity::left() const { return -right(); } - app::Vector3 Entity::up() + app::Vector3 Entity::up() const { if (m_RawEntity == nullptr) return {}; @@ -263,7 +263,7 @@ namespace cheat::game return app::MoleMole_BaseEntity_GetUp(m_RawEntity, nullptr); } - app::Vector3 Entity::down() + app::Vector3 Entity::down() const { return -up(); } diff --git a/cheat-library/src/user/cheat/game/Entity.h b/cheat-library/src/user/cheat/game/Entity.h index 6a4e9b2..7aa96a3 100644 --- a/cheat-library/src/user/cheat/game/Entity.h +++ b/cheat-library/src/user/cheat/game/Entity.h @@ -39,12 +39,12 @@ namespace cheat::game app::Rigidbody* rigidbody(); app::Animator* animator(); - app::Vector3 forward(); - app::Vector3 back(); - app::Vector3 right(); - app::Vector3 left(); - app::Vector3 up(); - app::Vector3 down(); + app::Vector3 forward() const; + app::Vector3 back() const; + app::Vector3 right() const; + app::Vector3 left() const; + app::Vector3 up() const; + app::Vector3 down() const; template T* plugin(void* pClass) From 1983fd37cffb2945e05e4724d8db4891c2be0d09 Mon Sep 17 00:00:00 2001 From: Andrei Abrudan Date: Sat, 6 Aug 2022 13:53:30 +0100 Subject: [PATCH 3/3] Added small improvements to FallControl --- .../src/user/cheat/player/FallControl.cpp | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/cheat-library/src/user/cheat/player/FallControl.cpp b/cheat-library/src/user/cheat/player/FallControl.cpp index 1d1962a..7851b75 100644 --- a/cheat-library/src/user/cheat/player/FallControl.cpp +++ b/cheat-library/src/user/cheat/player/FallControl.cpp @@ -10,7 +10,7 @@ namespace cheat::feature FallControl::FallControl() : Feature(), NF(f_Enabled, "Fall Control", "FallControl", false), - NF(f_Speed, "Speed", "FallControl", 1.0f) + NF(f_Speed, "Speed", "FallControl", 10.0f) { events::GameUpdateEvent += MY_METHOD_HANDLER(FallControl::OnGameUpdate); events::MoveSyncEvent += MY_METHOD_HANDLER(FallControl::OnMoveSync); @@ -25,7 +25,7 @@ namespace cheat::feature void cheat::feature::FallControl::DrawMain() { ConfigWidget("Enabled", f_Enabled, "Enables fall control"); - ConfigWidget("Speed", f_Speed, 0.1f, 5.0f, 10.0f, "Movement speed when using fall control"); + ConfigWidget("Speed", f_Speed, 1.0f, 0.0f, 100.0f, "Movement speed when using fall control"); } bool cheat::feature::FallControl::NeedStatusDraw() const @@ -52,29 +52,34 @@ namespace cheat::feature return; auto& manager = game::EntityManager::instance(); + const auto avatarEntity = manager.avatar(); - - app::Vector3 direction = {}; - if (Hotkey('W').IsPressed()) - direction = direction + avatarEntity->forward(); - if (Hotkey('S').IsPressed()) - direction = direction + avatarEntity->back(); - if (Hotkey('D').IsPressed()) - direction = direction + avatarEntity->right(); - if (Hotkey('A').IsPressed()) - direction = direction + avatarEntity->left(); - if (IsVectorZero(direction)) - return; - auto rigidBody = avatarEntity->rigidbody(); if (rigidBody == nullptr) return; - // // Alternative, using set_velocity. Does not work while falling? + const auto cameraEntity = game::Entity(reinterpret_cast(manager.mainCamera())); + app::Vector3 direction = {}; + if (Hotkey(ImGuiKey_W).IsPressed()) + direction = direction + cameraEntity.forward();; + if (Hotkey(ImGuiKey_S).IsPressed()) + direction = direction + cameraEntity.back();; + if (Hotkey(ImGuiKey_D).IsPressed()) + direction = direction + cameraEntity.right();; + if (Hotkey(ImGuiKey_A).IsPressed()) + direction = direction + cameraEntity.left();; + if (IsVectorZero(direction)) + return; + // Do not change falling velocity when camera relative + direction.y = 0; + + // Alternative, using set_velocity. Does not work while falling? // const float speed = f_Speed.value(); // const auto currentVelocity = app::Rigidbody_get_velocity(rigidBody, nullptr); // const auto desiredvelocity = currentVelocity + direction * speed; - // LOG_DEBUG("Current velocity: [%.1f,%.1f,%.1f]", desiredvelocity.x, desiredvelocity.y, desiredvelocity.z); + // LOG_DEBUG("Current velocity: [%.1f,%.1f,%.1f]", currentVelocity.x, currentVelocity.y, currentVelocity.z); + // LOG_DEBUG("Desired velocity: [%.1f,%.1f,%.1f]\n", desiredvelocity.x, desiredvelocity.y, desiredvelocity.z); + // app::Rigidbody_set_collisionDetectionMode(rigidBody, app::CollisionDetectionMode__Enum::Continuous, nullptr); // app::Rigidbody_set_velocity(rigidBody, desiredvelocity, nullptr); const app::Vector3 prevPos = avatarEntity->relativePosition(); @@ -82,12 +87,6 @@ namespace cheat::feature const float speed = f_Speed.value(); const float deltaTime = app::Time_get_deltaTime(nullptr); const app::Vector3 newPos = prevPos + (currentVelocity + direction * speed) * deltaTime; - // const auto debugvel = (currentVelocity + direction * speed); - // LOG_DEBUG("PrevPos: [%.1f,%.1f,%.1f]", prevPos.x, prevPos.y, prevPos.z); - // LOG_DEBUG("delta time: %f", deltaTime); - // LOG_DEBUG("currentVelocity: [%.1f,%.1f,%.1f]", currentVelocity.x, currentVelocity.y, currentVelocity.z); - // LOG_DEBUG("direction: [%.1f,%.1f,%.1f]", direction.x, direction.y, direction.z); - // LOG_DEBUG("(currentVelocity + direction * speed): [%.1f,%.1f,%.1f]\n", debugvel.x, debugvel.y, debugvel.z); avatarEntity->setRelativePosition(newPos); }