Move the Cheats tab to its own file and leave menu.cpp's font ranges alone, to stay clear of other open PRs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
conongnangandClaude Opus 5.5 committed 2026-11-01 09:15:54 +07:00
1 parent 183519190a
commit bf40602179
5 files changed
+77 -58

No files matched your search

+1 -1
View File
@@ -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
+9
View File
@@ -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, "
+58
View File
@@ -0,0 +1,58 @@
// The Cheats tab of the in-game menu: the cheats of cheats\<build id>.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 <stdio.h>
#include <string.h>
#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\\<build id>.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();
}
+6 -54
View File
@@ -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\<build id>.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\\<build id>.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
+3 -3
View File
@@ -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