From d79075eb0702ad9e7812704071bb88044eb8a35b Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Bernon?= Date: Wed, 21 Dec 2022 12:32:07 +0100 Subject: [PATCH] windows.gaming.input: Fix infinite effect duration scaling. --- dlls/dinput/tests/force_feedback.c | 9 --------- dlls/windows.gaming.input/force_feedback.c | 16 ++++++++-------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/dlls/dinput/tests/force_feedback.c b/dlls/dinput/tests/force_feedback.c index f6157a84df7..6fdfa20c130 100644 --- a/dlls/dinput/tests/force_feedback.c +++ b/dlls/dinput/tests/force_feedback.c @@ -5884,21 +5884,12 @@ static void test_windows_gaming_input(void) .report_len = 6, .report_buf = {10,0x01,0xe8,0x03,0xa0,0x0f}, }, - /* update effect (wine) */ - { - .code = IOCTL_HID_WRITE_REPORT, - .report_id = 3, - .report_len = 18, - .report_buf = {3,0x01,0x05,0x04,0x8f,0xe4,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x4e,0x01,0x00,0x00}, - .todo = TRUE, .wine_only = TRUE, - }, /* update effect */ { .code = IOCTL_HID_WRITE_REPORT, .report_id = 3, .report_len = 18, .report_buf = {3,0x01,0x05,0x04,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x4e,0x01,0x00,0x00}, - .todo = TRUE, }, }; struct hid_expect expect_create_ramp_neg[] = diff --git a/dlls/windows.gaming.input/force_feedback.c b/dlls/windows.gaming.input/force_feedback.c index f7a233b46d4..d404934c3a7 100644 --- a/dlls/windows.gaming.input/force_feedback.c +++ b/dlls/windows.gaming.input/force_feedback.c @@ -124,8 +124,8 @@ static HRESULT WINAPI effect_impl_put_Parameters( IWineForceFeedbackEffectImpl * case WineForceFeedbackEffectType_Constant: impl->repeat_count = params.constant.repeat_count; impl->constant_force.lMagnitude = round( params.constant.gain * params.constant.direction.X * 10000 ); - impl->params.dwDuration = params.constant.duration.Duration / 10; - impl->params.dwStartDelay = params.constant.start_delay.Duration / 10; + impl->params.dwDuration = min( max( params.constant.duration.Duration / 10, 0 ), INFINITE ); + impl->params.dwStartDelay = min( max( params.constant.start_delay.Duration / 10, 0 ), INFINITE ); if (impl->axes[count] == DIJOFS_X) impl->directions[count++] = round( -params.constant.direction.X * 10000 ); if (impl->axes[count] == DIJOFS_Y) impl->directions[count++] = round( -params.constant.direction.Y * 10000 ); if (impl->axes[count] == DIJOFS_Z) impl->directions[count++] = round( -params.constant.direction.Z * 10000 ); @@ -135,8 +135,8 @@ static HRESULT WINAPI effect_impl_put_Parameters( IWineForceFeedbackEffectImpl * impl->repeat_count = params.ramp.repeat_count; impl->ramp_force.lStart = round( params.ramp.gain * params.ramp.start_vector.X * 10000 ); impl->ramp_force.lEnd = round( params.ramp.gain * params.ramp.end_vector.X * 10000 ); - impl->params.dwDuration = params.ramp.duration.Duration / 10; - impl->params.dwStartDelay = params.ramp.start_delay.Duration / 10; + impl->params.dwDuration = min( max( params.ramp.duration.Duration / 10, 0 ), INFINITE ); + impl->params.dwStartDelay = min( max( params.ramp.start_delay.Duration / 10, 0 ), INFINITE ); if (impl->axes[count] == DIJOFS_X) impl->directions[count++] = round( -params.ramp.start_vector.X * 10000 ); if (impl->axes[count] == DIJOFS_Y) impl->directions[count++] = round( -params.ramp.start_vector.Y * 10000 ); if (impl->axes[count] == DIJOFS_Z) impl->directions[count++] = round( -params.ramp.start_vector.Z * 10000 ); @@ -152,8 +152,8 @@ static HRESULT WINAPI effect_impl_put_Parameters( IWineForceFeedbackEffectImpl * impl->periodic.dwPeriod = 1000000 / params.periodic.frequency; impl->periodic.dwPhase = round( params.periodic.phase * 36000 ); impl->periodic.lOffset = round( params.periodic.bias * 10000 ); - impl->params.dwDuration = params.periodic.duration.Duration / 10; - impl->params.dwStartDelay = params.periodic.start_delay.Duration / 10; + impl->params.dwDuration = min( max( params.periodic.duration.Duration / 10, 0 ), INFINITE ); + impl->params.dwStartDelay = min( max( params.periodic.start_delay.Duration / 10, 0 ), INFINITE ); if (impl->axes[count] == DIJOFS_X) impl->directions[count++] = round( -params.periodic.direction.X * 10000 ); if (impl->axes[count] == DIJOFS_Y) impl->directions[count++] = round( -params.periodic.direction.Y * 10000 ); if (impl->axes[count] == DIJOFS_Z) impl->directions[count++] = round( -params.periodic.direction.Z * 10000 ); @@ -181,9 +181,9 @@ static HRESULT WINAPI effect_impl_put_Parameters( IWineForceFeedbackEffectImpl * if (!envelope) impl->params.lpEnvelope = NULL; else { - impl->envelope.dwAttackTime = envelope->attack_duration.Duration / 10; + impl->envelope.dwAttackTime = min( max( envelope->attack_duration.Duration / 10, 0 ), INFINITE ); impl->envelope.dwAttackLevel = round( envelope->attack_gain * 10000 ); - impl->envelope.dwFadeTime = impl->params.dwDuration - envelope->release_duration.Duration / 10; + impl->envelope.dwFadeTime = impl->params.dwDuration - min( max( envelope->release_duration.Duration / 10, 0 ), INFINITE ); impl->envelope.dwFadeLevel = round( envelope->release_gain * 10000 ); impl->params.lpEnvelope = &impl->envelope; } -- 2.11.4.GIT