|
4 | 4 | * |
5 | 5 | */ |
6 | 6 |
|
| 7 | +#include "CommonFramework/Tools/ErrorDumper.h" |
| 8 | +#include "CommonFramework/Tools/ProgramEnvironment.h" |
7 | 9 | #include "CommonTools/Async/InferenceRoutines.h" |
| 10 | +#include "CommonTools/VisualDetectors/BlackScreenDetector.h" |
| 11 | +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" |
| 12 | +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" |
| 13 | +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" |
8 | 14 | #include "PokemonLZA/PokemonLZA_Settings.h" |
9 | 15 | #include "PokemonLZA_GameEntry.h" |
10 | 16 |
|
11 | 17 | namespace PokemonAutomation{ |
12 | 18 | namespace NintendoSwitch{ |
13 | 19 | namespace PokemonLZA{ |
14 | 20 |
|
| 21 | +bool reset_game_to_gamemenu( |
| 22 | + ConsoleHandle& console, ProControllerContext& context |
| 23 | +){ |
| 24 | + from_home_close_and_reopen_game(console, context, true); |
| 25 | + |
| 26 | + // Now the game has opened: |
| 27 | + return openedgame_to_gamemenu(console, context, GameSettings::instance().START_GAME_WAIT); |
| 28 | +} |
| 29 | + |
| 30 | +// From the game menu screen (where "Press A" is displayed to enter the game), |
| 31 | +// mash A to enter the game and wait until the black screen is gone. |
| 32 | +bool gamemenu_to_ingame( |
| 33 | + VideoStream& stream, ProControllerContext& context, |
| 34 | + Milliseconds mash_duration, Milliseconds enter_game_timeout |
| 35 | +){ |
| 36 | + stream.log("Mashing A to enter game..."); |
| 37 | + BlackScreenOverWatcher detector(COLOR_RED, {0.074, 0.044, 0.826, 0.278}); |
| 38 | + pbf_mash_button(context, BUTTON_A, mash_duration); |
| 39 | + context.wait_for_all_requests(); |
| 40 | + stream.log("Waiting to enter game..."); |
| 41 | + int ret = wait_until( |
| 42 | + stream, context, |
| 43 | + std::chrono::milliseconds(enter_game_timeout), |
| 44 | + {{detector}} |
| 45 | + ); |
| 46 | + if (ret == 0){ |
| 47 | + stream.log("Entered game!"); |
| 48 | + return true; |
| 49 | + }else{ |
| 50 | + stream.log("Timed out waiting to enter game.", COLOR_RED); |
| 51 | + return false; |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +bool reset_game_from_home( |
| 56 | + ProgramEnvironment& env, |
| 57 | + ConsoleHandle& console, ProControllerContext& context, |
| 58 | + bool backup_save, |
| 59 | + Milliseconds enter_game_mash, |
| 60 | + Milliseconds enter_game_timeout, |
| 61 | + Milliseconds post_wait_time |
| 62 | +){ |
| 63 | + bool ok = true; |
| 64 | + ok &= reset_game_to_gamemenu(console, context); |
| 65 | + |
| 66 | + if (backup_save){ |
| 67 | + console.log("Loading backup save!"); |
| 68 | + pbf_wait(context, 1000ms); |
| 69 | + ssf_press_dpad(context, DPAD_UP, 0ms, 200ms); |
| 70 | + ssf_press_button(context, BUTTON_B | BUTTON_X, 1000ms, 200ms); |
| 71 | + } |
| 72 | + |
| 73 | + ok &= gamemenu_to_ingame( |
| 74 | + console, context, |
| 75 | + enter_game_mash, |
| 76 | + enter_game_timeout |
| 77 | + ); |
| 78 | + if (!ok){ |
| 79 | + dump_image(console.logger(), env.program_info(), console.video(), "StartGame"); |
| 80 | + } |
| 81 | + console.log("Entered game! Waiting out grace period."); |
| 82 | + pbf_wait(context, post_wait_time); |
| 83 | + context.wait_for_all_requests(); |
| 84 | + return ok; |
| 85 | +} |
15 | 86 | bool reset_game_from_home( |
16 | 87 | ProgramEnvironment& env, |
17 | 88 | ConsoleHandle& console, ProControllerContext& context, |
18 | 89 | bool backup_save, |
19 | 90 | Milliseconds post_wait_time |
20 | 91 | ){ |
21 | | - return PokemonLA::reset_game_from_home( |
| 92 | + return reset_game_from_home( |
22 | 93 | env, console, context, |
23 | 94 | backup_save, |
24 | | - GameSettings::instance().ENTER_GAME_MASH, |
| 95 | + GameSettings::instance().ENTER_GAME_MASH0, |
25 | 96 | GameSettings::instance().ENTER_GAME_WAIT, |
26 | 97 | post_wait_time |
27 | 98 | ); |
|
0 commit comments