From 56c5b14c1cca0c399a4ab2ed78afa7409bb5268c Mon Sep 17 00:00:00 2001 From: jw098 Date: Fri, 5 Sep 2025 12:51:23 -0700 Subject: [PATCH] close_game: ensure it starts at Home screen. --- .../NintendoSwitch_Commands_Routines.cpp | 58 +++---------------- .../NintendoSwitch_Commands_Routines.h | 4 +- .../Programs/PokemonBDSP_GameEntry.cpp | 2 +- .../Programs/PokemonLA_GameEntry.cpp | 2 +- .../Programs/PokemonLGPE_GameEntry.cpp | 2 +- .../Programs/PokemonSV_GameEntry.cpp | 2 +- .../PokemonSwSh_Commands_GameEntry.cpp | 2 +- .../PokemonSwSh_AutoHost-MultiGame.cpp | 2 +- .../Hosting/PokemonSwSh_AutoHost-Rolling.cpp | 2 +- .../Programs/PokemonSwSh_GameEntry.cpp | 4 +- .../PokemonSwSh_RaidItemFarmerOKHO.cpp | 2 +- .../PokemonSwSh_MultiGameFossil.cpp | 2 +- .../PokemonSwSh_ShinyHuntTools.cpp | 2 +- 13 files changed, 22 insertions(+), 64 deletions(-) diff --git a/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp b/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp index 15ec2fb54f..69a340e96e 100644 --- a/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp @@ -9,6 +9,7 @@ #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/NintendoSwitch_Settings.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "NintendoSwitch_Commands_Routines.h" #include "NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch_Commands_Superscalar.h" @@ -23,7 +24,9 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ -void close_game(ConsoleHandle& console, ProControllerContext& context){ +void close_game_from_home(ConsoleHandle& console, ProControllerContext& context){ + ensure_at_home(console, context); + // Use mashing to ensure that the X press succeeds. If it fails, the SR // will fail and can kill a den for the autohosts. @@ -35,44 +38,15 @@ void close_game(ConsoleHandle& console, ProControllerContext& context){ ssf_press_dpad_ptv(context, DPAD_DOWN); // - Does nothing. | - moves selector away from the closed game to avoid opening it. ssf_press_dpad_ptv(context, DPAD_DOWN); // - Does nothing. | - Press Down a second time in case we drop one. pbf_mash_button(context, BUTTON_A, 50); // - Confirm close game. | - opens an app on the home screen (e.g. Online) - // - Does nothing. | - goes back to home screen. - pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); - context.wait_for_all_requests(); - -// cout << "waiting..." << endl; -// context.wait_for(10s); - - // send a second Home button press, if the first one is dropped - bool video_available = (bool)console.video().snapshot(); - if (video_available){ - HomeMenuWatcher detector(console); - int ret = wait_until( - console, context, - std::chrono::milliseconds(5000), - { detector } - ); - if (ret == 0){ - console.log("Detected Home screen."); - }else{ // if game initially open. | if game initially closed - // initial Home button press was dropped - // - Does nothing. | - goes back to home screen, from opened app - pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); - } - }else{ - // - wait some time after first Home button press - // to avoid triggering zoom - context.wait_for(std::chrono::milliseconds(1000)); - // - Does nothing. | - Press Home a second time in case we drop one. - pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); - } - + go_home(console, context); // - Does nothing. | - goes back to home screen. // fail-safe against button drops and unexpected error messages. pbf_mash_button(context, BUTTON_X, 50); pbf_mash_button(context, BUTTON_B, 350); } -void close_game(ConsoleHandle& console, JoyconContext& context){ +void close_game_from_home(ConsoleHandle& console, JoyconContext& context){ + ensure_at_home(console, context); // Use mashing to ensure that the X press succeeds. If it fails, the SR // will fail and can kill a den for the autohosts. @@ -84,23 +58,7 @@ void close_game(ConsoleHandle& console, JoyconContext& context){ pbf_move_joystick(context, 128, 255, 100ms, 10ms); // - Does nothing. | - moves selector away from the closed game to avoid opening it. pbf_move_joystick(context, 128, 255, 100ms, 10ms); // - Does nothing. | - Press Down a second time in case we drop one. pbf_mash_button(context, BUTTON_A, 400ms); // - Confirm close game. | - opens an app on the home screen (e.g. Online) - // - Does nothing. | - goes back to home screen. - pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); - context.wait_for_all_requests(); - - HomeMenuWatcher detector(console); - int ret = wait_until( - console, context, - std::chrono::milliseconds(5000), - { detector } - ); - if (ret == 0){ - console.log("Detected Home screen."); - }else{ // if game initially open. | if game initially closed - // initial Home button press was dropped - // - Does nothing. | - goes back to home screen, from opened app - pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); - } + go_home(console, context); // - Does nothing. | - goes back to home screen. // fail-safe against button drops and unexpected error messages. pbf_mash_button(context, BUTTON_X, 400ms); diff --git a/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.h b/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.h index d584d2a163..1beaedb553 100644 --- a/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.h +++ b/SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.h @@ -16,9 +16,9 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ -void close_game(ConsoleHandle& console, ProControllerContext& device); +void close_game_from_home(ConsoleHandle& console, ProControllerContext& device); -void close_game(ConsoleHandle& console, JoyconContext& device); +void close_game_from_home(ConsoleHandle& console, JoyconContext& device); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_GameEntry.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_GameEntry.cpp index 29763aa68e..0d55472c20 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_GameEntry.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_GameEntry.cpp @@ -79,7 +79,7 @@ bool reset_game_from_home( ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET || tolerate_update_menu ){ - close_game(console, context); + close_game_from_home(console, context); start_game_from_home( console, context, diff --git a/SerialPrograms/Source/PokemonLA/Programs/PokemonLA_GameEntry.cpp b/SerialPrograms/Source/PokemonLA/Programs/PokemonLA_GameEntry.cpp index 303bdd1426..e01018a410 100644 --- a/SerialPrograms/Source/PokemonLA/Programs/PokemonLA_GameEntry.cpp +++ b/SerialPrograms/Source/PokemonLA/Programs/PokemonLA_GameEntry.cpp @@ -34,7 +34,7 @@ bool reset_game_to_gamemenu( ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET || tolerate_update_menu ){ - close_game(console, context); + close_game_from_home(console, context); start_game_from_home( console, context, diff --git a/SerialPrograms/Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp b/SerialPrograms/Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp index d054364223..81d7638ed6 100644 --- a/SerialPrograms/Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp +++ b/SerialPrograms/Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp @@ -31,7 +31,7 @@ namespace PokemonLGPE{ bool reset_game_to_gamemenu( ConsoleHandle& console, JoyconContext& context ){ - close_game(console, context); + close_game_from_home(console, context); start_game_from_home_with_inference( console, context, diff --git a/SerialPrograms/Source/PokemonSV/Programs/PokemonSV_GameEntry.cpp b/SerialPrograms/Source/PokemonSV/Programs/PokemonSV_GameEntry.cpp index d60ccd5b3b..db20be36d6 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/PokemonSV_GameEntry.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/PokemonSV_GameEntry.cpp @@ -62,7 +62,7 @@ class WaitforWhiteLoadScreen : public VisualInferenceCallback{ bool reset_game_to_gamemenu(ConsoleHandle& console, ProControllerContext& context){ - close_game(console, context); + close_game_from_home(console, context); start_game_from_home( console, context, true, diff --git a/SerialPrograms/Source/PokemonSwSh/Commands/PokemonSwSh_Commands_GameEntry.cpp b/SerialPrograms/Source/PokemonSwSh/Commands/PokemonSwSh_Commands_GameEntry.cpp index 281c54a9bb..c111483465 100644 --- a/SerialPrograms/Source/PokemonSwSh/Commands/PokemonSwSh_Commands_GameEntry.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Commands/PokemonSwSh_Commands_GameEntry.cpp @@ -78,7 +78,7 @@ void reset_game_from_home( return; } - close_game(console, context); + close_game_from_home(console, context); start_game_from_home(context, tolerate_update_menu, 0, 0, false); } void settings_to_enter_game(ProControllerContext& context, bool fast){ diff --git a/SerialPrograms/Source/PokemonSwSh/Programs/Hosting/PokemonSwSh_AutoHost-MultiGame.cpp b/SerialPrograms/Source/PokemonSwSh/Programs/Hosting/PokemonSwSh_AutoHost-MultiGame.cpp index 2b8dace9d5..73c75efadf 100644 --- a/SerialPrograms/Source/PokemonSwSh/Programs/Hosting/PokemonSwSh_AutoHost-MultiGame.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Programs/Hosting/PokemonSwSh_AutoHost-MultiGame.cpp @@ -223,7 +223,7 @@ void AutoHostMultiGame::program(SingleSwitchProgramEnvironment& env, ProControll // Exit game. pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY_SAFE0); - close_game(env.console, context); + close_game_from_home(env.console, context); // Post-raid delay. pbf_wait(context, game.post_raid_delay); diff --git a/SerialPrograms/Source/PokemonSwSh/Programs/Hosting/PokemonSwSh_AutoHost-Rolling.cpp b/SerialPrograms/Source/PokemonSwSh/Programs/Hosting/PokemonSwSh_AutoHost-Rolling.cpp index b46900b23f..767028fa6e 100644 --- a/SerialPrograms/Source/PokemonSwSh/Programs/Hosting/PokemonSwSh_AutoHost-Rolling.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Programs/Hosting/PokemonSwSh_AutoHost-Rolling.cpp @@ -196,7 +196,7 @@ void AutoHostRolling::program(SingleSwitchProgramEnvironment& env, ProController // Exit game. ssf_press_button(context, BUTTON_HOME, GameSettings::instance().GAME_TO_HOME_DELAY_SAFE0, 160ms); - close_game(env.console, context); + close_game_from_home(env.console, context); // Post-raid delay. pbf_wait(context, EXTRA_DELAY_BETWEEN_RAIDS0); diff --git a/SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_GameEntry.cpp b/SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_GameEntry.cpp index 4d5e4a0ef8..168a79e86c 100644 --- a/SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_GameEntry.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_GameEntry.cpp @@ -138,7 +138,7 @@ void reset_game_from_home_with_inference( tolerate_update_menu ){ // cout << "close game" << endl; - close_game(console, context); + close_game_from_home(console, context); // cout << "start_game_from_home_with_inference game" << endl; start_game_from_home_with_inference( console, context, tolerate_update_menu, 0, 0, backup_save, post_wait_time @@ -168,7 +168,7 @@ void start_game_from_home( tolerate_update_menu ){ // cout << "close game" << endl; - close_game(console, context); + close_game_from_home(console, context); // cout << "start_game_from_home_with_inference game" << endl; start_game_from_home_with_inference( console, context, tolerate_update_menu, game_slot, user_slot, backup_save, post_wait_time diff --git a/SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_RaidItemFarmerOKHO.cpp b/SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_RaidItemFarmerOKHO.cpp index 00fec3763a..b9cfc7a456 100644 --- a/SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_RaidItemFarmerOKHO.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_RaidItemFarmerOKHO.cpp @@ -176,7 +176,7 @@ void RaidItemFarmerOHKO::program(MultiSwitchProgramEnvironment& env, Cancellable // Add a little extra wait time since correctness matters here. ssf_press_button(context, BUTTON_HOME, GameSettings::instance().GAME_TO_HOME_DELAY_SAFE0, 80ms); - close_game(console, context); + close_game_from_home(console, context); // Touch the date. if (TOUCH_DATE_INTERVAL > 0ms && current_time() - last_touch >= TOUCH_DATE_INTERVAL){ diff --git a/SerialPrograms/Source/PokemonSwSh/Programs/ShinyHuntUnattended/PokemonSwSh_MultiGameFossil.cpp b/SerialPrograms/Source/PokemonSwSh/Programs/ShinyHuntUnattended/PokemonSwSh_MultiGameFossil.cpp index c71dd66303..afa7738229 100644 --- a/SerialPrograms/Source/PokemonSwSh/Programs/ShinyHuntUnattended/PokemonSwSh_MultiGameFossil.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Programs/ShinyHuntUnattended/PokemonSwSh_MultiGameFossil.cpp @@ -139,7 +139,7 @@ void run_fossil_batch( // Exit game. ssf_press_button(context, BUTTON_HOME, GameSettings::instance().GAME_TO_HOME_DELAY_SAFE0, 80ms); - close_game(console, context); + close_game_from_home(console, context); } diff --git a/SerialPrograms/Source/PokemonSwSh/Programs/ShinyHuntUnattended/PokemonSwSh_ShinyHuntTools.cpp b/SerialPrograms/Source/PokemonSwSh/Programs/ShinyHuntUnattended/PokemonSwSh_ShinyHuntTools.cpp index 385792eb5f..0d37ddcf39 100644 --- a/SerialPrograms/Source/PokemonSwSh/Programs/ShinyHuntUnattended/PokemonSwSh_ShinyHuntTools.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Programs/ShinyHuntUnattended/PokemonSwSh_ShinyHuntTools.cpp @@ -71,7 +71,7 @@ void close_game_if_overworld( pbf_press_dpad(context, DPAD_DOWN, 10, 10); // Close and restart game. - close_game(console, context); + close_game_from_home(console, context); pbf_press_button(context, BUTTON_HOME, 10, 190); }