2
0
mirror of https://github.com/Alia5/GlosSI.git synced 2024-11-07 03:20:35 +00:00
GlosSI/GlosSITarget/SteamTarget.h

99 lines
2.9 KiB
C
Raw Normal View History

2021-10-15 15:10:57 +00:00
/*
Copyright 2021-2022 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
#pragma once
2021-10-15 13:02:36 +00:00
#include "SteamOverlayDetector.h"
2021-10-15 13:02:36 +00:00
#include "TargetWindow.h"
2021-10-16 20:36:30 +00:00
2021-10-20 19:47:24 +00:00
#ifdef _WIN32
#include "HidHide.h"
2021-10-20 19:47:24 +00:00
#include "InputRedirector.h"
2021-10-21 17:54:41 +00:00
#include <subhook.h>
2021-10-20 19:47:24 +00:00
#endif
2021-10-23 11:33:01 +00:00
#include "AppLauncher.h"
2021-10-22 10:17:46 +00:00
#include "Overlay.h"
#include <filesystem>
2021-10-15 15:10:57 +00:00
class SteamTarget {
public:
explicit SteamTarget();
2021-10-14 18:54:29 +00:00
int run();
2021-10-15 13:02:36 +00:00
2021-10-15 15:10:57 +00:00
private:
2021-10-17 01:47:20 +00:00
void onOverlayChanged(bool overlay_open);
2022-01-07 00:36:21 +00:00
void toggleGlossiOverlay();
2021-10-17 01:47:20 +00:00
void focusWindow(WindowHandle hndl);
std::filesystem::path getSteamPath() const;
std::wstring getSteamUserId() const;
std::filesystem::path steam_path_ = getSteamPath();
std::wstring steam_user_id_ = getSteamUserId();
2021-10-17 01:47:20 +00:00
std::vector<std::string> getOverlayHotkey();
std::vector<std::string> getScreenshotHotkey();
2021-10-23 00:27:31 +00:00
bool getXBCRebindingEnabled();
2021-10-17 01:47:20 +00:00
2021-10-22 16:07:08 +00:00
bool steam_overlay_present_ = false;
// Keep controllerConfig even is window is switched.
// On Windoze hooking "GetForeGroundWindow" is enough;
void keepControllerConfig(bool keep);
2021-10-21 17:54:41 +00:00
#ifdef _WIN32
static HWND keepFgWindowHookFn();
static inline subhook::Hook getFgWinHook;
static inline std::vector<HWND> force_config_hwnds_ = {};
static inline HWND last_real_hwnd_ = nullptr;
2021-10-21 17:54:41 +00:00
#endif
/*
* Run once per frame
* detects steam configured overlay hotkey, and simulates key presses to window
*
* actually opens the overlay, even if window is not currently focused.
*/
void overlayHotkeyWorkaround();
2021-10-15 13:02:36 +00:00
bool run_ = false;
2021-10-17 01:47:20 +00:00
std::vector<std::string> overlay_hotkey_ = getOverlayHotkey();
#ifdef _WIN32
HidHide hidhide_;
InputRedirector input_redirector_;
#endif
2021-10-15 13:02:36 +00:00
TargetWindow window_;
std::weak_ptr<Overlay> overlay_;
SteamOverlayDetector detector_;
2021-10-23 11:33:01 +00:00
AppLauncher launcher_;
2021-10-17 01:47:20 +00:00
WindowHandle last_foreground_window_ = nullptr;
2021-10-21 17:54:41 +00:00
static inline WindowHandle target_window_handle_ = nullptr;
2021-10-17 01:47:20 +00:00
2021-10-22 10:17:46 +00:00
sf::Clock overlay_trigger_clock_;
uint32_t overlay_trigger_max_seconds_ = 1;
2021-10-22 10:17:46 +00:00
bool overlay_trigger_flag_ = false;
2021-10-23 14:03:18 +00:00
bool delayed_shutdown_ = false;
sf::Clock delay_shutdown_clock_;
2021-10-17 01:47:20 +00:00
static constexpr std::wstring_view user_data_path_ = L"/userdata/";
static constexpr std::wstring_view config_file_name_ = L"/config/localconfig.vdf";
static constexpr std::string_view overlay_hotkey_name_ = "InGameOverlayShortcutKey ";
static constexpr std::string_view screenshot_hotkey_name_ = "InGameOverlayScreenshotHotKey ";
2021-10-14 18:54:29 +00:00
};