Merge pull request #228 from portra400nc/freecamera

Add free camera
This commit is contained in:
Callow 2022-07-09 13:21:26 +03:00 committed by GitHub
commit 83cc1642e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 321 additions and 1 deletions

View File

@ -21,6 +21,7 @@
<ClInclude Include="src\user\cheat\misc\sniffer\pipe\PipeClient.h" />
<ClInclude Include="src\user\cheat\misc\sniffer\pipe\PipeIO.h" />
<ClInclude Include="src\user\cheat\visuals\TextureChanger.h" />
<ClInclude Include="src\user\cheat\visuals\FreeCamera.h" />
<ClInclude Include="src\user\cheat\world\AutoSeelie.h" />
<ClInclude Include="src\user\cheat\world\FakeTime.h" />
<ClInclude Include="src\user\cheat\debugger.h">
@ -110,6 +111,7 @@
<ClCompile Include="src\user\cheat\misc\sniffer\pipe\PipeClient.cpp" />
<ClCompile Include="src\user\cheat\misc\sniffer\pipe\PipeIO.cpp" />
<ClCompile Include="src\user\cheat\visuals\TextureChanger.cpp" />
<ClCompile Include="src\user\cheat\visuals\FreeCamera.cpp" />
<ClCompile Include="src\user\cheat\world\AutoSeelie.cpp" />
<ClCompile Include="src\user\cheat\world\FakeTime.cpp" />
<ClCompile Include="src\user\cheat\debugger.cpp">

View File

@ -243,6 +243,9 @@
<ClInclude Include="src\user\cheat\world\VacuumLoot.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\user\cheat\visuals\FreeCamera.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Font Include="res\Ruda-Bold.ttf" />
@ -444,6 +447,9 @@
<ClCompile Include="src\user\cheat\misc\sniffer\pipe\PipeIO.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\user\cheat\visuals\FreeCamera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\res.rc">

View File

