Merge branch 'develop'

pull/169/head 0.0.7.0
Peter Repukat 2 years ago
commit 121ea4da93

@ -86,6 +86,7 @@ void UIModel::readConfigs()
json["disableOverlay"] = filejson["window"]["disableOverlay"];
json["maxControllers"] = filejson["controller"]["allowDesktopConfig"];
json["allowDesktopConfig"] = filejson["controller"]["allowDesktopConfig"];
json["emulateDS4"] = filejson["controller"]["emulateDS4"];
json["name"] = filejson.contains("name") ? filejson["name"] : QString(name).replace(QRegularExpression("\\.json"), "");
@ -371,6 +372,7 @@ void UIModel::writeTarget(const QJsonObject& json, const QString& name)
QJsonObject controllerObject;
controllerObject["maxControllers"] = json["maxControllers"];
controllerObject["allowDesktopConfig"] = json["allowDesktopConfig"];
controllerObject["emulateDS4"] = json["emulateDS4"];
fileJson["controller"] = controllerObject;
auto wtf = QString(QJsonDocument(fileJson).toJson(QJsonDocument::Indented)).toStdString();

@ -46,6 +46,7 @@ Item {
disableOverlay: false,
realDeviceIds: false,
allowDesktopConfig: true,
emulateDS4: false,
})
function resetInfo() {
@ -66,6 +67,7 @@ Item {
disableOverlay: false,
realDeviceIds: false,
allowDesktopConfig: true,
emulateDS4: false,
})
}
@ -82,6 +84,7 @@ Item {
disableOverlayCheckbox.checked = shortcutInfo.disableOverlay || false
realDeviceIds.checked = shortcutInfo.realDeviceIds || false
allowDesktopConfig.checked = shortcutInfo.allowDesktopConfig || true
emulateDS4.checked = shortcutInfo.emulateDS4 || false
}
Flickable {
@ -318,7 +321,7 @@ Item {
RPane {
width: parent.width / 2 - 8
height: 294
height: 394
radius: 4
Material.elevation: 32
bgOpacity: 0.97
@ -326,7 +329,7 @@ Item {
Column {
spacing: 2
width: parent.width
RadioButton {
CheckBox {
id: hideDevices
text: qsTr("Hide (Real) Controllers")
checked: shortcutInfo.hideDevices
@ -349,7 +352,7 @@ Item {
width: 1
height: 4
}
RadioButton {
CheckBox {
id: realDeviceIds
text: qsTr("Use real device (USB)-IDs")
checked: shortcutInfo.realDeviceIds
@ -372,6 +375,23 @@ Item {
width: 1
height: 4
}
CheckBox {
id: emulateDS4
text: qsTr("Emulate DS4")
checked: shortcutInfo.emulateDS4
onCheckedChanged: shortcutInfo.emulateDS4 = checked
}
Label {
text: qsTr("Instead of X360 Pad; Disable \"Playstation Configuration support\" in Steam")
wrapMode: Text.WordWrap
width: parent.width
leftPadding: 32
topPadding: -8
}
Item {
width: 1
height: 4
}
Row {
leftPadding: 16
Label {

@ -68,7 +68,7 @@ void AppLauncher::update()
}
if (!IsProcessRunning(pids_[0])) {
spdlog::info("Launched App with PID \"{}\" died", pids_[0]);
if (Settings::launch.closeOnExit && !Settings::launch.waitForChildProcs) {
if (Settings::launch.closeOnExit && !Settings::launch.waitForChildProcs && Settings::launch.launch) {
spdlog::info("Configured to close on exit. Shutting down...");
shutdown_();
}
@ -82,7 +82,7 @@ void AppLauncher::update()
spdlog::info("Child process with PID \"{}\" died", pid);
return !running;
});
if (Settings::launch.closeOnExit && pids_.empty()) {
if (Settings::launch.closeOnExit && pids_.empty() && Settings::launch.launch) {
spdlog::info("Configured to close on all children exit. Shutting down...");
shutdown_();
}

@ -53,8 +53,10 @@
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"></ImportGroup>
<ImportGroup Label="Shared"></ImportGroup>
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
@ -130,7 +132,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>hid.lib;Cfgmgr32.lib;opengl32.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>
<AdditionalDependencies>hid.lib;Cfgmgr32.lib;opengl32.lib;sfml-window-d.lib;sfml-system-d.lib;sfml-graphics-d.lib;dwmapi.lib;xinput9_1_0.lib;setupapi.lib;ViGEmClient.lib;Dbghelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
@ -155,7 +157,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>hid.lib;Cfgmgr32.lib;opengl32.lib;sfml-window.lib;sfml-system.lib;sfml-graphics.lib;dwmapi.lib;xinput9_1_0.lib;setupapi.lib;ViGEmClient.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>hid.lib;Cfgmgr32.lib;opengl32.lib;sfml-window.lib;sfml-system.lib;sfml-graphics.lib;dwmapi.lib;xinput9_1_0.lib;setupapi.lib;ViGEmClient.lib;Dbghelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
@ -252,5 +254,6 @@
<Image Include="$(SolutionDir)\GloSC_Icon.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"></ImportGroup>
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -192,10 +192,7 @@
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="..\GloSC_Icon.ico">
<Filter>Resource Files</Filter>
</Image>
<Image Include="GloSC_Icon.ico">
<Image Include="$(SolutionDir)\GloSC_Icon.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>

@ -94,7 +94,7 @@ void InputRedirector::stop()
run_ = false;
controller_thread_.join();
if (vigem_connected_) {
for (const auto& target : vt_x360_) {
for (const auto& target : vt_pad_) {
vigem_target_remove(driver_, target);
}
}
@ -113,22 +113,40 @@ void InputRedirector::runLoop()
// unplug all.
use_real_vid_pid_changed_ = false;
for (int i = 0; i < XUSER_MAX_COUNT; i++) {
unplugVigemX360(i);
unplugVigemPad(i);
}
}
if (max_controller_count_ < XUSER_MAX_COUNT) {
for (int i = max_controller_count_; i < XUSER_MAX_COUNT; i++) {
unplugVigemX360(i);
unplugVigemPad(i);
}
}
for (int i = 0; i < XUSER_MAX_COUNT && i < max_controller_count_; i++) {
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));
if (vt_pad_[i] != nullptr) {
if (Settings::controller.emulateDS4) {
DS4_REPORT rep;
DS4_REPORT_INIT(&rep);
// The DualShock 4 expects a different report format, so we call a helper
// function which will translate buttons and axes 1:1 from XUSB to DS4
// format and submit it to the update function afterwards.
XUSB_TO_DS4_REPORT(reinterpret_cast<PXUSB_REPORT>(&state.Gamepad), &rep);
vigem_target_ds4_update(driver_, vt_pad_[i], rep);
}
else {
vigem_target_x360_update(driver_, vt_pad_[i], *reinterpret_cast<XUSB_REPORT*>(&state.Gamepad));
}
}
else {
vt_x360_[i] = vigem_target_x360_alloc();
if (Settings::controller.emulateDS4) {
vt_pad_[i] = vigem_target_ds4_alloc();
}
else {
vt_pad_[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 )
// Steam doesn't give us ANOTHER "fake" XInput device
@ -144,31 +162,49 @@ void InputRedirector::runLoop()
// This however is configurable withon GlosSI overlay;
// Multiple controllers can be worked around with by setting max count.
if (!use_real_vid_pid_) {
vigem_target_set_vid(vt_x360_[i], 0x28de); //VALVE_DIRECTINPUT_GAMEPAD_VID
// vigem_target_set_pid(vt_x360_[i], 0x11FF); //VALVE_DIRECTINPUT_GAMEPAD_PID
vigem_target_set_vid(vt_pad_[i], 0x28de); //VALVE_DIRECTINPUT_GAMEPAD_VID
// vigem_target_set_pid(vt_pad_[i], 0x11FF); //VALVE_DIRECTINPUT_GAMEPAD_PID
}
// TODO: MAYBE!: In a future version, use something like OpenXInput
//and filter out emulated controllers to support a greater amount of controllers simultaneously
const int target_add_res = vigem_target_add(driver_, vt_x360_[i]);
const int target_add_res = vigem_target_add(driver_, vt_pad_[i]);
if (target_add_res == VIGEM_ERROR_TARGET_UNINITIALIZED) {
vt_x360_[i] = vigem_target_x360_alloc();
if (Settings::controller.emulateDS4) {
vt_pad_[i] = vigem_target_ds4_alloc();
}
else {
vt_pad_[i] = vigem_target_x360_alloc();
}
}
if (target_add_res == VIGEM_ERROR_NONE) {
spdlog::info("Plugged in controller {}, {}", i, vigem_target_get_index(vt_x360_[i]));
const auto callback_register_res = vigem_target_x360_register_notification(
driver_,
vt_x360_[i],
&InputRedirector::controllerCallback,
reinterpret_cast<LPVOID>(i));
if (!VIGEM_SUCCESS(callback_register_res)) {
spdlog::error("Registering controller {}, {} for notification failed with error code: {:#x}", i, vigem_target_get_index(vt_x360_[i]), callback_register_res);
spdlog::info("Plugged in controller {}, {}", i, vigem_target_get_index(vt_pad_[i]));
if (Settings::controller.emulateDS4) {
const auto callback_register_res = vigem_target_ds4_register_notification(
driver_,
vt_pad_[i],
&InputRedirector::ds4ControllerCallback,
reinterpret_cast<LPVOID>(i));
if (!VIGEM_SUCCESS(callback_register_res)) {
spdlog::error("Registering controller {}, {} for notification failed with error code: {:#x}", i, vigem_target_get_index(vt_pad_[i]), callback_register_res);
}
}
else {
const auto callback_register_res = vigem_target_x360_register_notification(
driver_,
vt_pad_[i],
&InputRedirector::x360ControllerCallback,
reinterpret_cast<LPVOID>(i));
if (!VIGEM_SUCCESS(callback_register_res)) {
spdlog::error("Registering controller {}, {} for notification failed with error code: {:#x}", i, vigem_target_get_index(vt_pad_[i]), callback_register_res);
}
}
}
}
}
else {
unplugVigemX360(i);
unplugVigemPad(i);
}
}
sf::sleep(sf::milliseconds(1));
@ -178,26 +214,39 @@ void InputRedirector::runLoop()
}
#ifdef _WIN32
void InputRedirector::controllerCallback(PVIGEM_CLIENT client, PVIGEM_TARGET Target, UCHAR LargeMotor, UCHAR SmallMotor, UCHAR LedNumber, LPVOID UserData)
void InputRedirector::x360ControllerCallback(PVIGEM_CLIENT client, PVIGEM_TARGET Target, UCHAR LargeMotor, UCHAR SmallMotor, UCHAR LedNumber, LPVOID UserData)
{
if (!enable_rumble_) {
return;
}
XINPUT_VIBRATION vibration;
ZeroMemory(&vibration, sizeof(XINPUT_VIBRATION));
vibration.wLeftMotorSpeed = LargeMotor * 0xff; //Controllers only use 1 byte, XInput-API uses two, ViGEm also only uses one, like the hardware does, so we have to multiply
vibration.wRightMotorSpeed = SmallMotor * 0xff; //Yeah yeah I do know about bitshifting and the multiplication not being 100% correct...
vibration.wLeftMotorSpeed = LargeMotor * 257;
vibration.wRightMotorSpeed = SmallMotor * 257;
XInputSetState(reinterpret_cast<int>(UserData), &vibration);
}
void InputRedirector::unplugVigemX360(int idx)
void InputRedirector::unplugVigemPad(int idx)
{
if (vt_x360_[idx] != nullptr) {
if (VIGEM_SUCCESS(vigem_target_remove(driver_, vt_x360_[idx]))) {
spdlog::info("Unplugged controller {}, {}", idx, vigem_target_get_index(vt_x360_[idx]));
vt_x360_[idx] = nullptr;
if (vt_pad_[idx] != nullptr) {
if (VIGEM_SUCCESS(vigem_target_remove(driver_, vt_pad_[idx]))) {
spdlog::info("Unplugged controller {}, {}", idx, vigem_target_get_index(vt_pad_[idx]));
vt_pad_[idx] = nullptr;
}
}
}
void InputRedirector::ds4ControllerCallback(PVIGEM_CLIENT client, PVIGEM_TARGET Target, UCHAR LargeMotor, UCHAR SmallMotor, DS4_LIGHTBAR_COLOR LightbarColor, LPVOID UserData)
{
if (!enable_rumble_) {
return;
}
XINPUT_VIBRATION vibration;
ZeroMemory(&vibration, sizeof(XINPUT_VIBRATION));
vibration.wLeftMotorSpeed = LargeMotor * 257;
vibration.wRightMotorSpeed = SmallMotor * 257;
XInputSetState(reinterpret_cast<int>(UserData), &vibration);
}
#endif

@ -20,6 +20,7 @@ limitations under the License.
#include <Windows.h>
#include <Xinput.h>
#include <ViGEm/Client.h>
#include <ViGEm/Util.h>
#endif
class InputRedirector {
@ -45,10 +46,13 @@ class InputRedirector {
static inline std::atomic<bool> use_real_vid_pid_ = false;
static inline std::atomic<bool> use_real_vid_pid_changed_ = false;
PVIGEM_TARGET vt_x360_[XUSER_MAX_COUNT]{};
bool vigem_connected_;
static void CALLBACK controllerCallback(PVIGEM_CLIENT client, PVIGEM_TARGET Target, UCHAR LargeMotor, UCHAR SmallMotor, UCHAR LedNumber, LPVOID UserData);
void unplugVigemX360(int idx);
PVIGEM_TARGET vt_pad_[XUSER_MAX_COUNT]{};
static void CALLBACK x360ControllerCallback(PVIGEM_CLIENT client, PVIGEM_TARGET Target, UCHAR LargeMotor, UCHAR SmallMotor, UCHAR LedNumber, LPVOID UserData);
void unplugVigemPad(int idx);
static void CALLBACK ds4ControllerCallback(PVIGEM_CLIENT client, PVIGEM_TARGET Target, UCHAR LargeMotor, UCHAR SmallMotor, DS4_LIGHTBAR_COLOR LightbarColor, LPVOID UserData);
#endif

@ -47,6 +47,7 @@ inline struct Window {
inline struct Controller {
int maxControllers = 4;
bool allowDesktopConfig = Settings::launch.launch;
bool emulateDS4 = false;
} controller;
inline bool checkIsUwp(const std::wstring& launch_path)
@ -140,6 +141,7 @@ inline void Parse(std::string arg1)
if (auto controllerConf = json["controller"]; controllerConf.is_object()) {
safeParseValue(controllerConf, "maxControllers", controller.maxControllers);
safeParseValue(controllerConf, "allowDesktopConfig", controller.allowDesktopConfig);
safeParseValue(controllerConf, "emulateDS4", controller.emulateDS4);
}
json_file.close();

@ -16,6 +16,7 @@ limitations under the License.
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#include <DbgHelp.h>
#endif
#include <spdlog/sinks/basic_file_sink.h>
@ -27,14 +28,12 @@ limitations under the License.
#include "OverlayLogSink.h"
#include "Settings.h"
#ifdef _WIN32
// default to high performance GPU
extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
LONG Win32FaultHandler(struct _EXCEPTION_POINTERS* ExInfo)
{
@ -49,20 +48,46 @@ LONG Win32FaultHandler(struct _EXCEPTION_POINTERS* ExInfo)
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
FaultTx = "FLT DIVIDE BY ZERO";
break;
default : FaultTx = "(unknown)";
default:
FaultTx = "(unknown)";
break;
}
int wsFault = ExInfo->ExceptionRecord->ExceptionCode;
PVOID CodeAdress = ExInfo->ExceptionRecord->ExceptionAddress;
spdlog::error("*** A Program Fault occurred:");
spdlog::error("*** Error code {:#x}: {}", wsFault, FaultTx);
spdlog::error("*** Address: {:#x}", (int)CodeAdress);
spdlog::error("*** Flags: {:#x}", ExInfo->ExceptionRecord->ExceptionFlags);
MINIDUMP_EXCEPTION_INFORMATION M;
HANDLE hDump_File;
auto path = std::filesystem::temp_directory_path()
.parent_path()
.parent_path()
.parent_path();
path /= "Roaming";
path /= "GlosSI";
if (!std::filesystem::exists(path))
std::filesystem::create_directories(path);
path /= "glossitarget.dmp";
M.ThreadId = GetCurrentThreadId();
M.ExceptionPointers = ExInfo;
M.ClientPointers = 0;
hDump_File = CreateFile(path.wstring().c_str(), GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
hDump_File, MiniDumpNormal,
(ExInfo) ? &M : NULL, NULL, NULL);
CloseHandle(hDump_File);
/*if(want to continue)
{
ExInfo->ContextRecord->Eip++;
@ -123,26 +148,28 @@ int main(int argc, char* argv[])
auto exit = 1;
try {
#ifdef _WIN32
std::string argsv = "";
if (__argc > 1) {
for (int i = 1; i < __argc; i++)
argsv += i == 1 ? __argv[i] : std::string(" ") + __argv[i];
}
Settings::Parse(argsv);
SteamTarget target(__argc, __argv);
std::string argsv = "";
if (__argc > 1) {
for (int i = 1; i < __argc; i++)
argsv += i == 1 ? __argv[i] : std::string(" ") + __argv[i];
}
Settings::Parse(argsv);
SteamTarget target(__argc, __argv);
#else
std::string argsv = "";
if (argc > 1) {
for (int i = 1; i < argc; i++)
argsv += i == 1 ? argv[i] : std::string(" ") + argv[i];
}
Settings::Parse(argsv);
SteamTarget target(argc, argv);
std::string argsv = "";
if (argc > 1) {
for (int i = 1; i < argc; i++)
argsv += i == 1 ? argv[i] : std::string(" ") + argv[i];
}
Settings::Parse(argsv);
SteamTarget target(argc, argv);
#endif
exit = target.run();
} catch (std::exception& e) {
exit = target.run();
}
catch (std::exception& e) {
spdlog::error("Exception occured: {}", e.what());
} catch (...) {
}
catch (...) {
spdlog::error("Unknown exception occured");
}
spdlog::shutdown();

Loading…
Cancel
Save