coastline 0.0.4
Loading...
Searching...
No Matches
input.h File Reference

The control bindings and the DirectInput devices of the PC port. More...

#include <windows.h>
#include <dinput.h>
#include "common/emulatedclock.h"
#include "common/inputbinding.h"
#include "common/inputpoll.h"
Include dependency graph for input.h:

Go to the source code of this file.

Classes

class  MouseDevice
 The mouse of the game. More...
struct  MouseMenuState
 The state of the menus the mouse and the arrows of the keyboard move. More...
struct  MouseInputState
 Mouse axes, accumulated movement, and buttons from input polling. More...
struct  InputControlName
 A control and its label in the menus. More...

Macros

#define DIRECTINPUT_VERSION   0x0500
 Select the DirectInput 5 declarations used by Boss Rally.
#define KEYBOARD_KEY_COUNT   256
 The number of keys of the state of a keyboard.
#define MOUSE_BUTTON_COUNT   4
 The number of buttons of the mouse the game reads.
#define JOYSTICK_CONTROL_BUTTON   0x100
 The control of a button of a game controller GetPressedJoystickControl() reports.
#define JOYSTICK_CONTROL_X_NEGATIVE   0x8000
 The control of the left of the X axis of a game controller.
#define JOYSTICK_CONTROL_X_POSITIVE   0x8100
 The control of the right of the X axis of a game controller.
#define JOYSTICK_CONTROL_Y_NEGATIVE   0x8200
 The control of the top of the Y axis of a game controller.
#define JOYSTICK_CONTROL_Y_POSITIVE   0x8300
 The control of the bottom of the Y axis of a game controller.
#define JOYSTICK_NAME_COUNT_A   10
 The number of entries of g_aJoystickButtonNamesA.
#define JOYSTICK_NAME_COUNT_B   134
 The number of entries of g_aJoystickButtonNamesB.
#define KEYBOARD_CONTROL_NAME_COUNT   120
 The number of keyboard control labels.

Functions

void UpdateMouseInput (void)
 Read the mouse for the main window.
int ShowInfoMessageBox (HWND hWnd, HRESULT hResult, const char *pszText)
 Show a message of the input with the caption of string 0xaa.
bool InitializeDirectInput (void)
 Add a user of DirectInput.
bool TryAcquireJoystickDevice (void)
 Acquire the DirectInput device of the game controller.
HRESULT SetJoystickPropertyDword (IDirectInputDevice2A *pDevice, REFGUID guidProperty, DWORD dwObject, DWORD dwHow, DWORD dwData)
 Set a property of a DIPROPDWORD on a DirectInput device.
HRESULT SetJoystickAxisRange (IDirectInputDevice2A *pDevice, REFGUID guidProperty, DWORD dwObject, DWORD dwHow, LONG lMin, LONG lMax)
 Set a property of a DIPROPRANGE on a DirectInput device.
void ReleaseKeyboardDevice (void)
 Drop a user of the keyboard device.
bool ShutdownDirectInput (void)
 Drop a user of DirectInput.
unsigned char IsInputBindingPressed (int nBinding)
 Read rising edges of an active binding and its keyboard alternatives.
unsigned char IsInputBindingHeld (int nBinding)
 Read an active binding and its keyboard alternatives.
void UpdateMouseButtonEdges (void)
 Find the buttons of the mouse that went down since the mouse was read before.
void PollInputAndUpdateEdges (void)
 Refresh keyboard and mouse button transitions for menu input.
bool WINAPI ResetMouseCursorToCenter (HWND hWnd)
 Put the cursor of the mouse in the centre of the screen and clear g_MouseMenuState.
int FindControlNameIndex (int nTable, int nCode)
 Find a control code in the keyboard or joystick label table.
void InitJoystickBindingNames (void)
 Fill the names of the controls of a game controller.
int GetPressedMouseButton (void)
 Read the buttons of the mouse and find the first one that went down.
int GetPressedJoystickControl (unsigned *pwControl)
 Read the game controller and find a control that is pressed, to bind it.
bool InitializeKeyboardDevice (void)
 Add a user of the keyboard.
HRESULT ReadKeyboardState (unsigned char *pabState)
 Read the state of the keyboard, acquiring the device again and reading once more when the input was lost.
