From 67d5c52a3be54fc74c853d0bc2d00cad7ee43169 Mon Sep 17 00:00:00 2001 From: Robert Fisk Date: Sun, 7 Jan 2018 09:19:24 +1300 Subject: [PATCH] Tweaks to mouse jump detection --- Upstream/Inc/build_config.h | 4 ++-- Upstream/Src/upstream_hid_botdetect.c | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Upstream/Inc/build_config.h b/Upstream/Inc/build_config.h index db425ec..cd5c7cf 100644 --- a/Upstream/Inc/build_config.h +++ b/Upstream/Inc/build_config.h @@ -43,7 +43,7 @@ #ifdef CONFIG_MOUSE_BOT_DETECT_ENABLED //----------------------------------------------------------- //Adjust this threshold first to tune mouse bot detection. Lower values = more sensitive - #define MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_COUNT 20 + #define MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_COUNT 10 //??????? //----------------------------------------------------------- @@ -53,7 +53,7 @@ #define MOUSE_BOTDETECT_VELOCITY_MATCH_ERROR 6 #define MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS 5 - #define MOUSE_BOTDETECT_MOVEMENT_VELOCITY_THRESHOLD (5 * MOUSE_BOTDETECT_VELOCITY_MULTIPLIER) + #define MOUSE_BOTDETECT_MOVEMENT_VELOCITY_THRESHOLD (10 * MOUSE_BOTDETECT_VELOCITY_MULTIPLIER) #endif //Configuration common to all bot detectors diff --git a/Upstream/Src/upstream_hid_botdetect.c b/Upstream/Src/upstream_hid_botdetect.c index 42ba687..0ab15ea 100644 --- a/Upstream/Src/upstream_hid_botdetect.c +++ b/Upstream/Src/upstream_hid_botdetect.c @@ -387,7 +387,6 @@ void Upstream_HID_BotDetectMouse(uint8_t* mouseInData) { uint32_t i; uint32_t now = HAL_GetTick(); - uint32_t moveDelayPeriods; uint32_t velocity; int8_t mouseX; int8_t mouseY; @@ -403,29 +402,26 @@ void Upstream_HID_BotDetectMouse(uint8_t* mouseInData) mouseY = mouseInData[2]; velocity = (sqrtf(((int32_t)mouseX * mouseX) + ((int32_t)mouseY * mouseY))) * MOUSE_BOTDETECT_VELOCITY_MULTIPLIER; //Multiply floating-point sqrt result to avoid integer rounding errors - moveDelayPeriods = (now - LastMouseMoveTime + (HID_FS_BINTERVAL / 2)) / HID_FS_BINTERVAL; //Number of poll intervals since last movement - if (moveDelayPeriods > MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS) //Did the mouse stop moving? + //Jump detection + if (MouseIsMoving) { - moveDelayPeriods = MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS; - if (MouseIsMoving) //Jump detection + if ((now - LastMouseMoveTime) > ((MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS * HID_FS_BINTERVAL) - (HID_FS_BINTERVAL / 2))) //Did the mouse stop moving? { MouseIsMoving = 0; - if (((LastMouseMoveTime - LastMouseMoveBeginTime + (HID_FS_BINTERVAL / 2)) / HID_FS_BINTERVAL) < MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS) + if ((LastMouseMoveTime - LastMouseMoveBeginTime) < ((MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS * HID_FS_BINTERVAL) - (HID_FS_BINTERVAL / 2))) { Upstream_HID_BotDetectMouse_DoLockout(); } } } - velocity = velocity / moveDelayPeriods; if (velocity != 0) { - LastMouseMoveTime = now; - //Jump detection + LastMouseMoveTime = now; if ((MouseIsMoving == 0) && (velocity > MOUSE_BOTDETECT_MOVEMENT_VELOCITY_THRESHOLD)) { MouseIsMoving = 1;