From 9c2f7e76516a892fae1da82fa9796dee75defc11 Mon Sep 17 00:00:00 2001 From: praydog Date: Wed, 3 Jan 2024 12:28:05 -0800 Subject: [PATCH] UObjectHook: Add "Disable UObject Hook Key" (#40) --- src/mods/UObjectHook.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/mods/UObjectHook.hpp | 7 ++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/mods/UObjectHook.cpp b/src/mods/UObjectHook.cpp index 24206082..c1aff78e 100644 --- a/src/mods/UObjectHook.cpp +++ b/src/mods/UObjectHook.cpp @@ -288,6 +288,10 @@ void UObjectHook::on_pre_calculate_stereo_view_offset(void* stereo_device, const return; } + if (m_uobject_hook_disabled) { + return; + } + auto view_d = (Vector3d*)view_location; auto rot_d = (Rotator*)view_rotation; @@ -351,6 +355,10 @@ void UObjectHook::on_post_calculate_stereo_view_offset(void* stereo_device, cons return; } + if (m_uobject_hook_disabled) { + return; + } + std::shared_lock _{m_mutex}; bool any_adjusting = false; for (auto& it : m_motion_controller_attached_components) { @@ -364,6 +372,10 @@ void UObjectHook::on_post_calculate_stereo_view_offset(void* stereo_device, cons } void UObjectHook::tick_attachments(Rotator* view_rotation, const float world_to_meters, Vector3f* view_location, bool is_double) { + if (m_uobject_hook_disabled) { + return; + } + auto& vr = VR::get(); auto view_d = (Vector3d*)view_location; auto rot_d = (Rotator*)view_rotation; @@ -1192,6 +1204,10 @@ std::shared_ptr UObjectHook::deserialize_cam } void UObjectHook::update_persistent_states() { + if (m_uobject_hook_disabled) { + return; + } + // Camera state if (m_persistent_camera_state != nullptr) { auto obj = m_persistent_camera_state->path.resolve(); @@ -1599,6 +1615,12 @@ sdk::UObject* UObjectHook::StatePath::resolve() const { return previous_object; } +void UObjectHook::on_frame() { + if (m_keybind_toggle_uobject_hook->is_key_down_once()) { + m_uobject_hook_disabled = !m_uobject_hook_disabled; + } +} + void UObjectHook::on_draw_ui() { activate(); @@ -1609,6 +1631,14 @@ void UObjectHook::on_draw_ui() { std::shared_lock _{m_mutex}; + if (m_uobject_hook_disabled) { + ImGui::TextColored(ImVec4{1.0f, 0.0f, 0.0f, 1.0f}, "UObjectHook is disabled"); + if (ImGui::Button("Re-enable")) { + m_uobject_hook_disabled = false; + } + return; + } + if (ImGui::Button("Reload Persistent States")) { reload_persistent_states(); } @@ -1647,6 +1677,13 @@ void UObjectHook::draw_config() { m_enabled_at_startup->draw("Enabled at Startup"); m_attach_lerp_enabled->draw("Enable Attach Lerp"); m_attach_lerp_speed->draw("Attach Lerp Speed"); + + ImGui::SetNextItemOpen(true, ImGuiCond_::ImGuiCond_Once); + if (ImGui::TreeNode("UObjectHook Keybinds")) { + m_keybind_toggle_uobject_hook->draw("Disable UObjectHook Key"); + + ImGui::TreePop(); + } } void UObjectHook::draw_developer() { diff --git a/src/mods/UObjectHook.hpp b/src/mods/UObjectHook.hpp index f319fd3a..18f44594 100644 --- a/src/mods/UObjectHook.hpp +++ b/src/mods/UObjectHook.hpp @@ -61,6 +61,7 @@ class UObjectHook : public Mod { void on_config_save(utility::Config& cfg) override; void on_pre_engine_tick(sdk::UGameEngine* engine, float delta) override; + void on_frame() override; void on_draw_sidebar_entry(std::string_view in_entry) override; void on_draw_ui() override; @@ -397,9 +398,13 @@ class UObjectHook : public Mod { ModToggle::Ptr m_attach_lerp_enabled{ModToggle::create(generate_name("AttachLerpEnabled"), true)}; ModSlider::Ptr m_attach_lerp_speed{ModSlider::create(generate_name("AttachLerpSpeed"), 0.01f, 30.0f, 15.0f)}; + ModKey::Ptr m_keybind_toggle_uobject_hook{ModKey::create(generate_name("ToggleUObjectHookKey"))}; + bool m_uobject_hook_disabled{false}; + ValueList m_options{ *m_enabled_at_startup, *m_attach_lerp_enabled, - *m_attach_lerp_speed + *m_attach_lerp_speed, + *m_keybind_toggle_uobject_hook }; }; \ No newline at end of file