void ClearKeyboardStateBuffers (void)
 Clear the state of the keyboard.
void UpdateKeyboardEdgeState (void)
 Find the keys that went down since the keyboard was read before.
void SetForceFeedbackMagnitude (LONG lMagnitude)
 Set both coefficients of the first spring of g_DiConditionEffect, and give the effect its new parameters when it exists.
HRESULT CreateForceFeedbackEffects (int nCoefficientX, int nCoefficientY)
 Create the condition effect, a spring on X and Y that lasts until it stops, and the jolt effect, a square wave, of force feedback of the game controller.
BOOL CALLBACK EnumJoysticksCallback_CreateDevice (const DIDEVICEINSTANCEA *pInstance, void *pContext)
 Create the device of the first attached game controller DirectInput enumerates, as its second interface, with the cooperation the enumeration passes and the format of DIJOYSTATE2.
void ProbeJoystickDevice (void)
 Create and release the first game controller with force feedback on, to find whether one is attached.
void PollKeyboardState (void)
 Read the keyboard into g_abKeyboardState and find the keys that went down.
int GetFirstPressedKeyIndex (char *pszKeyName=nullptr)
 The first key of g_adwKeyPressedEdge pressed in this frame.
bool IsInputOrEventActive (void)
 Whether a button of the mouse was pressed or, outside the setup of the car of network play, Return, Enter of the keypad, Left, or Right was pressed in this frame.
bool CheckForUserInput (void)
 Whether a key or a button of the mouse was pressed in this frame.

Variables

int g_fHostWindowActive
 Whether the game window has focus and can receive input.
int g_fCharInputSuppressed
 Whether the input of characters is held back, which stops the poll of the mouse.
short g_dwMouseScrollDirection
 The direction the hover of a menu moved last, -1 up and 1 down.
unsigned short g_wMenuHoverIndex
 The item of a menu under the hover.
DWORD g_dwLastInputActivityTime
 The time of the last change of the mouse, in milliseconds.
MouseDevice * g_pMousePosition
 The mouse that was read last.
MouseDevice * g_pMouseDevice
 The mouse, created with DirectInput.
int g_anMouseAxisRanges [8]
 Movement ranges for the eight mouse sensitivity settings.
unsigned char g_abKeyboardState [KEYBOARD_KEY_COUNT]
 The keys of the keyboard the game read last, as DirectInput reports them.
int g_adwKeyPressedEdge [KEYBOARD_KEY_COUNT]
 Whether each key went down since the keyboard was read before.
int g_adwMouseButtonRaw [MOUSE_BUTTON_COUNT]
 Whether each button of the mouse is down.
int g_adwMouseButtonPressed [MOUSE_BUTTON_COUNT]
 Whether each button of the mouse went down since the mouse was read before.
InputControlName g_aJoystickButtonNamesA [JOYSTICK_NAME_COUNT_A]
 The names of four buttons and six axes of a game controller.
InputControlName g_aJoystickButtonNamesB [JOYSTICK_NAME_COUNT_B]
 The names of 128 buttons and six axes of a game controller.
InputControlName g_aKeyboardControlNames [KEYBOARD_CONTROL_NAME_COUNT]
 The labels of the keyboard controls available for binding.
int g_bForceFeedbackAvailable
 Whether the game controller has force feedback.
LONG g_adwForceFeedbackDirection [2]
 The direction of the jolt, along the negative X axis.

Detailed Description

The control bindings and the DirectInput devices of the PC port.

Macro Definition Documentation

◆ DIRECTINPUT_VERSION

#define DIRECTINPUT_VERSION   0x0500

Select the DirectInput 5 declarations used by Boss Rally.

◆ KEYBOARD_KEY_COUNT

#define KEYBOARD_KEY_COUNT   256

The number of keys of the state of a keyboard.

◆ MOUSE_BUTTON_COUNT

#define MOUSE_BUTTON_COUNT   4

The number of buttons of the mouse the game reads.

◆ JOYSTICK_CONTROL_BUTTON

#define JOYSTICK_CONTROL_BUTTON   0x100

The control of a button of a game controller GetPressedJoystickControl() reports.

◆ JOYSTICK_CONTROL_X_NEGATIVE

#define JOYSTICK_CONTROL_X_NEGATIVE   0x8000

The control of the left of the X axis of a game controller.

