Skip to content

Commit c4baf9c

Browse files
authored
close_game: ensure it starts at Home screen. (#680)
1 parent 4b5aa6f commit c4baf9c

File tree

13 files changed

+22
-64
lines changed

13 files changed

+22
-64
lines changed

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "CommonFramework/VideoPipeline/VideoFeed.h"
1010
#include "CommonTools/Async/InferenceRoutines.h"
1111
#include "NintendoSwitch/NintendoSwitch_Settings.h"
12+
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
1213
#include "NintendoSwitch_Commands_Routines.h"
1314
#include "NintendoSwitch_Commands_PushButtons.h"
1415
#include "NintendoSwitch_Commands_Superscalar.h"
@@ -23,7 +24,9 @@ namespace PokemonAutomation{
2324
namespace NintendoSwitch{
2425

2526

26-
void close_game(ConsoleHandle& console, ProControllerContext& context){
27+
void close_game_from_home(ConsoleHandle& console, ProControllerContext& context){
28+
ensure_at_home(console, context);
29+
2730
// Use mashing to ensure that the X press succeeds. If it fails, the SR
2831
// will fail and can kill a den for the autohosts.
2932

@@ -35,44 +38,15 @@ void close_game(ConsoleHandle& console, ProControllerContext& context){
3538
ssf_press_dpad_ptv(context, DPAD_DOWN); // - Does nothing. | - moves selector away from the closed game to avoid opening it.
3639
ssf_press_dpad_ptv(context, DPAD_DOWN); // - Does nothing. | - Press Down a second time in case we drop one.
3740
pbf_mash_button(context, BUTTON_A, 50); // - Confirm close game. | - opens an app on the home screen (e.g. Online)
38-
// - Does nothing. | - goes back to home screen.
39-
pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
40-
context.wait_for_all_requests();
41-
42-
// cout << "waiting..." << endl;
43-
// context.wait_for(10s);
44-
45-
// send a second Home button press, if the first one is dropped
46-
bool video_available = (bool)console.video().snapshot();
47-
if (video_available){
48-
HomeMenuWatcher detector(console);
49-
int ret = wait_until(
50-
console, context,
51-
std::chrono::milliseconds(5000),
52-
{ detector }
53-
);
54-
if (ret == 0){
55-
console.log("Detected Home screen.");
56-
}else{ // if game initially open. | if game initially closed
57-
// initial Home button press was dropped
58-
// - Does nothing. | - goes back to home screen, from opened app
59-
pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
60-
}
61-
}else{
62-
// - wait some time after first Home button press
63-
// to avoid triggering zoom
64-
context.wait_for(std::chrono::milliseconds(1000));
65-
// - Does nothing. | - Press Home a second time in case we drop one.
66-
pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
67-
}
68-
41+
go_home(console, context); // - Does nothing. | - goes back to home screen.
6942

7043
// fail-safe against button drops and unexpected error messages.
7144
pbf_mash_button(context, BUTTON_X, 50);
7245
pbf_mash_button(context, BUTTON_B, 350);
7346
}
7447

75-
void close_game(ConsoleHandle& console, JoyconContext& context){
48+
void close_game_from_home(ConsoleHandle& console, JoyconContext& context){
49+
ensure_at_home(console, context);
7650
// Use mashing to ensure that the X press succeeds. If it fails, the SR
7751
// will fail and can kill a den for the autohosts.
7852

@@ -84,23 +58,7 @@ void close_game(ConsoleHandle& console, JoyconContext& context){
8458
pbf_move_joystick(context, 128, 255, 100ms, 10ms); // - Does nothing. | - moves selector away from the closed game to avoid opening it.
8559
pbf_move_joystick(context, 128, 255, 100ms, 10ms); // - Does nothing. | - Press Down a second time in case we drop one.
8660
pbf_mash_button(context, BUTTON_A, 400ms); // - Confirm close game. | - opens an app on the home screen (e.g. Online)
87-
// - Does nothing. | - goes back to home screen.
88-
pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
89-
context.wait_for_all_requests();
90-
91-
HomeMenuWatcher detector(console);
92-
int ret = wait_until(
93-
console, context,
94-
std::chrono::milliseconds(5000),
95-
{ detector }
96-
);
97-
if (ret == 0){
98-
console.log("Detected Home screen.");
99-
}else{ // if game initially open. | if game initially closed
100-
// initial Home button press was dropped
101-
// - Does nothing. | - goes back to home screen, from opened app
102-
pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
103-
}
61+
go_home(console, context); // - Does nothing. | - goes back to home screen.
10462

10563
// fail-safe against button drops and unexpected error messages.
10664
pbf_mash_button(context, BUTTON_X, 400ms);

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ namespace PokemonAutomation{
1616
namespace NintendoSwitch{
1717

1818

19-
void close_game(ConsoleHandle& console, ProControllerContext& device);
19+
void close_game_from_home(ConsoleHandle& console, ProControllerContext& device);
2020

21-
void close_game(ConsoleHandle& console, JoyconContext& device);
21+
void close_game_from_home(ConsoleHandle& console, JoyconContext& device);
2222

2323

2424

SerialPrograms/Source/PokemonBDSP/Programs/PokemonBDSP_GameEntry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool reset_game_from_home(
7979
ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET ||
8080
tolerate_update_menu
8181
){
82-
close_game(console, context);
82+
close_game_from_home(console, context);
8383
start_game_from_home(
8484
console,
8585
context,

SerialPrograms/Source/PokemonLA/Programs/PokemonLA_GameEntry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool reset_game_to_gamemenu(
3434
ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET ||
3535
tolerate_update_menu
3636
){
37-
close_game(console, context);
37+
close_game_from_home(console, context);
3838
start_game_from_home(
3939
console,
4040
context,

SerialPrograms/Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace PokemonLGPE{
3131
bool reset_game_to_gamemenu(
3232
ConsoleHandle& console, JoyconContext& context
3333
){
34-
close_game(console, context);
34+
close_game_from_home(console, context);
3535
start_game_from_home_with_inference(
3636
console,
3737
context,

SerialPrograms/Source/PokemonSV/Programs/PokemonSV_GameEntry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class WaitforWhiteLoadScreen : public VisualInferenceCallback{
6262

6363

6464
bool reset_game_to_gamemenu(ConsoleHandle& console, ProControllerContext& context){
65-
close_game(console, context);
65+
close_game_from_home(console, context);
6666
start_game_from_home(
6767
console, context,
6868
true,

SerialPrograms/Source/PokemonSwSh/Commands/PokemonSwSh_Commands_GameEntry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void reset_game_from_home(
7878
return;
7979
}
8080

81-
close_game(console, context);
81+
close_game_from_home(console, context);
8282
start_game_from_home(context, tolerate_update_menu, 0, 0, false);
8383
}
8484
void settings_to_enter_game(ProControllerContext& context, bool fast){

SerialPrograms/Source/PokemonSwSh/Programs/Hosting/PokemonSwSh_AutoHost-MultiGame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void AutoHostMultiGame::program(SingleSwitchProgramEnvironment& env, ProControll
223223

224224
// Exit game.
225225
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY_SAFE0);
226-
close_game(env.console, context);
226+
close_game_from_home(env.console, context);
227227

228228
// Post-raid delay.
229229
pbf_wait(context, game.post_raid_delay);

SerialPrograms/Source/PokemonSwSh/Programs/Hosting/PokemonSwSh_AutoHost-Rolling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void AutoHostRolling::program(SingleSwitchProgramEnvironment& env, ProController
196196

197197
// Exit game.
198198
ssf_press_button(context, BUTTON_HOME, GameSettings::instance().GAME_TO_HOME_DELAY_SAFE0, 160ms);
199-
close_game(env.console, context);
199+
close_game_from_home(env.console, context);
200200

201201
// Post-raid delay.
202202
pbf_wait(context, EXTRA_DELAY_BETWEEN_RAIDS0);

SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_GameEntry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void reset_game_from_home_with_inference(
138138
tolerate_update_menu
139139
){
140140
// cout << "close game" << endl;
141-
close_game(console, context);
141+
close_game_from_home(console, context);
142142
// cout << "start_game_from_home_with_inference game" << endl;
143143
start_game_from_home_with_inference(
144144
console, context, tolerate_update_menu, 0, 0, backup_save, post_wait_time
@@ -168,7 +168,7 @@ void start_game_from_home(
168168
tolerate_update_menu
169169
){
170170
// cout << "close game" << endl;
171-
close_game(console, context);
171+
close_game_from_home(console, context);
172172
// cout << "start_game_from_home_with_inference game" << endl;
173173
start_game_from_home_with_inference(
174174
console, context, tolerate_update_menu, game_slot, user_slot, backup_save, post_wait_time

0 commit comments

Comments
 (0)