From d5f7aec0f4b7f6483604e030e59ae24e64a9bcfb Mon Sep 17 00:00:00 2001 From: praydog Date: Sun, 9 Jun 2024 08:19:01 -0700 Subject: [PATCH] Plugins: Add functions to disable UObjectHook --- examples/example_plugin/Plugin.cpp | 6 ++++++ include/uevr/API.h | 5 ++++- include/uevr/API.hpp | 10 ++++++++++ src/mods/PluginLoader.cpp | 12 +++++++++++- src/mods/UObjectHook.hpp | 10 +++++++++- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/examples/example_plugin/Plugin.cpp b/examples/example_plugin/Plugin.cpp index d045ade0..0b546e37 100644 --- a/examples/example_plugin/Plugin.cpp +++ b/examples/example_plugin/Plugin.cpp @@ -552,6 +552,12 @@ class ExamplePlugin : public uevr::Plugin { if (ImGui::Button("Reload Config")) { API::get()->param()->vr->reload_config(); } + + if (ImGui::Button("Toggle UObjectHook disabled")) { + const auto value = API::UObjectHook::is_disabled(); + + API::UObjectHook::set_disabled(!value); + } #if defined(__clang__) ImGui::Text("Plugin Compiler: Clang"); #elif defined(_MSC_VER) diff --git a/include/uevr/API.h b/include/uevr/API.h index ba5eba29..3e87b671 100644 --- a/include/uevr/API.h +++ b/include/uevr/API.h @@ -36,7 +36,7 @@ SOFTWARE. #define UEVR_OUT #define UEVR_PLUGIN_VERSION_MAJOR 2 -#define UEVR_PLUGIN_VERSION_MINOR 19 +#define UEVR_PLUGIN_VERSION_MINOR 20 #define UEVR_PLUGIN_VERSION_PATCH 0 #define UEVR_RENDERER_D3D11 0 @@ -340,6 +340,9 @@ typedef struct { UEVR_UObjectHookMotionControllerStateHandle (*get_motion_controller_state)(UEVR_UObjectHandle object); UEVR_UObjectHookMotionControllerStateFunctions* mc_state; + + bool (*is_disabled)(); + void (*set_disabled)(bool disabled); } UEVR_UObjectHookFunctions; typedef struct { diff --git a/include/uevr/API.hpp b/include/uevr/API.hpp index 5ef1d10d..a6884f89 100644 --- a/include/uevr/API.hpp +++ b/include/uevr/API.hpp @@ -913,6 +913,16 @@ class API { return fn(obj->to_handle()); } + static bool is_disabled() { + static const auto fn = initialize()->is_disabled; + return fn(); + } + + static void set_disabled(bool disabled) { + static const auto fn = initialize()->set_disabled; + fn(disabled); + } + static std::vector get_objects_by_class(UClass* c, bool allow_default = false) { if (c == nullptr) { return {}; diff --git a/src/mods/PluginLoader.cpp b/src/mods/PluginLoader.cpp index 456359cb..2166460a 100644 --- a/src/mods/PluginLoader.cpp +++ b/src/mods/PluginLoader.cpp @@ -543,6 +543,14 @@ namespace uobjecthook { return (UEVR_UObjectHookMotionControllerStateHandle)result->get(); } + bool disabled() { + return UObjectHook::get()->is_disabled(); + } + + void set_disabled(bool disabled) { + UObjectHook::get()->set_disabled(disabled); + } + namespace mc_state { void set_rotation_offset(UEVR_UObjectHookMotionControllerStateHandle state, const UEVR_Quaternionf* rotation) { if (state == nullptr) { @@ -608,7 +616,9 @@ UEVR_UObjectHookFunctions g_uobjecthook_functions { uevr::uobjecthook::get_first_object_by_class_name, uevr::uobjecthook::get_or_add_motion_controller_state, uevr::uobjecthook::get_motion_controller_state, - &g_mc_functions + &g_mc_functions, + uevr::uobjecthook::disabled, + uevr::uobjecthook::set_disabled }; #define FFIELDCLASS(x) ((sdk::FFieldClass*)x) diff --git a/src/mods/UObjectHook.hpp b/src/mods/UObjectHook.hpp index f548652a..870e39e7 100644 --- a/src/mods/UObjectHook.hpp +++ b/src/mods/UObjectHook.hpp @@ -46,6 +46,14 @@ class UObjectHook : public Mod { void activate(); + bool is_disabled() const { + return m_uobject_hook_disabled; + } + + void set_disabled(bool disabled) { + m_uobject_hook_disabled = disabled; + } + protected: std::string_view get_name() const override { return "UObjectHook"; }; bool is_advanced_mod() const override { return true; } @@ -468,6 +476,6 @@ class UObjectHook : public Mod { *m_keybind_toggle_uobject_hook }; } - + private: }; \ No newline at end of file