diff --git a/docs/cheats.md b/docs/cheats.md index f41ff58d..2fc271f4 100644 --- a/docs/cheats.md +++ b/docs/cheats.md @@ -2,7 +2,7 @@ The port reads Atmosphère cheat files, the format Switch homebrew and the emulators use. The setup installs a cheat file for 1.2.1 and for 1.4.3, all cheats off: open the menu (F1) and switch them on the Cheats tab. The switches are saved under `[cheats]` in `totk.ini`. -The two files are from [MyNXCheats](https://github.com/Arch9SK7/MyNXCheats) by Skyla Kikari (Arch9SK7) and stay in `tools/data/cheats/` with that credit at the top. Only the 1.4.3 file has been tried in game. +The two files are from [MyNXCheats](https://github.com/Arch9SK7/MyNXCheats) by Skyla Kikari (Arch9SK7) and stay in `tools/data/cheats/` with that credit at the top. The 1.2.1 file has not been tried in game. ## Adding your own cheat file diff --git a/runtime/cheats.c b/runtime/cheats.c index 69495e22..132b3ebf 100644 --- a/runtime/cheats.c +++ b/runtime/cheats.c @@ -399,6 +399,14 @@ static int status_of(char *status, const char *key, char **fields) { return 0; } +// The menu's font has no numero sign (U+2116), which cheat names often start with: they show "No" instead. +static void plain_name(char *s) { + for (char *p; (p = strstr(s, "\xE2\x84\x96")) != NULL;) { + p[0] = 'N', p[1] = 'o'; + memmove(p + 2, p + 3, strlen(p + 3) + 1); + } +} + void cheats_init(void) { const RtLoaded *m = ldr_count() ? ldr_module(0) : NULL; char dir[PLAT_PATH_MAX], bid[17], path[PLAT_PATH_MAX + 64]; @@ -465,6 +473,7 @@ void cheats_init(void) { counts[kind]++; } free(status); + for (int i = 0; i < g_n; i++) plain_name((char *)g_cheats[i].info.name); // the hashes above read the file's bytes int on = 0; for (int i = 0; i < g_n; i++) on += g_cheats[i].on && g_cheats[i].info.kind != CHEAT_HEADING; rt_log("cheats: %s: %d cheats, %d on; %d code, %d while buttons are held, %d data, %d master, %d restore, " diff --git a/runtime/ui/cheats_tab.cpp b/runtime/ui/cheats_tab.cpp new file mode 100644 index 00000000..cd1967ba --- /dev/null +++ b/runtime/ui/cheats_tab.cpp @@ -0,0 +1,58 @@ +// The Cheats tab of the in-game menu: the cheats of cheats\.txt (cheats.c), a row per cheat in file order and +// a heading per group label; a cheat that cannot be switched here is greyed out with the reason. +#include +#include + +#include "imgui.h" +#include "ui/option_rows.h" + +extern "C" { +#include "cheats.h" +#include "ui_text.h" +} + +extern "C" void tab_cheats(float scale) { + opt_begin("##cheats", scale); + static char line[512], desc[768], buttons[192]; + int n = cheats_count(); + if (!n) { + snprintf(line, sizeof line, menu_text(UI_MENU_CHEATS_NONE), + cheats_file()[0] ? cheats_file() : "cheats\\.txt"); + opt_text_str(line); + opt_end(); + return; + } + int listed = 0; + for (int i = 0; i < n; i++) listed += cheats_info(i)->kind != CHEAT_HEADING; + snprintf(line, sizeof line, menu_text(UI_MENU_CHEATS_FILE), cheats_file(), listed); + opt_text_str(line); + for (int i = 0; i < n; i++) { + const CheatInfo *c = cheats_info(i); + UiTextId text = UI_MENU_CHEAT_CODE_DESC; + switch (c->kind) { + case CHEAT_HEADING: + if (!strstr(c->name, "TID=")) opt_group_text(c->name); // the file's title line only names the game + continue; + case CHEAT_CODE: break; + case CHEAT_KEY: text = UI_MENU_CHEAT_KEY_DESC; break; + case CHEAT_DATA: text = UI_MENU_CHEAT_DATA_DESC; break; + case CHEAT_MASTER: text = UI_MENU_CHEAT_MASTER_DESC, opt_disable_next(UI_MENU_CHEAT_MASTER); break; + case CHEAT_RESTORE: text = UI_MENU_CHEAT_RESTORE_DESC, opt_disable_next(UI_MENU_CHEAT_RESTORE); break; + case CHEAT_REBUILD: text = UI_MENU_CHEAT_REBUILD_DESC, opt_disable_next(UI_MENU_CHEAT_REBUILD); break; + case CHEAT_UNSUPPORTED: + text = UI_MENU_CHEAT_UNSUPPORTED_DESC, opt_disable_next(UI_MENU_CHEAT_UNSUPPORTED); + break; + } + if (c->kind == CHEAT_KEY) + snprintf(desc, sizeof desc, menu_text(text), cheats_buttons(c->buttons, buttons, sizeof buttons)); + else if (c->kind == CHEAT_UNSUPPORTED) + snprintf(desc, sizeof desc, "%s %s", menu_text(text), c->note); + else + snprintf(desc, sizeof desc, "%s", menu_text(text)); + if (opt_toggle_text(c->key, c->name, desc, cheats_on(i) != 0)) { + cheats_set(i, !cheats_on(i)); + opt_save_soon(); + } + } + opt_end(); +} diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 7a12b186..0b9fafd8 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -35,7 +35,6 @@ static int g_font_bad; extern "C" { #include "cfg.h" -#include "cheats.h" #include "input.h" #include "input_map.h" #include "perfmon.h" @@ -54,6 +53,8 @@ extern const int rt_game_version; int romfs_xbox_prompts_ready(void); int romfs_xbox_prompts_active(void); extern const char rt_port_version[]; +void cheats_frame(uint64_t frame); // cheats.c +void tab_cheats(float scale); // ui/cheats_tab.cpp } // Roboto Medium (Apache-2.0, ui/fonts/LICENSE-Roboto.txt) with Latin and Cyrillic glyphs. @@ -265,11 +266,10 @@ static int vk_up(const MenuTarget *t) { return 1; } -// Roboto Medium (Latin, Cyrillic, dashes, quotes and the numero sign of cheat names) at 26 px per 1080 lines, with -// the glyphs of the Japanese, Korean and Chinese language names merged in from a system font when there is one (each -// language is named in its own script). Made again when the window height changes; the old texture goes after the -// queue is idle (CreateFontsTexture). -static const ImWchar kRanges[] = {0x0020, 0x00FF, 0x0400, 0x052F, 0x2010, 0x2027, 0x2116, 0x2116, 0}; +// Roboto Medium (Latin, Cyrillic, dashes and quotes) at 26 px per 1080 lines, with the glyphs of the Japanese, Korean +// and Chinese language names merged in from a system font when there is one (each language is named in its own script). +// Made again when the window height changes; the old texture goes after the queue is idle (CreateFontsTexture). +static const ImWchar kRanges[] = {0x0020, 0x00FF, 0x0400, 0x052F, 0x2010, 0x2027, 0}; static const struct { const char *lang; UiTextId name; } kCjk[] = { {"ja", UI_MENU_LANGNAME_JA}, {"ko", UI_MENU_LANGNAME_KO}, {"zh-Hans", UI_MENU_LANGNAME_ZH_HANS}, {"zh-Hant", UI_MENU_LANGNAME_ZH_HANT}, @@ -693,54 +693,6 @@ static void tab_menu(float scale) { opt_end(); } -// ---- Cheats: the cheats of cheats\.txt (cheats.c), a row per cheat in file order and a heading per group -// label; a cheat that cannot be switched here is greyed out with the reason. -static void tab_cheats(float scale) { - opt_begin("##cheats", scale); - static char line[512], desc[768], buttons[192]; - int n = cheats_count(); - if (!n) { - snprintf(line, sizeof line, menu_text(UI_MENU_CHEATS_NONE), - cheats_file()[0] ? cheats_file() : "cheats\\.txt"); - opt_text_str(line); - opt_end(); - return; - } - int listed = 0; - for (int i = 0; i < n; i++) listed += cheats_info(i)->kind != CHEAT_HEADING; - snprintf(line, sizeof line, menu_text(UI_MENU_CHEATS_FILE), cheats_file(), listed); - opt_text_str(line); - for (int i = 0; i < n; i++) { - const CheatInfo *c = cheats_info(i); - UiTextId text = UI_MENU_CHEAT_CODE_DESC; - switch (c->kind) { - case CHEAT_HEADING: - if (!strstr(c->name, "TID=")) opt_group_text(c->name); // the file's title line only names the game - continue; - case CHEAT_CODE: break; - case CHEAT_KEY: text = UI_MENU_CHEAT_KEY_DESC; break; - case CHEAT_DATA: text = UI_MENU_CHEAT_DATA_DESC; break; - case CHEAT_MASTER: text = UI_MENU_CHEAT_MASTER_DESC, opt_disable_next(UI_MENU_CHEAT_MASTER); break; - case CHEAT_RESTORE: text = UI_MENU_CHEAT_RESTORE_DESC, opt_disable_next(UI_MENU_CHEAT_RESTORE); break; - case CHEAT_REBUILD: text = UI_MENU_CHEAT_REBUILD_DESC, opt_disable_next(UI_MENU_CHEAT_REBUILD); break; - case CHEAT_UNSUPPORTED: - text = UI_MENU_CHEAT_UNSUPPORTED_DESC, opt_disable_next(UI_MENU_CHEAT_UNSUPPORTED); - break; - } - if (c->kind == CHEAT_KEY) - snprintf(desc, sizeof desc, menu_text(text), cheats_buttons(c->buttons, buttons, sizeof buttons)); - else if (c->kind == CHEAT_UNSUPPORTED) - snprintf(desc, sizeof desc, "%s %s", menu_text(text), c->note); - else - snprintf(desc, sizeof desc, "%s", menu_text(text)); - if (opt_toggle_text(c->key, c->name, desc, cheats_on(i) != 0)) { - cheats_set(i, !cheats_on(i)); - opt_save_soon(); - } - } - opt_end(); -} - // ---- Advanced: the testing and troubleshooting keys, the bug report helpers and the reset of every setting static bool g_modal; // the reset confirmation is open: B and Esc close it, not the menu; L / R stay on the page diff --git a/tools/make_release.py b/tools/make_release.py index b5065be5..364b7af9 100644 --- a/tools/make_release.py +++ b/tools/make_release.py @@ -101,9 +101,9 @@ LLVM_SKIP_DIRS = {'aarch64-w64-mingw32', 'armv7-w64-mingw32', 'i686-w64-mingw32' LLVM_SKIP_SUFFIXES = {'.idl', '.tlb'} # tools/ files the installer steps run (and what they import), copied from the repo. -TOOLS_FILES = ['build_game.py', 'build_shaders.py', 'cheats.py', 'check_content.py', 'extract.py', 'hostmem.py', - 'make_romfs_patches.py', 'pack_shader_cache.py', 'prepare_shaders.py', 'romfs_index.py', 'shader_census.py', 'shader_list.py', - 'ultrawide_layout.py'] +TOOLS_FILES = ['build_game.py', 'build_shaders.py', 'check_content.py', 'extract.py', 'hostmem.py', 'make_romfs_patches.py', + 'pack_shader_cache.py', 'prepare_shaders.py', 'romfs_index.py', 'shader_census.py', 'shader_list.py', + 'ultrawide_layout.py', 'cheats.py'] TOOLS_DIRS = ['vendor/macnativegames', 'data'] # data/: expected hashes RUNTIME_SUFFIXES = {'.h', '.inc', '.ico'} # .ico: the installer window icon