Fix writing settings from GlosSITarget

pull/183/head
Peter Repukat 2 years ago
parent 315a58cfc1
commit a1397e05da

@ -50,13 +50,11 @@ void InputRedirector::run()
{ {
run_ = vigem_connected_; run_ = vigem_connected_;
controller_thread_ = std::thread(&InputRedirector::runLoop, this); controller_thread_ = std::thread(&InputRedirector::runLoop, this);
max_controller_count_ = Settings::controller.maxControllers;
use_real_vid_pid_ = Settings::devices.realDeviceIds;
#ifdef _WIN32 #ifdef _WIN32
Overlay::AddOverlayElem([this](bool window_has_focus, ImGuiID dockspace_id) { Overlay::AddOverlayElem([this](bool window_has_focus, ImGuiID dockspace_id) {
ImGui::SetNextWindowDockID(dockspace_id, ImGuiCond_FirstUseEver); ImGui::SetNextWindowDockID(dockspace_id, ImGuiCond_FirstUseEver);
ImGui::Begin("Controller Emulation"); ImGui::Begin("Controller Emulation");
int countcopy = max_controller_count_; int countcopy = Settings::controller.maxControllers;
ImGui::Text("Max. controller count"); ImGui::Text("Max. controller count");
ImGui::InputInt("##Max. controller count", &countcopy, 1, 1); ImGui::InputInt("##Max. controller count", &countcopy, 1, 1);
if (countcopy > XUSER_MAX_COUNT) { if (countcopy > XUSER_MAX_COUNT) {
@ -65,7 +63,7 @@ void InputRedirector::run()
if (countcopy < 0) { if (countcopy < 0) {
countcopy = 0; countcopy = 0;
} }
max_controller_count_ = countcopy; Settings::controller.maxControllers = countcopy;
bool enable_rumbe_copy = enable_rumble_; bool enable_rumbe_copy = enable_rumble_;
ImGui::Checkbox("Enable Rumble", &enable_rumbe_copy); ImGui::Checkbox("Enable Rumble", &enable_rumbe_copy);
enable_rumble_ = enable_rumbe_copy; enable_rumble_ = enable_rumbe_copy;
@ -76,12 +74,12 @@ void InputRedirector::run()
ImGui::Text("to prevent having multiple mirrored controllers plugged in"); ImGui::Text("to prevent having multiple mirrored controllers plugged in");
ImGui::Spacing(); ImGui::Spacing();
ImGui::Text("If enabled, Device hiding won't work! Use \"Max. Controller count\"-setting."); ImGui::Text("If enabled, Device hiding won't work! Use \"Max. Controller count\"-setting.");
bool use_real_copy = use_real_vid_pid_; bool use_real_copy = Settings::devices.realDeviceIds;
ImGui::Checkbox("Use real USB-IDs", &use_real_copy); ImGui::Checkbox("Use real USB-IDs", &use_real_copy);
if (use_real_vid_pid_ != use_real_copy) { if (Settings::devices.realDeviceIds != use_real_copy) {
use_real_vid_pid_changed_ = true; use_real_vid_pid_changed_ = true;
} }
use_real_vid_pid_ = use_real_copy; Settings::devices.realDeviceIds = use_real_copy;
} }
ImGui::End(); ImGui::End();
}); });
@ -115,12 +113,12 @@ void InputRedirector::runLoop()
unplugVigemPad(i); unplugVigemPad(i);
} }
} }
if (max_controller_count_ < XUSER_MAX_COUNT) { if (Settings::controller.maxControllers < XUSER_MAX_COUNT) {
for (int i = max_controller_count_; i < XUSER_MAX_COUNT; i++) { for (int i = Settings::controller.maxControllers; i < XUSER_MAX_COUNT; i++) {
unplugVigemPad(i); unplugVigemPad(i);
} }
} }
for (int i = 0; i < XUSER_MAX_COUNT && i < max_controller_count_; i++) { for (int i = 0; i < XUSER_MAX_COUNT && i < Settings::controller.maxControllers; i++) {
XINPUT_STATE state{}; XINPUT_STATE state{};
if (XInputGetState(i, &state) == ERROR_SUCCESS) { if (XInputGetState(i, &state) == ERROR_SUCCESS) {
if (vt_pad_[i] != nullptr) { if (vt_pad_[i] != nullptr) {
@ -160,7 +158,7 @@ void InputRedirector::runLoop()
// Otherwise, this application (GloSC/GlosSI) will pickup the emulated controller as well! // Otherwise, this application (GloSC/GlosSI) will pickup the emulated controller as well!
// This however is configurable withon GlosSI overlay; // This however is configurable withon GlosSI overlay;
// Multiple controllers can be worked around with by setting max count. // Multiple controllers can be worked around with by setting max count.
if (!use_real_vid_pid_) { if (!Settings::devices.realDeviceIds) {
vigem_target_set_vid(vt_pad_[i], 0x28de); //VALVE_DIRECTINPUT_GAMEPAD_VID vigem_target_set_vid(vt_pad_[i], 0x28de); //VALVE_DIRECTINPUT_GAMEPAD_VID
//vigem_target_set_pid(vt_pad_[i], 0x11FF); //VALVE_DIRECTINPUT_GAMEPAD_PID //vigem_target_set_pid(vt_pad_[i], 0x11FF); //VALVE_DIRECTINPUT_GAMEPAD_PID
vigem_target_set_pid(vt_pad_[i], 0x028E); // XBOX 360 Controller vigem_target_set_pid(vt_pad_[i], 0x028E); // XBOX 360 Controller

@ -41,9 +41,7 @@ class InputRedirector {
PVIGEM_CLIENT driver_; PVIGEM_CLIENT driver_;
// variables for overlay element; run in different thread // variables for overlay element; run in different thread
std::atomic<int> max_controller_count_ = XUSER_MAX_COUNT;
static inline std::atomic<bool> enable_rumble_ = true; static inline std::atomic<bool> enable_rumble_ = true;
static inline std::atomic<bool> use_real_vid_pid_ = false;
static inline std::atomic<bool> use_real_vid_pid_changed_ = false; static inline std::atomic<bool> use_real_vid_pid_changed_ = false;
bool vigem_connected_; bool vigem_connected_;

@ -51,8 +51,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,9,1014000053108 FILEVERSION 0,0,9,1017003150580
PRODUCTVERSION 0,0,9,1014000053108 PRODUCTVERSION 0,0,9,1017003150580
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -69,12 +69,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "Peter Repukat - FlatspotSoftware" VALUE "CompanyName", "Peter Repukat - FlatspotSoftware"
VALUE "FileDescription", "GlosSI - SteamTarget" VALUE "FileDescription", "GlosSI - SteamTarget"
VALUE "FileVersion", "0.0.9.1-14-gda531f8" VALUE "FileVersion", "0.0.9.1-17-g315a58c"
VALUE "InternalName", "GlosSITarget" VALUE "InternalName", "GlosSITarget"
VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware" VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware"
VALUE "OriginalFilename", "GlosSITarget.exe" VALUE "OriginalFilename", "GlosSITarget.exe"
VALUE "ProductName", "GlosSI" VALUE "ProductName", "GlosSI"
VALUE "ProductVersion", "0.0.9.1-14-gda531f8" VALUE "ProductVersion", "0.0.9.1-17-g315a58c"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

@ -48,15 +48,16 @@ TargetWindow::TargetWindow(
screenshot_keys_(std::move(screenshot_hotkey)), screenshot_keys_(std::move(screenshot_hotkey)),
on_window_changed_(std::move(on_window_changed)) on_window_changed_(std::move(on_window_changed))
{ {
createWindow(Settings::window.windowMode); createWindow();
Overlay::AddOverlayElem([this](bool window_has_focus, ImGuiID dockspace_id) { Overlay::AddOverlayElem([this](bool window_has_focus, ImGuiID dockspace_id) {
ImGui::SetNextWindowDockID(dockspace_id, ImGuiCond_FirstUseEver); ImGui::SetNextWindowDockID(dockspace_id, ImGuiCond_FirstUseEver);
bool windowed_copy = windowed_; bool windowed_copy = Settings::window.windowMode;
ImGui::Begin("Window mode"); ImGui::Begin("Window mode");
if (ImGui::Checkbox("Window mode", &windowed_copy)) { if (ImGui::Checkbox("Window mode", &windowed_copy)) {
toggle_window_mode_after_frame_ = true; toggle_window_mode_after_frame_ = true;
} }
Settings::window.windowMode = windowed_copy;
ImGui::End(); ImGui::End();
}); });
@ -102,7 +103,7 @@ void TargetWindow::update()
overlay_->update(); overlay_->update();
window_.display(); window_.display();
if (toggle_window_mode_after_frame_) { if (toggle_window_mode_after_frame_) {
createWindow(!windowed_); createWindow();
} }
// As SFML screws us out of most windows-events, just poll resolution every once in a while // As SFML screws us out of most windows-events, just poll resolution every once in a while
// If changed, recreate window. // If changed, recreate window.
@ -110,7 +111,7 @@ void TargetWindow::update()
// (WHY?!) // (WHY?!)
if (check_resolution_clock_.getElapsedTime().asSeconds() > RES_CHECK_SECONDS) { if (check_resolution_clock_.getElapsedTime().asSeconds() > RES_CHECK_SECONDS) {
if (sf::VideoMode::getDesktopMode().width != old_desktop_mode_.width) { if (sf::VideoMode::getDesktopMode().width != old_desktop_mode_.width) {
createWindow(windowed_); createWindow();
} }
check_resolution_clock_.restart(); check_resolution_clock_.restart();
} }
@ -238,17 +239,16 @@ WORD TargetWindow::GetWindowDPI(HWND hWnd)
} }
#endif #endif
void TargetWindow::createWindow(bool window_mode) void TargetWindow::createWindow()
{ {
toggle_window_mode_after_frame_ = false; toggle_window_mode_after_frame_ = false;
auto desktop_mode = sf::VideoMode::getDesktopMode(); auto desktop_mode = sf::VideoMode::getDesktopMode();
spdlog::info("Detected resolution: {}x{}", desktop_mode.width, desktop_mode.height); spdlog::info("Detected resolution: {}x{}", desktop_mode.width, desktop_mode.height);
old_desktop_mode_ = desktop_mode; old_desktop_mode_ = desktop_mode;
if (window_mode) { if (Settings::window.windowMode) {
spdlog::info("Creating Overlay window..."); spdlog::info("Creating Overlay window...");
window_.create(sf::VideoMode(desktop_mode.width * 0.75, desktop_mode.height * 0.75, 32), "GlosSITarget"); window_.create(sf::VideoMode(desktop_mode.width * 0.75, desktop_mode.height * 0.75, 32), "GlosSITarget");
windowed_ = true;
} }
else { else {
#ifdef _WIN32 #ifdef _WIN32
@ -270,12 +270,11 @@ void TargetWindow::createWindow(bool window_mode)
#else #else
window_.create(desktop_mode, "GlosSITarget", sf::Style::None); window_.create(desktop_mode, "GlosSITarget", sf::Style::None);
#endif #endif
windowed_ = false;
} }
window_.setActive(true); window_.setActive(true);
spdlog::debug("Window position: {}x{}", window_.getPosition().x, window_.getPosition().y); spdlog::debug("Window position: {}x{}", window_.getPosition().x, window_.getPosition().y);
if (!window_mode) { if (!Settings::window.windowMode) {
spdlog::info("Resizing window to 1px smaller than fullscreen..."); spdlog::info("Resizing window to 1px smaller than fullscreen...");
window_.setSize(sf::Vector2u(desktop_mode.width - 1, desktop_mode.height - 1)); window_.setSize(sf::Vector2u(desktop_mode.width - 1, desktop_mode.height - 1));
} }
@ -315,7 +314,7 @@ void TargetWindow::createWindow(bool window_mode)
} }
overlay_ = std::make_shared<Overlay>( overlay_ = std::make_shared<Overlay>(
window_, [this]() { close(); }, toggle_overlay_state_, windowed_); window_, [this]() { close(); }, toggle_overlay_state_, Settings::window.windowMode);
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.FontGlobalScale = dpi / 96.f; io.FontGlobalScale = dpi / 96.f;

@ -77,8 +77,7 @@ class TargetWindow {
std::shared_ptr<Overlay> overlay_; std::shared_ptr<Overlay> overlay_;
void createWindow(bool window_mode); void createWindow();
bool windowed_ = false;
bool toggle_window_mode_after_frame_ = false; bool toggle_window_mode_after_frame_ = false;
}; };

Loading…
Cancel
Save