From 73a1e1c580ceda3d11c031cc9dee00f283598bab Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 31 Oct 2026 20:12:58 -0700 Subject: [PATCH 1/2] Command File Runner: BDSP detectors, measured D-pad taps and bdsp_load_save The runner had no game detectors and no way for a game to hook in, so a lab operator could not ask "is this a dialog box?" or reload the BDSP save from a command file. - BDSP registers bdsp_dialog, bdsp_battle_text, bdsp_battle_menu, bdsp_exp_gain, bdsp_menu and bdsp_map, plus bdsp_load_save, from its PanelListFactory constructor (a static registrar in the static library would be dropped by the linker). - "taps DIR N [all] [hold] [release] [still]" taps the D-pad and reports, per tap, whether the screen moved (RMSD at 192x108, shared with walk). - run_command_file_line() lets a game command run built-ins such as close_game and state. - README: new commands, detectors and how a game registers them. - Tests: parsing of taps arguments. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../NintendoSwitch_CommandFileParsing.cpp | 26 +++++++ .../NintendoSwitch_CommandFileParsing.h | 12 +++ .../NintendoSwitch_CommandFileRunner.cpp | 77 ++++++++++++++++--- .../NintendoSwitch_CommandFileRunner.h | 5 ++ ...NintendoSwitch_CommandFileRunner_Tests.cpp | 31 ++++++++ .../Programs/CommandFileRunner/README.md | 30 +++++++- .../Source/PokemonBDSP/PokemonBDSP_Panels.cpp | 7 +- .../PokemonBDSP_CommandFileCommands.cpp | 72 +++++++++++++++++ .../PokemonBDSP_CommandFileCommands.h | 27 +++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 10 files changed, 278 insertions(+), 11 deletions(-) create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.h diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileParsing.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileParsing.cpp index 8039699fe0..fdc2b4171b 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileParsing.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileParsing.cpp @@ -86,6 +86,32 @@ DpadPosition parse_dpad(const std::string& text){ return iter->second; } +TapsArguments parse_taps(const std::vector& words){ + // 160 ms is a whole step in BDSP; 640 ms lets the step animation finish + // before the next frame is compared. A step there measures 21 to 50, a + // bump into a wall or an NPC brushing past 4 to 13. + constexpr Milliseconds TAP_HOLD(160); + constexpr Milliseconds TAP_RELEASE(640); + constexpr double TAP_STILL_RMSD = 16; + + TapsArguments taps; + taps.direction = parse_dpad(required_arg(words, 1)); + const double count = optional_number(words, 2, 0); + if (words.size() < 3 || count < 1 || count != (size_t)count){ + throw ParseException(words[0] + ": argument 2 must be a whole number of taps, got " + (words.size() < 3 ? "nothing" : words[2])); + } + taps.count = (size_t)count; + size_t next = 3; + if (words.size() > next && words[next] == "all"){ + taps.all = true; + next++; + } + taps.hold = optional_duration(words, next, TAP_HOLD); + taps.release = optional_duration(words, next + 1, TAP_RELEASE); + taps.still = optional_number(words, next + 2, TAP_STILL_RMSD); + return taps; +} + std::optional next_command_file(const std::string& inbox){ std::optional next; for (const Filesystem::Path& path : Filesystem::list_directory(Filesystem::Path(inbox))){ diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileParsing.h b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileParsing.h index 28ca34fd76..92d8d66f1e 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileParsing.h +++ b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileParsing.h @@ -44,6 +44,18 @@ Button parse_buttons(const std::string& text); // "UP", "DOWN", "LEFT" or "RIGHT". Throws ParseException otherwise. DpadPosition parse_dpad(const std::string& text); +// The arguments of "taps DIR N [all] [hold_ms] [release_ms] [still_rmsd]": +// N D-pad taps, each measured against the frame before it. +struct TapsArguments{ + DpadPosition direction = DPAD_NONE; + size_t count = 0; + bool all = false; // Keep tapping after two still taps in a row. + Milliseconds hold = Milliseconds(0); + Milliseconds release = Milliseconds(0); + double still = 0; // A tap changing the screen less than this (RMSD at 192x108) didn't move. +}; +TapsArguments parse_taps(const std::vector& words); + // The ".txt" file in `inbox` whose name sorts first, if any. std::optional next_command_file(const std::string& inbox); diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp index 757fe08d62..78fde848c1 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp @@ -50,6 +50,15 @@ constexpr Milliseconds WALK_SLICE = 200ms; constexpr Milliseconds WALK_LIMIT = 5000ms; constexpr double WALK_STILL_RMSD = 10; +// "walk" and "taps" compare frames scaled to this size, so the change +// measures movement rather than noise. +constexpr size_t CHANGE_WIDTH = 192; +constexpr size_t CHANGE_HEIGHT = 108; + +// "taps": two taps in a row that don't move the screen mean a wall, unless +// the line says "all". +constexpr int TAPS_STILL_LIMIT = 2; + // How often "wait_for" and "expect" check a new frame. constexpr Milliseconds DETECTOR_POLL_INTERVAL = 100ms; @@ -100,6 +109,13 @@ std::optional find_registered_command(const std::string& nam return iter->second.second; } +// How much the screen changed between two frames: RMSD at 192x108. +double screen_change(const VideoSnapshot& before, const VideoSnapshot& after){ + return ImageMatch::pixel_RMSD( + before.frame->scale_to(CHANGE_WIDTH, CHANGE_HEIGHT), after.frame->scale_to(CHANGE_WIDTH, CHANGE_HEIGHT) + ); +} + } @@ -122,9 +138,8 @@ namespace{ // Runs the lines of one command file. class LineRunner{ public: - LineRunner(CommandFileSession& session, std::string name) + explicit LineRunner(CommandFileSession& session) : m_session(session) - , m_name(std::move(name)) {} // Runs one line. Returns false for "stop". Throws to fail the line. @@ -151,7 +166,7 @@ class LineRunner{ if (!screen){ return "(no video frame)"; } - const std::string path = m_session.outbox + m_name + "_" + label + ".png"; + const std::string path = m_session.outbox + m_session.name + "_" + label + ".png"; screen.frame->save(path); return path; } @@ -169,6 +184,7 @@ class LineRunner{ {"stick", {"stick L|R x y [hold_ms] [release_ms] (x, y from -1 to 1)", &LineRunner::stick}}, {"wait", {"wait ms", &LineRunner::wait}}, {"walk", {"walk x y [max_ms] [still_rmsd] (left stick until the screen holds still)", &LineRunner::walk}}, + {"taps", {"taps DIR N [all] [hold_ms] [release_ms] [still_rmsd] (D-pad taps, each reported moved or still)", &LineRunner::taps}}, {"shot", {"shot label", &LineRunner::shot}}, {"shots", {"shots label count [interval_ms]", &LineRunner::shots}}, {"detect", {"detect detector [image] (image: a path, or a file in the outbox)", &LineRunner::detect}}, @@ -249,9 +265,7 @@ class LineRunner{ if (!after){ break; } - const double change = ImageMatch::pixel_RMSD( - before.frame->scale_to(192, 108), after.frame->scale_to(192, 108) - ); + const double change = screen_change(before, after); walked += WALK_SLICE; changes << " " << (int)change; if (change < still){ @@ -266,6 +280,43 @@ class LineRunner{ out() << "walk " << (quiet >= 2 ? "still" : "limit") << " after " << walked.count() << "ms, moving " << moving.count() << "ms; changes" << changes.str() << "\n"; } + // Taps the D-pad N times and reports, for each tap, whether the screen + // changed more than `still` between the frame before and after it: a step + // moves the screen, a bump into a wall doesn't. Stops after two still + // taps in a row unless the line says "all". A tap toward a new direction + // only turns the player, so the first tap of a new direction is still. + void taps(const std::vector& words){ + const TapsArguments args = parse_taps(words); + VideoSnapshot before = current_frame(); + if (!before){ + throw OperationFailedException(ErrorReportMode::NO_ERROR_REPORT, "taps: no video frame"); + } + size_t moved = 0; + size_t tapped = 0; + int quiet = 0; + while (tapped < args.count && (args.all || quiet < TAPS_STILL_LIMIT)){ + pbf_press_dpad(context(), args.direction, args.hold, args.release); + VideoSnapshot after = current_frame(); + if (!after){ + throw OperationFailedException(ErrorReportMode::NO_ERROR_REPORT, "taps: lost the video frame"); + } + const double change = screen_change(before, after); + tapped++; + if (change < args.still){ + quiet++; + }else{ + quiet = 0; + moved++; + } + out() << "tap " << tapped << ": change " << (int)change << (change < args.still ? " still" : " moved") << "\n"; + before = std::move(after); + } + out() << "moved " << moved << " of " << args.count; + if (tapped < args.count){ + out() << ", stopped after " << tapped << " taps: " << TAPS_STILL_LIMIT << " still in a row"; + } + out() << "\n"; + } void shot(const std::vector& words){ out() << "shot " << save_screenshot(required_arg(words, 1)) << "\n"; } @@ -358,7 +409,6 @@ class LineRunner{ } CommandFileSession& m_session; - std::string m_name; }; @@ -422,8 +472,8 @@ bool run_command_file( env.log("Command File Runner: running " + name); std::ostringstream out; - CommandFileSession session{env, context, out, folder + "outbox/"}; - LineRunner runner(session, name); + CommandFileSession session{env, context, out, folder + "outbox/", name}; + LineRunner runner(session); const std::string out_path = session.outbox + name; std::istringstream lines(script); @@ -450,6 +500,15 @@ bool run_command_file( +void run_command_file_line(CommandFileSession& session, const std::vector& words){ + if (words.empty()){ + throw ParseException("run_command_file_line: empty line"); + } + LineRunner(session).run(words); +} + + + CommandFileRunner_Descriptor::CommandFileRunner_Descriptor() : SingleSwitchProgramDescriptor( "NintendoSwitch:CommandFileRunner", diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.h b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.h index 72e24aaf0b..162714ca7d 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.h +++ b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.h @@ -53,6 +53,7 @@ struct CommandFileSession{ ProControllerContext& context; std::ostream& out; // Text printed here goes into the .out file. std::string outbox; // Folder for files a command saves, ending in '/'. + std::string name; // The command file's name: the prefix of the screenshots it saves. }; // A command. `words` is its line split on spaces; words[0] is the command name. @@ -66,6 +67,10 @@ using CommandFileDetectorFactory = std::function& words); + class CommandFileRunner_Descriptor : public SingleSwitchProgramDescriptor{ diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner_Tests.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner_Tests.cpp index d29a397c5c..c2f08e75ca 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner_Tests.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner_Tests.cpp @@ -111,6 +111,36 @@ UnitTestResult test_dpad(){ return true; } +UnitTestResult test_taps(){ + struct Case{ + std::string line; + TapsArguments expected; + }; + const Case CASES[] = { + {.line = "taps UP 3", .expected = {.direction = DPAD_UP, .count = 3, .all = false, .hold = 160ms, .release = 640ms, .still = 16}}, + {.line = "taps LEFT 4 all", .expected = {.direction = DPAD_LEFT, .count = 4, .all = true, .hold = 160ms, .release = 640ms, .still = 16}}, + {.line = "taps RIGHT 2 100 500", .expected = {.direction = DPAD_RIGHT, .count = 2, .all = false, .hold = 100ms, .release = 500ms, .still = 16}}, + {.line = "taps DOWN 1 all 200 700 20", .expected = {.direction = DPAD_DOWN, .count = 1, .all = true, .hold = 200ms, .release = 700ms, .still = 20}}, + }; + for (const Case& c : CASES){ + const TapsArguments taps = parse_taps(split_command_line(c.line)); + if (taps.direction != c.expected.direction || taps.count != c.expected.count || taps.all != c.expected.all){ + return c.line + ": wrong direction, count or all flag."; + } + if (taps.hold != c.expected.hold || taps.release != c.expected.release || taps.still != c.expected.still){ + return c.line + ": expected hold " + std::to_string(c.expected.hold.count()) + + ", release " + std::to_string(c.expected.release.count()) + ", still " + std::to_string(c.expected.still) + + "; read " + std::to_string(taps.hold.count()) + ", " + std::to_string(taps.release.count()) + ", " + std::to_string(taps.still); + } + } + for (const char* line : {"taps UP", "taps UP x", "taps UP 0", "taps UP 2.5", "taps NORTH 2", "taps UP 2 all soon"}){ + if (!throws_parse_error([&]{ parse_taps(split_command_line(line)); })){ + return std::string(line) + " should be a parse error."; + } + } + return true; +} + UnitTestResult test_next_file(){ const Filesystem::Path inbox = Filesystem::unique_temp_path( Filesystem::application_scratch_path() / "CommandFileRunnerTest" @@ -163,6 +193,7 @@ void add_tests_CommandFileRunner(UnitTestDatabase& database){ database.add("argument errors", test_argument_errors); database.add("buttons", test_buttons); database.add("D-pad", test_dpad); + database.add("taps arguments", test_taps); database.add("next inbox file", test_next_file); } diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/README.md b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/README.md index 88adb99c76..73dabcf16f 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/README.md +++ b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/README.md @@ -72,6 +72,7 @@ Any other line comes from a command, such as `detect home yes` or the path of a | --- | --- | --- | | `press BTN[+BTN] [hold] [release]` | Presses one button, or several together, joined with `+` (e.g. `L+R`). Buttons: `A B X Y L R ZL ZR PLUS MINUS LCLICK RCLICK HOME CAPTURE`. | hold 160, release 160 | | `dpad UP\|DOWN\|LEFT\|RIGHT [hold] [release]` | Presses the D-pad. | hold 100, release 200 | +| `taps DIR N [all] [hold] [release] [still]` | Taps the D-pad `N` times and measures the screen change (RMSD at 192x108, as `walk`) between the frame before and after each tap. Prints `tap k: change X moved\|still` per tap, `moved` when the change is at least `still`, then `moved M of N`. Stops after two still taps in a row (a wall) unless `N` is followed by `all`. A tap toward a new direction only turns the player, so send one tap first when changing direction. On BDSP a step measures 21 to 50, a bump into a wall or an NPC brushing past 4 to 13. | hold 160, release 640, still 16 | | `stick L\|R x y [hold] [release]` | Moves the left or right stick. `x` and `y` run from -1 to 1; `y` is +1 for up. | hold 160, release 160 | | `wait ms` | Waits. | | | `walk x y [max] [still]` | Holds the left stick in 200 ms slices until two slices in a row change the screen less than `still` (RMSD at 192x108): a wall or someone in the way. Prints `walk still\|limit after N ms, moving M ms` and each slice's change. For measuring maps: a timed `stick` hold moves a different number of tiles from try to try. | max 5000, still 10 | @@ -111,7 +112,34 @@ These work on any game: | `black` | A black screen. | | `white` | A white screen. | -Games can add their own commands and detectors with `register_command_file_command()` and `register_command_file_detector()` (see `NintendoSwitch_CommandFileRunner.h`); `help` lists them. +### Pokemon Brilliant Diamond and Shining Pearl + +| Name | Detects | +| --- | --- | +| `bdsp_dialog` | A short dialog box: talking to someone, signs, item pickups, the EXP text after a battle. | +| `bdsp_battle_text` | The long dialog box that only appears in battle. | +| `bdsp_battle_menu` | The Fight / Pokemon / Bag / Run menu of a standard (wild) battle. | +| `bdsp_exp_gain` | The experience gain screen after a battle. | +| `bdsp_menu` | The X menu. | +| `bdsp_map` | The town map. | + +These are the detectors a lab operator checks between steps while measuring maps and story routes: dialog and the battle menu say what stopped a walk, the menu and map say where a key press landed. They are all cheap box checks, so `state` stays fast. + +## Game-specific commands + +### Pokemon Brilliant Diamond and Shining Pearl + +| Command | What it does | +| --- | --- | +| `bdsp_load_save` | From anywhere: `close_game`, launch the tile the Home menu has highlighted (A, A, wait 35 s, A, wait 3 s, A, A held 6 s, wait 8 s) and print `state`. | + +**`bdsp_load_save` launches whatever Home has highlighted, and Home highlights the last game played, not BDSP.** Before sending it, take a `shot` of the Home menu and move the highlight to BDSP with `dpad`; a wrong tile launches another game and the command reports its `state` as if nothing were wrong. The console has been sent into Pokemon Violet this way. + +### How a game registers them + +A game adds commands and detectors with `register_command_file_command()` and `register_command_file_detector()` from `NintendoSwitch_CommandFileRunner.h`, and `help` lists them. The registration has to run at startup, before any command file: put it in a function in the game's own module (BDSP: `register_command_file_commands()` in `PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.cpp`, guarded so a second call does nothing) and call it from the game's `PanelListFactory` constructor, which the program list builds when the app starts. A static registrar object would not do: the game code is in a static library, and the linker drops an object file nothing references. + +A registered command gets a `CommandFileSession` (the environment, controller context, output stream and outbox) and its line's words, and can run built-in commands with `run_command_file_line()`, as `bdsp_load_save` does for `close_game` and `state`. Detector names are prefixed with the game (`bdsp_`) so `state` output reads at a glance. ## Options diff --git a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Panels.cpp b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Panels.cpp index e2aa07801f..934634ecdf 100644 --- a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Panels.cpp +++ b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Panels.cpp @@ -9,6 +9,7 @@ #include "PokemonBDSP_Panels.h" #include "PokemonBDSP_Settings.h" +#include "Programs/PokemonBDSP_CommandFileCommands.h" #include "Programs/General/PokemonBDSP_MassRelease.h" #include "Programs/General/PokemonBDSP_AutonomousBallThrower.h" @@ -55,7 +56,11 @@ PanelListFactory::PanelListFactory() Pokemon::STRING_POKEMON + " Brilliant Diamond and Shining Pearl", RESOURCE_PATH() + "CategoryIcons/PokemonBDSP.png" ) -{} +{ + // At startup, so the Command File Runner (under Nintendo Switch) can + // probe BDSP screens without BDSP's program list being opened first. + register_command_file_commands(); +} std::vector PanelListFactory::make_panels() const{ std::vector ret; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.cpp new file mode 100644 index 0000000000..5902092172 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.cpp @@ -0,0 +1,72 @@ +/* Command File Commands + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.h" +#include "PokemonBDSP/Inference/Battles/PokemonBDSP_BattleMenuDetector.h" +#include "PokemonBDSP/Inference/Battles/PokemonBDSP_ExperienceGainDetector.h" +#include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" +#include "PokemonBDSP/Inference/PokemonBDSP_MapDetector.h" +#include "PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h" +#include "PokemonBDSP_CommandFileCommands.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; + + +namespace{ + +// "bdsp_load_save": the lab's sequence from the Home menu to the overworld. +// The waits are what the lab console needs; a shorter one presses A into a +// loading screen and the next press lands on the wrong menu. +constexpr Milliseconds TAP = 160ms; +constexpr Milliseconds LAUNCH_WAIT = 35s; // Tile to the title screen. +constexpr Milliseconds TITLE_WAIT = 3s; // Title screen to the main menu. +constexpr Milliseconds CONTINUE_HOLD = 6s; // Through "Continue" and its confirmation. +constexpr Milliseconds LOAD_WAIT = 8s; // Loading the save into the overworld. + +// Closes the game, launches the tile HOME has highlighted and loads its save. +// HOME highlights the last game played, so the operator checks that tile with +// "shot" and moves to BDSP with "dpad" first. +void load_save(CommandFileSession& session, const std::vector&){ + run_command_file_line(session, {"close_game"}); + ProControllerContext& context = session.context; + pbf_press_button(context, BUTTON_A, TAP, TAP); // Launch the highlighted tile. + pbf_press_button(context, BUTTON_A, TAP, LAUNCH_WAIT); // Pick the user. + pbf_press_button(context, BUTTON_A, TAP, TITLE_WAIT); // Leave the title screen. + pbf_press_button(context, BUTTON_A, TAP, TAP); // Continue. + pbf_press_button(context, BUTTON_A, CONTINUE_HOLD, LOAD_WAIT); + run_command_file_line(session, {"state"}); +} + +} + + +void register_command_file_commands(){ + static const bool registered = []{ + register_command_file_detector("bdsp_dialog", [](ConsoleHandle&){ return std::make_unique(); }); + register_command_file_detector("bdsp_battle_text", [](ConsoleHandle&){ return std::make_unique(); }); + register_command_file_detector("bdsp_battle_menu", [](ConsoleHandle&){ return std::make_unique(BattleType::STANDARD); }); + register_command_file_detector("bdsp_exp_gain", [](ConsoleHandle&){ return std::make_unique(); }); + register_command_file_detector("bdsp_menu", [](ConsoleHandle&){ return std::make_unique(); }); + register_command_file_detector("bdsp_map", [](ConsoleHandle&){ return std::make_unique(); }); + register_command_file_command( + "bdsp_load_save", + "bdsp_load_save (close the game, launch the tile HOME highlights, load its save, print state)", + load_save + ); + return true; + }(); + (void)registered; +} + + +} +} +} diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.h b/SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.h new file mode 100644 index 0000000000..ad636f7739 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.h @@ -0,0 +1,27 @@ +/* Command File Commands + * + * From: https://github.com/PokemonAutomation/ + * + * BDSP's detectors and commands for the Nintendo Switch Command File Runner, + * so a lab operator can probe BDSP screens and reload the save from a + * command file. README.md in the Command File Runner's folder lists them. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_CommandFileCommands_H +#define PokemonAutomation_PokemonBDSP_CommandFileCommands_H + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Registers BDSP's command file detectors and commands. Called once at +// startup, from the BDSP panel list; later calls do nothing. +void register_command_file_commands(); + + +} +} +} +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 8d09d9057d..7d3e5f8a3d 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1618,6 +1618,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/PokemonBDSP_BasicCatcher.h Source/PokemonBDSP/Programs/PokemonBDSP_BoxRelease.cpp Source/PokemonBDSP/Programs/PokemonBDSP_BoxRelease.h + Source/PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.cpp + Source/PokemonBDSP/Programs/PokemonBDSP_CommandFileCommands.h Source/PokemonBDSP/Programs/PokemonBDSP_EncounterDetection.cpp Source/PokemonBDSP/Programs/PokemonBDSP_EncounterDetection.h Source/PokemonBDSP/Programs/PokemonBDSP_EncounterHandler.cpp From 7dfb5d1295b605a1c38e1137094cb85a44bd312f Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 31 Oct 2026 20:28:32 -0700 Subject: [PATCH 2/2] Command File Runner: a D-pad tap toward a new direction also steps The taps README and code comment said the first tap of a new direction only turns the player. Measured 2026-10-31 in Floaroma: a 160 ms left tap from facing north moved one tile, with a screen change of about 37 at 192x108, the same as a plain step. Say every tap is a step unless something blocks it. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp | 2 +- .../Source/NintendoSwitch/Programs/CommandFileRunner/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp index 78fde848c1..9c92493a68 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp @@ -284,7 +284,7 @@ class LineRunner{ // changed more than `still` between the frame before and after it: a step // moves the screen, a bump into a wall doesn't. Stops after two still // taps in a row unless the line says "all". A tap toward a new direction - // only turns the player, so the first tap of a new direction is still. + // turns and steps, so every tap is a step unless something blocks it. void taps(const std::vector& words){ const TapsArguments args = parse_taps(words); VideoSnapshot before = current_frame(); diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/README.md b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/README.md index 73dabcf16f..00dfd9e6e5 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/README.md +++ b/SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/README.md @@ -72,7 +72,7 @@ Any other line comes from a command, such as `detect home yes` or the path of a | --- | --- | --- | | `press BTN[+BTN] [hold] [release]` | Presses one button, or several together, joined with `+` (e.g. `L+R`). Buttons: `A B X Y L R ZL ZR PLUS MINUS LCLICK RCLICK HOME CAPTURE`. | hold 160, release 160 | | `dpad UP\|DOWN\|LEFT\|RIGHT [hold] [release]` | Presses the D-pad. | hold 100, release 200 | -| `taps DIR N [all] [hold] [release] [still]` | Taps the D-pad `N` times and measures the screen change (RMSD at 192x108, as `walk`) between the frame before and after each tap. Prints `tap k: change X moved\|still` per tap, `moved` when the change is at least `still`, then `moved M of N`. Stops after two still taps in a row (a wall) unless `N` is followed by `all`. A tap toward a new direction only turns the player, so send one tap first when changing direction. On BDSP a step measures 21 to 50, a bump into a wall or an NPC brushing past 4 to 13. | hold 160, release 640, still 16 | +| `taps DIR N [all] [hold] [release] [still]` | Taps the D-pad `N` times and measures the screen change (RMSD at 192x108, as `walk`) between the frame before and after each tap. Prints `tap k: change X moved\|still` per tap, `moved` when the change is at least `still`, then `moved M of N`. Stops after two still taps in a row (a wall) unless `N` is followed by `all`. Every tap is a step unless something blocks it: a tap toward a new direction turns and steps within the same 160 ms (measured 2026-10-31 in Floaroma: a left tap from facing north moved one tile, with a screen change of about 37, the same as a plain step). On BDSP a step measures 21 to 50, a bump into a wall or an NPC brushing past 4 to 13. | hold 160, release 640, still 16 | | `stick L\|R x y [hold] [release]` | Moves the left or right stick. `x` and `y` run from -1 to 1; `y` is +1 for up. | hold 160, release 160 | | `wait ms` | Waits. | | | `walk x y [max] [still]` | Holds the left stick in 200 ms slices until two slices in a row change the screen less than `still` (RMSD at 192x108): a wall or someone in the way. Prints `walk still\|limit after N ms, moving M ms` and each slice's change. For measuring maps: a timed `stick` hold moves a different number of tiles from try to try. | max 5000, still 10 |