Skip to content

Commit

Permalink
UObjectHook: Add "permanent change" button for component attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Nov 28, 2023
1 parent b9e985d commit ea1c109
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
}

Expand All @@ -72,6 +73,10 @@ void UObjectHook::MotionControllerStateBase::from_json(const nlohmann::json& dat
hand = data["hand"].get<uint8_t>();
hand = hand % 2;
}

if (data.contains("permanent") && data["permanent"].is_boolean()) {
permanent = data["permanent"].get<bool>();
}
}

void UObjectHook::activate() {
Expand Down Expand Up @@ -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);
});
}
}
}
}
Expand Down Expand Up @@ -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<std::string>& path) {
auto json = serialize_mc_state(path, state);

Expand Down
1 change: 1 addition & 0 deletions src/mods/UObjectHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class UObjectHook : public Mod {
glm::quat rotation_offset{glm::identity<glm::quat>()};
glm::vec3 location_offset{0.0f, 0.0f, 0.0f};
uint8_t hand{1};
bool permanent{false};
};

struct MotionControllerState : MotionControllerStateBase {
Expand Down

0 comments on commit ea1c109

Please sign in to comment.