Formatting

main
Peter Repukat 3 years ago
parent c7467003fb
commit d7af75a976

@ -3,4 +3,5 @@ IndentWidth: 4
BreakBeforeBraces: "Stroustrup"
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 0
ColumnLimit: 0
PointerAlignment: "Left"

@ -129,7 +129,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>sfml-window-d.lib;sfml-system-d.lib;sfml-graphics-d.lib;dwmapi.lib;xinput9_1_0.lib;setupapi.lib;ViGEmClient.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>hid.lib;Cfgmgr32.lib;sfml-window-d.lib;sfml-system-d.lib;sfml-graphics-d.lib;dwmapi.lib;xinput9_1_0.lib;setupapi.lib;ViGEmClient.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -147,11 +147,12 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>xinput9_1_0.lib;setupapi.lib;ViGEmClient.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>hid.lib;Cfgmgr32.lib;xinput9_1_0.lib;setupapi.lib;ViGEmClient.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\deps\subhook\subhook.c" />
<ClCompile Include="HidHide.cpp" />
<ClCompile Include="InputRedirector.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="OverlayDetector.cpp" />
@ -160,6 +161,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\deps\subhook\subhook.h" />
<ClInclude Include="HidHide.h" />
<ClInclude Include="InputRedirector.h" />
<ClInclude Include="OverlayDetector.h" />
<ClInclude Include="SteamTarget.h" />

@ -33,6 +33,9 @@
<ClCompile Include="InputRedirector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HidHide.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SteamTarget.h">
@ -53,6 +56,9 @@
<ClInclude Include="InputRedirector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HidHide.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\deps\SFML\out\build\x64-Debug\lib\sfml-system-d-2.dll" />

