102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
options.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
10#include "pcdogs/game/globals.h"
15#include "pcdogs/level/types.h"
17#include "pcdogs/menu/globals.h"
18#include "pcdogs/menu/types.h"
25#include "pcdogs/ui/functions.h"
26#include <math.h>
27#include <stdarg.h>
28#include <string.h>
29
30// Original pcdogs.exe: 0x429a10
31// Processes control remapping, controller preset selection, and preset confirmation, returning completion status to the options caller. Accept requires no binding conflicts, and reset changes live defaults immediately, so a later cancel does not undo that reset.
33{
34 int32_t submenu_state = g_optionsMenuSubState;
35
37
38 if (submenu_state == MENU_STATE_PAUSE)
39 {
41 {
42 int32_t pressed_button = Input_GetPressedButton();
43
44 if (pressed_button == VK_ESCAPE || (pressed_button == VK_RETURN && !g_optionsMenuState))
45 {
48 }
49 else if (pressed_button != INPUT_NO_CONTROL && pressed_button != VK_RETURN)
50 {
51 int32_t binding_device_column = g_optionsMenuColumn;
52
54
55 if (binding_device_column)
56 {
57 if (binding_device_column == 1 && pressed_button > INPUT_KEY_CODE_COUNT)
58 g_optionsMenuBackupData.joystick_bindings[Options_MenuSelection] = pressed_button;
59 }
60 else if (pressed_button < INPUT_KEY_CODE_COUNT)
61 g_optionsMenuBackupData.keyboard_bindings[Options_MenuSelection] = pressed_button;
62
65
66 int32_t column_after_conflict_check = g_optionsMenuColumn;
67
68 if (column_after_conflict_check)
69 {
70 if (column_after_conflict_check != 1 || pressed_button >= INPUT_KEY_CODE_COUNT)
72 else
73 {
76 }
77 }
78 else if (pressed_button >= INPUT_KEY_CODE_COUNT)
79 {
82 }
83 else
85 }
86 }
87 else
88 {
89 bool no_down_pulse = !g_menuInputDown;
90
92
93 int32_t selected_row;
94
95 if (no_down_pulse)
96 selected_row = Options_MenuSelection;
97 else
98 {
99 int32_t row_before_down = Options_MenuSelection;
100
102 selected_row = row_before_down + 1;
103 Options_MenuSelection = selected_row;
104
105 if (selected_row > MENU_BINDING_ROW_ACTIONS)
106 {
107 selected_row = MENU_BINDING_ROW_ACTIONS;
109 }
110 else if (selected_row == MENU_BINDING_ROW_KEYBOARD_ONLY)
112 else if (selected_row == MENU_BINDING_ROW_PRESETS)
114 }
115
116 int32_t selected_column;
117
118 if (!g_menuInputUp)
119 selected_column = g_optionsMenuColumn;
120 else
121 {
122 int32_t row_before_up = selected_row;
123
124 selected_row -= 1;
126 Options_MenuSelection = selected_row;
127
128 if (row_before_up - 1 < 0)
129 {
130 selected_row = MENU_BINDING_ROW_KEYBOARD_ONLY;
131 selected_column = 0;
134 }
135 else if (selected_row != MENU_BINDING_ROW_KEYBOARD_ONLY)
136 selected_column = g_optionsMenuColumn;
137 else
138 {
139 selected_column = 0;
141 }
142 }
143
144 if (g_menuInputLeft)
145 {
146 int32_t column_before_left = selected_column;
147
148 selected_column -= 1;
150 g_optionsMenuColumn = selected_column;
151
152 if (column_before_left - 1 < 0)
153 {
154 int32_t bottom_action_row_flag = (uint8_t)(selected_row >= MENU_BINDING_ROW_ACTIONS);
155
156 selected_column = bottom_action_row_flag + 1;
157 g_optionsMenuColumn = selected_column;
158 }
159
160 if (selected_row == MENU_BINDING_ROW_KEYBOARD_ONLY)
161 {
162 selected_column = 0;
164 }
165 }
166
168 {
170 g_optionsMenuColumn = selected_column + 1;
171
172 if (selected_row == MENU_BINDING_ROW_KEYBOARD_ONLY)
174 else if (selected_row >= MENU_BINDING_ROW_ACTIONS)
175 {
176 if (selected_column + 1 > 2)
178 }
179 else if (selected_column + 1 > 1)
181 }
182
183 if (Input_GetPressedButton() == VK_RETURN && !g_optionsMenuState)
184 {
185 int32_t confirmed_row = Options_MenuSelection;
186
188
189 if (confirmed_row <= MENU_BINDING_ROW_KEYBOARD_ONLY)
191 else if (confirmed_row == MENU_BINDING_ROW_PRESETS)
192 {
196 }
197 else if (confirmed_row == MENU_BINDING_ROW_ACTIONS)
198 {
199 int32_t confirmed_action_column = g_optionsMenuColumn;
200
201 if (confirmed_action_column)
202 {
203 if (confirmed_action_column != MENU_BINDING_ACTION_ACCEPT)
204 {
206
207 return 1;
208 }
209
210 if (((uint16_t)g_controlsMenuKeyIndex >> 8) == 0xff && ((uint16_t)g_controlsMenuButtonIndex >> 8) == 0xff)
211 {
213
214 return 1;
215 }
216
218 }
219 else
220 {
222 __builtin_memcpy(&g_optionsMenuBackupData, &g_displaySetting, 0x6c);
225 }
226 }
227 }
228 }
229
230 int32_t enter_held_flag = (uint8_t)(Input_GetPressedButton() == VK_RETURN);
231
232 g_optionsMenuState = enter_held_flag;
233 }
234 else if (submenu_state == MENU_STATE_OPTIONS)
235 {
236 bool no_confirm_pulse = !g_menuInputConfirm;
237
239
240 if (!no_confirm_pulse)
241 {
242 int32_t selected_preset = Options_MenuSelection;
243
249 memcpy(g_optionsMenuValue1, g_controllerPresets[selected_preset].bindings, sizeof(g_optionsMenuValue1));
250 }
251 else if (g_menuInputCancel)
252 {
260 }
261
262 if (g_menuInputDown)
263 {
264 int32_t preset_before_down = Options_MenuSelection;
265
267 Options_MenuSelection = preset_before_down + 1;
268
269 if (preset_before_down + 1 >= 4)
271 }
272 else if (g_menuInputUp)
273 {
274 int32_t preset_before_up = Options_MenuSelection;
275
277 Options_MenuSelection = preset_before_up - 1;
278
279 if (preset_before_up - 1 < 0)
281 }
282 }
283 else if (submenu_state == MENU_STATE_EXIT_CONFIRM)
284 {
285 bool no_confirmation_down_pulse = !g_menuInputDown;
286
288
289 if (!no_confirmation_down_pulse)
290 {
291 int32_t confirmation_before_down = Options_MenuSelection;
292
294 Options_MenuSelection = confirmation_before_down + 1;
295
296 if (confirmation_before_down + 1 > 1)
298 }
299 else if (g_menuInputUp)
300 {
301 int32_t confirmation_before_up = Options_MenuSelection;
302
304 Options_MenuSelection = confirmation_before_up - 1;
305
306 if (confirmation_before_up - 1 < 0)
308 }
309
311 {
312 __builtin_memcpy(&g_optionsMenuBackupData.joystick_bindings, &g_optionsMenuValue1,
313 0x28);
318
319 return 0;
320 }
321
323 {
328 }
329 }
330
331 return 0;
332}
333
334// Original pcdogs.exe: 0x429f10
335// Processes options navigation, settings changes, cancellation, and the control-remapping subhandler through the result buffer. It reads the incoming action byte before initializing the result and preserves the existing packed-byte settings and reload behavior.
336void Menu_ProcessOptionsInput(struct Menu_ActionResult *out_result, int32_t selected_row)
337{
338 uint8_t action = out_result->action;
339
340 out_result->sound_effect = UI_SOUND_NONE;
341
342 if (action != MENU_ACTION_BINDINGS)
343 {
344 out_result->action = MENU_ACTION_CONTINUE;
345
346 if (!g_menuUIState5)
347 {
348 int32_t next_selected_row;
349
351 {
352 next_selected_row = selected_row;
353
354 if (next_selected_row == OPTIONS_ROW_BACK)
355 {
356 out_result->sound_effect = 2;
357 out_result->action = MENU_ACTION_COMPLETE;
358 out_result->selected_index = (uint8_t)next_selected_row;
359
360 return;
361 }
362
363 if (next_selected_row == OPTIONS_ROW_CONTROLS)
364 {
365 out_result->sound_effect = 2;
366 out_result->action = MENU_ACTION_BINDINGS;
374
375 return;
376 }
377 }
378 else if (g_menuInputCancel)
379 {
380 out_result->sound_effect = 1;
381
383 out_result->action = MENU_ACTION_COMPLETE;
384 next_selected_row = selected_row;
385 }
386 else if (g_menuInputUp)
387 {
388 out_result->sound_effect = 0;
389 next_selected_row = selected_row - 1;
390
391 if (selected_row - 1 < 0)
392 {
393 out_result->selected_index = 6;
394
395 return;
396 }
397 }
398 else if (g_menuInputDown)
399 {
400 out_result->sound_effect = 0;
401 next_selected_row = selected_row + 1;
402
403 if (next_selected_row >= 7)
404 {
405 out_result->selected_index = 0;
406
407 return;
408 }
409 }
411 {
412 next_selected_row = selected_row;
413
414 if (next_selected_row != OPTIONS_ROW_BACK)
415 out_result->sound_effect = 0;
416
417 if (!next_selected_row)
418 {
419 int32_t music_volume = Settings_GetMusicVolume();
420 int32_t adjusted_music_volume;
421
422 if (!g_menuInputLeft)
423 {
424 adjusted_music_volume = music_volume + MENU_OPTION_VOLUME_STEP;
425
426 if (adjusted_music_volume >= MENU_OPTION_VOLUME_SNAP_THRESHOLD)
427 adjusted_music_volume = MENU_OPTION_VOLUME_MAX;
428 }
429 else
430 {
431 adjusted_music_volume = music_volume - MENU_OPTION_VOLUME_STEP;
432
433 if (adjusted_music_volume <= 6)
434 {
436 out_result->selected_index = (uint8_t)next_selected_row;
437
438 return;
439 }
440 }
441
442 Settings_SetMusicVolume((uint16_t)adjusted_music_volume);
443 out_result->selected_index = (uint8_t)next_selected_row;
444
445 return;
446 }
447
448 if (next_selected_row == OPTIONS_ROW_SFX_VOLUME)
449 {
450 int32_t sfx_volume = Settings_GetSfxVolume();
451 int32_t adjusted_sfx_volume;
452
453 if (!g_menuInputLeft)
454 {
455 adjusted_sfx_volume = sfx_volume + MENU_OPTION_VOLUME_STEP;
456
457 if (adjusted_sfx_volume >= MENU_OPTION_VOLUME_SNAP_THRESHOLD)
458 adjusted_sfx_volume = MENU_OPTION_VOLUME_MAX;
459 }
460 else
461 {
462 adjusted_sfx_volume = sfx_volume - MENU_OPTION_VOLUME_STEP;
463
464 if (adjusted_sfx_volume <= 6)
465 {
467 out_result->selected_index = (uint8_t)next_selected_row;
468
469 return;
470 }
471 }
472
473 Settings_SetSfxVolume((uint16_t)adjusted_sfx_volume);
474 out_result->selected_index = (uint8_t)next_selected_row;
475
476 return;
477 }
478
479 if (next_selected_row == OPTIONS_ROW_STEREO)
480 {
482 out_result->selected_index = (uint8_t)next_selected_row;
483
484 return;
485 }
486
487 if (next_selected_row == OPTIONS_ROW_RUMBLE)
488 {
490
491 int32_t rumble_suppressed = Settings_GetRumbleSuppressFlag();
492
493 if (!rumble_suppressed)
494 {
495 Input_TriggerRumbleIfAllowed(rumble_suppressed, rumble_suppressed, MATH_Q12_ONE, 7);
496 out_result->selected_index = (uint8_t)next_selected_row;
497
498 return;
499 }
500 }
501 else if (next_selected_row == OPTIONS_ROW_GAMMA)
502 {
503 char gamma_setting = g_displaySetting;
504
505 if (g_menuInputLeft)
506 {
507 g_displaySetting = gamma_setting - 1;
508
509 if ((int8_t)(gamma_setting - 1) < 0)
511
513 out_result->selected_index = (uint8_t)next_selected_row;
514
515 return;
516 }
517
518 gamma_setting += 1;
519 g_displaySetting = gamma_setting;
520
521 if (gamma_setting > MENU_GAMMA_MAX)
522 {
523 gamma_setting = MENU_GAMMA_MAX;
525 }
526
527 D3D_SetGammaFromMenuSetting((int32_t)gamma_setting);
528 out_result->selected_index = (uint8_t)next_selected_row;
529
530 return;
531 }
532 }
533 else
534 next_selected_row = selected_row;
535
536 out_result->selected_index = (uint8_t)next_selected_row;
537
538 return;
539 }
540 }
541
543 {
544 out_result->action = MENU_ACTION_CONTINUE;
545 out_result->selected_index = 0;
547 }
548
549 out_result->sound_effect = g_menuSoundEffect;
550}
551
552// Original pcdogs.exe: 0x42a880
553// Renders the main options or controls subview and returns the button-prompt mask. Delegated controls views return zero, the main exit row returns three, and other main rows return one.
554int32_t Menu_RenderOptionsMenu(int32_t selected_option_index, uint32_t highlight_tint)
555{
556 int32_t submenu_state = g_menuUIState5;
557 int16_t option_label_string_ids[0x7];
558
559 option_label_string_ids[0] = 5;
560 option_label_string_ids[1] = 6;
561 option_label_string_ids[2] = 7;
562 option_label_string_ids[3] = 0x29;
563 option_label_string_ids[4] = 0x81;
564 option_label_string_ids[5] = 0x76;
565 option_label_string_ids[6] = 8;
566
567 if (submenu_state == MENU_STATE_PAUSE)
568 {
570
571 return 0;
572 }
573
574 if (submenu_state == MENU_STATE_OPTIONS)
575 {
577
578 return 0;
579 }
580
581 if (submenu_state == MENU_STATE_EXIT_CONFIRM)
582 {
584
585 return 0;
586 }
587
588 char *text = String_GetByIndex(0xb);
589 int32_t title_window_height = Graphics_WindowHeight;
590 int32_t title_window_width = Graphics_WindowWidth;
591
593 ((title_window_height / 2) - 0x80) << UI_PACKED_Y_SHIFT | (uint32_t)(uint16_t)(title_window_width / 2), text,
595
596 int32_t result = 1;
597
598 if (selected_option_index == 6)
599 result = 3;
600
601 for (int32_t i = 0; i < 7; i += 1)
602 {
603 int32_t option_tint;
604
605 if (i != selected_option_index)
606 option_tint = 0;
607 else
608 {
609 uint32_t highlight_channel = (uint32_t)(uint8_t)highlight_tint;
610
611 option_tint = ((highlight_channel | UI_TEXT_PACKED_COLOR_PREFIX) << 8 | highlight_channel) << 8 | (highlight_tint & GRAPHICS_COLOR_RGB_MASK);
612 }
613
614 char option_text_buffer[0x50];
615
616 switch (i)
617 {
619 {
620 int32_t music_volume = Settings_GetMusicVolume();
621
622 String_FormatCRTString(option_text_buffer, "%s %d", String_GetByIndex(5),
623 music_volume / MENU_OPTION_VOLUME_STEP);
624
625 break;
626 }
627
629 {
630 int32_t sfx_volume = Settings_GetSfxVolume();
631
632 String_FormatCRTString(option_text_buffer, "%s %d", String_GetByIndex(6),
633 sfx_volume / MENU_OPTION_VOLUME_STEP);
634
635 break;
636 }
637
639 {
640 const char *sound_setting_text = String_GetByIndex(Settings_IsSoundEnabled() ? 20 : 19);
641
642 String_FormatCRTString(option_text_buffer, "%s %s", String_GetByIndex(7), sound_setting_text);
643
644 break;
645 }
646
648 {
649 char *rumble_setting_text =
651
652 String_FormatCRTString(option_text_buffer, "%s %s", String_GetByIndex(0x29), rumble_setting_text);
653
654 break;
655 }
656
658 {
659 String_FormatCRTString(option_text_buffer, "%s %d", String_GetByIndex(0x81),
660 (int32_t)g_displaySetting);
661
662 break;
663 }
664
666 case OPTIONS_ROW_BACK:
667 {
668 char *label_scan = String_GetByIndex((int32_t)option_label_string_ids[i]);
669 int32_t label_scan_remaining = UI_UNBOUNDED_SCAN_COUNT;
670
671 while (label_scan_remaining)
672 {
673 bool label_char_nonzero = 0 != *(uint8_t *)label_scan;
674
675 label_scan = &label_scan[1];
676 label_scan_remaining -= 1;
677
678 if (!label_char_nonzero)
679 break;
680 }
681
682 int32_t label_bytes_including_terminator = ~label_scan_remaining;
683
684 memcpy(option_text_buffer, label_scan - label_bytes_including_terminator, (uint32_t)label_bytes_including_terminator);
685
686 break;
687 }
688 }
689
690 int32_t option_window_height = Graphics_WindowHeight;
691 int32_t option_window_width = Graphics_WindowWidth;
692
694 (((i - 3) << 5) + (option_window_height / 2)) << UI_PACKED_Y_SHIFT | (uint32_t)(uint16_t)(option_window_width / 2),
695 option_text_buffer, option_tint | UI_TEXT_ALIGN_CENTER, NULL);
696 }
697
698 return result;
699}
#define GRAPHICS_COLOR_RGB_MASK
Definition constants.h:38
#define Graphics_WindowWidth
Definition globals.h:140
#define Graphics_WindowHeight
Definition globals.h:143
#define INPUT_NO_CONTROL
Definition constants.h:59
#define INPUT_KEY_CODE_COUNT
Definition constants.h:28
int32_t Input_GetPressedButton(void)
Definition state.c:317
void Input_InitializeButtonMappings(void)
Definition bindings.c:109
int32_t Input_TriggerRumbleIfAllowed(int32_t source_id, BOOL full_strength, int32_t magnitude_fp12, int32_t duration_units)
#define g_controllerPresets
Definition globals.h:126
#define MATH_Q12_ONE
Definition constants.h:9
#define MENU_BINDING_INDEX_NONE
Definition constants.h:65
#define MENU_GAMMA_MAX
Definition constants.h:71
@ OPTIONS_SUBMENU_PRESET_CONFIRM
Definition constants.h:28
@ OPTIONS_SUBMENU_BINDINGS
Definition constants.h:26
@ OPTIONS_SUBMENU_PRESET_LIST
Definition constants.h:27
@ OPTIONS_SUBMENU_MAIN
Definition constants.h:25
@ MENU_STATE_PAUSE
Definition constants.h:8
@ MENU_STATE_OPTIONS
Definition constants.h:9
@ MENU_STATE_EXIT_CONFIRM
Definition constants.h:10
@ MENU_BINDING_ACTION_ACCEPT
Definition constants.h:132
@ MENU_BINDING_ROW_ACTIONS
Definition constants.h:107
@ MENU_BINDING_ROW_PRESETS
Definition constants.h:106
@ MENU_BINDING_ROW_KEYBOARD_ONLY
Definition constants.h:105
@ MENU_ACTION_COMPLETE
Definition constants.h:35
@ MENU_ACTION_CONTINUE
Definition constants.h:33
@ MENU_ACTION_BINDINGS
Definition constants.h:36
#define MENU_OPTION_VOLUME_MAX
Definition constants.h:70
#define MENU_OPTION_VOLUME_STEP
Definition constants.h:68
#define MENU_OPTION_VOLUME_SNAP_THRESHOLD
Definition constants.h:69
@ OPTIONS_ROW_STEREO
Definition constants.h:43
@ OPTIONS_ROW_BACK
Definition constants.h:47
@ OPTIONS_ROW_GAMMA
Definition constants.h:45
@ OPTIONS_ROW_SFX_VOLUME
Definition constants.h:42
@ OPTIONS_ROW_CONTROLS
Definition constants.h:46
@ OPTIONS_ROW_RUMBLE
Definition constants.h:44
@ OPTIONS_ROW_MUSIC_VOLUME
Definition constants.h:41
void Menu_RenderControllerPresetConfirmation(void)
Definition controls.c:315
void Options_FindBindingConflict(struct Config_Data *settings, struct Options_BindingLocation *out_first_conflict, struct Options_BindingLocation *out_second_conflict)
Definition controls.c:29
void Menu_RenderControlsConfiguration(void)
Definition controls.c:87
void Menu_RenderControllerPresetSelection(void)
Definition controls.c:290
#define g_menuInputConfirm
Definition globals.h:96
#define g_optionsMenuSubState
Definition globals.h:132
#define g_optionsMenuBackupData
Definition globals.h:36
#define g_menuInputDown
Definition globals.h:87
#define g_optionsMenuValue1
Definition globals.h:33
#define g_controlsMenuButtonIndex
Definition globals.h:81
#define g_menuSoundEffect
Definition globals.h:54
#define g_menuInputUp
Definition globals.h:84
#define g_menuInputRight
Definition globals.h:93
#define g_controlsMenuKeyIndex
Definition globals.h:78
#define g_menuInputLeft
Definition globals.h:90
#define g_menuUIState5
Definition globals.h:129
#define g_optionsMenuState
Definition globals.h:126
#define Options_MenuSelection
Definition globals.h:123
#define g_menuInputCancel
Definition globals.h:99
#define g_optionsMenuColumn
Definition globals.h:120
void Menu_ProcessOptionsInput(struct Menu_ActionResult *out_result, int32_t selected_row)
Definition options.c:336
int32_t Menu_HandleOptionsLogic()
Definition options.c:32
int32_t Menu_RenderOptionsMenu(int32_t selected_option_index, uint32_t highlight_tint)
Definition options.c:554
void D3D_SetGammaFromMenuSetting(int32_t gamma_setting)
#define g_displaySetting
Definition globals.h:216
int32_t String_FormatCRTString(char *buffer, char const *format,...)
Definition formatting.c:18
void Settings_SetRumbleSuppressFlag(uint8_t suppress_rumble)
Definition preferences.c:84
uint16_t Settings_GetSfxVolume(void)
Definition preferences.c:13
void Settings_SetMusicVolume(uint16_t volume_fp12)
Definition preferences.c:34
int32_t Settings_GetRumbleSuppressFlag(void)
Definition preferences.c:77
uint16_t Settings_GetMusicVolume(void)
Definition preferences.c:27
void Settings_SetSfxVolume(uint16_t volume_fp12)
Definition preferences.c:20
void Config_SaveSettingsToINI(struct Config_Data const *config_data)
Definition config.c:86
void Settings_SetSoundEnabled(int32_t enabled)
Definition preferences.c:48
int32_t Settings_IsSoundEnabled(void)
Definition preferences.c:41
#define g_liveSettings
Definition globals.h:27
#define g_optionsEntrySettings
Definition globals.h:28
uint8_t action
Definition types.h:10
uint8_t sound_effect
Definition types.h:12
uint8_t selected_index
Definition types.h:11
char * String_GetByIndex(int32_t string_id)
Definition strings.c:66
#define UI_TEXT_PACKED_COLOR_PREFIX
Definition constants.h:14
#define UI_SOUND_NONE
Definition constants.h:84
#define UI_TEXT_ALIGN_CENTER
Definition constants.h:6
#define UI_PACKED_Y_SHIFT
Definition constants.h:93
#define UI_UNBOUNDED_SCAN_COUNT
Definition constants.h:97
void UI_RenderText(uint32_t packed_xy, char const *text, uint32_t text_flags, void *font_context)
Definition text.c:226
#define g_buttonRemappingActive
Definition values.h:429