◆ JOYSTICK_CONTROL_X_POSITIVE

#define JOYSTICK_CONTROL_X_POSITIVE   0x8100

The control of the right of the X axis of a game controller.

◆ JOYSTICK_CONTROL_Y_NEGATIVE

#define JOYSTICK_CONTROL_Y_NEGATIVE   0x8200

The control of the top of the Y axis of a game controller.

◆ JOYSTICK_CONTROL_Y_POSITIVE

#define JOYSTICK_CONTROL_Y_POSITIVE   0x8300

The control of the bottom of the Y axis of a game controller.

◆ JOYSTICK_NAME_COUNT_A

#define JOYSTICK_NAME_COUNT_A   10

The number of entries of g_aJoystickButtonNamesA.

◆ JOYSTICK_NAME_COUNT_B

#define JOYSTICK_NAME_COUNT_B   134

The number of entries of g_aJoystickButtonNamesB.

◆ KEYBOARD_CONTROL_NAME_COUNT

#define KEYBOARD_CONTROL_NAME_COUNT   120

The number of keyboard control labels.

Function Documentation

◆ UpdateMouseInput()

void UpdateMouseInput ( void )

Read the mouse for the main window.

Ghidra address:
BRD3D: 0x10060260
Ghidra address:
BRGlide: 0x100592d0

◆ ShowInfoMessageBox()

int ShowInfoMessageBox ( HWND hWnd,
HRESULT hResult,
const char * pszText )

Show a message of the input with the caption of string 0xaa.

Parameters
hWndThe window that owns the message.
hResultNot read.
pszTextThe message.
Returns
The result of MessageBoxA().
Ghidra address:
BRD3D: 0x10060030
Ghidra address:
BRGlide: 0x100590a0

◆ InitializeDirectInput()

bool InitializeDirectInput ( void )

Add a user of DirectInput.

The first user creates DirectInput, version 5, and the mouse, and a DirectInput that is not created shows a message.

Returns
Whether DirectInput exists.
Ghidra address:
BRD3D: 0x10078cd0
Ghidra address:
BRGlide: 0x10071fc0

◆ TryAcquireJoystickDevice()

bool TryAcquireJoystickDevice ( void )

Acquire the DirectInput device of the game controller.

Returns
Whether the device was acquired, and false without a device.
Ghidra address:
BRD3D: 0x100773d0
Ghidra address:
BRGlide: 0x100706b0

◆ SetJoystickPropertyDword()

HRESULT SetJoystickPropertyDword ( IDirectInputDevice2A * pDevice,
REFGUID guidProperty,
DWORD dwObject,
DWORD dwHow,
DWORD dwData )

Set a property of a DIPROPDWORD on a DirectInput device.

Parameters
pDeviceThe device.
guidPropertyThe property.
dwObjectThe object of the device, or 0 for the device.
dwHowHow dwObject is read.
dwDataThe value.
Returns
The result of SetProperty().
Ghidra address:
BRD3D: 0x10078c80
Ghidra address:
BRGlide: 0x10071f70

◆ SetJoystickAxisRange()

HRESULT SetJoystickAxisRange ( IDirectInputDevice2A * pDevice,
REFGUID guidProperty,
DWORD dwObject,
DWORD dwHow,
LONG lMin,
LONG lMax )

Set a property of a DIPROPRANGE on a DirectInput device.

Parameters
pDeviceThe device.
guidPropertyThe property.
dwObjectThe object of the device, or 0 for the device.
dwHowHow dwObject is read.
lMinThe low end of the range.
lMaxThe high end of the range.
Returns
The result of SetProperty().
Ghidra address:
BRD3D: 0x10078c30
Ghidra address:
BRGlide: 0x10071f20

◆ ReleaseKeyboardDevice()

void ReleaseKeyboardDevice ( void )

Drop a user of the keyboard device.

The last user releases the device. A count that falls below 0 is set back to 0.

Ghidra address:
BRD3D: 0x10078bc0
Ghidra address:
BRGlide: 0x10071eb0

◆ ShutdownDirectInput()

bool ShutdownDirectInput ( void )

Drop a user of DirectInput.

The last user frees the mouse and releases DirectInput.

Returns
Always true.
Ghidra address:
BRD3D: 0x10078db0
Ghidra address:
BRGlide: 0x100720a0

