diff --git a/cheat-library/cheat-library.vcxproj b/cheat-library/cheat-library.vcxproj index 41b929a..fa7f177 100644 --- a/cheat-library/cheat-library.vcxproj +++ b/cheat-library/cheat-library.vcxproj @@ -21,6 +21,7 @@ + @@ -110,6 +111,7 @@ + diff --git a/cheat-library/cheat-library.vcxproj.filters b/cheat-library/cheat-library.vcxproj.filters index a6ea540..91bba0d 100644 --- a/cheat-library/cheat-library.vcxproj.filters +++ b/cheat-library/cheat-library.vcxproj.filters @@ -243,6 +243,9 @@ Header Files + + Header Files + @@ -444,6 +447,9 @@ Source Files + + Source Files + diff --git a/cheat-library/src/appdata/il2cpp-functions.h b/cheat-library/src/appdata/il2cpp-functions.h index eeefcb1..87a320f 100644 --- a/cheat-library/src/appdata/il2cpp-functions.h +++ b/cheat-library/src/appdata/il2cpp-functions.h @@ -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 diff --git a/cheat-library/src/user/cheat/cheat.cpp b/cheat-library/src/user/cheat/cheat.cpp index 743760f..40d90bc 100644 --- a/cheat-library/src/user/cheat/cheat.cpp +++ b/cheat-library/src/user/cheat/cheat.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #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 diff --git a/cheat-library/src/user/cheat/visuals/FreeCamera.cpp b/cheat-library/src/user/cheat/visuals/FreeCamera.cpp new file mode 100644 index 0000000..eaa297f --- /dev/null +++ b/cheat-library/src/user/cheat/visuals/FreeCamera.cpp @@ -0,0 +1,249 @@ +#include "pch-il2cpp.h" +#include "FreeCamera.h" + +#include +#include + +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(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(freeCam_Camera), reinterpret_cast(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(freeCam_Camera), nullptr), settings.f_FOV, settings.f_Smoothing, nullptr); + app::Camera_set_fieldOfView(reinterpret_cast(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(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(freeCamObj), nullptr); + app::Transform_set_position(freeCamObjTransform, mainCamPos, nullptr); + + auto CinemachineBrain = app::GameObject_GetComponentByName(reinterpret_cast(freeCamObj), string_to_il2cppi("CinemachineBrain"), nullptr); + auto CinemachineExternalCamera = app::GameObject_GetComponentByName(reinterpret_cast(freeCamObj), string_to_il2cppi("CinemachineExternalCamera"), nullptr); + app::Object_1_Destroy_1(reinterpret_cast(CinemachineBrain), nullptr); + app::Object_1_Destroy_1(reinterpret_cast(CinemachineExternalCamera), nullptr); + + app::GameObject_set_active(mainCam, false, nullptr); + app::GameObject_set_active(mainCam, true, nullptr); + app::GameObject_set_active(reinterpret_cast(freeCamObj), false, nullptr); + } + if (freeCamObj) + EnableFreeCam(); + } + else + DisableFreeCam(); + } +} \ No newline at end of file diff --git a/cheat-library/src/user/cheat/visuals/FreeCamera.h b/cheat-library/src/user/cheat/visuals/FreeCamera.h new file mode 100644 index 0000000..9f0ea7e --- /dev/null +++ b/cheat-library/src/user/cheat/visuals/FreeCamera.h @@ -0,0 +1,43 @@ +#pragma once +#include +#include + +namespace cheat::feature +{ + class FreeCamera : public Feature + { + public: + config::Field> f_Enabled; + config::Field f_Speed; + config::Field f_LookSens; + config::Field f_RollSpeed; + config::Field f_FOVSpeed; + config::Field f_FOV; + config::Field f_Smoothing; + config::Field f_Forward; + config::Field f_Backward; + config::Field f_Left; + config::Field f_Right; + config::Field f_Up; + config::Field f_Down; + config::Field f_IncFOV; + config::Field f_DecFOV; + config::Field f_LeftRoll; + config::Field f_RightRoll; + config::Field f_ResetRoll; + + static FreeCamera& GetInstance(); + + const FeatureGUIInfo& GetGUIInfo() const override; + void DrawMain() override; + + bool NeedStatusDraw() const override; + void DrawStatus() override; + + void OnGameUpdate(); + + private: + FreeCamera(); + }; +} +