From 812ec0e2b7d1a84c13ebae5f821aeedc80bd1ea2 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 18 Jun 2023 16:36:34 -0500 Subject: [PATCH] Allow exceeding 4 controllers for Sunshine hosts --- src/InputStream.c | 8 ++++++++ src/Limelight.h | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/InputStream.c b/src/InputStream.c index 87f1f4f..a012940 100644 --- a/src/InputStream.c +++ b/src/InputStream.c @@ -961,6 +961,7 @@ static int sendControllerEventInternal(short controllerNumber, short activeGamep else { // Generation 4+ servers support passing the controller number holder->packet.multiController.header.size = BE32(sizeof(NV_MULTI_CONTROLLER_PACKET) - sizeof(uint32_t)); + // On Gen 5 servers, the header code is decremented by one if (AppVersionQuad[0] >= 5) { holder->packet.multiController.header.magic = LE32(MULTI_CONTROLLER_MAGIC_GEN5); @@ -968,6 +969,13 @@ static int sendControllerEventInternal(short controllerNumber, short activeGamep else { 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); diff --git a/src/Limelight.h b/src/Limelight.h index fd4551d..eb6e726 100644 --- a/src/Limelight.h +++ b/src/Limelight.h @@ -664,8 +664,10 @@ int LiSendControllerEvent(short buttonFlags, unsigned char leftTrigger, unsigned // This function queues a controller event to be sent to the remote server. The controllerNumber // parameter is a zero-based index of which controller this event corresponds to. The largest legal // controller number is 3 (for a total of 4 controllers, the Xinput maximum). On generation 3 servers (GFE 2.1.x), -// these will be sent as controller 0 regardless of the controllerNumber parameter. The activeGamepadMask -// parameter is a bitfield with bits set for each controller present up to a maximum of 4 (0xF). +// these will be sent as controller 0 regardless of the controllerNumber parameter. +// +// The activeGamepadMask parameter is a bitfield with bits set for each controller present. +// On GFE, activeGamepadMask is limited to a maximum of 4 (0xF). On Sunshine, it is limited to 16 (0xFFFF). int LiSendMultiControllerEvent(short controllerNumber, short activeGamepadMask, int buttonFlags, unsigned char leftTrigger, unsigned char rightTrigger, short leftStickX, short leftStickY, short rightStickX, short rightStickY);