Merge pull request #232 from andiabrudan/fall_control

Fall control
This commit is contained in:
Taiga 2022-08-24 01:41:37 -06:00 committed by GitHub
commit 2da131a6c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 175 additions and 12 deletions

View File

@ -22,6 +22,7 @@
<ClInclude Include="src\user\cheat\misc\sniffer\pipe\PipeIO.h" />
<ClInclude Include="src\user\cheat\player\AutoRun.h" />
<ClInclude Include="src\user\cheat\visuals\AnimationChanger.h" />
<ClInclude Include="src\user\cheat\player\FallControl.h" />
<ClInclude Include="src\user\cheat\visuals\TextureChanger.h" />
<ClInclude Include="src\user\cheat\visuals\FreeCamera.h" />
<ClInclude Include="src\user\cheat\world\AutoChallenge.h" />
@ -116,6 +117,7 @@
<ClCompile Include="src\user\cheat\misc\sniffer\pipe\PipeIO.cpp" />
<ClCompile Include="src\user\cheat\player\AutoRun.cpp" />
<ClCompile Include="src\user\cheat\visuals\AnimationChanger.cpp" />
<ClCompile Include="src\user\cheat\player\FallControl.cpp" />
<ClCompile Include="src\user\cheat\visuals\TextureChanger.cpp" />
<ClCompile Include="src\user\cheat\visuals\FreeCamera.cpp" />
<ClCompile Include="src\user\cheat\world\AutoChallenge.cpp" />

View File

@ -255,6 +255,9 @@
<ClInclude Include="src\user\cheat\visuals\AnimationChanger.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\user\cheat\player\FallControl.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\user\cheat\world\AutoChallenge.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -471,6 +474,9 @@
<ClCompile Include="src\user\cheat\visuals\AnimationChanger.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\user\cheat\player\FallControl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\user\cheat\world\AutoChallenge.cpp">
<Filter>Source Files</Filter>
</ClCompile>

View File

@ -57,6 +57,7 @@
#include <cheat/visuals/TextureChanger.h>
#include <cheat/visuals/FreeCamera.h>
#include <cheat/visuals/AnimationChanger.h>
#include <cheat/player/FallControl.h>
#include "GenshinCM.h"
@ -87,6 +88,7 @@ namespace cheat
FEAT_INST(NoClip),
FEAT_INST(RapidFire),
FEAT_INST(AutoRun),
FEAT_INST(FallControl),
FEAT_INST(AutoLoot),
FEAT_INST(AutoTreeFarm),

View File

@ -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();
}

View File

@ -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<class T>
T* plugin(void* pClass)

View File

@ -0,0 +1,121 @@
#include "pch-il2cpp.h"
#include "FallControl.h"
#include <cheat/events.h>
#include <cheat/game/EntityManager.h>
namespace cheat::feature
{
bool FallControl::isFalling = false;
FallControl::FallControl() : Feature(),
NF(f_Enabled, "Fall Control", "FallControl", false),
NF(f_Speed, "Speed", "FallControl", 10.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, 1.0f, 0.0f, 100.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();
auto rigidBody = avatarEntity->rigidbody();
if (rigidBody == nullptr)
return;
const auto cameraEntity = game::Entity(reinterpret_cast<app::BaseEntity*>(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]", 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();
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;
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;
}
}
}

View File

@ -0,0 +1,32 @@
#pragma once
#include <cheat-base/cheat/Feature.h>
#include <cheat-base/config/config.h>
#include <il2cpp-appdata.h>
namespace cheat::feature
{
class FallControl : public Feature
{
public:
config::Field<config::Toggle<Hotkey>> f_Enabled;
config::Field<float> 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;
};
}