So in fact, i really love to play DS3 with friends just one game and everytime someone dies the controller passes to the next so typical couch gaming. But often we have no time to visit each other and so the only option would be online MP. Since i don't really like that and my friends mostly don't have DS3 i wanted to create a program with XInput which constantly gets the Controllers State and mirrors it to the other via WinSockets so my friends could controle my game via their controller. I already wrote some quick code for a controller Class with some basic functions to get to know XInput a littlebit better. Now my questions are: does DS3 use XInput or DInput? And either way how do i get DS3 to interpret my inputs? I hope this quisteion is specific enough.
If neccesary here is my code so far:
CPad.h:
#pragma once
#include <iostream>
#include <Windows.h>
#include <Xinput.h>
#include <limits.h>
#include <time.h>
using namespace std;
class Ctimer
{
private:
clock_t cur_time;
clock_t last_time;
public:
Ctimer() {
cur_time = last_time = clock();
}
void update() {
cur_time = clock();
}
void reset() {
last_time = cur_time;
}
clock_t GetElapsed() {
return cur_time - last_time;
}
};
class CPad
{
private:
int DevID = -1;
int dwPacketNumber_last;
int vibration_duration;
bool vibrate = 0;
Ctimer vibration_timer;
XINPUT_VIBRATION vibration;
public:
XINPUT_STATE state;
CPad();
bool CheckInput();
void SetVibration(int lMotor, int rMotor, int vibration_duration);
void ProcVibration();
void UpdateVibrationTimer();
};
CPad.cpp:
#include "CPad.h"
CPad::CPad()
{
for (int i = 0; i < XUSER_MAX_COUNT; i++)
{
XINPUT_STATE tmp;
ZeroMemory(&tmp, sizeof(XINPUT_STATE));
if (XInputGetState(i, &tmp) == ERROR_SUCCESS)
{
DevID = i;
state = tmp;
}
}
if (DevID == -1)
{
cerr << "Error: couldn't find Controller" << endl;
delete(this);
exit(1);
}
dwPacketNumber_last = state.dwPacketNumber;
}
bool CPad::CheckInput()
{
dwPacketNumber_last = state.dwPacketNumber;
XInputGetState(DevID, &state);
if (dwPacketNumber_last != state.dwPacketNumber)
{
dwPacketNumber_last = state.dwPacketNumber;
return true;
}
else
{
return false;
}
}
void CPad::SetVibration(int lMotor, int rMotor, int vibration_duration)
{
this->vibration_duration = vibration_duration;
vibrate = true;
vibration.wLeftMotorSpeed = lMotor;
vibration.wRightMotorSpeed = rMotor;
XInputSetState(DevID, &vibration);
}
void CPad::ProcVibration()
{
if (vibrate)
{
if (vibration_timer.GetElapsed() > vibration_duration)
{
vibration_timer.reset();
vibrate = false;
vibration.wLeftMotorSpeed = 0;
vibration.wRightMotorSpeed = 0;
XInputSetState(DevID, &vibration);
}
}
}
void CPad::UpdateVibrationTimer()
{
vibration_timer.update();
}
main.cpp
#include "CPad.h"
int main(int argc, char **argv)
{
bool run = true;
CPad pad;
while (run)
{
pad.ProcVibration();
pad.UpdateVibrationTimer();
if (pad.CheckInput())
{
switch (pad.state.Gamepad.wButtons)
{
case(XINPUT_GAMEPAD_A):
{
cout << "Pressed A" << endl;
pad.SetVibration(INT_MAX, INT_MAX, 300);
break;
}
case(XINPUT_GAMEPAD_BACK):
{
run = false;
break;
}
}
}
}
return 0;
}