Skip to content

Commit

Permalink
Lua/Plugins: Add remove_motion_controller_state
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 10, 2024
1 parent 0e77b46 commit 8ba59a0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
4 changes: 3 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 30
#define UEVR_PLUGIN_VERSION_MINOR 31
#define UEVR_PLUGIN_VERSION_PATCH 0

#define UEVR_RENDERER_D3D11 0
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions include/uevr/API.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 2 additions & 1 deletion lua-api/lib/src/ScriptContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>("UEVR_API",
Expand Down
12 changes: 11 additions & 1 deletion src/mods/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/mods/UObjectHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8ba59a0

Please sign in to comment.