mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-04-13 19:26:19 +00:00
Constrain the reported controller number by the max gamepad count
This commit is contained in:
@@ -15,6 +15,9 @@ static PLT_THREAD inputSendThread;
|
||||
static float absCurrentPosX;
|
||||
static float absCurrentPosY;
|
||||
|
||||
// Limited by number of bits in activeGamepadMask
|
||||
#define MAX_GAMEPADS 16
|
||||
|
||||
#define CLAMP(val, min, max) (((val) < (min)) ? (min) : (((val) > (max)) ? (max) : (val)))
|
||||
|
||||
#define MAX_INPUT_PACKET_SIZE 128
|
||||
@@ -938,6 +941,16 @@ static int sendControllerEventInternal(short controllerNumber, short activeGamep
|
||||
return -2;
|
||||
}
|
||||
|
||||
// GFE only supports a maximum of 4 controllers
|
||||
if (!IS_SUNSHINE()) {
|
||||
controllerNumber %= 4;
|
||||
activeGamepadMask &= 0xF;
|
||||
}
|
||||
else {
|
||||
// Sunshine supports up to 16 (max number of bits in activeGamepadMask)
|
||||
controllerNumber %= MAX_GAMEPADS;
|
||||
}
|
||||
|
||||
holder = allocatePacketHolder(0);
|
||||
if (holder == NULL) {
|
||||
return -1;
|
||||
@@ -971,12 +984,6 @@ static int sendControllerEventInternal(short controllerNumber, short activeGamep
|
||||
holder->packet.multiController.header.magic = LE32(MULTI_CONTROLLER_MAGIC);
|
||||
}
|
||||
|
||||
// GFE only supports a maximum of 4 controllers
|
||||
if (!IS_SUNSHINE()) {
|
||||
controllerNumber %= 4;
|
||||
activeGamepadMask &= 0xF;
|
||||
}
|
||||
|
||||
holder->packet.multiController.headerB = LE16(MC_HEADER_B);
|
||||
holder->packet.multiController.controllerNumber = LE16(controllerNumber);
|
||||
holder->packet.multiController.activeGamepadMask = LE16(activeGamepadMask);
|
||||
@@ -1245,6 +1252,9 @@ int LiSendControllerArrivalEvent(uint8_t controllerNumber, uint16_t activeGamepa
|
||||
return -2;
|
||||
}
|
||||
|
||||
// Sunshine supports up to 16 controllers
|
||||
controllerNumber %= MAX_GAMEPADS;
|
||||
|
||||
// The arrival event is only supported by Sunshine
|
||||
if (IS_SUNSHINE()) {
|
||||
holder = allocatePacketHolder(0);
|
||||
@@ -1285,6 +1295,9 @@ int LiSendControllerTouchEvent(uint8_t controllerNumber, uint8_t eventType, uint
|
||||
return LI_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
// Sunshine supports up to 16 controllers
|
||||
controllerNumber %= MAX_GAMEPADS;
|
||||
|
||||
holder = allocatePacketHolder(0);
|
||||
if (holder == NULL) {
|
||||
return -1;
|
||||
@@ -1323,6 +1336,9 @@ int LiSendControllerMotionEvent(uint8_t controllerNumber, uint8_t motionType, fl
|
||||
return LI_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
// Sunshine supports up to 16 controllers
|
||||
controllerNumber %= MAX_GAMEPADS;
|
||||
|
||||
holder = allocatePacketHolder(0);
|
||||
if (holder == NULL) {
|
||||
return -1;
|
||||
@@ -1359,6 +1375,9 @@ int LiSendControllerBatteryEvent(uint8_t controllerNumber, uint8_t batteryState,
|
||||
return LI_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
// Sunshine supports up to 16 controllers
|
||||
controllerNumber %= MAX_GAMEPADS;
|
||||
|
||||
holder = allocatePacketHolder(0);
|
||||
if (holder == NULL) {
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user