◆ IsInputBindingPressed()

unsigned char IsInputBindingPressed ( int nBinding)

Read rising edges of an active binding and its keyboard alternatives.

Parameters
nBindingBinding index.
Returns
One for a button edge, 0x80 for an axis edge, or their bitwise union.
Ghidra address:
BRD3D: 0x100786e0
Ghidra address:
BRGlide: 0x100719d0

◆ IsInputBindingHeld()

unsigned char IsInputBindingHeld ( int nBinding)

Read an active binding and its keyboard alternatives.

Parameters
nBindingBinding index.
Returns
The high bit when a button or an axis beyond fifty is active.
Ghidra address:
BRD3D: 0x10078420
Ghidra address:
BRGlide: 0x10071710

◆ UpdateMouseButtonEdges()

void UpdateMouseButtonEdges ( void )

Find the buttons of the mouse that went down since the mouse was read before.

Ghidra address:
BRD3D: 0x1005fff0
Ghidra address:
BRGlide: 0x10059060

◆ PollInputAndUpdateEdges()

void PollInputAndUpdateEdges ( void )

Refresh keyboard and mouse button transitions for menu input.

Ghidra address:
BRD3D: 0x1003e070
Ghidra address:
BRGlide: 0x10037710

◆ ResetMouseCursorToCenter()

bool WINAPI ResetMouseCursorToCenter ( HWND hWnd)

Put the cursor of the mouse in the centre of the screen and clear g_MouseMenuState.

Parameters
hWndThe main window. It is not read.
Returns
Always true.
Ghidra address:
BRD3D: 0x10060210
Ghidra address:
BRGlide: 0x10059280

◆ FindControlNameIndex()

int FindControlNameIndex ( int nTable,
int nCode )

Find a control code in the keyboard or joystick label table.

Parameters
nTableZero for keyboard labels, one or two for joystick table B, or three for table A.
nCodeThe control code to locate.
Returns
The label index, or zero for an unknown code or table.
Ghidra address:
BRD3D: 0x10040040
Ghidra address:
BRGlide: 0x10039580

◆ InitJoystickBindingNames()

void InitJoystickBindingNames ( void )

Fill the names of the controls of a game controller.

A button is named with its number in the format of string 0xc3, and the axes take strings 0xc4 to 0xc9. Only the first bytes of the tables are cleared before, as in the original.

Ghidra address:
BRD3D: 0x1005fdb0
Ghidra address:
BRGlide: 0x10058af0

◆ GetPressedMouseButton()

int GetPressedMouseButton ( void )

Read the buttons of the mouse and find the first one that went down.

Returns
The button, or -1 for none or without a mouse.
Ghidra address:
BRD3D: 0x10077310
Ghidra address:
BRGlide: 0x100705f0

◆ GetPressedJoystickControl()

int GetPressedJoystickControl ( unsigned * pwControl)

Read the game controller and find a control that is pressed, to bind it.

A game controller that does not exist is created as the first one.

Parameters
pwControlReceives JOYSTICK_CONTROL_BUTTON for a button, or the control of an axis pushed past 50.
Returns
The button pressed, 0 for an axis, -1 for no control, or 1 without a game controller.
Ghidra address:
BRD3D: 0x10077200
Ghidra address:
BRGlide: 0x100704e0

◆ InitializeKeyboardDevice()

bool InitializeKeyboardDevice ( void )

Add a user of the keyboard.

The first user clears the states of the keyboard, the game controller, and the mouse, and creates and acquires the device of the system keyboard for the main window, shared in the foreground.

Returns
Whether the keyboard device exists.
Ghidra address:
BRD3D: 0x100770f0
Ghidra address:
BRGlide: 0x100703d0

◆ ReadKeyboardState()

HRESULT ReadKeyboardState ( unsigned char * pabState)

Read the state of the keyboard, acquiring the device again and reading once more when the input was lost.

Parameters
pabStateReceives the state of each key.
Returns
The result of the last read, or 1 without a device.
Ghidra address:
BRD3D: 0x100771b0
Ghidra address:
BRGlide: 0x10070490

◆ ClearKeyboardStateBuffers()

void ClearKeyboardStateBuffers ( void )

Clear the state of the keyboard.

