102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
bindings.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
12#include "pcdogs/text/globals.h"
13#include <math.h>
14#include <stdarg.h>
15#include <string.h>
16
17// Original pcdogs.exe: 0x42d080
18// Recognizes numeric keypad 1, 2, 3, 3, 2, 1 from virtual-key changes. Holding a key keeps the current step, another key restarts the sequence, and completion returns true once.
20{
21 int32_t pressed_button = Input_GetPressedButton();
22 int32_t previous_button = g_cheatPreviousButton;
23
24 g_cheatLastPressedButton = pressed_button;
25
26 if (pressed_button == previous_button)
27 {
28 g_cheatPreviousButton = pressed_button;
29
30 return 0;
31 }
32
33 char sequence_index = g_cheatSequenceIndex;
34
35 if ((uint32_t)pressed_button != g_cheatCodeSequence[(int32_t)sequence_index])
36 {
37 if (pressed_button > -1)
39 }
40 else if (pressed_button > -1)
41 {
42 g_cheatSequenceIndex = sequence_index + 1;
43
44 if (sequence_index == INPUT_CHEAT_SEQUENCE_LENGTH - 1)
45 {
46 g_cheatPreviousButton = pressed_button;
48
49 return 1;
50 }
51 }
52
53 g_cheatPreviousButton = pressed_button;
54
55 return 0;
56}
57
58// Original pcdogs.exe: 0x43cff0
59// Registers a keyboard mapping and refreshes its display name, or writes a direct gamepad mapping. The unsigned code split, direct indices, and allocation results are unchecked.
60void Input_RegisterButtonMapping(int32_t control_code, uint32_t button_mask)
61{
62 // Compare keyCode with 1000 (0x3e8) to determine keyboard vs gamepad
63 // Load keyCode parameter from stack
64 // INPUT MAPPING: KeyCodes 0-999 are keyboard (VK codes), 1000+ are gamepad. ButtonFlags: 0x0001=Left,
65 // 0x0002=Right, 0x0004=Up, 0x0008=Down, 0x0010=B1, 0x0020=B2, 0x0040=B3, 0x0080=Confirm, 0x0400=LTrig,
66 // 0x0800=RTrig, 0x4000=Special, 0x8000=Cancel
67 //
68 // Jump to keyboard mapping path if keyCode < 1000
69 if ((uint32_t)control_code >= INPUT_GAMEPAD_UP)
70 // Gamepad button mapping: Store directly in global array indexed by keyCode
71 {
72 // Store buttonFlags at g_gamepadMappingButtons[keyCode]
73 Input_GamepadActionMasks[(uint32_t)control_code - 1000u] = button_mask;
74
75 return;
76 }
77
78 // Load g_mappingCount for array indexing
79 // Calculate new size: (g_mappingCount * 4) + 4
80 // Load g_keyboardMappingKeys pointer
81 // Call Memory_Realloc to grow g_keyboardMappingKeys array
83 int32_t button_allocation_count = g_mappingCount;
84
85 g_keyboardMappingKeys = resized_key_mappings; // Store new g_keyboardMappingKeys pointer
86
87 // Store keyCode in the newly allocated slot
88 // Load g_keyboardMappingButtons pointer
89 // Call Memory_Realloc to grow g_keyboardMappingButtons array
90 uint32_t *resized_button_mappings = CRT_realloc(g_keyboardMappingButtons, (button_allocation_count << INPUT_MAPPING_ENTRY_SHIFT) + INPUT_MAPPING_ENTRY_BYTES);
91 // Store buttonFlags in the newly allocated slot
92 // Generate display name for UI (e.g., "Enter" for key 0x0D)
93 int32_t new_mapping_index = g_mappingCount;
94 // Increment mapping count to reflect new entry
95 int32_t *key_mappings = g_keyboardMappingKeys;
96
97 g_keyboardMappingButtons = resized_button_mappings; // Store new g_keyboardMappingButtons pointer
98 // Store keyCode at g_keyboardMappingKeys[g_mappingCount]
99 key_mappings[new_mapping_index] = control_code;
100 // Store buttonFlags at g_keyboardMappingButtons[g_mappingCount]
102 // Call Input_FormatButtonName to generate display name
103 Input_FormatButtonName(control_code, button_mask);
104 g_mappingCount += 1; // Increment g_mappingCount to reflect new mapping
105}
106
107// Original pcdogs.exe: 0x43d360
108// Replaces dynamic input mappings with defaults, resets gamma to five, and copies the default player binding tables into configuration state.
110{
111 int32_t *old_key_mappings = g_keyboardMappingKeys;
112
113 if (old_key_mappings)
114 {
115 CRT_free(old_key_mappings);
117 }
118
119 uint32_t *old_button_mappings = g_keyboardMappingButtons;
120
121 if (old_button_mappings)
122 {
123 CRT_free(old_button_mappings);
125 }
126
127 // DEFAULT INPUT MAPPINGS: Sets up keyboard (VK codes) and gamepad (codes 1000+) button mappings. Arrow
128 // keys map to d-pad, numpad to action buttons, gamepad axes/buttons to corresponding game inputs
129 g_mappingCount = 0;
154 __builtin_memcpy(&g_player1Controls,
155 "\x26\x00\x00\x00\x28\x00\x00\x00\x25\x00\x00\x00\x27\x00\x00\x00\x64\x00\x00\x00\x66\x00\x00"
156 "\x00\x60\x00\x00\x00\x61\x00\x00\x00\x63\x00\x00\x00\x62\x00\x00\x00\x20\x00\x00\x00",
158 __builtin_memcpy(&g_player2Controls,
159 "\xe8\x03\x00\x00\xe9\x03\x00\x00\xea\x03\x00\x00\xeb\x03\x00\x00\xf5\x03\x00\x00\xf4\x03\x00"
160 "\x00\xef\x03\x00\x00\xf0\x03\x00\x00\xf2\x03\x00\x00\xee\x03\x00\x00",
162}
163
164// Original pcdogs.exe: 0x43d590
165// Initializes the names and binding tables for the four built-in controller presets.
185
186// Original pcdogs.exe: 0x43dcd0
187// Maps a recognized logical control mask to its display-name index. Unknown masks return index twelve.
207
208// Original pcdogs.exe: 0x43dda0
209// Formats and caches the localized name for a logical control binding and lazily initializes the unassigned slot.
210void Input_FormatButtonName(int32_t control_code, uint32_t button_mask)
211{
212 int32_t button_index = Input_GetButtonIndex(button_mask);
213
214 if (!g_inputButtonNameBuffers[button_index])
216
217 int32_t string_table_index = control_code;
218
219 if ((uint32_t)string_table_index > INPUT_KEY_CODE_MAX)
220 string_table_index -= INPUT_LOCALIZED_GAMEPAD_CODE_BIAS;
221
222 char *localized_button_name = String_GetByIndex(Input_ButtonNameStringIDs[string_table_index]);
223
224 String_FormatCRTString(g_inputButtonNameBuffers[button_index], "%s", localized_button_name);
225
227 return;
228
229 char *unassigned_name_buffer = CRT_malloc(INPUT_BUTTON_NAME_CAPACITY);
230
232 String_FormatCRTString(unassigned_name_buffer, "No key assigned");
233}
234
235// Original pcdogs.exe: 0x43de30
236// Copies a localized button label into the shared controls-menu name buffer and returns that buffer. Codes above 0xff are rebased before indexing, and the resulting index is not checked.
237char *Input_GetButtonString(int32_t button_code)
238{
239 int32_t string_table_index = button_code;
240
241 if (string_table_index > INPUT_KEY_CODE_MAX)
242 string_table_index -= INPUT_LOCALIZED_GAMEPAD_CODE_BIAS;
243
245 String_GetByIndex(Input_ButtonNameStringIDs[string_table_index]));
246
248}
void Input_FormatButtonName(int32_t control_code, uint32_t button_mask)
Definition bindings.c:210
int32_t Input_GetButtonIndex(uint32_t control_mask)
Definition bindings.c:188
char * Input_GetButtonString(int32_t button_code)
Definition bindings.c:237
bool Input_CheckCheatCodeSequence()
Definition bindings.c:19
void Input_InitializeButtonMappings()
Definition bindings.c:109
void Input_InitializeControllerMappings()
Definition bindings.c:166
void Input_RegisterButtonMapping(int32_t control_code, uint32_t button_mask)
Definition bindings.c:60
#define g_player2Controls
Definition globals.h:65
#define g_player1Controls
Definition globals.h:59
#define INPUT_CHEAT_SEQUENCE_LENGTH
Definition constants.h:54
#define INPUT_BUTTON_CONFIRM
Definition constants.h:11
#define INPUT_LOCALIZED_GAMEPAD_CODE_BIAS
Definition constants.h:30
#define INPUT_BUTTON_ACTION_1
Definition constants.h:8
#define INPUT_BUTTON_UP
Definition constants.h:6
#define INPUT_MAPPING_ENTRY_BYTES
Definition constants.h:37
#define INPUT_MAPPING_ENTRY_SHIFT
Definition constants.h:36
#define INPUT_BUTTON_LEFT
Definition constants.h:4
#define INPUT_KEY_CODE_MAX
Definition constants.h:29
#define INPUT_BUTTON_RIGHT
Definition constants.h:5
#define INPUT_BUTTON_CANCEL
Definition constants.h:17
#define INPUT_BUTTON_LEFT_TRIGGER
Definition constants.h:12
@ INPUT_BUTTON_NAME_ACTION_2
Definition constants.h:124
@ INPUT_BUTTON_NAME_CANCEL
Definition constants.h:125
@ INPUT_BUTTON_NAME_ACTION_3
Definition constants.h:123
@ INPUT_BUTTON_NAME_UP
Definition constants.h:117
@ INPUT_BUTTON_NAME_DOWN
Definition constants.h:118
@ INPUT_BUTTON_NAME_LEFT
Definition constants.h:115
@ INPUT_BUTTON_NAME_CONFIRM
Definition constants.h:121
@ INPUT_BUTTON_NAME_LEFT_TRIGGER
Definition constants.h:119
@ INPUT_BUTTON_NAME_ACTION_1
Definition constants.h:122
@ INPUT_BUTTON_NAME_UNASSIGNED
Definition constants.h:127
@ INPUT_BUTTON_NAME_RIGHT_TRIGGER
Definition constants.h:120
@ INPUT_BUTTON_NAME_RIGHT
Definition constants.h:116
@ INPUT_BUTTON_NAME_SPECIAL
Definition constants.h:126
#define INPUT_BUTTON_ACTION_3
Definition constants.h:10
#define INPUT_DEFAULT_GAMMA
Definition constants.h:55
@ INPUT_GAMEPAD_BUTTON_6
Definition constants.h:83
@ INPUT_GAMEPAD_DOWN
Definition constants.h:72
@ INPUT_GAMEPAD_UP
Definition constants.h:71
@ INPUT_GAMEPAD_LEFT
Definition constants.h:73
@ INPUT_GAMEPAD_BUTTON_3
Definition constants.h:80
@ INPUT_GAMEPAD_BUTTON_7
Definition constants.h:84
@ INPUT_GAMEPAD_BUTTON_0
Definition constants.h:77
@ INPUT_GAMEPAD_BUTTON_2
Definition constants.h:79
@ INPUT_GAMEPAD_BUTTON_8
Definition constants.h:85
@ INPUT_GAMEPAD_BUTTON_1
Definition constants.h:78
@ INPUT_GAMEPAD_BUTTON_4
Definition constants.h:81
@ INPUT_GAMEPAD_RIGHT
Definition constants.h:74
@ INPUT_GAMEPAD_BUTTON_5
Definition constants.h:82
#define INPUT_BUTTON_DOWN
Definition constants.h:7
#define INPUT_BUTTON_RIGHT_TRIGGER
Definition constants.h:13
#define INPUT_DEFAULT_PLAYER_ONE_BINDING_COUNT
Definition constants.h:56
#define INPUT_BUTTON_ACTION_2
Definition constants.h:9
#define INPUT_BUTTON_NAME_CAPACITY
Definition constants.h:31
#define INPUT_BUTTON_SPECIAL
Definition constants.h:16
#define INPUT_DEFAULT_PLAYER_TWO_BINDING_COUNT
Definition constants.h:57
int32_t Input_GetPressedButton(void)
Definition state.c:317
#define g_controllerPresets
Definition globals.h:126
#define g_inputButtonNameBuffers
Definition globals.h:75
#define Input_GamepadActionMasks
Definition globals.h:144
#define Input_ButtonNameStringIDs
Definition globals.h:26
#define g_controlsMenuButtonNameBuffer
Definition globals.h:150
#define g_displaySetting
Definition globals.h:216
void * CRT_malloc(uint32_t size)
Definition heap.c:16
void * CRT_realloc(void *ptr, uint32_t size)
Definition heap.c:65
void CRT_free(void *ptr)
Definition heap.c:164
int32_t String_FormatCRTString(char *buffer, char const *format,...)
Definition formatting.c:18
#define g_cheatCodeSequence
Definition strings.h:397
char * String_GetByIndex(int32_t string_id)
Definition strings.c:66
#define g_cheatLastPressedButton
Definition values.h:438
#define g_keyboardMappingButtons
Definition values.h:489
#define g_cheatPreviousButton
Definition values.h:453
#define g_mappingCount
Definition values.h:558
#define g_keyboardMappingKeys
Definition values.h:486
#define g_cheatSequenceIndex
Definition values.h:450