Using the sampling callback instead of patching the KPADRead(Ex) and KPADGetUnifiedWpadStatus function.

This fixes the buttons pressed for unity games. This may break something, needs further testing.
This commit is contained in:
Maschell 2017-04-23 15:23:41 +02:00
parent 6b9cae49ed
commit 9de3b8be6d
3 changed files with 16 additions and 61 deletions

@ -1 +1 @@
Subproject commit 913ce2b31505f82b8b8e7d3727391bfb731992c7
Subproject commit a72f8e3879083924764fee11f9154ecc12aaa084

@ -1 +1 @@
Subproject commit a136b12c5225d932a73c299cb0edb638930f2d67
Subproject commit 64f225382a6b832458e3bcf054418c23edce4f1b

View File

@ -30,6 +30,8 @@
#include "controller_patcher/ConfigReader.hpp"
#include "controller_patcher/config/ConfigValues.hpp"
typedef void (* WPADSamplingCallback )( s32 chan );
DECL(void, GX2CopyColorBufferToScanBuffer, const GX2ColorBuffer *colorBuffer, s32 scan_target){
if(gHIDCurrentDevice & gHID_LIST_MOUSE && gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH) {
HID_Mouse_Data * mouse_data = ControllerPatcher::getMouseData();
@ -50,6 +52,7 @@ DECL(void, __PPCExit, void){
memset(gWPADConnectCallback,0,sizeof(gWPADConnectCallback));
memset(gKPADConnectCallback,0,sizeof(gKPADConnectCallback));
memset(gExtensionCallback,0,sizeof(gExtensionCallback));
gSamplingCallback = 0;
gCallbackCooldown = 0;
real___PPCExit();
@ -57,6 +60,10 @@ DECL(void, __PPCExit, void){
DECL(s32, VPADRead, s32 chan, VPADData *buffer, u32 buffer_size, s32 *error) {
s32 result = real_VPADRead(chan, buffer, buffer_size, error);
//A keyboard only sends data when the state changes. We force it to call the sampling callback on each frame!
if((gHIDCurrentDevice & gHID_LIST_KEYBOARD) == gHID_LIST_KEYBOARD){
ControllerPatcher::doSamplingForDeviceSlot(gHID_SLOT_KEYBOARD);
}
if(result > 0 && (buffer[0].btns_h & VPAD_BUTTON_TV) && gCallbackCooldown == 0){
gCallbackCooldown = 0xFF;
@ -117,42 +124,6 @@ DECL(s32, VPADRead, s32 chan, VPADData *buffer, u32 buffer_size, s32 *error) {
return result;
}
DECL(s32, KPADRead, s32 chan, KPADData * buffer, u32 buffer_count){
if(buffer_count > 0){
s32 res = ControllerPatcher::setProControllerDataFromHID((void*)&buffer[0],chan,PRO_CONTROLLER_MODE_KPADDATA); //Check if a controller is connected and fill the buffer with data.
if(res >= 0){
if(buffer[0].pro.btns_h & WPAD_PRO_BUTTON_HOME){ //Pro controller doesn't work in home menu so it's okay to let this enabled.
OSSendAppSwitchRequest(5,0,0); //Open the home menu!
}
return 1; // We have saved one set of data. Should be enough because its no wireless communication.
}else if(res != CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED){
//log_printf("KPADRead error: %d\n",res);
}
}
return real_KPADRead(chan,buffer,buffer_count);
}
DECL(s32,KPADReadEx, s32 chan, KPADData * buffer, u32 buffer_count, s32 *error ){
if(buffer_count > 0){
s32 res = ControllerPatcher::setProControllerDataFromHID((void*)&buffer[0],chan,PRO_CONTROLLER_MODE_KPADDATA); //Check if a controller is connected and fill the buffer with data.
if(res >= 0){
//if(chan == 0) log_printf("my %08X %08X %08X\n",buffer->pro.btns_h,buffer->pro.btns_d,buffer->pro.btns_r);
if(buffer[0].pro.btns_h & WPAD_PRO_BUTTON_HOME){ //Pro controller doesn't work in home menu so it's okay to let this enabled.
OSSendAppSwitchRequest(5,0,0); //Open the home menu!
}
if(error != NULL){
*error = 0;
}
return 1; // We have saved one set of data. Should be enough because its no wireless communication.
}else if(res != CONTROLLER_PATCHER_ERROR_MAPPING_DISABLED){
//log_printf("KPADReadEx error: %d\n",res);
}
}
return real_KPADReadEx(chan,buffer,buffer_count,error);
}
DECL(s32, WPADProbe, s32 chan, u32 * result ){
if( (chan == 0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) ||
(chan == 1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
@ -223,29 +194,26 @@ DECL(u8, WPADGetBatteryLevel, s32 chan){
//In case a game relies on this...
DECL(u32, WPADGetDataFormat, s32 chan){
u32 result = real_WPADGetDataFormat(chan);
//log_printf("WPADGetDataFormat chan: %d result: %d\n",chan,result);
if((chan == 0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) ||
(chan == 1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
(chan == 2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
(chan == 3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))){
result = WPAD_FMT_PRO_CONTROLLER;
return WPAD_FMT_PRO_CONTROLLER;
}
return result;
return real_WPADGetDataFormat(chan);
}
DECL(s32, WPADSetDataFormat, s32 chan, u32 fmt){
s32 result = real_WPADSetDataFormat(chan,fmt);
s32 result = -1;
if((chan == 0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) ||
(chan == 1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
(chan == 2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
(chan == 3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))){
if(fmt == WPAD_FMT_PRO_CONTROLLER ){
result = 0;
}
real_WPADSetDataFormat(chan,WPAD_FMT_PRO_CONTROLLER);
result = 0;
}
// log_printf("WPADSetDataFormat chan: %d fmt %d result: %d\n",chan,fmt,result);
result = real_WPADSetDataFormat(chan,fmt);
return result;
}
@ -257,17 +225,7 @@ DECL(void,WPADRead,s32 chan, WPADReadData *data ){
ControllerPatcher::setProControllerDataFromHID((void*)data,chan,PRO_CONTROLLER_MODE_WPADReadData);
}else{
real_WPADRead(chan,data);
}
}
DECL(void,KPADGetUnifiedWpadStatus,s32 chan, KPADUnifiedWpadData * data, void * unknown ){
if((chan == 0 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro1)) ||
(chan == 1 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro2)) ||
(chan == 2 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro3)) ||
(chan == 3 && ControllerPatcher::isControllerConnectedAndActive(UController_Type_Pro4))){
ControllerPatcher::setProControllerDataFromHID((void*)data,chan,PRO_CONTROLLER_MODE_WPADReadData);
}else{
real_KPADGetUnifiedWpadStatus(chan,data,unknown);
}
}
@ -290,11 +248,8 @@ hooks_magic_t method_hooks_hid_controller[] __attribute__((section(".data"))) =
MAKE_MAGIC(__PPCExit, LIB_CORE_INIT, STATIC_FUNCTION),
MAKE_MAGIC(WPADGetBatteryLevel, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(KPADSetConnectCallback, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(WPADSetConnectCallback, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(WPADSetConnectCallback, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(WPADSetExtensionCallback, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(KPADGetUnifiedWpadStatus, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(KPADRead, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(KPADReadEx, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(WPADRead, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(WPADGetDataFormat, LIB_PADSCORE, DYNAMIC_FUNCTION),
MAKE_MAGIC(WPADSetDataFormat, LIB_PADSCORE, DYNAMIC_FUNCTION),