From ea1c1092ece5202d0c2282f03919872c2b91ee18 Mon Sep 17 00:00:00 2001 From: praydog Date: Mon, 27 Nov 2023 19:19:51 -0800 Subject: [PATCH] UObjectHook: Add "permanent change" button for component attachments --- src/mods/UObjectHook.cpp | 27 +++++++++++++++++++-------- src/mods/UObjectHook.hpp | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/mods/UObjectHook.cpp b/src/mods/UObjectHook.cpp index 22fe9891..fa6f9842 100644 --- a/src/mods/UObjectHook.cpp +++ b/src/mods/UObjectHook.cpp @@ -55,7 +55,8 @@ nlohmann::json UObjectHook::MotionControllerStateBase::to_json() const { return { {"rotation_offset", utility::math::to_json(rotation_offset)}, {"location_offset", utility::math::to_json(location_offset)}, - {"hand", hand} + {"hand", hand}, + {"permanent", permanent} }; } @@ -72,6 +73,10 @@ void UObjectHook::MotionControllerStateBase::from_json(const nlohmann::json& dat hand = data["hand"].get(); hand = hand % 2; } + + if (data.contains("permanent") && data["permanent"].is_boolean()) { + permanent = data["permanent"].get(); + } } void UObjectHook::activate() { @@ -659,14 +664,16 @@ void UObjectHook::on_pre_calculate_stereo_view_offset(void* stereo_device, const comp->set_world_rotation(adjusted_euler, false, false); } - GameThreadWorker::get().enqueue([this, comp, orig_position, orig_rotation]() { - if (!this->exists(comp)) { - return; - } + if (!state.permanent) { + GameThreadWorker::get().enqueue([this, comp, orig_position, orig_rotation]() { + if (!this->exists(comp)) { + return; + } - comp->set_world_location(orig_position, false, false); - comp->set_world_rotation(orig_rotation, false, false); - }); + comp->set_world_location(orig_position, false, false); + comp->set_world_rotation(orig_rotation, false, false); + }); + } } } } @@ -1875,6 +1882,10 @@ void UObjectHook::ui_handle_scene_component(sdk::USceneComponent* comp) { } } + if (ImGui::Checkbox("Permanent Change", &state->permanent)) { + + } + auto save_state_logic = [&](const std::vector& path) { auto json = serialize_mc_state(path, state); diff --git a/src/mods/UObjectHook.hpp b/src/mods/UObjectHook.hpp index 3c2d6d79..6403bfa6 100644 --- a/src/mods/UObjectHook.hpp +++ b/src/mods/UObjectHook.hpp @@ -143,6 +143,7 @@ class UObjectHook : public Mod { glm::quat rotation_offset{glm::identity()}; glm::vec3 location_offset{0.0f, 0.0f, 0.0f}; uint8_t hand{1}; + bool permanent{false}; }; struct MotionControllerState : MotionControllerStateBase {