1313#include " NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1414#include " NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
1515#include " NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
16+ #include " PokemonSwSh/MaxLair/Ai/PokemonSwSh_MaxLair_AI.h"
1617#include " PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
1718#include " PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.h"
1819#include " PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h"
@@ -24,37 +25,78 @@ namespace NintendoSwitch{
2425namespace PokemonFRLG {
2526
2627
27- void soft_reset (const ProgramInfo& info, VideoStream& stream , ProControllerContext& context){
28+ void soft_reset (ConsoleHandle& console , ProControllerContext& context){
2829 // A + B + Select + Start
2930 pbf_press_button (context, BUTTON_B | BUTTON_A | BUTTON_MINUS | BUTTON_PLUS, 360ms, 1440ms);
3031
31- pbf_mash_button (context, BUTTON_PLUS , GameSettings::instance ().START_BUTTON_MASH1 );
32+ pbf_mash_button (context, BUTTON_MINUS , GameSettings::instance ().SELECT_BUTTON_MASH0 );
3233 context.wait_for_all_requests ();
3334
35+ // Random wait before pressing start/A
36+ console.log (" Randomly waiting..." );
37+ Milliseconds rng_wait = std::chrono::milliseconds (PokemonSwSh::MaxLairInternal::random (0 , 5000 ));
38+ pbf_wait (context, rng_wait);
39+ context.wait_for_all_requests ();
40+
41+ // Mash A until white screen to game load menu
42+ WhiteScreenOverWatcher whitescreen (COLOR_RED, {0.282 , 0.064 , 0.448 , 0.871 });
43+
44+ int ls = run_until<ProControllerContext>(
45+ console, context,
46+ [](ProControllerContext& context) {
47+ pbf_mash_button (context, BUTTON_A, 1000ms);
48+ pbf_wait (context, 5000ms);
49+ context.wait_for_all_requests ();
50+ },
51+ { whitescreen }
52+ );
53+ context.wait_for_all_requests ();
54+ if (ls == 0 ){
55+ console.log (" Entered load menu." );
56+ }else {
57+ console.log (" Unable to enter load menu." , COLOR_RED);
58+ OperationFailedException::fire (
59+ ErrorReport::SEND_ERROR_REPORT,
60+ " soft_reset(): Unable to enter load menu." ,
61+ console
62+ );
63+ }
64+ // Let the animation finish
65+ pbf_wait (context, 500ms);
66+ context.wait_for_all_requests ();
67+
68+ // Load game
3469 pbf_press_button (context, BUTTON_A, 160ms, 320ms);
3570
3671 // Wait for game to load in
3772 BlackScreenOverWatcher detector (COLOR_RED, {0.282 , 0.064 , 0.448 , 0.871 });
3873 int ret = wait_until (
39- stream , context,
74+ console , context,
4075 GameSettings::instance ().ENTER_GAME_WAIT0 ,
4176 {detector}
4277 );
4378 if (ret == 0 ){
44- stream .log (" Entered game!" );
79+ console .log (" Entered game!" );
4580 }else {
46- stream .log (" Timed out waiting to enter game." , COLOR_RED);
81+ console .log (" Timed out waiting to enter game." , COLOR_RED);
4782 OperationFailedException::fire (
4883 ErrorReport::SEND_ERROR_REPORT,
4984 " soft_reset(): Timed out waiting to enter game." ,
50- stream
85+ console
5186 );
5287 }
5388
5489 // Mash past "previously on..."
5590 pbf_mash_button (context, BUTTON_B, GameSettings::instance ().ENTER_GAME_MASH0 );
91+ context.wait_for_all_requests ();
5692
93+ // Random wait no.2
94+ console.log (" Randomly waiting..." );
95+ Milliseconds rng_wait2 = std::chrono::milliseconds (PokemonSwSh::MaxLairInternal::random (0 , 5000 ));
96+ pbf_wait (context, rng_wait2);
5797 context.wait_for_all_requests ();
98+
99+ console.log (" Soft reset completed." );
58100}
59101
60102void open_slot_six (ConsoleHandle& console, ProControllerContext& context){
@@ -85,20 +127,23 @@ void open_slot_six(ConsoleHandle& console, ProControllerContext& context){
85127 }
86128
87129 console.log (" Navigating to party menu." );
88- pbf_wait (context, 200ms);
89- context.wait_for_all_requests ();
90- pbf_press_dpad (context, DPAD_DOWN, 320ms, 320ms);
91- context.wait_for_all_requests ();
92-
93- pbf_press_button (context, BUTTON_A, 320ms, 640ms);
94-
95130 BlackScreenOverWatcher blk1 (COLOR_RED, {0.282 , 0.064 , 0.448 , 0.871 });
96- int ret1 = wait_until (
131+
132+ int pm = run_until<ProControllerContext>(
97133 console, context,
98- 5s,
99- {blk1}
134+ [](ProControllerContext& context) {
135+ pbf_wait (context, 200ms);
136+ context.wait_for_all_requests ();
137+ pbf_press_dpad (context, DPAD_DOWN, 320ms, 320ms);
138+ context.wait_for_all_requests ();
139+
140+ pbf_press_button (context, BUTTON_A, 320ms, 640ms);
141+ pbf_wait (context, 5000ms);
142+ context.wait_for_all_requests ();
143+ },
144+ { blk1 }
100145 );
101- if (ret1 == 0 ){
146+ if (pm == 0 ){
102147 console.log (" Entered party menu." );
103148 }else {
104149 console.log (" Unable to enter Party menu." , COLOR_RED);
@@ -115,16 +160,18 @@ void open_slot_six(ConsoleHandle& console, ProControllerContext& context){
115160 pbf_press_dpad (context, DPAD_UP, 320ms, 320ms);
116161
117162 // Two presses to open summary
118- pbf_press_button (context, BUTTON_A, 320ms, 640ms);
119- pbf_press_button (context, BUTTON_A, 320ms, 640ms);
120-
121163 BlackScreenOverWatcher blk2 (COLOR_RED, {0.282 , 0.064 , 0.448 , 0.871 });
122- int ret2 = wait_until (
164+ int sm = run_until<ProControllerContext> (
123165 console, context,
124- 5s,
125- {blk2}
166+ [](ProControllerContext& context) {
167+ pbf_press_button (context, BUTTON_A, 320ms, 640ms);
168+ pbf_press_button (context, BUTTON_A, 320ms, 640ms);
169+ pbf_wait (context, 5000ms);
170+ context.wait_for_all_requests ();
171+ },
172+ { blk2 }
126173 );
127- if (ret2 == 0 ){
174+ if (sm == 0 ){
128175 console.log (" Entered summary." );
129176 }else {
130177 console.log (" Unable to enter summary." , COLOR_RED);
0 commit comments