Skip to content

Commit 0c6f9e5

Browse files
kichithewolfMysticial
authored andcommitted
copy LA game entry to LZA to fix resets
lowered start game mash default
1 parent c74cc36 commit 0c6f9e5

File tree

4 files changed

+87
-11
lines changed

4 files changed

+87
-11
lines changed

SerialPrograms/Source/PokemonLZA/PokemonLZA_Settings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ GameSettings::GameSettings()
2828
LockMode::LOCK_WHILE_RUNNING,
2929
"40 s"
3030
)
31-
, ENTER_GAME_MASH(
31+
, ENTER_GAME_MASH0(
3232
"<b>Enter Game Mash:</b><br>Mash A for this long to enter the game.",
3333
LockMode::LOCK_WHILE_RUNNING,
34-
"5000 ms"
34+
"3000 ms"
3535
)
3636
, ENTER_GAME_WAIT(
3737
"<b>Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
@@ -46,7 +46,7 @@ GameSettings::GameSettings()
4646

4747
PA_ADD_STATIC(m_start_game_timings);
4848
PA_ADD_OPTION(START_GAME_WAIT);
49-
PA_ADD_OPTION(ENTER_GAME_MASH);
49+
PA_ADD_OPTION(ENTER_GAME_MASH0);
5050
PA_ADD_OPTION(ENTER_GAME_WAIT);
5151

5252
PA_ADD_STATIC(m_advanced_options);

SerialPrograms/Source/PokemonLZA/PokemonLZA_Settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class GameSettings : public BatchOption{
2626

2727
SectionDividerOption m_start_game_timings;
2828
MillisecondsOption START_GAME_WAIT;
29-
MillisecondsOption ENTER_GAME_MASH;
29+
MillisecondsOption ENTER_GAME_MASH0;
3030
MillisecondsOption ENTER_GAME_WAIT;
3131

3232
SectionDividerOption m_advanced_options;

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_GameEntry.cpp

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,95 @@
44
*
55
*/
66

7+
#include "CommonFramework/Tools/ErrorDumper.h"
8+
#include "CommonFramework/Tools/ProgramEnvironment.h"
79
#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"
814
#include "PokemonLZA/PokemonLZA_Settings.h"
915
#include "PokemonLZA_GameEntry.h"
1016

1117
namespace PokemonAutomation{
1218
namespace NintendoSwitch{
1319
namespace PokemonLZA{
1420

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+
}
1586
bool reset_game_from_home(
1687
ProgramEnvironment& env,
1788
ConsoleHandle& console, ProControllerContext& context,
1889
bool backup_save,
1990
Milliseconds post_wait_time
2091
){
21-
return PokemonLA::reset_game_from_home(
92+
return reset_game_from_home(
2293
env, console, context,
2394
backup_save,
24-
GameSettings::instance().ENTER_GAME_MASH,
95+
GameSettings::instance().ENTER_GAME_MASH0,
2596
GameSettings::instance().ENTER_GAME_WAIT,
2697
post_wait_time
2798
);

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_GameEntry.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
1111
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
12-
#include "PokemonLA/Programs/PokemonLA_GameEntry.h"
1312

1413
namespace PokemonAutomation{
1514
class ProgramEnvironment;
@@ -22,11 +21,9 @@ using namespace std::chrono_literals;
2221

2322
// From Switch Home menu, reset game and wait until the game menu screen (where
2423
// "Press A" is displayed to enter the game) is shown.
25-
inline bool reset_game_to_gamemenu(
24+
bool reset_game_to_gamemenu(
2625
ConsoleHandle& console, ProControllerContext& context
27-
){
28-
return PokemonLA::reset_game_to_gamemenu(console, context);
29-
}
26+
);
3027

3128
// From Switch Home menu, start game and wait until the player character
3229
// appears in game.
@@ -36,6 +33,14 @@ bool reset_game_from_home(
3633
ProgramEnvironment& env,
3734
ConsoleHandle& console, ProControllerContext& context,
3835
bool backup_save,
36+
Milliseconds enter_game_mash,
37+
Milliseconds enter_game_timeout,
38+
Milliseconds post_wait_time
39+
);
40+
bool reset_game_from_home(
41+
ProgramEnvironment& env,
42+
ConsoleHandle& console, ProControllerContext& context,
43+
bool backup_save = false,
3944
Milliseconds post_wait_time = 1000ms
4045
);
4146

0 commit comments

Comments
 (0)