"""((Triforce, 11-30) The ReShade comparison asked inside the pause menu's Options goes to play first ("ReShade Compare not taking you to gameplay screen", v0.8.5.2): the game is paused there and its scene draws nothing, so the comparison over its screens showed the Options and the pause menu. host/nn_hid.c's compare_to_play is compiled alone with stand-ins for the option and the screens: B once on the Options, once more only if that screen still runs 1.5 s later, then B on the pause menu, the renderer told 2 once neither has run for 300 ms, 3 when they are still up after 4 s, nothing while nothing is asked. The menu's side is read from the sources: the Compare row's way there (compare_leaves_menus, not from the title's Options nor with a close question waiting), the host's word taken, the comparison opened over the game and its Back closing the options, and the option answered by the renderer. python -I -B tests/test_reshade_compare_play.py (needs a C compiler) """ import shutil import subprocess import sys import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parents[1] def block(text, marker): start = text.index(marker) end = text.index("{", start) + 1 depth = 1 while depth: depth += (text[end] == "{") - (text[end] == "}") end += 1 return text[start:end] FIXTURE = r""" #include #include #include enum { HOS_OPT_COMPARE_PLAY = 432 }; static int option_now, told, told_value, options_up, pause_up, taps; static int64_t now; static char last_tap[32]; static int rx_option(int id, int otherwise) { return id == HOS_OPT_COMPARE_PLAY ? option_now : otherwise; } static void rx_option_set(int id, int value) { if (id == HOS_OPT_COMPARE_PLAY) told++, told_value = value, option_now = value; } static void hos_hid_tap(const char *press) { taps++, snprintf(last_tap, sizeof last_tap, "%s", press); } static void hos_log(const char *f, ...) { (void)f; } int hos_oot_options_front(void) { return options_up; } int hos_oot_pause_front(void) { return pause_up; } """ MAIN = r""" static int fails; #define CHECK(c) do { if (!(c)) { printf("FAIL line %d: %s\n", __LINE__, #c); fails++; } } while (0) static void run(int64_t ms) { for (int64_t t = 0; t < ms; t += 16) now += 16000000LL, compare_to_play(now); } int main(void) { now = 1000000000LL; options_up = 1; run(500); CHECK(taps == 0 && told == 0); /* (nothing asked: nothing pressed) */ option_now = 1; /* (Compare confirmed inside the pause menu's Options) */ run(16); CHECK(taps == 1 && !strcmp(last_tap, "0:B/80")); /* (B on the Options) */ run(1000); CHECK(taps == 1); /* (its animation: no second B yet) */ run(600); CHECK(taps == 2); /* (still up 1.5 s on: the press was lost, once more) */ run(2000); CHECK(taps == 2); /* (twice at most) */ options_up = 0, pause_up = 1; /* (back on the pause menu) */ run(16); CHECK(taps == 3 && told == 0); /* (B on the pause menu) */ pause_up = 0; /* (it closed: in play once 300 ms pass with neither screen) */ run(200); CHECK(told == 0); run(200); CHECK(told == 1 && told_value == 2 && taps == 3); run(1000); CHECK(told == 1 && taps == 3); /* (the word given: nothing more while it is not asked again) */ /* a second ask whose menus stay up: 3 after 4 s, the comparison where it is */ option_now = 1, options_up = 1, taps = 0; run(4100); CHECK(told == 2 && told_value == 3 && taps == 2); run(1000); CHECK(told == 2 && taps == 2); if (!fails) printf("PASS\n"); return fails != 0; } """ def check_sources(): menu = (ROOT / "gpu" / "vk" / "vk_menu.cpp").read_text(encoding="utf-8") replay = (ROOT / "gpu" / "vk" / "vk_replay.cpp").read_text(encoding="utf-8") api = (ROOT / "gpu" / "vk" / "vk_api.h").read_text(encoding="utf-8") hid = (ROOT / "host" / "nn_hid.c").read_text(encoding="utf-8") menu_c = (ROOT / "host" / "oot_menu.c").read_text(encoding="utf-8") if "enum { HOS_OPT_COMPARE_PLAY = 432 };" not in api: raise SystemExit("the option HOS_OPT_COMPARE_PLAY is gone") if "if (id == HOS_OPT_COMPARE_PLAY) return menu_compare_play();" not in replay: raise SystemExit("the renderer does not answer HOS_OPT_COMPARE_PLAY: the host never sees the ask") leaves = block(menu, "bool compare_leaves_menus() {") for need in ("embed_open", "game_options_from_pause", "!apply_ask()", "!restart_ask()"): if need not in leaves: raise SystemExit("compare_leaves_menus lost a condition: " + need) press = "else if (press[7] && r.name == kReshadeCompare && compare_leaves_menus()) {" if press not in menu or menu.index(press) > menu.index("else if (press[7] && reshade_menu::act(r.name))"): raise SystemExit("the Compare row inside the pause menu's Options does not go to play first") if "compare_play.store(1, std::memory_order_relaxed);" not in menu: raise SystemExit("the Compare row does not ask the host") if "if (id == HOS_OPT_COMPARE_PLAY) {" not in menu or "compare_exchange_strong(asked, value" not in menu: raise SystemExit("the host's word (2 in play, 3 not) is not taken by the menu") if "reshade_menu::start_comparison();" not in menu or "compare_from_game = ready == 2;" not in menu: raise SystemExit("the comparison does not open once the host says so") if "if (!reshade_menu::comparing() && compare_from_game) compare_from_game = false, open_now = false" not in menu: raise SystemExit("the comparison's Back no longer closes the options it opened over the game") read = block(hid, "static void read_input(") if "compare_to_play(hos_now_ns());" not in read: raise SystemExit("read_input does not run compare_to_play") if menu_c.count("int hos_oot_pause_front(void) {") != 2: raise SystemExit("hos_oot_pause_front is not in both halves of host/oot_menu.c") def main(): check_sources() compiler = shutil.which("gcc") or shutil.which("clang") if not compiler: print("SKIP: no C compiler (the sources checked)") return hid = (ROOT / "host" / "nn_hid.c").read_text(encoding="utf-8") code = FIXTURE + block(hid, "static void compare_to_play(int64_t now) {") + "\n" + MAIN with tempfile.TemporaryDirectory(prefix="triforce-compare-play-") as tmp: tmp = Path(tmp) (tmp / "t.c").write_text(code, encoding="utf-8") binary = tmp / ("t.exe" if sys.platform == "win32" else "t") build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-Werror", str(tmp / "t.c"), "-o", str(binary)], text=True, capture_output=True) if build.returncode: raise SystemExit(build.stderr) run = subprocess.run([str(binary)], text=True, capture_output=True, timeout=30) if run.returncode: raise SystemExit(run.stdout + run.stderr) print("PASS: Compare from the pause menu's Options leaves its menus (B, B), opens over the game, and gives up after 4 s") if __name__ == "__main__": main()