Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 6 additions & 2 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1364,10 +1364,14 @@ file(GLOB MAIN_SOURCES
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h
Source/PokemonLGPE/Programs/PokemonLGPE_AlolanTrade.cpp
Source/PokemonLGPE/Programs/PokemonLGPE_AlolanTrade.h
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h
Source/PokemonLGPE/PokemonLGPE_Panels.cpp
Source/PokemonLGPE/PokemonLGPE_Panels.h
Source/PokemonLGPE/PokemonLGPE_Settings.cpp
Source/PokemonLGPE/PokemonLGPE_Settings.h
Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.cpp
Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h
Source/PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.cpp
Expand Down
8 changes: 6 additions & 2 deletions SerialPrograms/SerialPrograms.pro
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,10 @@ SOURCES += \
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.cpp \
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.cpp \
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp \
Source/PokemonLGPE/Programs/PokemonLGPE_AlolanTrade.cpp \
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp \
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp \
Source/PokemonLGPE/PokemonLGPE_Panels.cpp \
Source/PokemonLGPE/PokemonLGPE_Settings.cpp \
Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.cpp \
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.cpp \
Source/PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.cpp \
Expand Down Expand Up @@ -1852,8 +1854,10 @@ HEADERS += \
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.h \
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h \
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h \
Source/PokemonLGPE/Programs/PokemonLGPE_AlolanTrade.h \
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h \
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h \
Source/PokemonLGPE/PokemonLGPE_Panels.h \
Source/PokemonLGPE/PokemonLGPE_Settings.h \
Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h \
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.h \
Source/PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,54 @@ void close_game(VideoStream& stream, ProControllerContext& context){
pbf_mash_button(context, BUTTON_B, 350);
}

void close_game(VideoStream& stream, JoyconContext& 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.

// this sequence will close the game from the home screen,
// regardless of whether the game is initially open or closed.

// if game initially open. | if game initially closed
pbf_mash_button(context, BUTTON_X, 800ms); // - Close game. | - does nothing
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();

// cout << "waiting..." << endl;
// context.wait_for(10s);

// send a second Home button press, if the first one is dropped
bool video_available = (bool)stream.video().snapshot();
if (video_available){
HomeWatcher detector;
int ret = wait_until(
stream, context,
std::chrono::milliseconds(5000),
{ detector }
);
if (ret == 0){
stream.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);
}


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


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

#include "CommonFramework/Tools/VideoStream.h"
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"

namespace PokemonAutomation{
namespace NintendoSwitch{


void close_game(VideoStream& stream, ProControllerContext& device);

void close_game(VideoStream& stream, JoyconContext& device);




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,206 @@ bool openedgame_to_gamemenu(



void move_to_user(JoyconContext& context, uint8_t user_slot){
if (user_slot != 0){
// Move to correct user.
for (uint8_t c = 0; c < 9; c++){ // Extra iteration in case one gets dropped.
pbf_move_joystick(context, 0, 128, 160ms, 160ms);
}
for (uint8_t c = 1; c < user_slot; c++){
pbf_move_joystick(context, 0, 128, 160ms, 160ms);
}
}
}

void start_game_from_home_with_inference(
VideoStream& stream, JoyconContext& context,
uint8_t game_slot,
uint8_t user_slot,
Milliseconds start_game_wait
){
context.wait_for_all_requests();
{
HomeWatcher detector;
int ret = run_until<JoyconContext>(
stream, context,
[](JoyconContext& context){
pbf_mash_button(context, BUTTON_B, 10000ms);
},
{ detector }
);
if (ret == 0){
stream.log("Detected Home screen.");
}else{
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"start_game_from_home_with_inference(): Failed to detect Home screen after 10 seconds.",
stream
);
}
context.wait_for(std::chrono::milliseconds(100));
}

if (game_slot != 0){
ssf_press_button(context, BUTTON_HOME, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0, 160ms);
for (uint8_t c = 1; c < game_slot; c++){
pbf_move_joystick(context, 255, 128, 160ms, 0ms);
}
context.wait_for_all_requests();
}

pbf_press_button(context, BUTTON_A, 160ms, 840ms);

while (true){
HomeWatcher home(std::chrono::milliseconds(2000));
StartGameUserSelectWatcher user_select(COLOR_GREEN);
UpdateMenuWatcher update_menu(COLOR_PURPLE);
CheckOnlineWatcher check_online(COLOR_CYAN);
BlackScreenWatcher black_screen(COLOR_BLUE);
context.wait_for_all_requests();
int ret = wait_until(
stream, context,
std::chrono::seconds(30),
{
home,
user_select,
update_menu,
check_online,
black_screen,
}
);

// Wait for screen to stabilize.
context.wait_for(std::chrono::milliseconds(100));

switch (ret){
case 0:
stream.log("Detected home screen (again).", COLOR_RED);
pbf_press_button(context, BUTTON_A, 160ms, 840ms);
break;
case 1:
stream.log("Detected user-select screen.");
move_to_user(context, user_slot);
pbf_press_button(context, BUTTON_A, 80ms, start_game_wait);
break;
case 2:
stream.log("Detected update menu.", COLOR_RED);
pbf_move_joystick(context, 128, 0, 50ms, 0ms);
pbf_press_button(context, BUTTON_A, 160ms, 840ms);
break;
case 3:
stream.log("Detected check online.", COLOR_RED);
context.wait_for(std::chrono::seconds(1));
break;
case 4:
stream.log("Detected black screen. Game started...");
return;
default:
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"start_game_from_home_with_inference(): No recognizable state after 30 seconds.",
stream
);
}
}
}

void start_game_from_home(
VideoStream& stream, JoyconContext& context,
bool tolerate_update_menu,
uint8_t game_slot,
uint8_t user_slot,
Milliseconds start_game_mash
){
context.wait_for_all_requests();
if (stream.video().snapshot()){
stream.log("start_game_from_home(): Video capture available. Using inference...");
start_game_from_home_with_inference(stream, context, game_slot, user_slot, start_game_mash);
return;
}else{
stream.log("start_game_from_home(): Video capture not available.", COLOR_RED);
}

if (game_slot != 0){
ssf_press_button(context, BUTTON_HOME, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0, 160ms);
for (uint8_t c = 1; c < game_slot; c++){
pbf_move_joystick(context, 255, 128, 80ms, 0ms);
}
}

if (tolerate_update_menu){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify this logic now and assume that feedback is available. This fallback system was for the old SwSh programs that could run without feedback.

if (ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET){
throw UserSetupError(
stream.logger(),
"Cannot have both \"Tolerate Update Menu\" and \"Start Game Requires Internet\" enabled at the same time without video feedback."
);
}

// If the update menu isn't there, these will get swallowed by the opening
// animation for the select user menu.
pbf_press_button(context, BUTTON_A, 80ms, 1400ms); // Choose game
pbf_move_joystick(context, 128, 255, 100ms, 0ms); // Skip the update window.
move_to_user(context, user_slot);
}

// cout << "START_GAME_REQUIRES_INTERNET = " << ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET << endl;
if (!ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET && user_slot == 0){
// Mash your way into the game.
pbf_mash_button(context, BUTTON_A, start_game_mash);
}else{
pbf_press_button(context, BUTTON_A, 80ms, 1400ms); // Enter select user menu.
move_to_user(context, user_slot);
ssf_press_button(context, BUTTON_A, 160ms); // Enter game

// Switch to mashing ZL instead of A to get into the game.
// Mash your way into the game.
Milliseconds duration = start_game_mash;
if (ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET){
// Need to wait a bit longer for the internet check.
duration += ConsoleSettings::instance().START_GAME_INTERNET_CHECK_DELAY0;
}
// pbf_mash_button(context, BUTTON_ZL, duration);
pbf_wait(context, duration);
}
context.wait_for_all_requests();
}

bool openedgame_to_gamemenu(
VideoStream& stream, JoyconContext& context,
Milliseconds timeout
){
{
stream.log("Waiting to load game...");
GameLoadingDetector detector(false);
int ret = wait_until(
stream, context,
timeout,
{{detector}}
);
if (ret < 0){
stream.log("Timed out waiting to enter game.", COLOR_RED);
return false;
}
}
{
stream.log("Waiting for game menu...");
GameLoadingDetector detector(true);
int ret = wait_until(
stream, context,
timeout,
{{detector}}
);
if (ret < 0){
stream.log("Timed out waiting for game menu.", COLOR_RED);
return false;
}
}
return true;
}







Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "CommonFramework/Tools/VideoStream.h"
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -35,6 +36,20 @@ bool openedgame_to_gamemenu(



void start_game_from_home(
VideoStream& stream, JoyconContext& context,
bool tolerate_update_menu,
uint8_t game_slot,
uint8_t user_slot,
Milliseconds start_game_mash
);

bool openedgame_to_gamemenu(
VideoStream& stream, JoyconContext& context,
Milliseconds timeout
);


}
}
#endif
5 changes: 3 additions & 2 deletions SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#include "CommonFramework/GlobalSettingsPanel.h"
#include "Pokemon/Pokemon_Strings.h"
#include "PokemonLGPE_Panels.h"
#include "PokemonLGPE_Settings.h"

#include "Programs/PokemonLGPE_AlolanTrade.h"
#include "Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -22,7 +23,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
std::vector<PanelEntry> ret;

ret.emplace_back("---- Settings ----");
//ret.emplace_back(make_settings<GameSettings_Descriptor, GameSettingsPanel>());
ret.emplace_back(make_settings<GameSettings_Descriptor, GameSettingsPanel>());

//ret.emplace_back("---- General ----");

Expand Down
Loading