Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down