Support changing hideDevices from GlosSITarget

As well as initially enabling it
pull/183/head
Peter Repukat 2 years ago
parent 5ff02433db
commit a5f6d2d975

@ -68,12 +68,14 @@ void HidHide::closeCtrlDevice()
void HidHide::hideDevices(const std::filesystem::path& steam_path) void HidHide::hideDevices(const std::filesystem::path& steam_path)
{ {
steam_path_ = steam_path;
enableOverlayElement();
if (!Settings::devices.hideDevices) { if (!Settings::devices.hideDevices) {
spdlog::info("Hiding devices is disabled; Not un-patching valve hooks, not looking for HidHide"); spdlog::info("Hiding devices is disabled; Not un-patching valve hooks, not looking for HidHide");
return; return;
} }
spdlog::debug("Device hiding enabled;"); spdlog::debug("Setting up device hiding...");
UnPatchValveHooks(); UnPatchValveHooks();
@ -149,9 +151,9 @@ void HidHide::hideDevices(const std::filesystem::path& steam_path)
spdlog::trace(L"Blacklisted device: {}", dev); spdlog::trace(L"Blacklisted device: {}", dev);
}); });
} }
enableOverlayElement();
} }
closeCtrlDevice(); closeCtrlDevice();
device_hiding_setup_ = true;
} }
void HidHide::disableHidHide() void HidHide::disableHidHide()
@ -217,66 +219,75 @@ void HidHide::enableOverlayElement()
Overlay::AddOverlayElem([this](bool window_has_focus, ImGuiID dockspace_id) { Overlay::AddOverlayElem([this](bool window_has_focus, ImGuiID dockspace_id) {
ImGui::SetNextWindowDockID(dockspace_id, ImGuiCond_FirstUseEver); ImGui::SetNextWindowDockID(dockspace_id, ImGuiCond_FirstUseEver);
if (ImGui::Begin("Hidden Devices")) { if (ImGui::Begin("Hidden Devices")) {
if (window_has_focus && (overlay_elem_clock_.getElapsedTime().asSeconds() > OVERLAY_ELEM_REFRESH_INTERVAL_S_)) { if (device_hiding_setup_) {
// UnPatchValveHooks(); if (window_has_focus && (overlay_elem_clock_.getElapsedTime().asSeconds() > OVERLAY_ELEM_REFRESH_INTERVAL_S_)) {
openCtrlDevice(); // UnPatchValveHooks();
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)) {
openCtrlDevice(); openCtrlDevice();
if (hidden) { bool hidehide_state_store = hidhide_active_;
if (std::ranges::none_of(blacklisted_devices_, findDeviceFn)) { if (Settings::extendedLogging) {
if (!device.device_instance_path.empty()) { spdlog::debug("Refreshing HID devices");
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 { if (hidhide_active_) {
blacklisted_devices_.erase(std::ranges::remove_if(blacklisted_devices_, findDeviceFn).begin(), setActive(false);
blacklisted_devices_.end());
} }
setBlacklistDevices(blacklisted_devices_); avail_devices_ = GetHidDeviceList();
if (Settings::extendedLogging) { if (Settings::extendedLogging) {
std::ranges::for_each(blacklisted_devices_, [](const auto& dev) { std::ranges::for_each(avail_devices_, [](const auto& dev) {
spdlog::trace(L"Blacklisted device: {}", 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(); closeCtrlDevice();
} }
});
ImGui::EndChild();
if (ImGui::Checkbox("Devices Hidden", &hidhide_active_)) {
openCtrlDevice();
setActive(hidhide_active_);
closeCtrlDevice();
} }
} }
ImGui::End(); ImGui::End();

@ -69,6 +69,10 @@ class HidHide {
private: private:
HANDLE hidhide_handle = nullptr; HANDLE hidhide_handle = nullptr;
std::filesystem::path steam_path_;
bool device_hiding_setup_ = false;
// Valve Hooks various functions and hides Gaming devices like this. // Valve Hooks various functions and hides Gaming devices like this.
// To be able to query them, unpatch the hook with the original bytes... // To be able to query them, unpatch the hook with the original bytes...
static inline const std::map<std::string, std::string> ORIGINAL_BYTES = { static inline const std::map<std::string, std::string> ORIGINAL_BYTES = {

Loading…
Cancel
Save