Only the first 64 entries of g_adwKeyPressedEdge and g_adwKeyPrevDown are cleared, as in the original.

Ghidra address:
BRD3D: 0x1005ff30
Ghidra address:
BRGlide: 0x10058fa0

◆ UpdateKeyboardEdgeState()

void UpdateKeyboardEdgeState ( void )

Find the keys that went down since the keyboard was read before.

Ghidra address:
BRD3D: 0x1005ff60
Ghidra address:
BRGlide: 0x10058fd0

◆ SetForceFeedbackMagnitude()

void SetForceFeedbackMagnitude ( LONG lMagnitude)

Set both coefficients of the first spring of g_DiConditionEffect, and give the effect its new parameters when it exists.

Parameters
lMagnitudeThe coefficient.
Ghidra address:
BRD3D: 0x100790b0
Ghidra address:
BRGlide: 0x100723a0

◆ CreateForceFeedbackEffects()

HRESULT CreateForceFeedbackEffects ( int nCoefficientX,
int nCoefficientY )

Create the condition effect, a spring on X and Y that lasts until it stops, and the jolt effect, a square wave, of force feedback of the game controller.

Parameters
nCoefficientXThe strength of the spring of X, 1000 as the game passes it.
nCoefficientYThe strength of the spring of Y, 8000 as the game passes it.
Returns
The result of the creation of the jolt.
Ghidra address:
BRD3D: 0x10079390
Ghidra address:
BRGlide: 0x10072680

◆ EnumJoysticksCallback_CreateDevice()

BOOL CALLBACK EnumJoysticksCallback_CreateDevice ( const DIDEVICEINSTANCEA * pInstance,
void * pContext )

Create the device of the first attached game controller DirectInput enumerates, as its second interface, with the cooperation the enumeration passes and the format of DIJOYSTATE2.

A step that fails is written to the debugger and releases the device.

Parameters
pInstanceThe game controller.
pContextThe flags of cooperation.
Returns
Always DIENUM_STOP.
Ghidra address:
BRD3D: 0x100790e0
Ghidra address:
BRGlide: 0x100723d0

◆ ProbeJoystickDevice()

void ProbeJoystickDevice ( void )

Create and release the first game controller with force feedback on, to find whether one is attached.

The type of the input device, its bindings, and force feedback are restored after.

Ghidra address:
BRD3D: 0x100795d0
Ghidra address:
BRGlide: 0x100728c0

◆ PollKeyboardState()

void PollKeyboardState ( void )

Read the keyboard into g_abKeyboardState and find the keys that went down.

Ghidra address:
BRD3D: 0x1005ffb0
Ghidra address:
BRGlide: 0x10059020

◆ GetFirstPressedKeyIndex()

int GetFirstPressedKeyIndex ( char * pszKeyName = nullptr)

The first key of g_adwKeyPressedEdge pressed in this frame.

Parameters
pszKeyNameNot read. PollKeyCapture() passes a buffer of 256 bytes, and CheckForUserInput() passes nothing in the binaries.
Returns
The index of the key, or -1 when none was pressed.
Ghidra address:
BRD3D: 0x1005ffd0
Ghidra address:
BRGlide: 0x10059040

◆ IsInputOrEventActive()

bool IsInputOrEventActive ( void )

Whether a button of the mouse was pressed or, outside the setup of the car of network play, Return, Enter of the keypad, Left, or Right was pressed in this frame.

Returns
Whether one was pressed.
Ghidra address:
BRD3D: 0x1003e080
Ghidra address:
BRGlide: 0x10037720

◆ CheckForUserInput()

bool CheckForUserInput ( void )

Whether a key or a button of the mouse was pressed in this frame.

Returns
Whether one was pressed.
Ghidra address:
BRD3D: 0x1003e0e0
Ghidra address:
BRGlide: 0x10037780

Variable Documentation

◆ g_fHostWindowActive

int g_fHostWindowActive
extern

Whether the game window has focus and can receive input.

Ghidra address:
BRD3D: 0x10aa33e0
Ghidra address:
BRGlide: 0x10ac6740

◆ g_fCharInputSuppressed

int g_fCharInputSuppressed
extern

Whether the input of characters is held back, which stops the poll of the mouse.

Ghidra address:
BRD3D: 0x10aa2844
Ghidra address:
BRGlide: 0x10ac5b9c

