Skip to content

Commit

Permalink
UObjectHook: Add "Disable UObject Hook Key" (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jan 3, 2024
1 parent 3970610 commit 9c2f7e7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>*)view_rotation;

Expand Down Expand Up @@ -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) {
Expand All @@ -364,6 +372,10 @@ void UObjectHook::on_post_calculate_stereo_view_offset(void* stereo_device, cons
}

void UObjectHook::tick_attachments(Rotator<float>* 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<double>*)view_rotation;
Expand Down Expand Up @@ -1192,6 +1204,10 @@ std::shared_ptr<UObjectHook::PersistentCameraState> 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();
Expand Down Expand Up @@ -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();

Expand All @@ -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();
}
Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion src/mods/UObjectHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
};
};

0 comments on commit 9c2f7e7

Please sign in to comment.