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
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,40 @@ 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();

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);
}

// 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 @@ -12,6 +12,7 @@
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
#include "CommonTools/Async/InferenceRoutines.h"
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
#include "Controllers/ControllerTypes.h"
#include "NintendoSwitch/NintendoSwitch_Settings.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
Expand Down Expand Up @@ -312,6 +313,156 @@ 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();

if (!(context.controller().controller_type() == ControllerType::NintendoSwitch_RightJoycon)) {
stream.log("Right Joycon required!", COLOR_RED);
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"start_game_from_home_with_inference(): Right Joycon required.",
stream
);
}

{
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
);
}
}
}

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,19 @@ bool openedgame_to_gamemenu(



void start_game_from_home_with_inference(
VideoStream& stream, JoyconContext& context,
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
Loading