◆ g_dwMouseScrollDirection

short g_dwMouseScrollDirection
extern

The direction the hover of a menu moved last, -1 up and 1 down.

Ghidra address:
BRD3D: 0x100ab3dc
Ghidra address:
BRGlide: 0x100aab7c

◆ g_wMenuHoverIndex

unsigned short g_wMenuHoverIndex
extern

The item of a menu under the hover.

Ghidra address:
BRD3D: 0x10aa286c
Ghidra address:
BRGlide: 0x10ac5bc4

◆ g_dwLastInputActivityTime

DWORD g_dwLastInputActivityTime
extern

The time of the last change of the mouse, in milliseconds.

Ghidra address:
BRD3D: 0x10aa33e8
Ghidra address:
BRGlide: 0x10ac6748

◆ g_pMousePosition

MouseDevice* g_pMousePosition
extern

The mouse that was read last.

Ghidra address:
BRD3D: 0x10aa2a78
Ghidra address:
BRGlide: 0x10ac5dd8

◆ g_pMouseDevice

MouseDevice* g_pMouseDevice
extern

The mouse, created with DirectInput.

Ghidra address:
BRD3D: 0x10aa2e80
Ghidra address:
BRGlide: 0x10ac61e0

◆ g_anMouseAxisRanges

int g_anMouseAxisRanges[8]
extern

Movement ranges for the eight mouse sensitivity settings.

Ghidra address:
BRD3D: 0x100bd400
Ghidra address:
BRGlide: 0x100bcc08

◆ g_abKeyboardState

unsigned char g_abKeyboardState[KEYBOARD_KEY_COUNT]
extern

The keys of the keyboard the game read last, as DirectInput reports them.

Ghidra address:
BRD3D: 0x10aa3288
Ghidra address:
BRGlide: 0x10ac65e8

◆ g_adwKeyPressedEdge

int g_adwKeyPressedEdge[KEYBOARD_KEY_COUNT]
extern

Whether each key went down since the keyboard was read before.

Ghidra address:
BRD3D: 0x10aa2a80
Ghidra address:
BRGlide: 0x10ac5de0

◆ g_adwMouseButtonRaw

int g_adwMouseButtonRaw[MOUSE_BUTTON_COUNT]
extern

Whether each button of the mouse is down.

Ghidra address:
BRD3D: 0x10aa33c0
Ghidra address:
BRGlide: 0x10ac6720

◆ g_adwMouseButtonPressed

int g_adwMouseButtonPressed[MOUSE_BUTTON_COUNT]
extern

Whether each button of the mouse went down since the mouse was read before.

Ghidra address:
BRD3D: 0x10aa33d0
Ghidra address:
BRGlide: 0x10ac6730

◆ g_aJoystickButtonNamesA

InputControlName g_aJoystickButtonNamesA[JOYSTICK_NAME_COUNT_A]
extern

The names of four buttons and six axes of a game controller.

Its use is not recovered yet.

Ghidra address:
BRD3D: 0x10b4e7a8
Ghidra address:
BRGlide: 0x10b71b08

◆ g_aJoystickButtonNamesB

InputControlName g_aJoystickButtonNamesB[JOYSTICK_NAME_COUNT_B]
extern

The names of 128 buttons and six axes of a game controller.

Its use is not recovered yet.

Ghidra address:
BRD3D: 0x10b4e910
Ghidra address:
BRGlide: 0x10b71c70

◆ g_aKeyboardControlNames

InputControlName g_aKeyboardControlNames[KEYBOARD_CONTROL_NAME_COUNT]
extern

The labels of the keyboard controls available for binding.

Ghidra address:
BRD3D: 0x100b4338
Ghidra address:
BRGlide: 0x100b3b40

◆ g_bForceFeedbackAvailable

int g_bForceFeedbackAvailable
extern

Whether the game controller has force feedback.

Ghidra address:
BRD3D: 0x118abdbc
Ghidra address:
BRGlide: 0x118eeed4

◆ g_adwForceFeedbackDirection

LONG g_adwForceFeedbackDirection[2]
extern

The direction of the jolt, along the negative X axis.

Ghidra address:
BRD3D: 0x100bd430
Ghidra address:
BRGlide: 0x100bcc38