Skip to content

Commit

Permalink
Plugins: Add functions to disable UObjectHook
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jun 9, 2024
1 parent d51b4c9 commit d5f7aec
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions examples/example_plugin/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion include/uevr/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions include/uevr/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UObject*> get_objects_by_class(UClass* c, bool allow_default = false) {
if (c == nullptr) {
return {};
Expand Down
12 changes: 11 additions & 1 deletion src/mods/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion src/mods/UObjectHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -468,6 +476,6 @@ class UObjectHook : public Mod {
*m_keybind_toggle_uobject_hook
};
}

private:
};

0 comments on commit d5f7aec

Please sign in to comment.