2021-10-20 19:47:24 +00:00
|
|
|
/*
|
2022-01-06 23:38:21 +00:00
|
|
|
Copyright 2021-2022 Peter Repukat - FlatspotSoftware
|
2021-10-20 19:47:24 +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-17 21:41:15 +00:00
|
|
|
#pragma once
|
|
|
|
#include <thread>
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define NOMINMAX
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <Xinput.h>
|
2021-10-20 19:47:24 +00:00
|
|
|
#include <ViGEm/Client.h>
|
2022-06-06 18:23:05 +00:00
|
|
|
#include <ViGEm/Util.h>
|
2021-10-17 21:41:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
class InputRedirector {
|
|
|
|
public:
|
|
|
|
InputRedirector();
|
|
|
|
~InputRedirector();
|
|
|
|
|
|
|
|
void run();
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void runLoop();
|
|
|
|
|
|
|
|
static constexpr int start_delay_ms_ = 2000;
|
|
|
|
bool run_ = false;
|
2021-10-30 01:07:51 +00:00
|
|
|
int overlay_elem_id_ = -1;
|
2021-10-17 21:41:15 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
PVIGEM_CLIENT driver_;
|
2021-10-30 01:07:51 +00:00
|
|
|
|
|
|
|
// 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> use_real_vid_pid_ = false;
|
|
|
|
static inline std::atomic<bool> use_real_vid_pid_changed_ = false;
|
|
|
|
|
2021-10-17 21:41:15 +00:00
|
|
|
bool vigem_connected_;
|
2022-06-06 18:23:05 +00:00
|
|
|
|
|
|
|
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);
|
2021-10-30 01:07:51 +00:00
|
|
|
|
2021-10-17 21:41:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
std::thread controller_thread_;
|
|
|
|
};
|