diff --git a/GlosSITarget/HidHide.cpp b/GlosSITarget/HidHide.cpp index a0c0b53..db5ab73 100644 --- a/GlosSITarget/HidHide.cpp +++ b/GlosSITarget/HidHide.cpp @@ -68,12 +68,14 @@ void HidHide::closeCtrlDevice() void HidHide::hideDevices(const std::filesystem::path& steam_path) { + steam_path_ = steam_path; + enableOverlayElement(); if (!Settings::devices.hideDevices) { spdlog::info("Hiding devices is disabled; Not un-patching valve hooks, not looking for HidHide"); return; } - - spdlog::debug("Device hiding enabled;"); + + spdlog::debug("Setting up device hiding..."); UnPatchValveHooks(); @@ -149,9 +151,9 @@ void HidHide::hideDevices(const std::filesystem::path& steam_path) spdlog::trace(L"Blacklisted device: {}", dev); }); } - enableOverlayElement(); } closeCtrlDevice(); + device_hiding_setup_ = true; } void HidHide::disableHidHide() @@ -217,66 +219,75 @@ void HidHide::enableOverlayElement() Overlay::AddOverlayElem([this](bool window_has_focus, ImGuiID dockspace_id) { ImGui::SetNextWindowDockID(dockspace_id, ImGuiCond_FirstUseEver); if (ImGui::Begin("Hidden Devices")) { - if (window_has_focus && (overlay_elem_clock_.getElapsedTime().asSeconds() > OVERLAY_ELEM_REFRESH_INTERVAL_S_)) { - // UnPatchValveHooks(); - openCtrlDevice(); - bool hidehide_state_store = hidhide_active_; - if (Settings::extendedLogging) { - spdlog::debug("Refreshing HID devices"); - } - if (hidhide_active_) { - setActive(false); - } - avail_devices_ = GetHidDeviceList(); - if (Settings::extendedLogging) { - std::ranges::for_each(avail_devices_, [](const auto& dev) { - spdlog::trace(L"AvailDevice device: {}", dev.name); - }); - } - blacklisted_devices_ = getBlackListDevices(); - if (hidehide_state_store) { - setActive(true); - } - closeCtrlDevice(); - overlay_elem_clock_.restart(); - } - ImGui::BeginChild("Inner", {0.f, ImGui::GetItemRectSize().y - 64}, true); - std::ranges::for_each(avail_devices_, [this](const auto& device) { - std::string label = (std::string(device.name.begin(), std::ranges::find(device.name, L'\0')) + "##" + std::string(device.device_instance_path.begin(), device.device_instance_path.end())); - const auto findDeviceFn = [&device](const auto& blackdev) { - return device.device_instance_path == blackdev || device.base_container_device_instance_path == blackdev; - }; - bool hidden = std::ranges::find_if(blacklisted_devices_, findDeviceFn) != blacklisted_devices_.end(); - if (ImGui::Checkbox(label.data(), &hidden)) { + if (device_hiding_setup_) { + if (window_has_focus && (overlay_elem_clock_.getElapsedTime().asSeconds() > OVERLAY_ELEM_REFRESH_INTERVAL_S_)) { + // UnPatchValveHooks(); openCtrlDevice(); - if (hidden) { - if (std::ranges::none_of(blacklisted_devices_, findDeviceFn)) { - if (!device.device_instance_path.empty()) { - blacklisted_devices_.push_back(device.device_instance_path); - } - if (!device.device_instance_path.empty()) { - blacklisted_devices_.push_back(device.base_container_device_instance_path); - } - } + bool hidehide_state_store = hidhide_active_; + if (Settings::extendedLogging) { + spdlog::debug("Refreshing HID devices"); } - else { - blacklisted_devices_.erase(std::ranges::remove_if(blacklisted_devices_, findDeviceFn).begin(), - blacklisted_devices_.end()); + if (hidhide_active_) { + setActive(false); } - setBlacklistDevices(blacklisted_devices_); + avail_devices_ = GetHidDeviceList(); if (Settings::extendedLogging) { - std::ranges::for_each(blacklisted_devices_, [](const auto& dev) { - spdlog::trace(L"Blacklisted device: {}", dev); + std::ranges::for_each(avail_devices_, [](const auto& dev) { + spdlog::trace(L"AvailDevice device: {}", dev.name); }); } + blacklisted_devices_ = getBlackListDevices(); + if (hidehide_state_store && Settings::devices.hideDevices) { + setActive(true); + } + closeCtrlDevice(); + overlay_elem_clock_.restart(); + } + ImGui::BeginChild("Inner", {0.f, ImGui::GetItemRectSize().y - 64}, true); + std::ranges::for_each(avail_devices_, [this](const auto& device) { + std::string label = (std::string(device.name.begin(), std::ranges::find(device.name, L'\0')) + "##" + std::string(device.device_instance_path.begin(), device.device_instance_path.end())); + const auto findDeviceFn = [&device](const auto& blackdev) { + return device.device_instance_path == blackdev || device.base_container_device_instance_path == blackdev; + }; + bool hidden = std::ranges::find_if(blacklisted_devices_, findDeviceFn) != blacklisted_devices_.end(); + if (ImGui::Checkbox(label.data(), &hidden)) { + openCtrlDevice(); + if (hidden) { + if (std::ranges::none_of(blacklisted_devices_, findDeviceFn)) { + if (!device.device_instance_path.empty()) { + blacklisted_devices_.push_back(device.device_instance_path); + } + if (!device.device_instance_path.empty()) { + blacklisted_devices_.push_back(device.base_container_device_instance_path); + } + } + } + else { + blacklisted_devices_.erase(std::ranges::remove_if(blacklisted_devices_, findDeviceFn).begin(), + blacklisted_devices_.end()); + } + setBlacklistDevices(blacklisted_devices_); + if (Settings::extendedLogging) { + std::ranges::for_each(blacklisted_devices_, [](const auto& dev) { + spdlog::trace(L"Blacklisted device: {}", dev); + }); + } + closeCtrlDevice(); + } + }); + ImGui::EndChild(); + } else { + ImGui::Text("Enable \"Hide Devices\" to see a list of gaming-devices"); + } + if (ImGui::Checkbox("Hide devices", &Settings::devices.hideDevices)) { + if (!device_hiding_setup_) { + hideDevices(steam_path_); + } + if (hidhide_active_ != Settings::devices.hideDevices) { + openCtrlDevice(); + setActive(Settings::devices.hideDevices); closeCtrlDevice(); } - }); - ImGui::EndChild(); - if (ImGui::Checkbox("Devices Hidden", &hidhide_active_)) { - openCtrlDevice(); - setActive(hidhide_active_); - closeCtrlDevice(); } } ImGui::End(); diff --git a/GlosSITarget/HidHide.h b/GlosSITarget/HidHide.h index 0f398bd..1e3790e 100644 --- a/GlosSITarget/HidHide.h +++ b/GlosSITarget/HidHide.h @@ -69,6 +69,10 @@ class HidHide { private: HANDLE hidhide_handle = nullptr; + std::filesystem::path steam_path_; + bool device_hiding_setup_ = false; + + // Valve Hooks various functions and hides Gaming devices like this. // To be able to query them, unpatch the hook with the original bytes... static inline const std::map ORIGINAL_BYTES = {