Merge task/xboxprompts: Xbox button prompts layout, from pull request #126

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	installer/steps.py
#	runtime/romfs.c
#	tools/make_romfs_patches.py
This commit is contained in:
Valiantsin Dzerakh committed 2026-10-31 08:19:29 +03:00
commit 9044d4c02b
20 files changed
+445 -60

No files matched your search

+1 -1
View File
@@ -104,7 +104,7 @@ static const CfgMeta metas[] = {
// Sound, Controls, Menu
{"VOLUME", "100", "0..100", LIVE},
{"MOTION", "1", "0|1", LIVE}, {"RUMBLE_STRENGTH", "130", "0..300", LIVE}, {"RUMBLE_CURVE", "0.6", "0.2..1.5", LIVE},
{"RUMBLE_TRIGGERS", "0", "0|1", LIVE}, {"PAD_LAYOUT", "auto", "auto|nintendo|xbox", LIVE},
{"RUMBLE_TRIGGERS", "0", "0|1", LIVE}, {"PAD_LAYOUT", "auto", "auto|nintendo|xbox|xbox_prompts", LIVE},
{"STICK_DEADZONE", "8", "0..50", LIVE}, {"MOUSE_SENS", "1", "0..10", LIVE},
{"MENU_LANG", "", "en|ru", LIVE},
// Advanced: scheduling
+3
View File
@@ -277,6 +277,9 @@ int probe_cfg(void) {
"pad layout: automatic is Nintendo for an east button labelled A, Xbox otherwise");
CHECK(input_pad_layout_pick("Xbox", 1) == PAD_LAYOUT_XBOX && input_pad_layout_pick("nintendo", 0) == PAD_LAYOUT_NINTENDO,
"pad layout: a set layout wins over the labels");
CHECK(input_pad_layout_pick("xbox_prompts", 0) == PAD_LAYOUT_NINTENDO &&
input_pad_layout_pick("Xbox_Prompts", 1) == PAD_LAYOUT_NINTENDO,
"pad layout: Xbox prompts keep the Nintendo positions (only the prompts change, romfs.c overlay_init)");
uint8_t pd[PAD_COUNT] = {0};
pd[PAD_SOUTH] = pd[PAD_NORTH] = 1;
CHECK(input_map_pad_buttons(pd, PAD_LAYOUT_NINTENDO) == (1ull << B_B | 1ull << B_X) &&
+2
View File
@@ -38,6 +38,8 @@ uint64_t romfs_file_count(void); // files in the index
const char *romfs_entry(uint64_t i, uint64_t *offset, uint64_t *size); // path, image offset and size of index row i
const char *romfs_image_path(void); // the romfs.bin path fs_init opened
size_t romfs_overlay_count(void);
int romfs_xbox_prompts_ready(void); // romfs-patches-xbox was there at start
int romfs_xbox_prompts_active(void); // and was loaded (pad_layout = xbox_prompts at start)
const char *romfs_overlay(size_t k, const char **file, uint64_t *size, int *is_added); // RomFS path of overlay k
void fs_trace(const char *what, const char *path); // TOTK_TRACE=fs: one line per open
+1 -1
View File
@@ -283,7 +283,7 @@ void input_map_line(const InputMap *m, int action, char *out, size_t n) {
}
int input_pad_layout_pick(const char *setting, int east_labelled_a) {
if (setting && !_stricmp(setting, "nintendo")) return PAD_LAYOUT_NINTENDO;
if (setting && (!_stricmp(setting, "nintendo") || !_stricmp(setting, "xbox_prompts"))) return PAD_LAYOUT_NINTENDO;
if (setting && !_stricmp(setting, "xbox")) return PAD_LAYOUT_XBOX;
return east_labelled_a ? PAD_LAYOUT_NINTENDO : PAD_LAYOUT_XBOX;
}
+4 -2
View File
@@ -80,8 +80,10 @@ int input_map_bind(const char *button, const char *list);
// Applies the TOTK_BIND_<action> settings (cfg_get) over the defaults: at start, and again when one of them changes.
void input_map_configure(void);
// The layout for a TOTK_PAD_LAYOUT value: "nintendo" or "xbox" (any case); anything else ("auto", NULL) picks Nintendo
// when the pad's east button is labelled A (a Switch Pro Controller, a GuliKit) and Xbox otherwise.
// The layout for a TOTK_PAD_LAYOUT value: "nintendo" or "xbox" (any case); "xbox_prompts" is the Nintendo layout with
// the A/B and X/Y prompts swapped (runtime/romfs.c overlay_init), so the buttons map as "nintendo". Anything else
// ("auto", NULL) picks Nintendo when the pad's east button is labelled A (a Switch Pro Controller, a GuliKit) and Xbox
// otherwise.
int input_pad_layout_pick(const char *setting, int east_labelled_a);
// down[pad] != 0 for the gamepad inputs held. Returns the Switch button bits (0..15) the layout's pad table presses.
uint64_t input_map_pad_buttons(const uint8_t down[PAD_COUNT], int layout);
+58 -16
View File
@@ -244,7 +244,11 @@ static uint32_t overlay_slot(uint64_t i) {
}
// ---- overlays
static void overlay_load(const char *dir) {
// Loads and checks one overlay folder. A failed check stops the game, except with optional set (the Xbox prompts
// folder): the folder is dropped, the reason logged, and 0 returned. Returns 1 when the folder is loaded or has no
// manifest.
static int overlay_load(const char *dir, int optional) {
#define BAD(...) do { if (!optional) rt_fatal(__VA_ARGS__); rt_log(__VA_ARGS__); goto bad; } while (0)
char path[2100];
need(snprintf(path, sizeof path, "%s/manifest.tsv", dir) < (int)sizeof path, "overlay path");
wchar_t *w = fs_wide(path);
@@ -252,7 +256,7 @@ static void overlay_load(const char *dir) {
free(w);
if (!m) {
rt_log("RomFS overlay: none (%s)", path);
return;
return 1;
}
char line[8192];
size_t first = noverlay;
@@ -268,30 +272,32 @@ static void overlay_load(const char *dir) {
uint64_t i = lower(name);
int known = i < file_count && !strcmp(entry_name(entry(i)), name), add = !strcmp(orig, "-");
if (!known && !add)
rt_fatal("RomFS overlay: %s/manifest.tsv names %s, which the RomFS lacks; a new file has \"-\" as its "
"original's SHA-256", dir, name);
BAD("RomFS overlay: %s/manifest.tsv names %s, which the RomFS lacks; a new file has \"-\" as its "
"original's SHA-256", dir, name);
if (known && add)
rt_fatal("RomFS overlay: %s/manifest.tsv adds %s, which the RomFS already has; give its original's SHA-256",
dir, name);
BAD("RomFS overlay: %s/manifest.tsv adds %s, which the RomFS already has; give its original's SHA-256",
dir, name);
Entry e = {0};
if (known) {
e = entry(i);
sha_range(image, e.offset, e.size, hex, 0);
if (strcmp(hex, orig)) rt_fatal("RomFS overlay: the original of %s has SHA-256 %s, %s/manifest.tsv says %s",
name, hex, dir, orig);
if (strcmp(hex, orig)) BAD("RomFS overlay: the original of %s has SHA-256 %s, %s/manifest.tsv says %s",
name, hex, dir, orig);
} else {
i = ADDED;
}
char file[8200];
need(snprintf(file, sizeof file, "%s/%s", dir, name) < (int)sizeof file, "overlay file path");
HANDLE f = open_read(file, 1);
if (f == INVALID_HANDLE_VALUE) rt_fatal("RomFS overlay: %s missing", file);
if (f == INVALID_HANDLE_VALUE) BAD("RomFS overlay: %s missing", file);
Identity id = identity_of(f);
if (id.size != size) rt_fatal("RomFS overlay: %s has %llu bytes, its manifest says %llu", file,
(unsigned long long)id.size, size);
if (id.size != size) {
CloseHandle(f);
BAD("RomFS overlay: %s has %llu bytes, its manifest says %llu", file, (unsigned long long)id.size, size);
}
sha_range(f, 0, size, hex, 0);
CloseHandle(f);
if (strcmp(hex, sha)) rt_fatal("RomFS overlay: %s has SHA-256 %s, its manifest says %s", file, hex, sha);
if (strcmp(hex, sha)) BAD("RomFS overlay: %s has SHA-256 %s, its manifest says %s", file, hex, sha);
hashed += e.size + size;
if (noverlay == overlay_cap) {
overlay_cap = overlay_cap ? overlay_cap * 2 : 16;
@@ -309,6 +315,16 @@ static void overlay_load(const char *dir) {
noverlay - first - 16);
if (noverlay > first) rt_log("RomFS overlay: %s checked, %zu files, %.1f MiB hashed in %.2f s", dir,
noverlay - first, hashed / 1048576.0, now_s() - t0);
return 1;
bad:
fclose(m);
for (size_t k = first; k < noverlay; k++) {
free((void *)overlays[k].path);
free((void *)overlays[k].name);
}
noverlay = first;
return 0;
#undef BAD
}
static int overlay_order(const void *a, const void *b) {
@@ -407,33 +423,59 @@ static void heapdef_overlay(void) {
res_heapdef_served();
}
static int xbox_prompts_ready; // romfs-patches-xbox/manifest.tsv was next to romfs-index.bin at start
static int xbox_prompts_active; // and overlay_init loaded it
int romfs_xbox_prompts_ready(void) { return xbox_prompts_ready; }
int romfs_xbox_prompts_active(void) { return xbox_prompts_active; }
static void overlay_init(void) {
// TOTK_ROMFS_PATCHES unset: romfs-patches next to romfs-index.bin if it has a manifest (tools/make_romfs_patches.py).
// A game resolution that is not 16:9 takes romfs-patches-<w>x<h> instead when it is there: the same overlay with
// the UI laid out for that shape (make_romfs_patches.py --aspect). 1.2.1 has no camera aspect patch, so it keeps
// the 16:9 layout (res_wants_wide_overlay).
char def[2100];
// With pad_layout = xbox_prompts, romfs-patches-xbox in its place: the same patches with the A/B and X/Y prompts
// swapped (make_romfs_patches.py --xbox-prompts). The game reads the archives once at boot, so the prompts stay
// until restart even though the layout itself changes live. Each folder replaces romfs-patches as a whole and the
// setup builds no wide folder with Xbox prompts, so a wide game resolution keeps the Switch prompts.
char def[2100], xbox[2100];
const char *patches = cfg_get("TOTK_ROMFS_PATCHES");
int wide = 0;
unsigned out[2];
res_wanted(out);
if (!patches && res_wants_wide_overlay(out)) {
if (snprintf(def, sizeof def, "%s/romfs-patches-%ux%u/manifest.tsv", index_dir, out[0], out[1]) < (int)sizeof def &&
GetFileAttributesA(def) != INVALID_FILE_ATTRIBUTES) {
def[strlen(def) - strlen("/manifest.tsv")] = 0;
patches = def;
patches = def, wide = 1;
} else {
rt_log("RomFS overlay: no romfs-patches-%ux%u for this game resolution, the UI keeps its 16:9 layout "
"(tools/make_romfs_patches.py --aspect %ux%u)", out[0], out[1], out[0], out[1]);
}
}
if (!patches && snprintf(def, sizeof def, "%s/romfs-patches/manifest.tsv", index_dir) < (int)sizeof def &&
xbox_prompts_ready =
snprintf(xbox, sizeof xbox, "%s/romfs-patches-xbox/manifest.tsv", index_dir) < (int)sizeof xbox &&
GetFileAttributesA(xbox) != INVALID_FILE_ATTRIBUTES;
int want_xbox = !_stricmp(cfg_value("TOTK_PAD_LAYOUT"), "xbox_prompts");
if (!patches && want_xbox && xbox_prompts_ready) {
xbox[strlen(xbox) - strlen("/manifest.tsv")] = 0;
xbox_prompts_active = overlay_load(xbox, 1);
if (xbox_prompts_active) rt_log("RomFS overlay: Xbox button prompts (%s)", xbox);
else rt_log("RomFS overlay: %s failed its check (run the setup again); romfs-patches loads instead", xbox);
} else if (want_xbox) {
rt_log("RomFS overlay: pad_layout = xbox_prompts, but %s; Switch prompts stay",
wide ? "the game resolution takes the wide UI layout"
: patches ? "TOTK_ROMFS_PATCHES is set"
: "romfs-patches-xbox has no manifest.tsv (run the setup again)");
}
if (!patches && !xbox_prompts_active && snprintf(def, sizeof def, "%s/romfs-patches/manifest.tsv", index_dir) < (int)sizeof def &&
GetFileAttributesA(def) != INVALID_FILE_ATTRIBUTES) {
def[strlen(def) - strlen("/manifest.tsv")] = 0;
patches = def;
}
const char *dirs[2] = {patches, cfg_get("TOTK_ROMFS_MODS")};
for (int i = 0; i < 2; i++)
if (dirs[i] && *dirs[i] && strcmp(dirs[i], "0")) overlay_load(dirs[i]);
if (dirs[i] && *dirs[i] && strcmp(dirs[i], "0")) overlay_load(dirs[i], 0);
heapdef_overlay();
added_init();
if (noverlay) qsort(overlays, noverlay, sizeof *overlays, overlay_order);
+13 -3
View File
@@ -38,6 +38,9 @@ void vk_queue_unlock(void);
void res_sizes(unsigned out[2], unsigned scene[2]);
double frame_step_limit_hz(void);
extern const int rt_game_version;
// fs.h (romfs.c): romfs-patches-xbox was next to romfs-index.bin at start, and was loaded.
int romfs_xbox_prompts_ready(void);
int romfs_xbox_prompts_active(void);
extern const char rt_port_version[];
}
@@ -559,8 +562,14 @@ static void tab_sound(float scale) {
opt_end();
}
// "in use: Xbox" under the layout when it is Automatic and a gamepad is connected; NULL otherwise.
// The note under the layout. Xbox prompts (the Nintendo layout with the A/B and X/Y prompts swapped, romfs.c
// overlay_init) change the buttons at once but the prompts only at the next start: "files missing" without
// romfs-patches-xbox, "prompts change after restart" while the prompts in use differ from the choice. Automatic with a
// gamepad connected: "in use: Xbox". NULL otherwise.
static const char *pad_layout_note(void) {
bool want = !_stricmp(cfg_value("TOTK_PAD_LAYOUT"), "xbox_prompts");
if (want && !romfs_xbox_prompts_ready()) return menu_text(UI_MENU_PAD_LAYOUT_PROMPTS_MISSING);
if (want != (romfs_xbox_prompts_active() != 0)) return menu_text(UI_MENU_PAD_LAYOUT_PROMPTS_RESTART);
int got = input_pad_layout();
if (got < 0 || strcmp(cfg_value("TOTK_PAD_LAYOUT"), "auto")) return nullptr;
static char note[96];
@@ -571,8 +580,9 @@ static const char *pad_layout_note(void) {
static void tab_controls(float scale) {
opt_begin("##controls", scale);
static const UiTextId layout[] = {UI_MENU_PAD_LAYOUT_AUTO, UI_MENU_PAD_LAYOUT_NINTENDO, UI_MENU_PAD_LAYOUT_XBOX};
opt_choice("TOTK_PAD_LAYOUT", UI_MENU_PAD_LAYOUT, layout, 3, UI_MENU_PAD_LAYOUT_DESC, pad_layout_note());
static const UiTextId layout[] = {UI_MENU_PAD_LAYOUT_AUTO, UI_MENU_PAD_LAYOUT_NINTENDO, UI_MENU_PAD_LAYOUT_XBOX,
UI_MENU_PAD_LAYOUT_XBOX_PROMPTS};
opt_choice("TOTK_PAD_LAYOUT", UI_MENU_PAD_LAYOUT, layout, 4, UI_MENU_PAD_LAYOUT_DESC, pad_layout_note());
opt_toggle("TOTK_MOTION", UI_MENU_MOTION, UI_MENU_MOTION_DESC);
opt_slider("TOTK_RUMBLE_STRENGTH", UI_MENU_RUMBLE_STRENGTH, 0, 300, UI_MENU_RUMBLE_STRENGTH_DESC, 10, "%.0f %%");
opt_slider("TOTK_RUMBLE_CURVE", UI_MENU_RUMBLE_CURVE, 0.2f, 1.5f, UI_MENU_RUMBLE_CURVE_DESC, 0.05f, "%.2f");
+17 -4
View File
@@ -99,9 +99,15 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_PAD_LAYOUT] = "Button layout",
[UI_MENU_PAD_LAYOUT_DESC] = "Which button is A. Nintendo: the right one, as on a Switch. Xbox: the bottom one, as "
"labelled on an Xbox controller (cross on a PlayStation controller). Automatic picks "
"Nintendo for controllers with Nintendo labels and Xbox for the others.",
"Nintendo for controllers with Nintendo labels and Xbox for the others. Xbox prompts: "
"A is the right one as with Nintendo, and the game shows the Xbox labels (B for A, A "
"for B, Y for X, X for Y); the prompts change after a restart. The letters are part of the "
"game's files, so a button you remap in Controls keeps the old letter on screen.",
[UI_MENU_PAD_LAYOUT_AUTO] = "Automatic", [UI_MENU_PAD_LAYOUT_NINTENDO] = "Nintendo (A right)",
[UI_MENU_PAD_LAYOUT_XBOX] = "Xbox (A bottom)", [UI_MENU_PAD_LAYOUT_IN_USE] = "in use: %s",
[UI_MENU_PAD_LAYOUT_XBOX] = "Xbox (A bottom)", [UI_MENU_PAD_LAYOUT_XBOX_PROMPTS] = "Xbox prompts (A right)",
[UI_MENU_PAD_LAYOUT_IN_USE] = "in use: %s",
[UI_MENU_PAD_LAYOUT_PROMPTS_MISSING] = "prompt files missing: run the setup again",
[UI_MENU_PAD_LAYOUT_PROMPTS_RESTART] = "prompts change after restart",
[UI_MENU_STICK_DEADZONE] = "Stick dead zone",
[UI_MENU_STICK_DEADZONE_DESC] = "How far a gamepad stick moves before the game sees it. Raise it if the character or the camera moves on its own.",
[UI_MENU_MOUSE_SENS] = "Mouse camera sensitivity",
@@ -327,9 +333,16 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_PAD_LAYOUT] = "Раскладка кнопок",
[UI_MENU_PAD_LAYOUT_DESC] = "Какая кнопка работает как A. Nintendo: правая, как на Switch. Xbox: нижняя, как "
"подписано на контроллере Xbox (крест на контроллере PlayStation). Автоматически: "
"Nintendo для контроллеров с подписями Nintendo, Xbox для остальных.",
"Nintendo для контроллеров с подписями Nintendo, Xbox для остальных. Подсказки Xbox: "
"A справа, как в Nintendo, а игра показывает надписи Xbox (B вместо A, A вместо B, Y "
"вместо X, X вместо Y); подсказки меняются после перезапуска. Буквы записаны в файлах "
"игры, поэтому у кнопки, переназначенной на вкладке управления, на экране остаётся "
"прежняя буква.",
[UI_MENU_PAD_LAYOUT_AUTO] = "Автоматически", [UI_MENU_PAD_LAYOUT_NINTENDO] = "Nintendo (A справа)",
[UI_MENU_PAD_LAYOUT_XBOX] = "Xbox (A снизу)", [UI_MENU_PAD_LAYOUT_IN_USE] = "сейчас: %s",
[UI_MENU_PAD_LAYOUT_XBOX] = "Xbox (A снизу)", [UI_MENU_PAD_LAYOUT_XBOX_PROMPTS] = "Подсказки Xbox (A справа)",
[UI_MENU_PAD_LAYOUT_IN_USE] = "сейчас: %s",
[UI_MENU_PAD_LAYOUT_PROMPTS_MISSING] = "нет файлов подсказок: запустите установку снова",
[UI_MENU_PAD_LAYOUT_PROMPTS_RESTART] = "подсказки сменятся после перезапуска",
[UI_MENU_STICK_DEADZONE] = "Мёртвая зона стиков",
[UI_MENU_STICK_DEADZONE_DESC] = "Насколько нужно отклонить стик геймпада, чтобы игра это заметила. Увеличьте, если персонаж или камера двигаются сами.",
[UI_MENU_MOUSE_SENS] = "Чувствительность мыши",
+2 -1
View File
@@ -57,7 +57,8 @@ typedef enum {
UI_MENU_RUMBLE_CURVE, UI_MENU_RUMBLE_CURVE_DESC,
UI_MENU_RUMBLE_TRIGGERS, UI_MENU_RUMBLE_TRIGGERS_DESC,
UI_MENU_PAD_LAYOUT, UI_MENU_PAD_LAYOUT_DESC, UI_MENU_PAD_LAYOUT_AUTO, UI_MENU_PAD_LAYOUT_NINTENDO,
UI_MENU_PAD_LAYOUT_XBOX, UI_MENU_PAD_LAYOUT_IN_USE,
UI_MENU_PAD_LAYOUT_XBOX, UI_MENU_PAD_LAYOUT_XBOX_PROMPTS, UI_MENU_PAD_LAYOUT_IN_USE,
UI_MENU_PAD_LAYOUT_PROMPTS_MISSING, UI_MENU_PAD_LAYOUT_PROMPTS_RESTART,
UI_MENU_STICK_DEADZONE, UI_MENU_STICK_DEADZONE_DESC,
UI_MENU_MOUSE_SENS, UI_MENU_MOUSE_SENS_DESC,