@ -159,6 +159,11 @@ DO_APP_FUNC(0x032256C0, void, CookingQtePageContext_CloseItemGotPanel, (CookingQ
DO_APP_FUNC(0x027A41A0, Button_1*, ProfilePage, (MonoInLevelPlayerProfilePage* __this, MethodInfo* method)); // MonoInLevelPlayerProfilePage_get_logoutButton
DO_APP_FUNC(0x016A77B0, void, ProfileEditPage, (MonoFriendInformationDialog* __this, Sprite* value, MethodInfo* method)); // MonoFriendInformationDialog_set_icon
// Free Camera
DO_APP_FUNC(0x06595250, float, Camera_get_fieldOfView, (Camera* __this, MethodInfo* method));
DO_APP_FUNC(0x065956C0, void, Camera_set_fieldOfView, (Camera* __this, float value, MethodInfo* method));
DO_APP_FUNC(0x065949D0, void, Camera_CopyFrom, (Camera* __this, Camera* other, MethodInfo* method));
// Game Object, Component, Transform Utility
DO_APP_FUNC(0x0662F130, GameObject*, GameObject_Find, (String* name, MethodInfo* method));
DO_APP_FUNC(0x0662F190, Component_1*, GameObject_GetComponentByName, (GameObject* __this, String* type, MethodInfo* method));
@ -186,6 +191,19 @@ DO_APP_FUNC(0x0652EBC0, GameObject*, Component_1_get_gameObject, (Component_1* _
DO_APP_FUNC(0x06551030, String*, Object_1_get_name, (Object_1* __this, MethodInfo* method));
DO_APP_FUNC(0x0665DA90, Material__Array*, Renderer_GetMaterialArray, (Renderer* __this, MethodInfo* method));
DO_APP_FUNC(0x0652FB40, void, Material_set_mainTexture, (Material* __this, Texture* value, MethodInfo* method));
DO_APP_FUNC(0x0664E800, Vector3, Vector3_Lerp, (Vector3 a, Vector3 b, float t, MethodInfo* method));
DO_APP_FUNC(0x06555890, Vector3, Transform_get_eulerAngles, (Transform* __this, MethodInfo* method));
DO_APP_FUNC(0x06555DD0, void, Transform_set_eulerAngles, (Transform* __this, Vector3 value, MethodInfo* method));
DO_APP_FUNC(0x06555BE0, Vector3, Transform_get_right, (Transform* __this, MethodInfo* method));
DO_APP_FUNC(0x06555F70, void, Transform_set_right, (Transform* __this, Vector3 value, MethodInfo* method));
DO_APP_FUNC(0x06555CC0, Vector3, Transform_get_up, (Transform* __this, MethodInfo* method));
DO_APP_FUNC(0x06555FF0, void, Transform_set_up, (Transform* __this, Vector3 value, MethodInfo* method));
DO_APP_FUNC(0x06555900, Vector3, Transform_get_forward, (Transform* __this, MethodInfo* method));
DO_APP_FUNC(0x06555E20, void, Transform_set_forward, (Transform* __this, Vector3 value, MethodInfo* method));
DO_APP_FUNC(0x06555FE0, void, Transform_set_rotation, (Transform* __this, Quaternion value, MethodInfo* method));
DO_APP_FUNC(0x065E1EC0, float, Mathf_Lerp, (float a, float b, float t, MethodInfo* method));
DO_APP_FUNC(0x065F56F0, float, Input_GetAxis, (String* axisName, MethodInfo* method));
DO_APP_FUNC(0x06550910, void, Object_1_Destroy_1, (Object_1* obj, MethodInfo* method));
// Music game event

View File

@ -52,6 +52,7 @@
#include <cheat/visuals/Browser.h>
#include <cheat/visuals/EnablePeaking.h>
#include <cheat/visuals/TextureChanger.h>
#include <cheat/visuals/FreeCamera.h>
#include "GenshinCM.h"
@ -116,7 +117,8 @@ namespace cheat
FEAT_INST(HideUI),
FEAT_INST(Browser),
FEAT_INST(EnablePeaking),
FEAT_INST(TextureChanger)
FEAT_INST(TextureChanger),
FEAT_INST(FreeCamera)
});
#undef FEAT_INST

View File

@ -0,0 +1,249 @@
#include "pch-il2cpp.h"
#include "FreeCamera.h"
#include <helpers.h>
#include <cheat/events.h>
namespace cheat::feature
{
app::GameObject* freeCam = nullptr;
app::GameObject* mainCam = nullptr;
app::Object_1* freeCamObj = nullptr;
app::Object_1* mainCamObj = nullptr;
app::Transform* freeCam_Transform;
app::Component_1* freeCam_Camera;
app::Component_1* mainCam_Camera;
app::Vector3 targetPosition;
app::Vector3 smoothPosition;
float smoothFOV;
bool isEnabled = false;
FreeCamera::FreeCamera() : Feature(),
NF(f_Enabled, "Free Camera", "Visuals::FreeCamera", false),
NF(f_Speed, "Speed", "Visuals::FreeCamera", 1.0f),
NF(f_LookSens, "Look Sensitivity", "Visuals::FreeCamera", 1.0f),
NF(f_RollSpeed, "Roll Speed", "Visuals::FreeCamera", 1.0f),
NF(f_FOVSpeed, "FOV Speed", "Visuals::FreeCamera", 0.1f),
NF(f_FOV, "Field of View", "Visuals::FreeCamera", 45.0f),
NF(f_Smoothing, "Smoothing", "Visuals::FreeCamera", 1.0f),
NF(f_Forward, "Forward", "Visuals::FreeCamera", Hotkey('W')),
NF(f_Backward, "Backward", "Visuals::FreeCamera", Hotkey('S')),
NF(f_Left, "Left", "Visuals::FreeCamera", Hotkey('A')),
NF(f_Right, "Right", "Visuals::FreeCamera", Hotkey('D')),
NF(f_Up, "Up", "Visuals::FreeCamera", Hotkey(VK_SPACE)),
NF(f_Down, "Down", "Visuals::FreeCamera", Hotkey(VK_LCONTROL)),
NF(f_LeftRoll, "Roll Left", "Visuals::FreeCamera", Hotkey('Z')),
NF(f_RightRoll, "Roll Right", "Visuals::FreeCamera", Hotkey('X')),
NF(f_ResetRoll, "Reset Roll", "Visuals::FreeCamera", Hotkey('C')),
NF(f_IncFOV, "Increase FOV", "Visuals::FreeCamera", Hotkey('3')),
NF(f_DecFOV, "Decrease FOV", "Visuals::FreeCamera", Hotkey('1'))
{
events::GameUpdateEvent += MY_METHOD_HANDLER(FreeCamera::OnGameUpdate);
}
const FeatureGUIInfo& FreeCamera::GetGUIInfo() const
{
static const FeatureGUIInfo info{ "Free Camera", "Visuals", true };
return info;
}
void FreeCamera::DrawMain()
{
ConfigWidget("Enable", f_Enabled);
if (ImGui::BeginTable("FreeCameraDrawTable", 1, ImGuiTableFlags_NoBordersInBody))
{
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::BeginGroupPanel("Settings");
{
ConfigWidget("Movement Speed", f_Speed, 0.01f, 0.01f, 1000.0f);
ConfigWidget("Look Sensitivity", f_LookSens, 0.01f, 0.01f, 100.0f);
ConfigWidget("Roll Speed", f_RollSpeed, 0.01f, 0.01f, 100.0f);
ConfigWidget("FOV Speed", f_FOVSpeed, 0.01f, 0.01f, 100.0f);
ConfigWidget("Field of View", f_FOV, 0.1f, 0.01f, 200.0f);
ConfigWidget("Smoothing", f_Smoothing, 0.01f, 0.001f, 1.0f, "Lower = Smoother");
}
ImGui::EndGroupPanel();
ImGui::BeginGroupPanel("Hotkeys");
{
ConfigWidget("Forward", f_Forward, true);
ConfigWidget("Backward", f_Backward, true);
ConfigWidget("Left", f_Left, true);
ConfigWidget("Right", f_Right, true);
ConfigWidget("Up", f_Up, true);
ConfigWidget("Down", f_Down, true);
ConfigWidget("Roll Left", f_LeftRoll, true);
ConfigWidget("Roll Right", f_RightRoll, true);
ConfigWidget("Reset Roll", f_ResetRoll, true);
ConfigWidget("Increase FOV", f_IncFOV, true);
ConfigWidget("Decrease FOV", f_DecFOV, true);
}
ImGui::EndGroupPanel();
ImGui::EndTable();
}
}
bool FreeCamera::NeedStatusDraw() const
{
return f_Enabled;
}
void FreeCamera::DrawStatus()
{
ImGui::Text("Free Camera");
}
FreeCamera& FreeCamera::GetInstance()
{
static FreeCamera instance;
return instance;
}
class CameraRotation
{
public:
float pitch, yaw, roll;
void InitializeFromTransform(app::Transform* t)
{
auto t_eulerAngles = app::Transform_get_eulerAngles(t, nullptr);
pitch = t_eulerAngles.x;
yaw = t_eulerAngles.y;
roll = t_eulerAngles.z;
}
void LerpTowards(CameraRotation target, float rotationLerpPct)
{
yaw = app::Mathf_Lerp(yaw, target.yaw, rotationLerpPct, nullptr);
pitch = app::Mathf_Lerp(pitch, target.pitch, rotationLerpPct, nullptr);
roll = app::Mathf_Lerp(roll, target.roll, rotationLerpPct, nullptr);
}
void UpdateTransform(app::Transform* t)
{
app::Transform_set_eulerAngles(t, app::Vector3{ pitch, yaw, roll }, nullptr);
}
};
auto targetRotation = CameraRotation();
auto currentRotation = CameraRotation();
void EnableFreeCam()
{
auto& settings = FreeCamera::GetInstance();
freeCam = reinterpret_cast<app::GameObject*>(freeCamObj);
freeCam_Transform = app::GameObject_get_transform(freeCam, nullptr);
auto freeCam_Transform_position = app::Transform_get_position(freeCam_Transform, nullptr);
freeCam_Camera = app::GameObject_GetComponentByName(freeCam, string_to_il2cppi("Camera"), nullptr);
mainCam_Camera = app::GameObject_GetComponentByName(mainCam, string_to_il2cppi("Camera"), nullptr);
if (isEnabled == false)
{
targetRotation.InitializeFromTransform(freeCam_Transform);
currentRotation.InitializeFromTransform(freeCam_Transform);
app::Camera_CopyFrom(reinterpret_cast<app::Camera*>(freeCam_Camera), reinterpret_cast<app::Camera*>(mainCam_Camera), nullptr);
targetPosition = freeCam_Transform_position;
isEnabled = true;
}
app::GameObject_set_active(mainCam, false, nullptr);
app::GameObject_set_active(freeCam, true, nullptr);
// MOVEMENT
if (settings.f_Forward.value().IsPressed())
targetPosition = targetPosition + app::Transform_get_forward(freeCam_Transform, nullptr) * settings.f_Speed;
if (settings.f_Backward.value().IsPressed())
targetPosition = targetPosition - app::Transform_get_forward(freeCam_Transform, nullptr) * settings.f_Speed;
if (settings.f_Right.value().IsPressed())
targetPosition = targetPosition + app::Transform_get_right(freeCam_Transform, nullptr) * settings.f_Speed;
if (settings.f_Left.value().IsPressed())
targetPosition = targetPosition - app::Transform_get_right(freeCam_Transform, nullptr) * settings.f_Speed;
if (settings.f_LeftRoll.value().IsPressed())
targetRotation.roll += settings.f_Speed;
if (settings.f_RightRoll.value().IsPressed())
targetRotation.roll -= settings.f_Speed;
if (settings.f_ResetRoll.value().IsPressed())
targetRotation.roll = 0.0f;
if (settings.f_Up.value().IsPressed())
targetPosition = targetPosition + app::Transform_get_up(freeCam_Transform, nullptr) * settings.f_Speed;
if (settings.f_Down.value().IsPressed())
targetPosition = targetPosition - app::Transform_get_up(freeCam_Transform, nullptr) * settings.f_Speed;
if (settings.f_DecFOV.value().IsPressed())
settings.f_FOV -= settings.f_FOVSpeed;
if (settings.f_IncFOV.value().IsPressed())
settings.f_FOV += settings.f_FOVSpeed;
// Update the target rotation based on mouse input
auto mouseX = app::Input_GetAxis(string_to_il2cppi("Mouse X"), nullptr);
auto mouseY = app::Input_GetAxis(string_to_il2cppi("Mouse Y"), nullptr);
auto mouseInput = app::Vector2{ mouseX, mouseY * -1.0f };
targetRotation.yaw += mouseInput.x * settings.f_LookSens;
targetRotation.pitch += mouseInput.y * settings.f_LookSens;
// Commit the rotation changes to the transform
currentRotation.UpdateTransform(freeCam_Transform);
smoothPosition = app::Vector3_Lerp(freeCam_Transform_position, targetPosition, settings.f_Smoothing, nullptr);
app::Transform_set_position(freeCam_Transform, smoothPosition, nullptr);
smoothFOV = app::Mathf_Lerp(app::Camera_get_fieldOfView(reinterpret_cast<app::Camera*>(freeCam_Camera), nullptr), settings.f_FOV, settings.f_Smoothing, nullptr);
app::Camera_set_fieldOfView(reinterpret_cast<app::Camera*>(freeCam_Camera), smoothFOV, nullptr);
currentRotation.LerpTowards(targetRotation, settings.f_Smoothing);
}
void DisableFreeCam()
{
if (!isEnabled)
return;
if (mainCam)
{
app::GameObject_set_active(mainCam, true, nullptr);
mainCam = nullptr;
}
if (freeCamObj)
{
app::Object_1_Destroy_1(freeCamObj, nullptr);
freeCamObj = nullptr;
}
isEnabled = false;
}
void FreeCamera::OnGameUpdate()
{
if (f_Enabled)
{
if (mainCam == nullptr)
mainCam = app::GameObject_Find(string_to_il2cppi("/EntityRoot/MainCamera(Clone)"), nullptr);
if (freeCamObj == nullptr && mainCam)
{
freeCamObj = app::Object_1_Instantiate_2(reinterpret_cast<app::Object_1*>(mainCam), nullptr);
auto mainCamTransform = app::GameObject_get_transform(mainCam, nullptr);
auto mainCamPos = app::Transform_get_position(mainCamTransform, nullptr);
auto freeCamObjTransform = app::GameObject_get_transform(reinterpret_cast<app::GameObject*>(freeCamObj), nullptr);
app::Transform_set_position(freeCamObjTransform, mainCamPos, nullptr);
auto CinemachineBrain = app::GameObject_GetComponentByName(reinterpret_cast<app::GameObject*>(freeCamObj), string_to_il2cppi("CinemachineBrain"), nullptr);
auto CinemachineExternalCamera = app::GameObject_GetComponentByName(reinterpret_cast<app::GameObject*>(freeCamObj), string_to_il2cppi("CinemachineExternalCamera"), nullptr);
app::Object_1_Destroy_1(reinterpret_cast<app::Object_1*>(CinemachineBrain), nullptr);
app::Object_1_Destroy_1(reinterpret_cast<app::Object_1*>(CinemachineExternalCamera), nullptr);
app::GameObject_set_active(mainCam, false, nullptr);
app::GameObject_set_active(mainCam, true, nullptr);
app::GameObject_set_active(reinterpret_cast<app::GameObject*>(freeCamObj), false, nullptr);
}
if (freeCamObj)
EnableFreeCam();
}
else
DisableFreeCam();
}
}

View File

@ -0,0 +1,43 @@
#pragma once
#include <cheat-base/cheat/Feature.h>
#include <cheat-base/config/config.h>
namespace cheat::feature
{
class FreeCamera : public Feature
{
public:
config::Field<config::Toggle<Hotkey>> f_Enabled;
config::Field<float> f_Speed;
config::Field<float> f_LookSens;
config::Field<float> f_RollSpeed;
config::Field<float> f_FOVSpeed;
config::Field<float> f_FOV;
config::Field<float> f_Smoothing;
config::Field<Hotkey> f_Forward;
config::Field<Hotkey> f_Backward;
config::Field<Hotkey> f_Left;
config::Field<Hotkey> f_Right;
config::Field<Hotkey> f_Up;
config::Field<Hotkey> f_Down;
config::Field<Hotkey> f_IncFOV;
config::Field<Hotkey> f_DecFOV;
config::Field<Hotkey> f_LeftRoll;
config::Field<Hotkey> f_RightRoll;
config::Field<Hotkey> f_ResetRoll;
static FreeCamera& GetInstance();
const FeatureGUIInfo& GetGUIInfo() const override;
void DrawMain() override;
bool NeedStatusDraw() const override;
void DrawStatus() override;
void OnGameUpdate();
private:
FreeCamera();
};
}