From 54b321ad6e4cccdb2ea847b66da58359661084a4 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 16 Feb 2018 18:57:45 +0100 Subject: [PATCH] Added memory flushing to getMouseData function, added cooldown to mouse mode changing --- source/ControllerPatcher.cpp | 12 ++++++++++++ source/ControllerPatcherDefs.h | 1 + source/patcher/ControllerPatcherUtils.cpp | 10 +++++++--- source/utils/CPRetainVars.cpp | 2 ++ source/utils/CPRetainVars.hpp | 2 ++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/source/ControllerPatcher.cpp b/source/ControllerPatcher.cpp index 31cea9d..ddec2aa 100644 --- a/source/ControllerPatcher.cpp +++ b/source/ControllerPatcher.cpp @@ -741,6 +741,9 @@ HID_Mouse_Data * ControllerPatcher::getMouseData(){ } if(padinfo->type == CM_Type_Mouse){ result = &(gHID_Devices[gMouseSlot].pad_data[padinfo->pad].data_union.mouse.cur_mouse_data); + DCFlushRange(&result,sizeof(result)); + DCInvalidateRange(&result,sizeof(result)); + break; } } return result; @@ -766,12 +769,21 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcher::gettingInputAllDevices(Inp s32 newhid = (1 << i); s32 deviceslot = ControllerPatcherUtils::getDeviceSlot(newhid); if(deviceslot < 0) continue; + + output[result].type = CM_Type_Controller; + DeviceInfo * deviceinfo = &(output[result].device_info); InputButtonData * buttondata = output[result].button_data; deviceinfo->slotdata.deviceslot = deviceslot; deviceinfo->slotdata.hidmask = newhid; + if(newhid == gHID_LIST_MOUSE){ + output[result].type = CM_Type_Mouse; + } else if(newhid == gHID_LIST_KEYBOARD){ + output[result].type = CM_Type_Keyboard; + } + deviceinfo->vidpid.vid = config_controller[deviceslot][CONTRPS_VID][0] * 0x100 + config_controller[deviceslot][CONTRPS_VID][1]; deviceinfo->vidpid.pid = config_controller[deviceslot][CONTRPS_PID][0] * 0x100 + config_controller[deviceslot][CONTRPS_PID][1]; diff --git a/source/ControllerPatcherDefs.h b/source/ControllerPatcherDefs.h index f558624..5953416 100644 --- a/source/ControllerPatcherDefs.h +++ b/source/ControllerPatcherDefs.h @@ -359,6 +359,7 @@ typedef struct _InputButtonData{ */ typedef struct _InputData{ DeviceInfo device_info; /**< Infos about the device where the data is coming from */ + ControllerMapping_Type_Defines type; InputButtonData button_data[HID_MAX_PADS_COUNT]; }InputData; diff --git a/source/patcher/ControllerPatcherUtils.cpp b/source/patcher/ControllerPatcherUtils.cpp index ed9f570..f8f5145 100644 --- a/source/patcher/ControllerPatcherUtils.cpp +++ b/source/patcher/ControllerPatcherUtils.cpp @@ -613,15 +613,19 @@ CONTROLLER_PATCHER_RESULT_OR_ERROR ControllerPatcherUtils::checkAndSetMouseMode( if(hidmask & gHID_LIST_KEYBOARD){ u8 * cur_data = &data->data_union.controller.cur_hid_data[0]; u8 * last_data = &data->data_union.controller.last_hid_data[0]; - if((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) && ((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) != (isInKeyboardData(last_data,HID_KEYBOARD_BUTTON_F1) > 0))){ + if((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) && ((isInKeyboardData(cur_data,HID_KEYBOARD_BUTTON_F1) > 0) != (isInKeyboardData(last_data,HID_KEYBOARD_BUTTON_F1) > 0)) && gMouseModeCoolDown == 0){ + gMouseModeCoolDown = 60; if(gHID_Mouse_Mode == HID_MOUSE_MODE_AIM){ gHID_Mouse_Mode = HID_MOUSE_MODE_TOUCH; - if(HID_DEBUG){ log_printf("ControllerPatcherUtils::checkAndSetMouseMode(line %d): Mouse mode changed! to touch \n",__LINE__); } + //log_printf("ControllerPatcherUtils::checkAndSetMouseMode(line %d): Mouse mode changed! to touch \n",__LINE__); }else if(gHID_Mouse_Mode == HID_MOUSE_MODE_TOUCH){ - if(HID_DEBUG){ log_printf("ControllerPatcherUtils::checkAndSetMouseMode(line %d): Mouse mode changed! to aim \n",__LINE__); } + //log_printf("ControllerPatcherUtils::checkAndSetMouseMode(line %d): Mouse mode changed! to aim \n",__LINE__); gHID_Mouse_Mode = HID_MOUSE_MODE_AIM; } } + if(gMouseModeCoolDown > 0){ + gMouseModeCoolDown--; + } } return CONTROLLER_PATCHER_ERROR_NONE; } diff --git a/source/utils/CPRetainVars.cpp b/source/utils/CPRetainVars.cpp index 8d34115..fdb1b22 100644 --- a/source/utils/CPRetainVars.cpp +++ b/source/utils/CPRetainVars.cpp @@ -33,6 +33,8 @@ HID_DEVICE_DATA gHID_Devices[gHIDMaxDevices] __attribute__((section(".data"))); u8 gHID_Mouse_Mode __attribute__((section(".data"))) = HID_MOUSE_MODE_TOUCH; +u8 gMouseModeCoolDown __attribute__((section(".data"))) = 0; + u32 gGamePadValues[CONTRPS_MAX_VALUE] __attribute__((section(".data"))); u8 config_controller[gHIDMaxDevices][CONTRPS_MAX_VALUE][2] __attribute__((section(".data"))); diff --git a/source/utils/CPRetainVars.hpp b/source/utils/CPRetainVars.hpp index 7f804bc..212deea 100644 --- a/source/utils/CPRetainVars.hpp +++ b/source/utils/CPRetainVars.hpp @@ -36,6 +36,8 @@ extern HID_DEVICE_DATA gHID_Devices[gHIDMaxDevices]; extern u8 gHID_Mouse_Mode; +extern u8 gMouseModeCoolDown; + extern u32 gGamePadValues[CONTRPS_MAX_VALUE]; extern u8 config_controller[gHIDMaxDevices][CONTRPS_MAX_VALUE][2];