Skip to content

Commit

Permalink
UObjectHook: Add "Attach HMD" option
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jul 20, 2024
1 parent 90fb65d commit 4429c8f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void UObjectHook::add_new_object(sdk::UObjectBase* object) {
});
}
}

m_meta_objects[object] = std::move(meta_object);

#ifdef VERBOSE_UOBJECTHOOK
Expand Down Expand Up @@ -624,6 +624,8 @@ void UObjectHook::tick_attachments(Rotator<float>* view_rotation, const float wo
} else if (!is_a_down_raw_right) {
state.adjusting = false;
}
} else {
state.adjusting = false;
}
}

Expand Down Expand Up @@ -706,9 +708,12 @@ void UObjectHook::tick_attachments(Rotator<float>* view_rotation, const float wo
glm::radians(-orig_rotation.z));
const auto orig_rotation_quat = glm::quat{orig_rotation_mat};

const auto& hand_rotation = state.hand == 1 ? right_hand_rotation : left_hand_rotation;
const auto& hand_position = state.hand == 1 ? right_hand_position : left_hand_position;
const auto& hand_euler = state.hand == 1 ? right_hand_euler : left_hand_euler;
const auto head_rotation = vqi_norm * glm::quat{vr->get_rotation(0)};

const auto& hand_rotation = state.hand != 2 ? (state.hand == 1 ? right_hand_rotation : left_hand_rotation) : head_rotation;
const auto& hand_position = state.hand != 2 ? (state.hand == 1 ? right_hand_position : left_hand_position) : final_position;
const auto head_euler = glm::degrees(utility::math::euler_angles_from_steamvr(head_rotation));
const auto& hand_euler = state.hand != 2 ? (state.hand == 1 ? right_hand_euler : left_hand_euler) : head_euler;

const auto adjusted_rotation = hand_rotation * glm::inverse(state.rotation_offset);
const auto adjusted_euler = glm::degrees(utility::math::euler_angles_from_steamvr(adjusted_rotation));
Expand Down Expand Up @@ -2511,6 +2516,13 @@ void UObjectHook::ui_handle_scene_component(sdk::USceneComponent* comp) {
m_motion_controller_attached_components[comp]->hand = 1;
}

ImGui::SameLine();

if (ImGui::Button("Attach HMD")) {
m_motion_controller_attached_components[comp] = std::make_shared<MotionControllerState>();
m_motion_controller_attached_components[comp]->hand = 2;
}

if (ImGui::Button("Attach Camera to")) {
m_camera_attach.object = comp;
m_camera_attach.offset = glm::vec3{0.0f, 0.0f, 0.0f};
Expand Down
2 changes: 1 addition & 1 deletion src/mods/UObjectHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class UObjectHook : public Mod {
// State that can be parsed from disk
glm::quat rotation_offset{glm::identity<glm::quat>()};
glm::vec3 location_offset{0.0f, 0.0f, 0.0f};
uint8_t hand{1};
uint8_t hand{1}; // 2 == HMD
bool permanent{false};
};

Expand Down
1 change: 1 addition & 0 deletions src/mods/vr/IXRTrackingSystemHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ detail::IHeadMountedDisplayVT& get_hmd_vtable(std::optional<std::string> version
}

// TODO: actually dump 5.4
// 5.4
if (version.dwFileVersionMS == 0x50004 || str_version.starts_with("5.4")) {
return ue5_3::IHeadMountedDisplayVT::get();
}
Expand Down

0 comments on commit 4429c8f

Please sign in to comment.