From 63d9f35a78c37e2d1d43f6a73aae544ed09e8770 Mon Sep 17 00:00:00 2001 From: Didac Date: Sun, 24 Nov 2024 20:09:56 +0100 Subject: [PATCH] Added safeui option to Nyx and ofw as launch option to be selected en launch menu and konami code --- bdk/input/joycon.h | 26 ++++++++++++ nyx/Makefile | 1 + nyx/nyx_gui/config.c | 5 +++ nyx/nyx_gui/config.h | 1 + nyx/nyx_gui/frontend/gui.c | 75 +++++++++++++++++++++++++++++++++-- nyx/nyx_gui/frontend/konami.c | 41 +++++++++++++++++++ nyx/nyx_gui/frontend/konami.h | 10 +++++ nyx/nyx_gui/nyx.c | 2 + 8 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 nyx/nyx_gui/frontend/konami.c create mode 100644 nyx/nyx_gui/frontend/konami.h diff --git a/bdk/input/joycon.h b/bdk/input/joycon.h index fbb789f..9d0c63f 100644 --- a/bdk/input/joycon.h +++ b/bdk/input/joycon.h @@ -28,6 +28,32 @@ #define JC_BTNS_ALL (JC_BTNS_PREV_NEXT | JC_BTNS_ENTER | JC_BTNS_DIRECTION_PAD | JC_BTNS_ESC) +// Joy-Con buttons mask +#define JC_BTNS_Y 0x000001 +#define JC_BTNS_X 0x000002 +#define JC_BTNS_B 0x000004 +#define JC_BTNS_A 0x000008 +#define JC_BTNS_SR_R 0x000010 +#define JC_BTNS_SL_R 0x000020 +#define JC_BTNS_R 0x000040 +#define JC_BTNS_ZR 0x000080 +#define JC_BTNS_MINUS 0x000100 +#define JC_BTNS_PLUS 0x000200 +#define JC_BTNS_R3 0x000400 +#define JC_BTNS_L3 0x000800 +#define JC_BTNS_HOME 0x001000 +#define JC_BTNS_CAPTURE 0x002000 +#define JC_BTNS_PAD 0x004000 +#define JC_BTNS_WIRED 0x008000 +#define JC_BTNS_DOWN 0x010000 +#define JC_BTNS_UP 0x020000 +#define JC_BTNS_RIGHT 0x040000 +#define JC_BTNS_LEFT 0x080000 +#define JC_BTNS_SR_L 0x100000 +#define JC_BTNS_SL_L 0x200000 +#define JC_BTNS_L 0x400000 +#define JC_BTNS_ZL 0x800000 + typedef struct _jc_bt_conn_t { u8 type; diff --git a/nyx/Makefile b/nyx/Makefile index af7ab34..b33c1a9 100644 --- a/nyx/Makefile +++ b/nyx/Makefile @@ -27,6 +27,7 @@ OBJS = $(addprefix $(BUILDDIR)/$(TARGET)/, \ start.o exception_handlers.o \ nyx.o heap.o \ gfx.o \ + konami.o \ gui.o gui_info.o gui_tools.o gui_options.o gui_emmc_tools.o gui_emummc_tools.o gui_tools_partition_manager.o \ fe_emummc_tools.o fe_emmc_tools.o \ ) diff --git a/nyx/nyx_gui/config.c b/nyx/nyx_gui/config.c index b70d437..e0efc8e 100644 --- a/nyx/nyx_gui/config.c +++ b/nyx/nyx_gui/config.c @@ -60,6 +60,7 @@ void set_nyx_default_configuration() n_cfg.jc_disable = 0; n_cfg.jc_force_right = 0; n_cfg.bpmp_clock = 0; + n_cfg.safeui = 0; } int create_config_entry() @@ -242,6 +243,10 @@ int create_nyx_config_entry(bool force_unmount) itoa(n_cfg.bpmp_clock, lbuf, 10); f_puts(lbuf, &fp); + f_puts("\nsafeui=", &fp); + itoa(n_cfg.safeui, lbuf, 10); + f_puts(lbuf, &fp); + f_puts("\n", &fp); f_close(&fp); diff --git a/nyx/nyx_gui/config.h b/nyx/nyx_gui/config.h index d2076e8..2e49543 100644 --- a/nyx/nyx_gui/config.h +++ b/nyx/nyx_gui/config.h @@ -54,6 +54,7 @@ typedef struct _nyx_config u32 jc_disable; u32 jc_force_right; u32 bpmp_clock; + u32 safeui; } nyx_config; void set_default_configuration(); diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index e5cbdd2..d9cee13 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -29,6 +29,7 @@ #include "../config.h" #include +#include "konami.h" extern hekate_config h_cfg; extern nyx_config n_cfg; @@ -615,6 +616,8 @@ static bool _jc_virt_mouse_read(lv_indev_data_t *data) close_btn = NULL; } + check_konami_code(jc_pad); + return false; // No buffering so no more data read. } @@ -779,6 +782,35 @@ lv_res_t mbox_action(lv_obj_t *btns, const char *txt) return LV_RES_INV; } +lv_res_t mbox_konami_action(lv_obj_t *btns, const char *txt) +{ + lv_obj_t *mbox = lv_mbox_get_from_btn(btns); + + // Do here some konami code related stuff + // put safeui to false and homescreen to 0 + n_cfg.safeui = 0; + n_cfg.home_screen = 0; + + //store nyx config + int res = !create_nyx_config_entry(true); + + if(res){ + lv_obj_t *dark_bg = lv_obj_get_parent(mbox); + lv_obj_del(dark_bg); // Deletes children also (mbox). + reload_nyx(); + return LV_RES_INV; + }else { + static const char * mbox_btn_map[] = {"\251", "\222OK!", "\251", ""}; + mbox = lv_mbox_create(lv_scr_act(), NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_mbox_set_text(mbox, "#FF8000 Nyx Configuration#\n\n#FFDD00 Failed to save the configuration#\n#FFDD00 to sd card!#"); + lv_mbox_add_btns(mbox, mbox_btn_map, NULL); + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); + return LV_RES_OK; + } +} + bool nyx_emmc_check_battery_enough() { if (fuse_read_hw_state() == FUSE_NX_HW_STATE_DEV) @@ -1508,7 +1540,10 @@ static lv_obj_t *create_window_launch(const char *win_title) lv_win_set_style(win, LV_WIN_STYLE_BG, &win_bg_style); - close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", _win_launch_close_action); + if(!n_cfg.safeui) + close_btn = lv_win_add_btn(win, NULL, SYMBOL_CLOSE" Close", _win_launch_close_action); + else + close_btn = NULL; return win; } @@ -1522,6 +1557,12 @@ static lv_res_t _launch_action(lv_obj_t *btn) return LV_RES_OK; } +static lv_res_t _launch_ofw_action(lv_obj_t *btn) +{ + power_set_state(REBOOT_BYPASS_FUSES); + return LV_RES_OK; +} + static lv_res_t logs_onoff_toggle(lv_obj_t *btn) { launch_logs_enable = !launch_logs_enable; @@ -1639,7 +1680,8 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn) else win = create_window_launch(SYMBOL_GPS" More Configurations"); - lv_win_add_btn(win, NULL, SYMBOL_LIST" Logs #D0D0D0 OFF#", logs_onoff_toggle); + if(!n_cfg.safeui) + lv_win_add_btn(win, NULL, SYMBOL_LIST" Logs #D0D0D0 OFF#", logs_onoff_toggle); launch_logs_enable = false; lv_cont_set_fit(lv_page_get_scrl(lv_win_get_content(win)), false, false); @@ -1733,6 +1775,7 @@ ini_parsing: icon_path = NULL; bool payload = false; + bool ofw = false; bool img_colorize = false; bool img_noborder = false; lv_img_dsc_t *bmp = NULL; @@ -1745,6 +1788,9 @@ ini_parsing: icon_path = kv->val; else if (!strcmp("payload", kv->key)) payload = true; + else if (!strcmp("ofw", kv->key)) + if (kv->val[0] == '1') + ofw = true; } // If icon not found, check res folder for section_name.bmp. @@ -1863,7 +1909,9 @@ ini_parsing: ext->idx = entry_idx; // Set action. - if (!more_cfg) + if(ofw) + lv_btn_set_action(btns, LV_BTN_ACTION_CLICK, _launch_ofw_action); + else if (!more_cfg) lv_btn_set_action(btns, LV_BTN_ACTION_CLICK, _launch_action); else lv_btn_set_action(btns, LV_BTN_ACTION_CLICK, _launch_more_cfg_action); @@ -2276,6 +2324,24 @@ void first_time_bpmp_clock(void *param) create_nyx_config_entry(false); } +static void _show_mbox_konami(){ + + lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style(dark_bg, &mbox_darken); + lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); + + static const char * mbox_btn_map[] = { "\251", "\222OK", "\251", "" }; + lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL); + lv_mbox_set_recolor_text(mbox, true); + lv_obj_set_width(mbox, LV_HOR_RES * 5 / 9); + + lv_mbox_set_text(mbox, "#FF8000 Konami Code#\n\n#96FF00 You found a secret!#"); + lv_mbox_add_btns(mbox, mbox_btn_map, mbox_konami_action); + + lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_top(mbox, true); +} + static void _nyx_main_menu(lv_theme_t * th) { static lv_style_t no_padding; @@ -2446,6 +2512,9 @@ void nyx_load_and_run() // Create main menu _nyx_main_menu(th); + // Register konami code handler + register_konami_code_handler(_show_mbox_konami); + jc_drv_ctx.cursor = lv_img_create(lv_scr_act(), NULL); lv_img_set_src(jc_drv_ctx.cursor, &touch_cursor); lv_obj_set_opa_scale(jc_drv_ctx.cursor, LV_OPA_TRANSP); diff --git a/nyx/nyx_gui/frontend/konami.c b/nyx/nyx_gui/frontend/konami.c new file mode 100644 index 0000000..0d97d80 --- /dev/null +++ b/nyx/nyx_gui/frontend/konami.c @@ -0,0 +1,41 @@ +#include "konami.h" + +// pointer to function +static void (*konami_code_handler)(void) = NULL; + +void check_konami_code(jc_gamepad_rpt_t *jc_pad){ + + static u32 konami_code[] = { + JC_BTNS_UP, + JC_BTNS_UP, + JC_BTNS_DOWN, + JC_BTNS_DOWN, + JC_BTNS_LEFT, + JC_BTNS_RIGHT, + JC_BTNS_LEFT, + JC_BTNS_RIGHT, + JC_BTNS_B, + JC_BTNS_A + }; + + static u8 konami_code_idx = 0; + + u32 key_pressed = (jc_pad->buttons & konami_code[konami_code_idx]); + if (key_pressed && (key_pressed == konami_code[konami_code_idx] || key_pressed == konami_code[(konami_code_idx = 0)])) + { + konami_code_idx++; + if (konami_code_idx == 10) + { + konami_code_idx = 0; + if (konami_code_handler) + { + (*konami_code_handler)(); + } + } + } +} + +void register_konami_code_handler(// pointer to function +void (*handler)(void)) { + konami_code_handler = handler; +} diff --git a/nyx/nyx_gui/frontend/konami.h b/nyx/nyx_gui/frontend/konami.h new file mode 100644 index 0000000..c2079b7 --- /dev/null +++ b/nyx/nyx_gui/frontend/konami.h @@ -0,0 +1,10 @@ +#ifndef _KONAMI_H_ +#define _KONAMI_H_ + +#include + +void check_konami_code(jc_gamepad_rpt_t *jc_pad); +void register_konami_code_handler(// pointer to function +void (*handler)(void)); + +#endif /* _KONAMI_H_ */ \ No newline at end of file diff --git a/nyx/nyx_gui/nyx.c b/nyx/nyx_gui/nyx.c index 86d90cd..d2b05b1 100644 --- a/nyx/nyx_gui/nyx.c +++ b/nyx/nyx_gui/nyx.c @@ -286,6 +286,8 @@ skip_main_cfg_parse: n_cfg.jc_force_right = atoi(kv->val) == 1; else if (!strcmp("bpmpclock", kv->key)) n_cfg.bpmp_clock = atoi(kv->val); + else if (!strcmp("safeui", kv->key)) + n_cfg.safeui = atoi(kv->val) == 1; } break;