Improve button combo detection

This commit is contained in:
Maschell 2023-01-26 16:20:13 +01:00
parent 028946cd50
commit 378654f668
3 changed files with 32 additions and 146 deletions

View File

@ -83,6 +83,7 @@ void RequestScreenshot() {
} }
} }
static uint32_t sWasHoldForXFrameGamePad;
DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error) { DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buffer_size, VPADReadError *error) {
VPADReadError real_error; VPADReadError real_error;
int32_t result = real_VPADRead(chan, buffer, buffer_size, &real_error); int32_t result = real_VPADRead(chan, buffer, buffer_size, &real_error);
@ -94,12 +95,22 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buf
if (VPADGetButtonProcMode(chan) == 1) { if (VPADGetButtonProcMode(chan) == 1) {
end = result; end = result;
} }
bool found = false;
for (uint32_t i = 0; i < end; i++) { for (uint32_t i = 0; i < end; i++) {
if (((buffer[i].trigger & 0x000FFFFF) == gButtonCombo)) { if ((((buffer[i].hold & 0x000FFFFF) & gButtonCombo) == gButtonCombo)) {
RequestScreenshot(); found = true;
break; break;
} }
} }
if (found) {
if (sWasHoldForXFrameGamePad == 0) {
RequestScreenshot();
}
sWasHoldForXFrameGamePad++;
} else {
sWasHoldForXFrameGamePad = 0;
}
} }
} }
@ -110,36 +121,42 @@ DECL_FUNCTION(int32_t, VPADRead, VPADChan chan, VPADStatus *buffer, uint32_t buf
} }
static uint32_t sWPADLastButtonHold[4]; static uint32_t sWPADLastButtonHold[4];
static uint32_t sWasHoldForXFrame[4];
DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatusProController *data) { DECL_FUNCTION(void, WPADRead, WPADChan chan, WPADStatusProController *data) {
real_WPADRead(chan, data); real_WPADRead(chan, data);
if (gEnabled && chan >= 0 && chan < 4) { if (gEnabled && chan >= 0 && chan < 4) {
if (data[0].err == 0) { if (data[0].err == 0) {
if (data[0].extensionType != 0xFF) { if (data[0].extensionType != 0xFF) {
uint32_t curButtonHold = 0; uint32_t curButtonHold = 0;
uint32_t buttonComboConverted = 0;
if (data[0].extensionType == WPAD_EXT_CORE || data[0].extensionType == WPAD_EXT_NUNCHUK) { if (data[0].extensionType == WPAD_EXT_CORE || data[0].extensionType == WPAD_EXT_NUNCHUK) {
buttonComboConverted = remapVPADtoWiimote(gButtonCombo);
// button data is in the first 2 bytes for wiimotes // button data is in the first 2 bytes for wiimotes
curButtonHold = ((uint16_t *) data)[0]; curButtonHold = remapWiiMoteButtons(((uint16_t *) data)[0]);
} else if (data[0].extensionType == WPAD_EXT_CLASSIC) { } else if (data[0].extensionType == WPAD_EXT_CLASSIC) {
buttonComboConverted = remapVPADtoClassic(gButtonCombo); curButtonHold = remapClassicButtons(((uint32_t *) data)[10] & 0xFFFF);
curButtonHold = (((uint32_t *) data)[10] & 0xFFFF);
} else if (data[0].extensionType == WPAD_EXT_PRO_CONTROLLER) { } else if (data[0].extensionType == WPAD_EXT_PRO_CONTROLLER) {
buttonComboConverted = remapVPADtoPro(gButtonCombo); curButtonHold = remapProButtons(data[0].buttons);
curButtonHold = data[0].buttons;
} }
uint32_t curButtonTrigger = (curButtonHold & (~(sWPADLastButtonHold[chan]))); uint32_t curButtonTrigger = (curButtonHold & (~(sWPADLastButtonHold[chan])));
bool forceScreenshot = false; bool takeScreenshot = false;
if (gReservedBitUsage && data[0].extensionType == WPAD_EXT_PRO_CONTROLLER) { if (gReservedBitUsage && curButtonTrigger & VPAD_BUTTON_RESERVED_BIT) {
if (curButtonTrigger == WPAD_PRO_RESERVED) { takeScreenshot = true;
forceScreenshot = true; }
if (!takeScreenshot) {
if ((gButtonCombo != 0 && (curButtonHold & gButtonCombo) == gButtonCombo)) {
if (sWasHoldForXFrame[chan] == 0) {
takeScreenshot = true;
}
sWasHoldForXFrame[chan]++;
} else {
sWasHoldForXFrame[chan] = 0;
} }
} }
if (forceScreenshot || (buttonComboConverted != 0 && curButtonTrigger == buttonComboConverted)) { if (takeScreenshot) {
RequestScreenshot(); RequestScreenshot();
} }

View File

@ -1,132 +1,5 @@
#include "input.h" #include "input.h"
uint32_t remapVPADtoWiimote(uint32_t buttons) {
uint32_t conv_buttons = 0;
if (buttons & VPAD_BUTTON_A) {
conv_buttons |= WPAD_BUTTON_A;
}
if (buttons & VPAD_BUTTON_B) {
conv_buttons |= WPAD_BUTTON_B;
}
if (buttons & VPAD_BUTTON_UP) {
conv_buttons |= WPAD_BUTTON_UP;
}
if (buttons & VPAD_BUTTON_DOWN) {
conv_buttons |= WPAD_BUTTON_DOWN;
}
if (buttons & VPAD_BUTTON_LEFT) {
conv_buttons |= WPAD_BUTTON_LEFT;
}
if (buttons & VPAD_BUTTON_RIGHT) {
conv_buttons |= WPAD_BUTTON_RIGHT;
}
if (buttons & VPAD_BUTTON_PLUS) {
conv_buttons |= WPAD_BUTTON_PLUS;
}
if (buttons & VPAD_BUTTON_MINUS) {
conv_buttons |= WPAD_BUTTON_MINUS;
}
return conv_buttons;
}
uint32_t remapVPADtoClassic(uint32_t buttons) {
uint32_t conv_buttons = 0;
if (buttons & VPAD_BUTTON_A) {
conv_buttons |= WPAD_CLASSIC_BUTTON_A;
}
if (buttons & VPAD_BUTTON_B) {
conv_buttons |= WPAD_CLASSIC_BUTTON_B;
}
if (buttons & VPAD_BUTTON_X) {
conv_buttons |= WPAD_CLASSIC_BUTTON_X;
}
if (buttons & VPAD_BUTTON_Y) {
conv_buttons |= WPAD_CLASSIC_BUTTON_Y;
}
if (buttons & VPAD_BUTTON_L) {
conv_buttons |= WPAD_CLASSIC_BUTTON_L;
}
if (buttons & VPAD_BUTTON_R) {
conv_buttons |= WPAD_CLASSIC_BUTTON_R;
}
if (buttons & VPAD_BUTTON_ZL) {
conv_buttons |= WPAD_CLASSIC_BUTTON_ZL;
}
if (buttons & VPAD_BUTTON_ZR) {
conv_buttons |= WPAD_CLASSIC_BUTTON_ZR;
}
if (buttons & VPAD_BUTTON_UP) {
conv_buttons |= WPAD_CLASSIC_BUTTON_UP;
}
if (buttons & VPAD_BUTTON_DOWN) {
conv_buttons |= WPAD_CLASSIC_BUTTON_DOWN;
}
if (buttons & VPAD_BUTTON_LEFT) {
conv_buttons |= WPAD_CLASSIC_BUTTON_LEFT;
}
if (buttons & VPAD_BUTTON_RIGHT) {
conv_buttons |= WPAD_CLASSIC_BUTTON_RIGHT;
}
if (buttons & VPAD_BUTTON_PLUS) {
conv_buttons |= WPAD_CLASSIC_BUTTON_PLUS;
}
if (buttons & VPAD_BUTTON_MINUS) {
conv_buttons |= WPAD_CLASSIC_BUTTON_MINUS;
}
return conv_buttons;
}
uint32_t remapVPADtoPro(uint32_t buttons) {
uint32_t conv_buttons = 0;
if (buttons & VPAD_BUTTON_A) {
conv_buttons |= WPAD_PRO_BUTTON_A;
}
if (buttons & VPAD_BUTTON_B) {
conv_buttons |= WPAD_PRO_BUTTON_B;
}
if (buttons & VPAD_BUTTON_X) {
conv_buttons |= WPAD_PRO_BUTTON_X;
}
if (buttons & VPAD_BUTTON_Y) {
conv_buttons |= WPAD_PRO_BUTTON_Y;
}
if (buttons & VPAD_BUTTON_L) {
conv_buttons |= WPAD_PRO_TRIGGER_L;
}
if (buttons & VPAD_BUTTON_R) {
conv_buttons |= WPAD_PRO_TRIGGER_R;
}
if (buttons & VPAD_BUTTON_ZL) {
conv_buttons |= WPAD_PRO_TRIGGER_ZL;
}
if (buttons & VPAD_BUTTON_ZR) {
conv_buttons |= WPAD_PRO_TRIGGER_ZR;
}
if (buttons & VPAD_BUTTON_UP) {
conv_buttons |= WPAD_PRO_BUTTON_UP;
}
if (buttons & VPAD_BUTTON_DOWN) {
conv_buttons |= WPAD_PRO_BUTTON_DOWN;
}
if (buttons & VPAD_BUTTON_LEFT) {
conv_buttons |= WPAD_PRO_BUTTON_LEFT;
}
if (buttons & VPAD_BUTTON_RIGHT) {
conv_buttons |= WPAD_PRO_BUTTON_RIGHT;
}
if (buttons & VPAD_BUTTON_PLUS) {
conv_buttons |= WPAD_PRO_BUTTON_PLUS;
}
if (buttons & VPAD_BUTTON_MINUS) {
conv_buttons |= WPAD_PRO_BUTTON_MINUS;
}
if (buttons & VPAD_BUTTON_RESERVED_BIT) {
conv_buttons |= WPAD_PRO_RESERVED;
}
return conv_buttons;
}
uint32_t remapWiiMoteButtons(uint32_t buttons) { uint32_t remapWiiMoteButtons(uint32_t buttons) {
uint32_t conv_buttons = 0; uint32_t conv_buttons = 0;

View File

@ -6,10 +6,6 @@
#define VPAD_BUTTON_RESERVED_BIT 0x80000 #define VPAD_BUTTON_RESERVED_BIT 0x80000
uint32_t remapVPADtoWiimote(uint32_t buttons);
uint32_t remapVPADtoClassic(uint32_t buttons);
uint32_t remapVPADtoPro(uint32_t buttons);
uint32_t remapWiiMoteButtons(uint32_t buttons); uint32_t remapWiiMoteButtons(uint32_t buttons);
uint32_t remapClassicButtons(uint32_t buttons); uint32_t remapClassicButtons(uint32_t buttons);
uint32_t remapProButtons(uint32_t buttons); uint32_t remapProButtons(uint32_t buttons);