2
0
mirror of https://github.com/Thracky/GlosSI.git synced 2024-11-15 06:12:54 +00:00
GlosSI-fork/SteamTarget/VirtualControllerThread.h

86 lines
2.3 KiB
C
Raw Normal View History

/*
2018-03-10 22:02:39 +00:00
Copyright 2018 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>
#include <chrono>
#include <iostream>
#include <atomic>
#include <vector>
#include <Windows.h>
2018-03-10 22:07:25 +00:00
#include <Psapi.h>
#include <SFML/System.hpp>
#include <Xinput.h>
2017-09-29 17:52:20 +00:00
#include <ViGEmClient.h>
#include <VersionHelpers.h>
class VirtualControllerThread
{
public:
VirtualControllerThread();
2018-03-10 22:07:25 +00:00
VirtualControllerThread(const VirtualControllerThread& other) = delete;
VirtualControllerThread(VirtualControllerThread&& other) noexcept = delete;
VirtualControllerThread& operator=(const VirtualControllerThread& other) = delete;
VirtualControllerThread& operator=(VirtualControllerThread&& other) noexcept = delete;
~VirtualControllerThread();
void run();
void stop();
2018-03-10 22:02:39 +00:00
bool isRunning() const;
private:
2018-03-10 22:07:25 +00:00
std::atomic<bool> b_should_run_ = false;
typedef DWORD(WINAPI* XInputGetState_t)(DWORD dwUserIndex, XINPUT_STATE* pState);
2018-03-10 22:02:39 +00:00
static const uint8_t op_patch_lenght = 5;
2018-03-10 22:07:25 +00:00
uint8_t valve_hook_bytes_[5]{};
2018-03-10 22:02:39 +00:00
bool seven_ = false;
#ifdef _AMD64_
const uint8_t realBytes[5] = {0x48, 0x89, 0x5C, 0x24, 0x08};
#else
2018-03-10 22:02:39 +00:00
const uint8_t real_bytes_[5] = { 0x8B, 0xFF, 0x55, 0x8B, 0xEC };
#endif
//uint8_t realBytes[5] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x90 };
2018-03-10 22:02:39 +00:00
int controller_count_ = 0;
XInputGetState_t x_get_state_ = nullptr;
2018-03-10 22:02:39 +00:00
PVIGEM_CLIENT driver_;
2018-03-10 22:07:25 +00:00
PVIGEM_TARGET vt_x360_[XUSER_MAX_COUNT]{};
2018-03-10 22:02:39 +00:00
std::thread controller_thread_;
2018-03-10 22:02:39 +00:00
sf::Clock sf_clock_;
int tick_time_ = 0;
int delay_ = 1000000 / 200;
void controllerLoop();
2018-03-10 22:02:39 +00:00
static void __RPC_CALLEE controllerCallback(PVIGEM_CLIENT client, PVIGEM_TARGET Target, UCHAR LargeMotor, UCHAR SmallMotor, UCHAR LedNumber);
2017-02-15 20:43:29 +00:00
static DWORD XInputGetStateWrapper(DWORD dwUserIndex, XINPUT_STATE* pState); //Easier to find in x64dbg...
DWORD callRealXinputGetState(DWORD dwUserIndex, XINPUT_STATE* pState);
};