@ -1,3 +1,18 @@
/*
Copyright 2021 Peter Repukat - FlatspotSoftware
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.
*/
#include "InputRedirector.h"
#include <SFML/System/Clock.hpp>
@ -11,7 +26,8 @@ InputRedirector::InputRedirector()
vigem_connected_ = VIGEM_SUCCESS(vigem_connect(driver_));
if (vigem_connected_) {
spdlog::debug("Connected to ViGEm");
} else {
}
else {
spdlog::error("Error initializing ViGEm");
// TODO: setup some mechanic to draw to window...
}
@ -39,7 +55,7 @@ void InputRedirector::stop()
{
run_ = false;
if (vigem_connected_) {
for (const auto &target : vt_x360_) {
for (const auto& target : vt_x360_) {
vigem_target_remove(driver_, target);
}
}
@ -59,8 +75,9 @@ void InputRedirector::runLoop()
XINPUT_STATE state{};
if (XInputGetState(i, &state) == ERROR_SUCCESS) {
if (vt_x360_[i] != nullptr) {
vigem_target_x360_update(driver_, vt_x360_[i], *reinterpret_cast<XUSB_REPORT *>(&state.Gamepad));
} else {
vigem_target_x360_update(driver_, vt_x360_[i], *reinterpret_cast<XUSB_REPORT*>(&state.Gamepad));
}
else {
vt_x360_[i] = vigem_target_x360_alloc();
// By using VID and PID of Valve's Emulated Controller
// ( https://partner.steamgames.com/doc/features/steam_controller/steam_input_gamepad_emulation_bestpractices )
@ -95,7 +112,8 @@ void InputRedirector::runLoop()
}
}
}
} else {
}
else {
if (vt_x360_[i] != nullptr) {
if (VIGEM_SUCCESS(vigem_target_remove(driver_, vt_x360_[i]))) {
spdlog::info("Unplugged controller {}, {}", i, vigem_target_get_index(vt_x360_[i]));

@ -1,10 +1,25 @@
/*
Copyright 2021 Peter Repukat - FlatspotSoftware
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.
*/
#pragma once
#include <thread>
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#include <ViGEm/Client.h>
#include <Xinput.h>
#include <ViGEm/Client.h>
#endif
class InputRedirector {

@ -22,7 +22,6 @@ limitations under the License.
#include <Windows.h>
#endif
OverlayDetector::OverlayDetector(std::function<void(bool)> overlay_changed)
: overlay_changed_(std::move(overlay_changed))
{
@ -68,5 +67,4 @@ void OverlayDetector::update()
}
}
#endif
}

@ -24,7 +24,6 @@ limitations under the License.
class OverlayDetector {
public:
explicit OverlayDetector(
std::function<void(bool)> overlay_changed = [](bool) {});
void update();
@ -35,5 +34,4 @@ class OverlayDetector {
bool overlay_open_ = false;
int msg_count_ = 0;
#endif
};

@ -37,7 +37,7 @@ HWND keepForegroundWindow()
#endif
SteamTarget::SteamTarget(int argc, char *argv[])
SteamTarget::SteamTarget(int argc, char* argv[])
: window_([this] { run_ = false; }, getScreenshotHotkey()),
detector_([this](bool overlay_open) { onOverlayChanged(overlay_open); }), target_window_handle_(window_.getSystemHandle())
{
@ -229,12 +229,12 @@ void SteamTarget::overlayHotkeyWorkaround()
{
static bool pressed = false;
if (std::ranges::all_of(overlay_hotkey_,
[](const auto &key) {
[](const auto& key) {
return sf::Keyboard::isKeyPressed(keymap::sfkey[key]);
})) {
spdlog::debug("Detected overlay hotkey(s)");
pressed = true;
std::ranges::for_each(overlay_hotkey_, [this](const auto &key) {
std::ranges::for_each(overlay_hotkey_, [this](const auto& key) {
#ifdef _WIN32
PostMessage(target_window_handle_, WM_KEYDOWN, keymap::winkey[key], 0);
#else
@ -245,7 +245,7 @@ void SteamTarget::overlayHotkeyWorkaround()
}
else if (pressed) {
pressed = false;
std::ranges::for_each(overlay_hotkey_, [this](const auto &key) {
std::ranges::for_each(overlay_hotkey_, [this](const auto& key) {
#ifdef _WIN32
PostMessage(target_window_handle_, WM_KEYUP, keymap::winkey[key], 0);
#else

@ -15,14 +15,17 @@ limitations under the License.
*/
#pragma once
#include "InputRedirector.h"
#include "OverlayDetector.h"
#include "TargetWindow.h"
#ifdef _WIN32
#include "InputRedirector.h"
#endif
class SteamTarget {
public:
explicit SteamTarget(int argc, char *argv[]);
explicit SteamTarget(int argc, char* argv[]);
int run();
private:

@ -17,7 +17,6 @@ limitations under the License.
#include "steam_sf_keymap.h"
#include <iostream>
#include <utility>
#include <SFML/Window/Event.hpp>
@ -119,7 +118,7 @@ void TargetWindow::screenShotWorkaround()
{
#ifdef _WIN32
if (std::ranges::all_of(screenshot_keys_,
[](const auto &key) {
[](const auto& key) {
return sf::Keyboard::isKeyPressed(keymap::sfkey[key]);
})) {
spdlog::debug("Detected screenshot hotkey(s); Taking screenshot");
@ -168,10 +167,10 @@ void TargetWindow::screenShotWorkaround()
sprite.setTexture(texture);
spdlog::debug("Sending screenshot key events and rendering screen...");
std::ranges::for_each(screenshot_keys_, [this](const auto &key) {
std::ranges::for_each(screenshot_keys_, [this](const auto& key) {
PostMessage(window_.getSystemHandle(), WM_KEYDOWN, keymap::winkey[key], 0);
});
std::ranges::for_each(screenshot_keys_, [this](const auto &key) {
std::ranges::for_each(screenshot_keys_, [this](const auto& key) {
PostMessage(window_.getSystemHandle(), WM_KEYUP, keymap::winkey[key], 0);
});
//actually run event loop, so steam gets notified about keys.

@ -26,7 +26,6 @@ using WindowHandle = HWND;
using WindowHandle = int; // ???
#endif
class TargetWindow {
public:
explicit TargetWindow(
@ -56,5 +55,4 @@ class TargetWindow {
const std::function<void()> on_close_;
sf::RenderWindow window_;
std::vector<std::string> screenshot_keys_;
};

@ -27,17 +27,16 @@ limitations under the License.
#define CONSOLE
#ifdef _WIN32
#ifdef CONSOLE
int main(int argc, char *argv[])
int main(int argc, char* argv[])
#else
int CALLBACK WinMain(
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow
)
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow)
#endif
#else
int main(int argc, char *argv[])
int main(int argc, char* argv[])
#endif
{
const auto console_sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();

@ -1,3 +1,18 @@
/*
Copyright 2021 Peter Repukat - FlatspotSoftware
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.
*/
#pragma once
#include <SFML/Window/Keyboard.hpp>
#include <unordered_map>

Loading…
Cancel
Save