From 8ba59a0fd800b1e7f2319337fcf706f4cee961b1 Mon Sep 17 00:00:00 2001 From: praydog Date: Thu, 10 Oct 2024 14:32:39 -0700 Subject: [PATCH] Lua/Plugins: Add remove_motion_controller_state --- include/uevr/API.h | 4 +++- include/uevr/API.hpp | 5 +++++ lua-api/lib/src/ScriptContext.cpp | 3 ++- src/mods/PluginLoader.cpp | 12 +++++++++++- src/mods/UObjectHook.hpp | 10 +++++----- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/uevr/API.h b/include/uevr/API.h index dce43dec..c536ac9b 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 30 +#define UEVR_PLUGIN_VERSION_MINOR 31 #define UEVR_PLUGIN_VERSION_PATCH 0 #define UEVR_RENDERER_D3D11 0 @@ -372,6 +372,8 @@ typedef struct { bool (*is_disabled)(); void (*set_disabled)(bool disabled); + + void (*remove_motion_controller_state)(UEVR_UObjectHandle object); } UEVR_UObjectHookFunctions; typedef struct { diff --git a/include/uevr/API.hpp b/include/uevr/API.hpp index 296a6ec7..6b2c6d48 100644 --- a/include/uevr/API.hpp +++ b/include/uevr/API.hpp @@ -1509,6 +1509,11 @@ class API { static const auto fn = initialize()->get_motion_controller_state; return (MotionControllerState*)fn(obj->to_handle()); } + + static void remove_motion_controller_state(UObject* obj) { + static const auto fn = initialize()->remove_motion_controller_state; + fn(obj->to_handle()); + } struct MotionControllerState { inline UEVR_UObjectHookMotionControllerStateHandle to_handle() { return (UEVR_UObjectHookMotionControllerStateHandle)this; } diff --git a/lua-api/lib/src/ScriptContext.cpp b/lua-api/lib/src/ScriptContext.cpp index b6e9ca7d..bce9c6c3 100644 --- a/lua-api/lib/src/ScriptContext.cpp +++ b/lua-api/lib/src/ScriptContext.cpp @@ -702,7 +702,8 @@ int ScriptContext::setup_bindings() { return uevr::API::UObjectHook::get_objects_by_class(c, allow_default); }, "get_or_add_motion_controller_state", &uevr::API::UObjectHook::get_or_add_motion_controller_state, - "get_motion_controller_state", &uevr::API::UObjectHook::get_motion_controller_state + "get_motion_controller_state", &uevr::API::UObjectHook::get_motion_controller_state, + "remove_motion_controller_state", &uevr::API::UObjectHook::remove_motion_controller_state ); m_lua.new_usertype("UEVR_API", diff --git a/src/mods/PluginLoader.cpp b/src/mods/PluginLoader.cpp index 54bd4304..150d548c 100644 --- a/src/mods/PluginLoader.cpp +++ b/src/mods/PluginLoader.cpp @@ -737,6 +737,15 @@ namespace uobjecthook { return (UEVR_UObjectHookMotionControllerStateHandle)result->get(); } + void remove_motion_controller_state(UEVR_UObjectHandle obj_handle) { + const auto obj = (sdk::USceneComponent*)obj_handle; + if (obj == nullptr || !obj->is_a(sdk::USceneComponent::static_class())) { + return; + } + + UObjectHook::get()->remove_motion_controller_state(obj); + } + bool disabled() { return UObjectHook::get()->is_disabled(); } @@ -812,7 +821,8 @@ UEVR_UObjectHookFunctions g_uobjecthook_functions { uevr::uobjecthook::get_motion_controller_state, &g_mc_functions, uevr::uobjecthook::disabled, - uevr::uobjecthook::set_disabled + uevr::uobjecthook::set_disabled, + uevr::uobjecthook::remove_motion_controller_state }; #define FFIELDCLASS(x) ((sdk::FFieldClass*)x) diff --git a/src/mods/UObjectHook.hpp b/src/mods/UObjectHook.hpp index 12e28051..5f110a58 100644 --- a/src/mods/UObjectHook.hpp +++ b/src/mods/UObjectHook.hpp @@ -152,6 +152,11 @@ class UObjectHook : public Mod { return {}; } + void remove_motion_controller_state(sdk::USceneComponent* component) { + std::unique_lock _{m_mutex}; + m_motion_controller_attached_components.erase(component); + } + private: struct StatePath; struct PersistentState; @@ -258,11 +263,6 @@ class UObjectHook : public Mod { glm::vec3 offset{}; } m_camera_attach{}; - void remove_motion_controller_state(sdk::USceneComponent* component) { - std::unique_lock _{m_mutex}; - m_motion_controller_attached_components.erase(component); - } - auto get_spawned_spheres() const { std::shared_lock _{m_mutex}; return m_spawned_spheres;