HidHide Gui Overlay Widget

pull/130/head
Peter Repukat 3 years ago
parent 0bf9ec1108
commit a7335552ab

@ -153,6 +153,7 @@
<ItemGroup>
<ClCompile Include="..\deps\imgui-sfml\imgui-SFML.cpp" />
<ClCompile Include="..\deps\imgui\imgui.cpp" />
<ClCompile Include="..\deps\imgui\imgui_demo.cpp" />
<ClCompile Include="..\deps\imgui\imgui_draw.cpp" />
<ClCompile Include="..\deps\imgui\imgui_tables.cpp" />
<ClCompile Include="..\deps\imgui\imgui_widgets.cpp" />

@ -72,6 +72,9 @@
<ClCompile Include="..\deps\imgui-sfml\imgui-SFML.cpp">
<Filter>Source Files\imgui-sfml</Filter>
</ClCompile>
<ClCompile Include="..\deps\imgui\imgui_demo.cpp">
<Filter>Source Files\imgui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SteamTarget.h">

@ -30,6 +30,8 @@ limitations under the License.
#include <initguid.h>
//
#include "Overlay.h"
#include <devguid.h>
#include <devpkey.h>
#include <regex>
@ -90,7 +92,7 @@ void HidHide::hideDevices(const std::filesystem::path& steam_path)
auto path = std::regex_replace(steam_path_string, std::wregex(L"(.:)(\\/|\\\\)"), dos_device + L"\\");
path = std::regex_replace(path, std::wregex(L"\\/"), L"\\") + L"\\" + std::wstring{exe};
if (std::ranges::none_of(whitelist, [&path](auto ep) { // make copy!
auto p = path; // non-const(!) copy of path
auto p = path; // non-const(!) copy of path
std::ranges::transform(path, p.begin(), tolower);
std::ranges::transform(ep, ep.begin(), tolower);
return p == ep;
@ -100,25 +102,26 @@ void HidHide::hideDevices(const std::filesystem::path& steam_path)
}
setAppWhiteList(whitelist);
const auto device_list = GetHidDeviceList();
auto blacklist = getBlackListDevices();
avail_devices_ = GetHidDeviceList();
blacklisted_devices_ = getBlackListDevices();
for (const auto& dev : device_list) {
if (std::ranges::none_of(blacklist, [&dev](const auto& blackdev) {
for (const auto& dev : avail_devices_) {
if (std::ranges::none_of(blacklisted_devices_, [&dev](const auto& blackdev) {
return blackdev == dev.device_instance_path || blackdev == dev.base_container_device_instance_path;
})) {
})) {
if (!dev.device_instance_path.empty()) {
blacklist.push_back(dev.device_instance_path);
blacklisted_devices_.push_back(dev.device_instance_path);
}
if (!dev.device_instance_path.empty()) {
blacklist.push_back(dev.base_container_device_instance_path);
blacklisted_devices_.push_back(dev.base_container_device_instance_path);
}
}
}
setBlacklistDevices(blacklist);
setBlacklistDevices(blacklisted_devices_);
setActive(true);
closeCtrlDevice();
spdlog::info("Hid Gaming Devices"); // TODO: add list of blacklisted devices
spdlog::info("Hid Gaming Devices; Enabling Overlay element...");
enableOverlayElement();
}
void HidHide::disableHidHide()
@ -126,7 +129,62 @@ void HidHide::disableHidHide()
openCtrlDevice();
setActive(false);
closeCtrlDevice();
spdlog::info("Un-hid Gaming Devices"); // TODO: add list of blacklisted devices
spdlog::info("Un-hid Gaming Devices");
}
void HidHide::enableOverlayElement()
{
Overlay::AddOverlayElem([this]() {
if (overlay_elem_clock_.getElapsedTime().asSeconds() > OVERLAY_ELEM_REFRESH_INTERVAL_S_) {
openCtrlDevice();
bool hidehide_state_store = hidhide_active_;
if (hidhide_active_) {
setActive(false);
}
avail_devices_ = GetHidDeviceList();
blacklisted_devices_ = getBlackListDevices();
if (hidehide_state_store) {
setActive(true);
}
closeCtrlDevice();
overlay_elem_clock_.restart();
}
ImGui::Begin("Hidden Devices");
ImGui::BeginChild("Inner", {0.f, ImGui::GetItemRectSize().y - 48}, 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_);
closeCtrlDevice();
}
});
ImGui::EndChild();
if (ImGui::Checkbox("Devices Hidden", &hidhide_active_)) {
openCtrlDevice();
setActive(hidhide_active_);
closeCtrlDevice();
}
ImGui::End();
});
}
std::wstring HidHide::DosDeviceForVolume(const std::wstring& volume)
@ -166,7 +224,7 @@ std::vector<std::wstring> HidHide::getBlackListDevices() const
return BufferToStringVec(buffer);
}
bool HidHide::getActive() const
bool HidHide::getActive()
{
DWORD bytes_needed;
BOOLEAN res;
@ -175,6 +233,7 @@ bool HidHide::getActive() const
spdlog::error("Couldn't retrieve HidHide State");
return false;
}
hidhide_active_ = res;
return res;
}
@ -198,13 +257,15 @@ void HidHide::setBlacklistDevices(const std::vector<std::wstring>& blacklist) co
}
}
void HidHide::setActive(bool active) const
void HidHide::setActive(bool active)
{
DWORD bytes_needed;
if (!DeviceIoControl(
hidhide_handle, static_cast<DWORD>(IOCTL_TYPE::SET_ACTIVE), &active, sizeof(BOOLEAN), nullptr, 0, &bytes_needed, nullptr)) {
spdlog::error("Couldn't set HidHide State");
return;
}
hidhide_active_ = active;
}
DWORD HidHide::getRequiredOutputBufferSize(IOCTL_TYPE type) const
@ -352,6 +413,10 @@ HidHide::SmallHidInfo HidHide::GetDeviceInfo(const DeviceInstancePath& instance_
res.name = (HidD_GetProductString(device_object.get(), buffer.data(), static_cast<ULONG>(sizeof(WCHAR) * buffer.size()))
? buffer
: L"");
// Valve emulated gamepad PID/VID; mirrord by ViGEm
if (attributes.VendorID == 0x28de && attributes.ProductID == 0x11FF) {
res.name = std::wstring(L"ViGEm Emulated: ") + res.name;
}
res.base_container_device_instance_path = BaseContainerDeviceInstancePath(instance_path);
res.gaming_device = IsGamingDevice(attributes, capabilities);

@ -24,6 +24,7 @@ limitations under the License.
#include <filesystem>
#include <string>
#include <vector>
#include <SFML/System/Clock.hpp>
class HidHide {
private:
@ -65,6 +66,14 @@ class HidHide {
private:
HANDLE hidhide_handle = nullptr;
void enableOverlayElement();
sf::Clock overlay_elem_clock_;
std::vector<std::wstring> blacklisted_devices_;
std::vector<SmallHidInfo> avail_devices_;
bool hidhide_active_ = false;
static constexpr int OVERLAY_ELEM_REFRESH_INTERVAL_S_ = 5;
static inline constexpr std::array<std::wstring_view, 3> whitelist_executeables_{
L"GameOverlayUI.exe",
L"steam.exe",
@ -74,10 +83,10 @@ class HidHide {
[[nodiscard]] std::vector<std::wstring> getAppWhiteList() const;
[[nodiscard]] std::vector<std::wstring> getBlackListDevices() const;
[[nodiscard]] bool getActive() const;
[[nodiscard]] bool getActive();
void setAppWhiteList(const std::vector<std::wstring>& whitelist) const;
void setBlacklistDevices(const std::vector<std::wstring>& blacklist) const;
void setActive(bool active) const;
void setActive(bool active);
[[nodiscard]] DWORD getRequiredOutputBufferSize(IOCTL_TYPE type) const;

@ -1,11 +1,5 @@
#include "Overlay.h"
#include <utility>
#define IMGUI_USER_CONFIG "imconfig.h"
#include "imgui-SFML.h"
#include "imgui.h"
Overlay::Overlay(sf::RenderWindow& window, const std::function<void()>& on_close) : window_(window), on_close_(on_close)
{
ImGui::SFML::Init(window_);
@ -24,14 +18,14 @@ Overlay::Overlay(sf::RenderWindow& window, const std::function<void()>& on_close
style.ScrollbarRounding = 12;
style.GrabRounding = 5;
ImVec4* colors = ImGui::GetStyle().Colors;
ImVec4* colors = ImGui::GetStyle().Colors;
colors[ImGuiCol_Text] = ImVec4(0.95f, 0.96f, 0.98f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.36f, 0.42f, 0.47f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.13f, 0.14f, 0.95f);
colors[ImGuiCol_ChildBg] = ImVec4(0.15f, 0.18f, 0.22f, 1.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
colors[ImGuiCol_Border] = ImVec4(0.08f, 0.10f, 0.12f, 1.00f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_Border] = ImVec4(0.08f, 0.10f, 0.12f, 0.05f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.24f);
colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.25f, 0.29f, 1.00f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.12f, 0.20f, 0.28f, 1.00f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.09f, 0.12f, 0.14f, 1.00f);
@ -108,6 +102,8 @@ void Overlay::update()
std::ranges::for_each(OVERLAY_ELEMS_, [](const auto& fn) { fn(); });
ImGui::ShowDemoWindow();
if (closeButton()) {
return;
}

@ -5,6 +5,10 @@
#include <spdlog/spdlog.h>
#define IMGUI_USER_CONFIG "imconfig.h"
#include "imgui-SFML.h"
#include "imgui.h"
class Overlay {
public:
Overlay(sf::RenderWindow& window, const std::function<void()>& on_close);

@ -27,8 +27,8 @@ limitations under the License.
SteamTarget::SteamTarget(int argc, char* argv[])
: window_([this] { run_ = false; }, getScreenshotHotkey()),
detector_([this](bool overlay_open) { onOverlayChanged(overlay_open); }),
overlay_(window_.getOverlay())
overlay_(window_.getOverlay()),
detector_([this](bool overlay_open) { onOverlayChanged(overlay_open); })
{
target_window_handle_ = window_.getSystemHandle();
}
@ -40,18 +40,20 @@ int SteamTarget::run()
Application will not function!");
window_.setClickThrough(false);
overlay_.setEnabled(true);
steam_overlay_present_ = false;
} else {
spdlog::info("Steam-overlay detected.");
spdlog::warn("Open/Close Steam-overlay twice to show GlosSI-overlay"); // Just to color output and really get users attention
window_.setClickThrough(true);
overlay_.setEnabled(false);
steam_overlay_present_ = true;
}
run_ = true;
#ifdef _WIN32
hidhide_.hideDevices(steam_path_);
input_redirector_.run();
input_redirector_.run();
#endif
keepControllerConfig(true);

@ -46,6 +46,8 @@ class SteamTarget {
std::vector<std::string> getOverlayHotkey();
std::vector<std::string> getScreenshotHotkey();
bool steam_overlay_present_ = false;
// Keep controllerConfig even is window is switched.
// On Windoze hooking "GetForeGroundWindow" is enough;
void keepControllerConfig(bool keep);

Loading…
Cancel
Save