From 3fc7ac038d89197c8901dd2fb9bb31a6c9617a43 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Mon, 9 Sep 2024 23:45:20 +0200 Subject: [PATCH] input: fix retaining default layout conflicts Resolves #228. --- src/decomp/decomp.c | 1 + src/game/input.c | 15 +++++++++++++++ src/game/input.h | 2 ++ src/game/option/option_controls.c | 16 +--------------- src/inject_exec.c | 1 - 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/decomp/decomp.c b/src/decomp/decomp.c index 5b1c343e..dda24529 100644 --- a/src/decomp/decomp.c +++ b/src/decomp/decomp.c @@ -3037,5 +3037,6 @@ void __cdecl S_SaveSettings(void) SetRegistryBinaryValue( "Layout", (uint8_t *)&g_Layout[1], sizeof(uint16_t) * INPUT_ROLE_NUMBER_OF); + Input_CheckConflictsWithDefaults(); CloseGameRegistryKey(); } diff --git a/src/game/input.c b/src/game/input.c index 32ba201f..da06f77f 100644 --- a/src/game/input.c +++ b/src/game/input.c @@ -127,3 +127,18 @@ const char *Input_GetKeyName(const uint16_t key) { return m_KeyNames[key]; } + +void __cdecl Input_CheckConflictsWithDefaults(void) +{ + for (int32_t i = 0; i < INPUT_ROLE_NUMBER_OF; i++) { + g_ConflictLayout[i] = false; + for (int32_t j = 0; j < INPUT_ROLE_NUMBER_OF; j++) { + const uint16_t key1 = Input_GetAssignedKey(0, i); + const uint16_t key2 = Input_GetAssignedKey(1, j); + if (key1 == key2) { + g_ConflictLayout[i] = true; + break; + } + } + } +} diff --git a/src/game/input.h b/src/game/input.h index 9802c642..5fdbf057 100644 --- a/src/game/input.h +++ b/src/game/input.h @@ -73,3 +73,5 @@ uint16_t Input_GetAssignedKey(int32_t layout, INPUT_ROLE role); const char *Input_GetLayoutName(int32_t layout); const char *Input_GetRoleName(INPUT_ROLE role); const char *Input_GetKeyName(uint16_t key); + +void __cdecl Input_CheckConflictsWithDefaults(void); diff --git a/src/game/option/option_controls.c b/src/game/option/option_controls.c index 71c48d80..35ec856e 100644 --- a/src/game/option/option_controls.c +++ b/src/game/option/option_controls.c @@ -7,25 +7,11 @@ static UI_WIDGET *m_ControlsDialog; static UI_CONTROLS_CONTROLLER m_ControlsDialogController; -void __cdecl Option_Controls_DefaultConflict(void) -{ - for (int32_t i = 0; i < INPUT_ROLE_NUMBER_OF; i++) { - g_ConflictLayout[i] = false; - for (int32_t j = 0; j < INPUT_ROLE_NUMBER_OF; j++) { - const uint16_t key1 = Input_GetAssignedKey(0, i); - const uint16_t key2 = Input_GetAssignedKey(1, j); - if (key1 == key2) { - g_ConflictLayout[i] = true; - } - } - } -} - void Option_Controls_Shutdown(void) { m_ControlsDialog->free(m_ControlsDialog); m_ControlsDialog = NULL; - Option_Controls_DefaultConflict(); + Input_CheckConflictsWithDefaults(); } void __cdecl Option_Controls(INVENTORY_ITEM *const item) diff --git a/src/inject_exec.c b/src/inject_exec.c index 5cf2d9f5..44e01137 100644 --- a/src/inject_exec.c +++ b/src/inject_exec.c @@ -384,7 +384,6 @@ static void Inject_Option(const bool enable) INJECT(enable, 0x0044F520, Option_Detail); INJECT(enable, 0x0044F800, Option_Sound); INJECT(enable, 0x0044FCA0, Option_Compass); - INJECT(enable, 0x0044FDE0, Option_Controls_DefaultConflict); INJECT(enable, 0x0044FE20, Option_Controls); }