Skip to content

Commit

Permalink
UObjectHook: Add "Visible" checkbox for SceneComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Nov 1, 2023
1 parent 3535ca1 commit 3c27f3d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 24 deletions.
32 changes: 32 additions & 0 deletions shared/sdk/USceneComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,36 @@ void USceneComponent::set_hidden_in_game(bool hidden, bool propagate) {

this->process_event(func, &params);
}

bool USceneComponent::is_visible() {
static const auto func = static_class()->find_function(L"IsVisible");

if (func == nullptr) {
return false;
}

bool result{};

this->process_event(func, &result);

return result;
}

void USceneComponent::set_visibility(bool visible, bool propagate) {
static const auto func = static_class()->find_function(L"SetVisibility");

if (func == nullptr) {
return;
}

struct {
bool visible{};
bool propagate{};
} params{};

params.visible = visible;
params.propagate = propagate;

this->process_event(func, &params);
}
}
3 changes: 3 additions & 0 deletions shared/sdk/USceneComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class USceneComponent : public UActorComponent {

bool attach_to(USceneComponent* parent, const std::wstring& socket_name = L"None", uint8_t attach_type = 0, bool weld = true);
void set_hidden_in_game(bool hidden, bool propagate_to_children = true);

bool is_visible();
void set_visibility(bool visible, bool propagate_to_children = true);
};

class UPrimitiveComponent : public USceneComponent {
Expand Down
61 changes: 37 additions & 24 deletions src/mods/UObjectHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,40 +1209,53 @@ void UObjectHook::ui_handle_object(sdk::UObject* object) {
}

if (uclass->is_a(sdk::USceneComponent::static_class())) {
auto comp = (sdk::USceneComponent*)object;
bool attached = m_motion_controller_attached_components.contains(comp);
ui_handle_scene_component((sdk::USceneComponent*)object);
}

if (attached) {
if (ImGui::Button("Detach")) {
m_motion_controller_attached_components.erase(comp);
}
if (uclass->is_a(sdk::AActor::static_class())) {
ui_handle_actor(object);
}

if (m_motion_controller_attached_components.contains(comp)) {
ImGui::SameLine();
auto& state = m_motion_controller_attached_components[comp];
ui_handle_struct(object, uclass);
}

ImGui::Checkbox("Adjust", &state->adjusting);
}
} else {
if (ImGui::Button("Attach left")) {
m_motion_controller_attached_components[comp] = std::make_shared<MotionControllerState>();
m_motion_controller_attached_components[comp]->hand = 0;
}
void UObjectHook::ui_handle_scene_component(sdk::USceneComponent* comp) {
if (comp == nullptr) {
return;
}

bool attached = m_motion_controller_attached_components.contains(comp);

if (attached) {
if (ImGui::Button("Detach")) {
m_motion_controller_attached_components.erase(comp);
}

if (m_motion_controller_attached_components.contains(comp)) {
ImGui::SameLine();
auto& state = m_motion_controller_attached_components[comp];

if (ImGui::Button("Attach right")) {
m_motion_controller_attached_components[comp] = std::make_shared<MotionControllerState>();
m_motion_controller_attached_components[comp]->hand = 1;
}
ImGui::Checkbox("Adjust", &state->adjusting);
}
} else {
if (ImGui::Button("Attach left")) {
m_motion_controller_attached_components[comp] = std::make_shared<MotionControllerState>();
m_motion_controller_attached_components[comp]->hand = 0;
}
}

if (uclass->is_a(sdk::AActor::static_class())) {
ui_handle_actor(object);
ImGui::SameLine();

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

ui_handle_struct(object, uclass);
bool visible = comp->is_visible();

if (ImGui::Checkbox("Visible", &visible)) {
comp->set_visibility(visible, false);
}
}

void UObjectHook::ui_handle_material_interface(sdk::UObject* object) {
Expand Down
2 changes: 2 additions & 0 deletions src/mods/UObjectHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ class UObjectHook : public Mod {
void ui_handle_functions(void* object, sdk::UStruct* definition);
void ui_handle_struct(void* addr, sdk::UStruct* definition);

void ui_handle_scene_component(sdk::USceneComponent* component);
void ui_handle_material_interface(sdk::UObject* object);
void ui_handle_actor(sdk::UObject* object);


void spawn_overlapper(uint32_t hand = 0);
void destroy_overlapper();

Expand Down

0 comments on commit 3c27f3d

Please sign in to comment.