102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
force_feedback.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
9#include <math.h>
10#include <stdarg.h>
11#include <string.h>
12
13// Original pcdogs.exe: 0x41a2a0
14// Enumerates attached force-feedback joysticks and sets availability from the collected count. The flag records discovery rather than effect readiness, and enumeration status and output capacity are unchecked.
15int32_t DInput_EnumerateForceFeedbackJoysticks(IDirectInputA *direct_input, GUID *device_guid_buffer)
16{
17 struct DInput_DeviceEnumContext enum_context = {.guid_list = device_guid_buffer};
18 direct_input->lpVtbl->EnumDevices(direct_input, DIDEVTYPE_JOYSTICK, DInput_EnumJoystickDeviceCallback,
19 &enum_context, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK);
20 g_dinputForceFeedbackAvailable = enum_context.count != 0;
21 return enum_context.count;
22}
23
24// Original pcdogs.exe: 0x41a620
25// Builds constant-force parameters using the configured magnitude scale and submits them to the cached effect. Availability alone guards the call, so partial initialization can leave the effect pointer null or stale.
26HRESULT DInput_SetConstantForceEffect(LONG direction_x, LONG direction_y_and_base_magnitude, DWORD duration_microseconds)
27{
29 return 0;
30
31 DICONSTANTFORCE constant_force;
32 constant_force.lMagnitude =
33 // The Y direction also supplies the base force magnitude.
34 __ftol_msvc((long double)direction_y_and_base_magnitude * (long double)g_forceFeedbackScale);
35 LONG direction_vector[2] = {direction_x, direction_y_and_base_magnitude};
36 // Unspecified effect fields remain zero.
37 DIEFFECT effect_params;
38 __builtin_memset(&effect_params, 0, sizeof(DIEFFECT));
39 effect_params.lpvTypeSpecificParams = &constant_force;
40 IDirectInputEffect *constant_force_effect = g_pDInputConstantForceEffect;
41 effect_params.dwDuration = duration_microseconds;
42 effect_params.dwSize = sizeof(DIEFFECT);
43 effect_params.dwFlags = DIEFF_OBJECTOFFSETS | DIEFF_CARTESIAN;
44 effect_params.cAxes = 2;
45 effect_params.rglDirection = direction_vector;
46 effect_params.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
47
48 // Availability alone does not ensure that the cached effect is valid.
49 return constant_force_effect->lpVtbl->SetParameters(constant_force_effect, &effect_params,
50 DIEP_START | DIEP_DURATION | DIEP_DIRECTION | DIEP_TYPESPECIFICPARAMS);
51}
52
53// Original pcdogs.exe: 0x41a6d0
54// Starts the cached constant-force effect once when discovery availability is set. It does not validate the effect pointer, which can remain null or stale after setup failure.
56{
57 int32_t force_feedback_available = g_dinputForceFeedbackAvailable;
58
59 if (!force_feedback_available)
60 return force_feedback_available;
61
62 IDirectInputEffect *constant_force_effect = g_pDInputConstantForceEffect;
63
64 return constant_force_effect->lpVtbl->Start(constant_force_effect, 1, 0);
65}
66
67// Original pcdogs.exe: 0x41a6f0
68// Sets the global scale used to convert requested force-feedback magnitude.
70{
72}
73
74// Original pcdogs.exe: 0x43dc70
75// Triggers constant-force rumble when the game and input settings permit it, using strength selection, Q12 magnitude, and duration units. The source identifier is unused.
76int32_t Input_TriggerRumbleIfAllowed(int32_t source_id, BOOL full_strength, int32_t magnitude_fp12, int32_t duration_units)
77{
78 (void)source_id;
79 int32_t result = Settings_GetRumbleSuppressFlag();
80
81 if (result)
82 return result;
83
84 long double normalized_magnitude = (long double)magnitude_fp12 * (long double)INPUT_Q12_RECIPROCAL;
85 long double scaled_force_magnitude;
86
87 scaled_force_magnitude = full_strength ? normalized_magnitude * (long double)INPUT_RUMBLE_FULL_MAGNITUDE : normalized_magnitude * (long double)INPUT_RUMBLE_HALF_MAGNITUDE;
88
89 DInput_SetConstantForceEffect(0, __ftol_msvc(scaled_force_magnitude), duration_units * INPUT_RUMBLE_DURATION_MICROSECONDS);
90
91 /* tailcall */
93}
void Input_SetForceFeedbackScale(float scale)
HRESULT DInput_SetConstantForceEffect(LONG direction_x, LONG direction_y_and_base_magnitude, DWORD duration_microseconds)
HRESULT DInput_StartConstantForceEffect()
int32_t DInput_EnumerateForceFeedbackJoysticks(IDirectInputA *direct_input, GUID *device_guid_buffer)
int32_t Input_TriggerRumbleIfAllowed(int32_t source_id, BOOL full_strength, int32_t magnitude_fp12, int32_t duration_units)
#define INPUT_Q12_RECIPROCAL
Definition constants.h:51
#define INPUT_RUMBLE_FULL_MAGNITUDE
Definition constants.h:52
#define INPUT_RUMBLE_HALF_MAGNITUDE
Definition constants.h:53
#define INPUT_RUMBLE_DURATION_MICROSECONDS
Definition constants.h:48
BOOL DInput_EnumJoystickDeviceCallback(DIDEVICEINSTANCEA const *device_instance, void *context)
Definition devices.c:88
#define g_pDInputConstantForceEffect
Definition globals.h:53
#define g_dinputForceFeedbackAvailable
Definition globals.h:129
int64_t __ftol_msvc(long double value)
int32_t Settings_GetRumbleSuppressFlag(void)
Definition preferences.c:77
#define g_forceFeedbackScale
Definition values.h:69