Skip to content

Commit 42ec6a8

Browse files
committed
roll date forward/backward, resume game from home
1 parent 45452fc commit 42ec6a8

File tree

6 files changed

+79
-77
lines changed

6 files changed

+79
-77
lines changed

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_GameEntry.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,44 @@ bool openedgame_to_gamemenu(
312312

313313

314314

315+
void resume_game_from_home(
316+
VideoStream& stream, JoyconContext& context,
317+
bool skip_home_press
318+
){
319+
if (!skip_home_press){
320+
pbf_press_button(context, BUTTON_HOME, 20ms, 10ms);
321+
}
322+
context.wait_for_all_requests();
315323

324+
while (true){
325+
{
326+
UpdateMenuWatcher update_detector;
327+
int ret = wait_until(
328+
stream, context,
329+
std::chrono::milliseconds(1000),
330+
{ update_detector }
331+
);
332+
if (ret == 0){
333+
stream.log("Detected update window.", COLOR_RED);
334+
335+
pbf_move_joystick(context, 128, 0, 10ms, 0ms);
336+
pbf_press_button(context, BUTTON_A, 10ms, 500ms);
337+
context.wait_for_all_requests();
338+
continue;
339+
}
340+
}
341+
342+
// In case we failed to enter the game.
343+
HomeWatcher home_detector;
344+
if (home_detector.detect(stream.video().snapshot())){
345+
stream.log("Failed to re-enter game. Trying again...", COLOR_RED);
346+
pbf_press_button(context, BUTTON_HOME, 20ms, 10ms);
347+
continue;
348+
}else{
349+
break;
350+
}
351+
}
352+
}
316353
void move_to_user(JoyconContext& context, uint8_t user_slot){
317354
if (user_slot != 0){
318355
// Move to correct user.

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_GameEntry.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ bool openedgame_to_gamemenu(
3535
);
3636

3737

38-
38+
void resume_game_from_home(
39+
VideoStream& stream, JoyconContext& context,
40+
bool skip_home_press = false
41+
);
3942
void start_game_from_home_with_inference(
4043
VideoStream& stream, JoyconContext& context,
4144
uint8_t game_slot,

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Navigation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void home_to_date_time(ProControllerContext& context, bool to_date_change, bool
167167

168168
void home_to_date_time(JoyconContext& context, bool to_date_change){
169169
Milliseconds tv = context->timing_variation();
170-
Milliseconds unit = 50ms + tv;
170+
Milliseconds unit = 32ms + tv;
171171

172172
//From ControllerPerformanceClass::SerialPABotBase_Wireless_ESP32
173173
//as Joycon will only have that controller type

SerialPrograms/Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.cpp

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,75 +16,48 @@ namespace NintendoSwitch{
1616
namespace PokemonLGPE{
1717

1818
void roll_date_forward_1(JoyconContext& context){
19-
/*
20-
uint8_t scroll_delay = fast ? 3 : 4;
21-
uint8_t up_delay = fast ? 2 : 3;
22-
23-
pbf_press_button(context, BUTTON_A, 20, 10);
24-
ssf_issue_scroll(context, SSF_SCROLL_UP, 0);
25-
pbf_press_button(context, BUTTON_A, up_delay);
26-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, scroll_delay);
27-
ssf_issue_scroll(context, SSF_SCROLL_UP, up_delay);
28-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, scroll_delay);
29-
pbf_press_button(context, BUTTON_A, 0);
30-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, scroll_delay);
31-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, scroll_delay);
32-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 0);
33-
pbf_press_button(context, BUTTON_A, 20, 10);
34-
*/
19+
Milliseconds tv = context->timing_variation();
20+
Milliseconds unit = 34ms + tv;
21+
22+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
23+
pbf_move_joystick(context, 128, 0, 2*unit, unit);
24+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
25+
26+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
27+
pbf_move_joystick(context, 128, 0, 2*unit, unit);
28+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
29+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
30+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
31+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
32+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
3533
}
36-
void roll_date_backward_N(JoyconContext& context, uint8_t skips){
37-
/*
38-
// If (fast == true) this will run faster, but slightly less reliably.
3934

35+
void roll_date_backward_N(JoyconContext& context, uint8_t skips){
4036
if (skips == 0){
4137
return;
4238
}
4339

4440
Milliseconds tv = context->timing_variation();
45-
uint8_t scroll_delay = fast ? 3 : 4;
46-
uint8_t up_delay = 3;
41+
Milliseconds unit = 32ms + tv;
42+
43+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
4744

48-
pbf_press_button(context, BUTTON_A, 20, 10);
4945
for (uint8_t c = 0; c < skips - 1; c++){
50-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, up_delay);
46+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
5147
}
52-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 0);
53-
pbf_press_button(context, BUTTON_A, up_delay);
54-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, scroll_delay);
48+
49+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
50+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
51+
5552
for (uint8_t c = 0; c < skips - 1; c++){
56-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, up_delay);
57-
}
58-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 0);
59-
pbf_press_button(context, BUTTON_A, up_delay);
60-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, scroll_delay);
61-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, scroll_delay);
62-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 0);
63-
pbf_press_button(context, BUTTON_A, 20, 10);
64-
*/
65-
}
66-
void rollback_hours_from_home(
67-
JoyconContext& context,
68-
uint8_t hours,
69-
Milliseconds settings_to_home_delay
70-
){
71-
/*
72-
home_to_date_time(context, true, false);
73-
ssf_press_button_ptv(context, BUTTON_A, 160ms, 80ms);
74-
75-
ssf_press_button_ptv(context, BUTTON_A, 0ms);
76-
ssf_issue_scroll_ptv(context, SSF_SCROLL_RIGHT);
77-
ssf_issue_scroll_ptv(context, SSF_SCROLL_RIGHT);
78-
for (uint8_t c = 0; c < hours; c++){
79-
ssf_issue_scroll_ptv(context, SSF_SCROLL_DOWN);
53+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
8054
}
81-
ssf_press_button_ptv(context, BUTTON_A, 0ms);
82-
ssf_issue_scroll_ptv(context, SSF_SCROLL_RIGHT);
83-
ssf_issue_scroll_ptv(context, SSF_SCROLL_RIGHT);
8455

85-
pbf_press_button(context, BUTTON_A, 160ms, 80ms);
86-
ssf_press_button(context, BUTTON_HOME, settings_to_home_delay, 80ms);
87-
*/
56+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
57+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
58+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
59+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
60+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
8861
}
8962

9063

SerialPrograms/Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,10 @@
1212

1313
namespace PokemonAutomation{
1414
namespace NintendoSwitch{
15-
16-
17-
constexpr uint8_t MAX_YEAR = 60;
18-
19-
2015
namespace PokemonLGPE{
2116

22-
void roll_date_forward_1 (JoyconContext& context, bool fast);
23-
void roll_date_backward_N (JoyconContext& context, uint8_t skips, bool fast);
24-
void rollback_hours_from_home(
25-
JoyconContext& context,
26-
uint8_t hours,
27-
Milliseconds settings_to_home_delay
28-
);
17+
void roll_date_forward_1 (JoyconContext& context);
18+
void roll_date_backward_N (JoyconContext& context, uint8_t skips);
2919

3020
}
3121

SerialPrograms/Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemRespawnFarmer.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
1515
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
1616
#include "NintendoSwitch/Programs/NintendoSwitch_Navigation.h"
17+
#include "NintendoSwitch/NintendoSwitch_Settings.h"
1718
#include "Pokemon/Pokemon_Strings.h"
1819
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
20+
#include "PokemonLGPE/Commands/PokemonLGPE_DateSpam.h"
1921
#include "PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h"
2022
#include "PokemonLGPE/Programs/PokemonLGPE_GameEntry.h"
23+
#include "PokemonSwSh/Commands/PokemonSwSh_Commands_DateSpam.h"
2124
#include "PokemonLGPE_DailyItemRespawnFarmer.h"
2225

2326
namespace PokemonAutomation{
@@ -96,7 +99,7 @@ DailyItemRespawnFarmer::DailyItemRespawnFarmer()
9699
void DailyItemRespawnFarmer::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){
97100
JoyconContext context(scope, env.console.controller<JoyconController>());
98101
assert_16_9_720p_min(env.logger(), env.console);
99-
//DailyItemRespawnFarmer_Descriptor::Stats& stats = env.current_stats<DailyItemRespawnFarmer_Descriptor::Stats>();
102+
DailyItemRespawnFarmer_Descriptor::Stats& stats = env.current_stats<DailyItemRespawnFarmer_Descriptor::Stats>();
100103

101104
/* Stand in front of the fossil spawn near Mewtwo.
102105
* Use a repel to keep wild encounters away.
@@ -106,9 +109,6 @@ void DailyItemRespawnFarmer::program(SingleSwitchProgramEnvironment& env, Cancel
106109
* Should work for other hidden daily items, game corner, mt moon moonstones, etc.
107110
*/
108111

109-
home_to_date_time(context, true);
110-
111-
/*
112112
for (uint32_t count = 0; count < ATTEMPTS; count++) {
113113
//Pick up item
114114
pbf_mash_button(context, BUTTON_A, 3000ms);
@@ -184,8 +184,8 @@ void DailyItemRespawnFarmer::program(SingleSwitchProgramEnvironment& env, Cancel
184184
if (FIX_TIME_WHEN_DONE){
185185
pbf_press_button(context, BUTTON_HOME, 80ms, 1000ms);
186186
home_to_date_time(context, false);
187-
pbf_press_button(context, BUTTON_A, 20, 105);
188-
pbf_press_button(context, BUTTON_A, 20, 105);
187+
pbf_press_button(context, BUTTON_A, 20ms, 10ms);
188+
pbf_press_button(context, BUTTON_A, 20ms, 10ms);
189189
pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
190190
resume_game_from_home(env.console, context);
191191
}
@@ -194,7 +194,6 @@ void DailyItemRespawnFarmer::program(SingleSwitchProgramEnvironment& env, Cancel
194194
pbf_press_button(context, BUTTON_HOME, 200ms, 1000ms);
195195
}
196196
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
197-
*/
198197
}
199198

200199

0 commit comments

Comments
 (0)