2021-10-15 15:10:57 +00:00
|
|
|
/*
|
2023-01-08 14:46:12 +00:00
|
|
|
Copyright 2021-2023 Peter Repukat - FlatspotSoftware
|
2021-10-15 15:10:57 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2021-10-14 18:54:29 +00:00
|
|
|
#include "SteamTarget.h"
|
|
|
|
|
2023-01-29 16:22:28 +00:00
|
|
|
#include "../common/Settings.h"
|
2021-10-17 16:20:16 +00:00
|
|
|
#include "steam_sf_keymap.h"
|
|
|
|
|
|
|
|
#include <SFML/Window/Keyboard.hpp>
|
|
|
|
#include <spdlog/spdlog.h>
|
2021-10-17 01:47:20 +00:00
|
|
|
|
2021-10-29 17:51:59 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "UWPOverlayEnabler.h"
|
2022-03-06 16:41:29 +00:00
|
|
|
#include <tray.hpp>
|
2021-10-29 17:51:59 +00:00
|
|
|
#endif
|
|
|
|
|
2023-01-29 12:51:23 +00:00
|
|
|
#include <CEFInject.h>
|
2022-10-09 22:28:28 +00:00
|
|
|
|
2023-02-27 18:47:34 +00:00
|
|
|
#include "CommonHttpEndpoints.h"
|
|
|
|
|
2022-07-13 20:53:57 +00:00
|
|
|
SteamTarget::SteamTarget()
|
2021-10-28 11:38:16 +00:00
|
|
|
: window_(
|
|
|
|
[this] { run_ = false; },
|
2022-01-07 00:36:21 +00:00
|
|
|
[this] { toggleGlossiOverlay(); },
|
2023-01-29 15:43:01 +00:00
|
|
|
util::steam::getScreenshotHotkey(steam_path_, steam_user_id_),
|
2021-10-28 11:38:16 +00:00
|
|
|
[this]() {
|
|
|
|
target_window_handle_ = window_.getSystemHandle();
|
|
|
|
overlay_ = window_.getOverlay();
|
|
|
|
}),
|
2021-10-22 16:07:08 +00:00
|
|
|
overlay_(window_.getOverlay()),
|
2021-10-23 11:33:01 +00:00
|
|
|
detector_([this](bool overlay_open) { onOverlayChanged(overlay_open); }),
|
2022-03-14 19:13:43 +00:00
|
|
|
launcher_(force_config_hwnds_, [this] {
|
2021-10-23 14:03:18 +00:00
|
|
|
delayed_shutdown_ = true;
|
|
|
|
delay_shutdown_clock_.restart();
|
2022-10-09 22:28:28 +00:00
|
|
|
}),
|
2023-02-27 18:47:34 +00:00
|
|
|
server_([this] { run_ = false; })
|
2021-10-15 15:10:57 +00:00
|
|
|
{
|
2021-10-21 17:54:41 +00:00
|
|
|
target_window_handle_ = window_.getSystemHandle();
|
2021-10-14 18:54:29 +00:00
|
|
|
}
|
|
|
|
|
2021-10-15 15:10:57 +00:00
|
|
|
int SteamTarget::run()
|
|
|
|
{
|
2023-02-04 14:26:12 +00:00
|
|
|
run_ = true;
|
2023-01-21 22:56:26 +00:00
|
|
|
auto closeBPM = false;
|
|
|
|
auto closeBPMTimer = sf::Clock{};
|
2021-10-22 13:40:37 +00:00
|
|
|
if (!SteamOverlayDetector::IsSteamInjected()) {
|
2024-09-19 18:48:23 +00:00
|
|
|
if (Settings::common.allowGlobalMode) {
|
2023-01-29 20:58:56 +00:00
|
|
|
spdlog::warn("GlosSI not launched via Steam.\nEnabling EXPERIMENTAL global controller and overlay...");
|
2024-09-19 18:48:23 +00:00
|
|
|
if (Settings::common.globalModeGameId == L"") {
|
2023-01-29 20:58:56 +00:00
|
|
|
spdlog::error("No game id set for standalone mode. Controller will use desktop-config!");
|
|
|
|
}
|
2024-09-19 18:48:23 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-31 21:02:12 +00:00
|
|
|
auto steam_tweaks = CEFInject::SteamTweaks();
|
|
|
|
steam_tweaks.setAutoInject(true);
|
2023-02-25 13:51:35 +00:00
|
|
|
|
2023-02-27 18:47:34 +00:00
|
|
|
CHTE::addEndpoints();
|
|
|
|
|
2023-02-25 13:51:35 +00:00
|
|
|
server_.run();
|
|
|
|
|
|
|
|
|
2023-01-31 21:02:12 +00:00
|
|
|
if (!overlay_.expired())
|
|
|
|
overlay_.lock()->setEnabled(false);
|
2023-01-29 20:58:56 +00:00
|
|
|
|
2023-01-30 17:19:36 +00:00
|
|
|
std::vector<std::function<void()>> end_frame_callbacks;
|
|
|
|
|
2023-02-04 14:26:12 +00:00
|
|
|
if (!CEFInject::CEFDebugAvailable()) {
|
|
|
|
auto overlay_id = std::make_shared<int>(-1);
|
|
|
|
*overlay_id = Overlay::AddOverlayElem(
|
|
|
|
[this, overlay_id, &end_frame_callbacks](bool window_has_focus, ImGuiID dockspace_id) {
|
|
|
|
can_fully_initialize_ = false;
|
2023-02-28 14:17:17 +00:00
|
|
|
ImGui::Begin("GlosSI - CEF remote debug not available");
|
|
|
|
ImGui::Text("GlosSI makes use of Steam CEF remote debugging for some functionality and plugins.");
|
2023-02-04 14:26:12 +00:00
|
|
|
ImGui::Text("GlosSI might not work fully without it.");
|
|
|
|
|
|
|
|
if (ImGui::Button("Ignore and continue")) {
|
|
|
|
can_fully_initialize_ = true;
|
|
|
|
cef_tweaks_enabled_ = false;
|
|
|
|
if (*overlay_id != -1) {
|
|
|
|
end_frame_callbacks.emplace_back([this, overlay_id] {
|
|
|
|
Overlay::RemoveOverlayElem(*overlay_id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::Button("Enable and restart Steam")) {
|
|
|
|
|
|
|
|
std::ofstream{steam_path_ / ".cef-enable-remote-debugging"};
|
|
|
|
system("taskkill.exe /im steam.exe /f");
|
|
|
|
Sleep(200);
|
|
|
|
launcher_.launchApp((steam_path_ / "Steam.exe").wstring());
|
|
|
|
|
|
|
|
run_ = false;
|
|
|
|
}
|
|
|
|
ImGui::Text("GlosSI will close upon restarting Steam");
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
can_fully_initialize_ = false;
|
|
|
|
cef_tweaks_enabled_ = false;
|
|
|
|
}
|
|
|
|
|
2023-01-30 17:41:46 +00:00
|
|
|
if (!SteamOverlayDetector::IsSteamInjected() && Settings::common.allowGlobalMode && Settings::common.globalModeGameId == L"") {
|
|
|
|
auto overlay_id = std::make_shared<int>(-1);
|
|
|
|
*overlay_id = Overlay::AddOverlayElem(
|
|
|
|
[this, overlay_id, &end_frame_callbacks](bool window_has_focus, ImGuiID dockspace_id) {
|
|
|
|
can_fully_initialize_ = false;
|
|
|
|
ImGui::Begin("Global mode", nullptr, ImGuiWindowFlags_NoSavedSettings);
|
|
|
|
ImGui::Text("You are running GlosSI in (experimental) global mode (=outside of Steam)");
|
|
|
|
ImGui::Text("but global mode doesn't appear to be setup properly.");
|
|
|
|
ImGui::Text("");
|
|
|
|
ImGui::Text("Please open GlosSI-Config first and setup global mode");
|
|
|
|
ImGui::Text("");
|
|
|
|
ImGui::Text("Application will exit on confirm");
|
|
|
|
if (ImGui::Button("OK")) {
|
|
|
|
can_fully_initialize_ = true;
|
|
|
|
if (*overlay_id != -1) {
|
|
|
|
end_frame_callbacks.emplace_back([this, overlay_id] {
|
|
|
|
Overlay::RemoveOverlayElem(*overlay_id);
|
|
|
|
run_ = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
can_fully_initialize_ = false;
|
|
|
|
}
|
|
|
|
|
2023-02-28 15:34:29 +00:00
|
|
|
if (!SteamOverlayDetector::IsSteamInjected() && Settings::common.allowGlobalMode) {
|
|
|
|
auto overlay_id = std::make_shared<int>(-1);
|
|
|
|
*overlay_id = Overlay::AddOverlayElem(
|
|
|
|
[this, overlay_id, &end_frame_callbacks](bool window_has_focus, ImGuiID dockspace_id) {
|
|
|
|
ImGui::Begin("Global mode", nullptr, ImGuiWindowFlags_NoSavedSettings);
|
|
|
|
ImGui::Text("Global mode is initializing, please stand by...");
|
|
|
|
ImGui::End();
|
|
|
|
if (fully_initialized_) {
|
|
|
|
end_frame_callbacks.emplace_back([this, overlay_id] {
|
|
|
|
Overlay::RemoveOverlayElem(*overlay_id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
window_.update();
|
|
|
|
}
|
|
|
|
|
2023-01-30 17:19:36 +00:00
|
|
|
if (!util::steam::getXBCRebindingEnabled(steam_path_, steam_user_id_)) {
|
|
|
|
auto overlay_id = std::make_shared<int>(-1);
|
|
|
|
*overlay_id = Overlay::AddOverlayElem(
|
|
|
|
[this, overlay_id, &end_frame_callbacks](bool window_has_focus, ImGuiID dockspace_id) {
|
|
|
|
can_fully_initialize_ = false;
|
|
|
|
ImGui::Begin("XBox Controller configuration support Disabled", nullptr, ImGuiWindowFlags_NoSavedSettings);
|
|
|
|
ImGui::TextColored({1.f, 0.8f, 0.f, 1.f}, "XBox Controller configuration support is disabled in Steam. Please enable it in Steam Settings.");
|
|
|
|
if (ImGui::Button("OK")) {
|
|
|
|
can_fully_initialize_ = true;
|
|
|
|
if (*overlay_id != -1) {
|
|
|
|
end_frame_callbacks.emplace_back([this, overlay_id] {
|
|
|
|
Overlay::RemoveOverlayElem(*overlay_id);
|
|
|
|
});
|
|
|
|
}
|
2023-01-29 20:58:56 +00:00
|
|
|
}
|
2023-01-30 17:19:36 +00:00
|
|
|
ImGui::End();
|
|
|
|
},
|
|
|
|
true);
|
|
|
|
can_fully_initialize_ = false;
|
2021-10-22 10:17:46 +00:00
|
|
|
}
|
2023-02-04 14:26:12 +00:00
|
|
|
|
2023-01-29 15:43:01 +00:00
|
|
|
const auto tray = createTrayMenu();
|
2023-02-25 13:51:35 +00:00
|
|
|
|
2023-01-30 17:41:46 +00:00
|
|
|
bool delayed_full_init_1_frame = false;
|
2023-01-31 21:02:12 +00:00
|
|
|
sf::Clock frame_time_clock;
|
|
|
|
|
2021-10-15 13:02:36 +00:00
|
|
|
while (run_) {
|
2023-01-30 17:41:46 +00:00
|
|
|
if (!fully_initialized_ && can_fully_initialize_ && delayed_full_init_1_frame) {
|
2023-01-30 17:19:36 +00:00
|
|
|
init_FuckingRenameMe();
|
|
|
|
}
|
2023-01-30 17:41:46 +00:00
|
|
|
else if (!fully_initialized_ && can_fully_initialize_) {
|
|
|
|
delayed_full_init_1_frame = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delayed_full_init_1_frame = false;
|
|
|
|
}
|
2021-10-16 20:36:30 +00:00
|
|
|
detector_.update();
|
2021-10-17 16:20:16 +00:00
|
|
|
overlayHotkeyWorkaround();
|
2021-10-28 11:38:16 +00:00
|
|
|
window_.update();
|
2023-01-21 22:56:26 +00:00
|
|
|
|
2023-02-04 14:26:12 +00:00
|
|
|
if (cef_tweaks_enabled_ && fully_initialized_) {
|
|
|
|
steam_tweaks_.update(frame_time_clock.getElapsedTime().asSeconds());
|
|
|
|
}
|
2023-01-31 21:02:12 +00:00
|
|
|
|
2021-10-23 14:03:18 +00:00
|
|
|
// Wait on shutdown; User might get confused if window closes to fast if anything with launchApp get's borked.
|
|
|
|
if (delayed_shutdown_) {
|
|
|
|
if (delay_shutdown_clock_.getElapsedTime().asSeconds() >= 3) {
|
|
|
|
run_ = false;
|
|
|
|
}
|
2021-10-28 11:38:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-01-30 17:19:36 +00:00
|
|
|
if (fully_initialized_) {
|
|
|
|
launcher_.update();
|
|
|
|
}
|
2021-10-23 14:03:18 +00:00
|
|
|
}
|
2023-01-30 17:19:36 +00:00
|
|
|
for (auto& efc : end_frame_callbacks) {
|
|
|
|
efc();
|
|
|
|
}
|
|
|
|
end_frame_callbacks.clear();
|
2023-01-31 21:02:12 +00:00
|
|
|
frame_time_clock.restart();
|
2021-10-15 13:02:36 +00:00
|
|
|
}
|
2023-01-29 15:43:01 +00:00
|
|
|
tray->exit();
|
2021-10-22 10:17:46 +00:00
|
|
|
|
2022-10-09 22:28:28 +00:00
|
|
|
server_.stop();
|
2023-01-30 17:19:36 +00:00
|
|
|
if (fully_initialized_) {
|
2021-10-20 19:48:19 +00:00
|
|
|
#ifdef _WIN32
|
2023-01-30 17:19:36 +00:00
|
|
|
input_redirector_.stop();
|
|
|
|
hidhide_.disableHidHide();
|
2021-10-20 19:48:19 +00:00
|
|
|
#endif
|
2023-01-30 17:19:36 +00:00
|
|
|
launcher_.close();
|
2023-02-04 14:26:12 +00:00
|
|
|
if (cef_tweaks_enabled_) {
|
|
|
|
steam_tweaks_.uninstallTweaks();
|
|
|
|
}
|
2023-01-30 17:19:36 +00:00
|
|
|
}
|
2023-02-04 14:26:12 +00:00
|
|
|
|
2021-10-23 11:33:45 +00:00
|
|
|
return 0;
|
2021-10-15 13:02:36 +00:00
|
|
|
}
|
2021-10-17 01:46:18 +00:00
|
|
|
|
|
|
|
void SteamTarget::onOverlayChanged(bool overlay_open)
|
|
|
|
{
|
2021-10-17 01:48:47 +00:00
|
|
|
if (overlay_open) {
|
|
|
|
focusWindow(target_window_handle_);
|
2021-10-23 00:27:31 +00:00
|
|
|
window_.setClickThrough(!overlay_open);
|
2023-02-27 12:57:30 +00:00
|
|
|
if (!Settings::window.windowMode && Settings::window.opaqueSteamOverlay) {
|
|
|
|
window_.setTransparent(false);
|
|
|
|
}
|
2022-03-05 14:34:23 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-01-07 00:36:21 +00:00
|
|
|
if (!(overlay_.expired() ? false : overlay_.lock()->isEnabled())) {
|
|
|
|
window_.setClickThrough(!overlay_open);
|
|
|
|
focusWindow(last_foreground_window_);
|
2023-02-27 12:57:30 +00:00
|
|
|
if (!Settings::window.windowMode && Settings::window.opaqueSteamOverlay) {
|
|
|
|
window_.setTransparent(true);
|
|
|
|
}
|
2022-01-07 00:36:21 +00:00
|
|
|
}
|
2021-10-17 16:20:16 +00:00
|
|
|
}
|
2022-01-07 00:01:29 +00:00
|
|
|
if (!overlay_trigger_flag_) {
|
|
|
|
overlay_trigger_flag_ = true;
|
|
|
|
overlay_trigger_clock_.restart();
|
|
|
|
}
|
2021-10-17 16:20:16 +00:00
|
|
|
else {
|
2022-01-07 00:01:29 +00:00
|
|
|
if (overlay_trigger_clock_.getElapsedTime().asSeconds() <= overlay_trigger_max_seconds_) {
|
2022-01-07 00:36:21 +00:00
|
|
|
toggleGlossiOverlay();
|
2021-10-22 13:40:37 +00:00
|
|
|
}
|
2022-01-07 00:01:29 +00:00
|
|
|
overlay_trigger_flag_ = false;
|
|
|
|
}
|
2022-01-07 00:36:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SteamTarget::toggleGlossiOverlay()
|
|
|
|
{
|
2023-01-16 12:42:38 +00:00
|
|
|
if (Settings::window.disableGlosSIOverlay) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-07 00:36:21 +00:00
|
|
|
if (overlay_.expired()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto ov_opened = overlay_.lock()->toggle();
|
|
|
|
window_.setClickThrough(!ov_opened);
|
|
|
|
if (ov_opened) {
|
2022-03-05 14:34:23 +00:00
|
|
|
spdlog::debug("Opened GlosSI-overlay");
|
2022-01-07 00:36:21 +00:00
|
|
|
focusWindow(target_window_handle_);
|
|
|
|
}
|
|
|
|
else {
|
2022-01-07 00:01:29 +00:00
|
|
|
focusWindow(last_foreground_window_);
|
2022-03-05 14:34:23 +00:00
|
|
|
spdlog::debug("Closed GlosSI-overlay");
|
2021-10-17 01:48:47 +00:00
|
|
|
}
|
2021-10-17 01:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SteamTarget::focusWindow(WindowHandle hndl)
|
|
|
|
{
|
2022-09-20 18:43:37 +00:00
|
|
|
if (reinterpret_cast<uint64_t>(hndl) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2021-10-17 01:46:18 +00:00
|
|
|
#ifdef _WIN32
|
2021-10-17 19:04:41 +00:00
|
|
|
if (hndl == target_window_handle_) {
|
2021-10-22 13:40:37 +00:00
|
|
|
spdlog::debug("Bring own window to foreground");
|
2021-10-17 19:04:41 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-10-22 13:40:37 +00:00
|
|
|
spdlog::debug("Bring window \"{:#x}\" to foreground", reinterpret_cast<uint64_t>(hndl));
|
2021-10-17 19:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
keepControllerConfig(false); // unhook GetForegroundWindow
|
2021-10-22 13:40:37 +00:00
|
|
|
const auto current_fgw = GetForegroundWindow();
|
|
|
|
if (current_fgw != target_window_handle_) {
|
|
|
|
last_foreground_window_ = current_fgw;
|
2021-10-28 11:38:16 +00:00
|
|
|
}
|
2021-10-22 13:40:37 +00:00
|
|
|
const auto fg_thread = GetWindowThreadProcessId(current_fgw, nullptr);
|
|
|
|
|
2021-10-17 19:04:41 +00:00
|
|
|
keepControllerConfig(true); // re-hook GetForegroundWindow
|
2021-10-17 01:46:18 +00:00
|
|
|
|
|
|
|
// lot's of ways actually bringing our window to foreground...
|
2021-10-22 13:40:37 +00:00
|
|
|
const auto current_thread = GetCurrentThreadId();
|
2021-10-17 01:46:18 +00:00
|
|
|
AttachThreadInput(current_thread, fg_thread, TRUE);
|
|
|
|
|
|
|
|
SetForegroundWindow(hndl);
|
|
|
|
SetCapture(hndl);
|
|
|
|
SetFocus(hndl);
|
|
|
|
SetActiveWindow(hndl);
|
|
|
|
EnableWindow(hndl, TRUE);
|
|
|
|
|
|
|
|
AttachThreadInput(current_thread, fg_thread, FALSE);
|
|
|
|
|
2022-10-04 19:53:04 +00:00
|
|
|
// try to forcefully set foreground window at least a few times
|
2021-10-17 01:46:18 +00:00
|
|
|
sf::Clock clock;
|
2021-10-17 16:20:16 +00:00
|
|
|
while (!SetForegroundWindow(hndl) && clock.getElapsedTime().asMilliseconds() < 20) {
|
2021-10-17 01:46:18 +00:00
|
|
|
SetActiveWindow(hndl);
|
|
|
|
Sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
2023-01-30 17:19:36 +00:00
|
|
|
void SteamTarget::init_FuckingRenameMe()
|
|
|
|
{
|
|
|
|
if (!SteamOverlayDetector::IsSteamInjected()) {
|
2023-01-30 17:26:50 +00:00
|
|
|
if (Settings::common.allowGlobalMode) {
|
2023-01-30 17:19:36 +00:00
|
|
|
spdlog::warn("GlosSI not launched via Steam.\nEnabling EXPERIMENTAL global controller and overlay...");
|
2023-01-30 17:26:50 +00:00
|
|
|
if (Settings::common.globalModeGameId == L"") {
|
|
|
|
spdlog::error("No game id set for global mode. Controller will use desktop-config!");
|
2023-01-30 17:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetEnvironmentVariable(L"SteamAppId", L"0");
|
|
|
|
SetEnvironmentVariable(L"SteamClientLaunch", L"0");
|
|
|
|
SetEnvironmentVariable(L"SteamEnv", L"1");
|
|
|
|
SetEnvironmentVariable(L"SteamPath", steam_path_.wstring().c_str());
|
2023-01-30 17:26:50 +00:00
|
|
|
SetEnvironmentVariable(L"SteamTenfoot", Settings::common.globalModeUseGamepadUI ? L"1" : L"0");
|
2023-01-30 17:19:36 +00:00
|
|
|
// SetEnvironmentVariable(L"SteamTenfootHybrid", L"1");
|
2023-01-30 17:26:50 +00:00
|
|
|
SetEnvironmentVariable(L"SteamGamepadUI", Settings::common.globalModeUseGamepadUI ? L"1" : L"0");
|
|
|
|
SetEnvironmentVariable(L"SteamGameId", Settings::common.globalModeGameId.c_str());
|
|
|
|
SetEnvironmentVariable(L"SteamOverlayGameId", Settings::common.globalModeGameId.c_str());
|
2023-01-30 17:19:36 +00:00
|
|
|
SetEnvironmentVariable(L"EnableConfiguratorSupport", L"15");
|
|
|
|
SetEnvironmentVariable(L"SteamStreamingForceWindowedD3D9", L"1");
|
|
|
|
|
2023-01-30 17:26:50 +00:00
|
|
|
if (Settings::common.globalModeUseGamepadUI) {
|
2023-01-30 17:19:36 +00:00
|
|
|
system("start steam://open/bigpicture");
|
|
|
|
auto steamwindow = FindWindow(L"Steam Big Picture Mode", nullptr);
|
|
|
|
auto timer = sf::Clock{};
|
|
|
|
while (!steamwindow && timer.getElapsedTime().asSeconds() < 2) {
|
|
|
|
steamwindow = FindWindow(L"Steam Big Picture Mode", nullptr);
|
|
|
|
Sleep(50);
|
|
|
|
}
|
2023-02-25 13:58:24 +00:00
|
|
|
|
|
|
|
if (cef_tweaks_enabled_) {
|
|
|
|
steam_tweaks_.setAutoInject(true);
|
|
|
|
steam_tweaks_.update(999);
|
|
|
|
}
|
|
|
|
|
2023-01-30 17:19:36 +00:00
|
|
|
Sleep(6000); // DIRTY HACK to wait until BPM (GamepadUI) is initialized
|
|
|
|
// TODO: find way to force BPM even if BPM is not active
|
|
|
|
LoadLibrary((steam_path_ / "GameOverlayRenderer64.dll").wstring().c_str());
|
|
|
|
|
|
|
|
// Overlay switches back to desktop one, once BPM is closed... Disable closing BPM for now.
|
|
|
|
// TODO: find way to force BPM even if BPM is not active
|
|
|
|
// closeBPM = true;
|
|
|
|
// closeBPMTimer.restart();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LoadLibrary((steam_path_ / "GameOverlayRenderer64.dll").wstring().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
window_.setClickThrough(true);
|
|
|
|
steam_overlay_present_ = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
spdlog::warn("Steam-overlay not detected and global mode disabled. Showing GlosSI-overlay!\n\
|
|
|
|
Application will not function!");
|
|
|
|
window_.setClickThrough(false);
|
|
|
|
if (!overlay_.expired())
|
|
|
|
overlay_.lock()->setEnabled(true);
|
|
|
|
steam_overlay_present_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
spdlog::info("Steam-overlay detected.");
|
|
|
|
spdlog::warn("Double press Steam- overlay key(s)/Controller button to show GlosSI-overlay"); // Just to color output and really get users attention
|
|
|
|
window_.setClickThrough(true);
|
|
|
|
steam_overlay_present_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
if (!Settings::common.disable_watchdog) {
|
|
|
|
wchar_t buff[MAX_PATH];
|
|
|
|
GetModuleFileName(GetModuleHandle(NULL), buff, MAX_PATH);
|
|
|
|
std::wstring watchDogPath(buff);
|
|
|
|
watchDogPath = watchDogPath.substr(0, 1 + watchDogPath.find_last_of(L'\\')) + L"GlosSIWatchdog.dll";
|
|
|
|
|
|
|
|
DllInjector::injectDllInto(watchDogPath, L"explorer.exe");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Settings::common.no_uwp_overlay) {
|
|
|
|
UWPOverlayEnabler::AddUwpOverlayOvWidget();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
UWPOverlayEnabler::EnableUwpOverlay();
|
|
|
|
}
|
|
|
|
|
|
|
|
hidhide_.hideDevices(steam_path_);
|
|
|
|
input_redirector_.run();
|
|
|
|
#endif
|
|
|
|
if (Settings::launch.launch) {
|
|
|
|
launcher_.launchApp(Settings::launch.launchPath, Settings::launch.launchAppArgs);
|
|
|
|
}
|
|
|
|
keepControllerConfig(true);
|
2023-02-04 14:26:12 +00:00
|
|
|
|
|
|
|
if (cef_tweaks_enabled_) {
|
|
|
|
steam_tweaks_.setAutoInject(true);
|
|
|
|
}
|
|
|
|
|
2023-01-30 17:19:36 +00:00
|
|
|
fully_initialized_ = true;
|
|
|
|
}
|
2021-10-17 01:47:20 +00:00
|
|
|
|
2022-03-14 19:13:43 +00:00
|
|
|
/*
|
|
|
|
* The "magic" that keeps a controller-config forced (without hooking into Steam)
|
|
|
|
*
|
|
|
|
* Hook into own process and detour "GetForegroundWindow"
|
2023-01-29 15:43:01 +00:00
|
|
|
* Detour function always returns HWND of own application window
|
2022-03-14 19:13:43 +00:00
|
|
|
* Steam now doesn't detect application changes and keeps the game-specific input config without reverting to desktop-conf
|
|
|
|
*/
|
2021-10-17 19:04:41 +00:00
|
|
|
void SteamTarget::keepControllerConfig(bool keep)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (keep && !getFgWinHook.IsInstalled()) {
|
2021-10-22 13:40:37 +00:00
|
|
|
spdlog::debug("Hooking GetForegroundWindow (in own process)");
|
2021-10-21 17:54:41 +00:00
|
|
|
getFgWinHook.Install(&GetForegroundWindow, &keepFgWindowHookFn, subhook::HookFlags::HookFlag64BitOffset);
|
2021-10-17 19:04:41 +00:00
|
|
|
if (!getFgWinHook.IsInstalled()) {
|
|
|
|
spdlog::error("Couldn't install GetForegroundWindow hook!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!keep && getFgWinHook.IsInstalled()) {
|
2021-10-22 13:40:37 +00:00
|
|
|
spdlog::debug("Un-Hooking GetForegroundWindow (in own process)");
|
2021-10-17 19:04:41 +00:00
|
|
|
getFgWinHook.Remove();
|
|
|
|
if (getFgWinHook.IsInstalled()) {
|
|
|
|
spdlog::error("Couldn't un-install GetForegroundWindow hook!");
|
|
|
|
}
|
|
|
|
}
|
2023-01-30 17:19:36 +00:00
|
|
|
|
2021-10-17 19:04:41 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-10-21 17:54:41 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
HWND SteamTarget::keepFgWindowHookFn()
|
|
|
|
{
|
2022-03-14 19:23:30 +00:00
|
|
|
if (!Settings::controller.allowDesktopConfig || !Settings::launch.launch) {
|
2022-03-14 19:13:43 +00:00
|
|
|
return target_window_handle_;
|
|
|
|
}
|
|
|
|
subhook::ScopedHookRemove remove(&getFgWinHook);
|
|
|
|
HWND real_fg_win = GetForegroundWindow();
|
|
|
|
if (real_fg_win == nullptr) {
|
|
|
|
return target_window_handle_;
|
|
|
|
}
|
|
|
|
if (std::ranges::find_if(force_config_hwnds_, [real_fg_win](auto hwnd) {
|
|
|
|
return hwnd == real_fg_win;
|
|
|
|
}) != force_config_hwnds_.end()) {
|
|
|
|
if (last_real_hwnd_ != real_fg_win) {
|
|
|
|
last_real_hwnd_ = real_fg_win;
|
|
|
|
spdlog::debug("Active window (\"{:#x}\") in launched process window list, forcing specific config", reinterpret_cast<uint64_t>(real_fg_win));
|
|
|
|
}
|
|
|
|
return target_window_handle_;
|
|
|
|
}
|
|
|
|
if (last_real_hwnd_ != real_fg_win) {
|
|
|
|
last_real_hwnd_ = real_fg_win;
|
|
|
|
spdlog::debug("Active window (\"{:#x}\") not in launched process window list, allowing desktop-config", reinterpret_cast<uint64_t>(real_fg_win));
|
|
|
|
}
|
|
|
|
return real_fg_win;
|
2021-10-21 17:54:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-29 15:43:01 +00:00
|
|
|
std::unique_ptr<Tray::Tray> SteamTarget::createTrayMenu()
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
HICON icon = 0;
|
|
|
|
TCHAR path[MAX_PATH];
|
|
|
|
GetModuleFileName(nullptr, path, MAX_PATH);
|
|
|
|
icon = (HICON)LoadImage(
|
|
|
|
0,
|
|
|
|
path,
|
|
|
|
IMAGE_ICON,
|
|
|
|
GetSystemMetrics(SM_CXSMICON),
|
|
|
|
GetSystemMetrics(SM_CYSMICON),
|
|
|
|
LR_LOADFROMFILE | LR_LOADMAP3DCOLORS);
|
|
|
|
if (!icon) {
|
|
|
|
ExtractIconEx(path, 0, &icon, nullptr, 1);
|
|
|
|
}
|
|
|
|
auto tray = std::make_unique<Tray::Tray>("GlosSITarget", icon);
|
|
|
|
#else
|
|
|
|
auto tray = std::make_unique<Tray::Tray>("GlosSITarget", "ico.png");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tray->addEntry(Tray::Button{
|
|
|
|
"Quit", [this, &tray]() {
|
|
|
|
run_ = false;
|
|
|
|
}});
|
|
|
|
return tray;
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:20:16 +00:00
|
|
|
void SteamTarget::overlayHotkeyWorkaround()
|
|
|
|
{
|
|
|
|
static bool pressed = false;
|
2021-10-17 19:04:41 +00:00
|
|
|
if (std::ranges::all_of(overlay_hotkey_,
|
2021-10-20 19:47:24 +00:00
|
|
|
[](const auto& key) {
|
2021-10-17 19:04:41 +00:00
|
|
|
return sf::Keyboard::isKeyPressed(keymap::sfkey[key]);
|
|
|
|
})) {
|
2021-10-22 13:40:37 +00:00
|
|
|
spdlog::trace("Detected overlay hotkey(s)");
|
2021-10-17 16:20:16 +00:00
|
|
|
pressed = true;
|
2021-10-20 19:47:24 +00:00
|
|
|
std::ranges::for_each(overlay_hotkey_, [this](const auto& key) {
|
2021-10-17 16:20:16 +00:00
|
|
|
#ifdef _WIN32
|
2021-10-17 19:04:41 +00:00
|
|
|
PostMessage(target_window_handle_, WM_KEYDOWN, keymap::winkey[key], 0);
|
2021-10-17 16:20:16 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
#endif
|
2021-10-17 19:04:41 +00:00
|
|
|
});
|
2021-10-22 13:40:37 +00:00
|
|
|
spdlog::trace("Sending Overlay KeyDown events...");
|
2021-10-17 19:04:41 +00:00
|
|
|
}
|
|
|
|
else if (pressed) {
|
2021-10-17 16:20:16 +00:00
|
|
|
pressed = false;
|
2021-10-20 19:47:24 +00:00
|
|
|
std::ranges::for_each(overlay_hotkey_, [this](const auto& key) {
|
2021-10-17 16:20:16 +00:00
|
|
|
#ifdef _WIN32
|
2021-10-17 19:04:41 +00:00
|
|
|
PostMessage(target_window_handle_, WM_KEYUP, keymap::winkey[key], 0);
|
2021-10-17 16:20:16 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
#endif
|
2021-10-17 19:04:41 +00:00
|
|
|
});
|
2021-10-22 13:40:37 +00:00
|
|
|
spdlog::trace("Sending Overlay KeyUp events...");
|
2021-10-17 16:20:16 +00:00
|
|
|
}
|
|
|
|
}
|