From d8521dfdb9bfa8101d0612e3b5e34a78e45f60bb Mon Sep 17 00:00:00 2001 From: d0k3 Date: Thu, 7 Dec 2017 02:58:49 +0100 Subject: [PATCH] Added TIMER_UNLOCK build parameter --- Makefile.common | 4 +++ arm9/source/common/ui.c | 56 +++++++++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/Makefile.common b/Makefile.common index 43b589e..fd42219 100644 --- a/Makefile.common +++ b/Makefile.common @@ -42,6 +42,10 @@ ifeq ($(AUTO_UNLOCK),1) CFLAGS += -DAUTO_UNLOCK endif +ifeq ($(TIMER_UNLOCK),1) + CFLAGS += -DTIMER_UNLOCK +endif + ifdef FIXED_BRIGHTNESS CFLAGS += -DFIXED_BRIGHTNESS=$(FIXED_BRIGHTNESS) endif diff --git a/arm9/source/common/ui.c b/arm9/source/common/ui.c index 59c879d..38be6ec 100644 --- a/arm9/source/common/ui.c +++ b/arm9/source/common/ui.c @@ -323,7 +323,6 @@ bool ShowPrompt(bool ask, const char *format, ...) #ifndef AUTO_UNLOCK #define PRNG (*(volatile u32*)0x10011000) bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) { - const char dpad_symbols[] = { '\x1A', '\x1B', '\x18', '\x19' }; // R L U D const int seqcolors[7] = { COLOR_STD_FONT, COLOR_BRIGHTGREEN, COLOR_BRIGHTYELLOW, COLOR_ORANGE, COLOR_BRIGHTBLUE, COLOR_RED, COLOR_DARKRED }; const u32 seqlen_max = 7; @@ -340,21 +339,6 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) { u32 x, y; - // generate sequence - u32 sequence[seqlen_max]; - char seqsymbols[seqlen_max]; - u32 lastlsh = (u32) -1; - for (u32 n = 0; n < (seqlen-1); n++) { - u32 lsh = lastlsh; - while (lsh == lastlsh) lsh = (PRNG & 0x3); - lastlsh = lsh; - sequence[n] = BUTTON_RIGHT << lsh; - seqsymbols[n] = dpad_symbols[lsh]; - } - sequence[seqlen-1] = BUTTON_A; - seqsymbols[seqlen-1] = 'A'; - - char str[STRBUF_SIZE] = { 0 }; va_list va; va_start(va, format); @@ -376,8 +360,26 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) { ClearScreenF(true, false, color_bg); DrawStringF(MAIN_SCREEN, x, y, color_font, color_bg, str); + #ifndef TIMER_UNLOCK DrawStringF(MAIN_SCREEN, x, y + str_height - 28, color_font, color_bg, "To proceed, enter this:"); + // generate sequence + const char dpad_symbols[] = { '\x1A', '\x1B', '\x18', '\x19' }; // R L U D + + u32 sequence[seqlen_max]; + char seqsymbols[seqlen_max]; + u32 lastlsh = (u32) -1; + for (u32 n = 0; n < (seqlen-1); n++) { + u32 lsh = lastlsh; + while (lsh == lastlsh) lsh = (PRNG & 0x3); + lastlsh = lsh; + sequence[n] = BUTTON_RIGHT << lsh; + seqsymbols[n] = dpad_symbols[lsh]; + } + sequence[seqlen-1] = BUTTON_A; + seqsymbols[seqlen-1] = 'A'; + + while (true) { for (u32 n = 0; n < seqlen; n++) { DrawStringF(MAIN_SCREEN, x + (n*4*FONT_WIDTH_EXT), y + str_height - 18, @@ -395,6 +397,28 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) { else if (lvl == 0 || !(pad_state & sequence[lvl-1])) lvl = 0; } + #else + DrawStringF(MAIN_SCREEN, x, y + str_height - 28, color_font, color_bg, "To proceed, hold :"); + + while (!CheckButton(BUTTON_B)) { + for (u32 n = 0; n < seqlen; n++) { + DrawStringF(MAIN_SCREEN, x + (n*4*FONT_WIDTH_EXT), y + str_height - 18, + (lvl > n) ? color_on : color_off, color_bg, "<%c>", (lvl > n) ? 'X' : ' '); + } + if (lvl == seqlen) + break; + + u32 prev_lvl = lvl; + while (lvl == prev_lvl) { + u64 timer = timer_start(); + while ((lvl != 0) && CheckButton(BUTTON_X) && (timer_msec(timer) < 400)); + + if (CheckButton(BUTTON_B)) break; + else if (CheckButton(BUTTON_X)) lvl++; + else lvl = 0; + } + } + #endif ClearScreenF(true, false, COLOR_STD_BG);