diff --git a/GlosSITarget/SteamTarget.cpp b/GlosSITarget/SteamTarget.cpp index 4d7d276..44258a1 100644 --- a/GlosSITarget/SteamTarget.cpp +++ b/GlosSITarget/SteamTarget.cpp @@ -15,7 +15,11 @@ limitations under the License. */ #include "SteamTarget.h" -SteamTarget::SteamTarget(int argc, char *argv[]) : window_([this] { run_ = false; }) +#include +#include +#include +#include + SteamTarget::SteamTarget(int argc, char *argv[]) : window_([this] { run_ = false; }), detector_([this](bool overlay_open) { onOverlayChanged(overlay_open); }), target_window_handle_(window_.getSystemHandle()) @@ -71,3 +75,53 @@ void SteamTarget::focusWindow(WindowHandle hndl) #endif } + +std::wstring SteamTarget::getSteamPath() +{ +#ifdef _WIN32 + // TODO: check if keys/value exist + // steam should always be open and have written reg values... + winreg::RegKey key{HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam"}; + return key.GetStringValue(L"SteamPath"); +#else + return L""; // TODO +#endif +} + +std::wstring SteamTarget::getSteamUserId() +{ +#ifdef _WIN32 + // TODO: check if keys/value exist + // steam should always be open and have written reg values... + winreg::RegKey key{HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam\\ActiveProcess"}; + return std::to_wstring( key.GetDwordValue(L"ActiveUser")); +#else + return L""; // TODO +#endif +} + +std::vector SteamTarget::getOverlayHotkey() +{ + const auto steam_path = getSteamPath(); + const auto user_id = getSteamUserId(); + + const auto config_path = steam_path + std::wstring(user_data_path_) + user_id + std::wstring(config_file_name_); + std::ifstream config_file(config_path); + // TODO: check if file exists + auto root = tyti::vdf::read(config_file); + + auto children = root.childs["system"]; + auto hotkeys = children->attribs.at("InGameOverlayShortcutKey"); + + // has anyone more than 4 keys to open overlay?! + std::smatch m; + if(!std::regex_match(hotkeys, m, std::regex(R"((.*?)\s*?(.*?)\s*?(.*?)\s*?(.*?))"))) { + return {"Shift", "Tab"}; + } + + std::vector res; + for (auto i = 1; i < m.size(); i++) { + res.emplace_back(m[i]); + } + return res; +} diff --git a/GlosSITarget/SteamTarget.h b/GlosSITarget/SteamTarget.h index f075020..f281c12 100644 --- a/GlosSITarget/SteamTarget.h +++ b/GlosSITarget/SteamTarget.h @@ -25,7 +25,21 @@ class SteamTarget { int run(); private: + void onOverlayChanged(bool overlay_open); + void focusWindow(WindowHandle hndl); + std::wstring getSteamPath(); + std::wstring getSteamUserId(); + std::vector getOverlayHotkey(); + bool run_ = false; + std::vector overlay_hotkey_ = getOverlayHotkey(); + TargetWindow window_; OverlayDetector detector_; + WindowHandle last_foreground_window_ = nullptr; + WindowHandle target_window_handle_; + + 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 hotkey_name_ = "InGameOverlayShortcutKey "; }; diff --git a/GlosSITarget/steam_sf_keymap.h b/GlosSITarget/steam_sf_keymap.h new file mode 100644 index 0000000..b461e5a --- /dev/null +++ b/GlosSITarget/steam_sf_keymap.h @@ -0,0 +1,115 @@ +#pragma once +#include +#include + +#define QQ(x) #x +#define QUOTE(x) QQ(x) + +#define KEYCONVSF(KEY) \ + { QUOTE(KEY), sf::Keyboard::Key::KEY } + +namespace keymap { +std::unordered_map sfkey = { + {"Shift", sf::Keyboard::Key::LShift}, + {"Alt", sf::Keyboard::Key::LAlt}, + {"Ctrl", sf::Keyboard::Key::LControl}, + {"Del", sf::Keyboard::Key::Delete}, + {"Ins", sf::Keyboard::Key::Insert}, + {"Home", sf::Keyboard::Key::Home}, + {"Space", sf::Keyboard::Key::Space}, + {"Backspace", sf::Keyboard::Key::Backspace}, + {"Enter", sf::Keyboard::Key::Enter}, + // TODO: more special keys with keylayout mapping... nope.. + {"KEY_0", sf::Keyboard::Key::Num0}, + {"KEY_1", sf::Keyboard::Key::Num1}, + {"KEY_2", sf::Keyboard::Key::Num2}, + {"KEY_3", sf::Keyboard::Key::Num3}, + {"KEY_4", sf::Keyboard::Key::Num4}, + {"KEY_5", sf::Keyboard::Key::Num5}, + {"KEY_6", sf::Keyboard::Key::Num6}, + {"KEY_7", sf::Keyboard::Key::Num7}, + {"KEY_8", sf::Keyboard::Key::Num8}, + {"KEY_9", sf::Keyboard::Key::Num9}, + KEYCONVSF(A), + KEYCONVSF(B), + KEYCONVSF(C), + KEYCONVSF(D), + KEYCONVSF(E), + KEYCONVSF(F), + KEYCONVSF(G), + KEYCONVSF(H), + KEYCONVSF(I), + KEYCONVSF(J), + KEYCONVSF(K), + KEYCONVSF(L), + KEYCONVSF(M), + KEYCONVSF(N), + KEYCONVSF(O), + KEYCONVSF(P), + KEYCONVSF(Q), + KEYCONVSF(R), + KEYCONVSF(S), + KEYCONVSF(T), + KEYCONVSF(U), + KEYCONVSF(V), + KEYCONVSF(W), + KEYCONVSF(X), + KEYCONVSF(Y), + KEYCONVSF(Z) +}; + +#ifdef _WIN32 +#define NOMINMAX +#include +//yep.. there are smarter ways to tho this... +std::unordered_map winkey = { + {"Shift", VK_SHIFT}, + {"Alt", VK_MENU}, + {"Ctrl", VK_CONTROL}, + {"Del", VK_DELETE}, + {"Ins",VK_INSERT}, + {"Home",VK_HOME}, + {"Space", VK_SPACE}, + {"Backspace", VK_BACK}, + {"Enter", VK_RETURN}, + // TODO: more special keys with keylayout mapping... nope.. + {"KEY_0", 0x30}, + {"KEY_1", 0x31}, + {"KEY_2", 0x32}, + {"KEY_3", 0x33}, + {"KEY_4", 0x34}, + {"KEY_5", 0x35}, + {"KEY_6", 0x36}, + {"KEY_7", 0x37}, + {"KEY_8", 0x38}, + {"KEY_9", 0x39}, + {"KEY_A", 0x41}, + {"KEY_B", 0x42}, + {"KEY_C", 0x43}, + {"KEY_D", 0x44}, + {"KEY_E", 0x45}, + {"KEY_F", 0x46}, + {"KEY_G", 0x47}, + {"KEY_H", 0x48}, + {"KEY_I", 0x49}, + {"KEY_J", 0x4A}, + {"KEY_K", 0x4B}, + {"KEY_L", 0x4C}, + {"KEY_M", 0x4D}, + {"KEY_N", 0x4E}, + {"KEY_O", 0x5F}, + {"KEY_P", 0x50}, + {"KEY_Q", 0x51}, + {"KEY_R", 0x52}, + {"KEY_S", 0x53}, + {"KEY_T", 0x54}, + {"KEY_U", 0x55}, + {"KEY_V", 0x56}, + {"KEY_W", 0x57}, + {"KEY_X", 0x58}, + {"KEY_Y", 0x59}, + {"KEY_Z", 0x5A} + +}; +#endif +}