Skip to content

Commit 9eb99d7

Browse files
authored
Merge pull request #549 from kichithewolf/daily-farm
LGPE: Daily Item Farmer
2 parents 91561be + ee02ad9 commit 9eb99d7

File tree

11 files changed

+491
-2
lines changed

11 files changed

+491
-2
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,12 @@ file(GLOB MAIN_SOURCES
13721372
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.h
13731373
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.cpp
13741374
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h
1375+
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.cpp
1376+
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.h
13751377
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp
13761378
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h
1379+
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.cpp
1380+
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.h
13771381
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp
13781382
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h
13791383
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ SOURCES += \
674674
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.cpp \
675675
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.cpp \
676676
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp \
677+
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.cpp \
677678
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp \
678679
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp \
679680
Source/PokemonLGPE/PokemonLGPE_Panels.cpp \
@@ -1864,6 +1865,7 @@ HEADERS += \
18641865
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.h \
18651866
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h \
18661867
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h \
1868+
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.h \
18671869
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h \
18681870
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h \
18691871
Source/PokemonLGPE/PokemonLGPE_Panels.h \

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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,66 @@ void home_to_date_time(ProControllerContext& context, bool to_date_change, bool
165165

166166

167167

168+
void home_to_date_time(JoyconContext& context, bool to_date_change){
169+
Milliseconds tv = context->timing_variation();
170+
Milliseconds unit = 32ms + tv;
171+
172+
//From ControllerPerformanceClass::SerialPABotBase_Wireless_ESP32
173+
//as Joycon will only have that controller type
174+
175+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
176+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
177+
178+
// Down twice in case we drop one.
179+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
180+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
181+
182+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
183+
184+
// Press A multiple times to make sure one goes through.
185+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
186+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
187+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
188+
189+
190+
// Just button mash it. lol
191+
{
192+
auto iterations = Milliseconds(1100) / unit + 1;
193+
do{
194+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
195+
}while (--iterations);
196+
}
197+
{
198+
auto iterations = Milliseconds(336) / unit + 1;
199+
do{
200+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
201+
}while (--iterations);
202+
}
203+
204+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
205+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
206+
pbf_move_joystick(context, 128, 255, 4*unit, unit);
207+
pbf_move_joystick(context, 128, 255, 360ms, 304ms);
208+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
209+
//pbf_move_joystick(context, 128, 255, 2*unit, unit);
210+
211+
if (!to_date_change){
212+
ssf_press_button(context, BUTTON_A, 360ms, 2*unit, unit);
213+
return;
214+
}
215+
216+
ssf_press_button(context, BUTTON_A, unit);
217+
{
218+
auto iterations = Milliseconds(216) / unit + 1;
219+
do{
220+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
221+
}while (--iterations);
222+
}
223+
pbf_move_joystick(context, 128, 255, 2*unit, 0ms);
224+
}
225+
226+
227+
168228

169229
}
170230
}

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Navigation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define PokemonAutomation_NintendoSwitch_Navigation_H
99

1010
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
11+
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
1112

1213
namespace PokemonAutomation{
1314
namespace NintendoSwitch{
@@ -16,6 +17,9 @@ namespace NintendoSwitch{
1617

1718
void home_to_date_time(ProControllerContext& context, bool to_date_change, bool fast);
1819

20+
//Joycon must not be sideways
21+
void home_to_date_time(JoyconContext& context, bool to_date_change);
22+
1923

2024

2125
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* Auto Host Routines
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "ClientSource/Libraries/MessageConverter.h"
8+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
9+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
10+
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
11+
#include "NintendoSwitch/Programs/NintendoSwitch_Navigation.h"
12+
#include "PokemonLGPE_DateSpam.h"
13+
14+
namespace PokemonAutomation{
15+
namespace NintendoSwitch{
16+
namespace PokemonLGPE{
17+
18+
void roll_date_forward_1(JoyconContext& context){
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);
33+
}
34+
35+
void roll_date_backward_N(JoyconContext& context, uint8_t skips){
36+
if (skips == 0){
37+
return;
38+
}
39+
40+
Milliseconds tv = context->timing_variation();
41+
Milliseconds unit = 32ms + tv;
42+
43+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
44+
45+
for (uint8_t c = 0; c < skips - 1; c++){
46+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
47+
}
48+
49+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
50+
pbf_move_joystick(context, 255, 128, 2*unit, unit);
51+
52+
for (uint8_t c = 0; c < skips - 1; c++){
53+
pbf_move_joystick(context, 128, 255, 2*unit, unit);
54+
}
55+
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);
61+
}
62+
63+
64+
65+
66+
67+
}
68+
69+
}
70+
}
71+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* Date Spamming Routines
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLGPE_Commands_DateSpam_H
8+
#define PokemonAutomation_PokemonLGPE_Commands_DateSpam_H
9+
10+
#include "CommonFramework/Tools/VideoStream.h"
11+
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
12+
13+
namespace PokemonAutomation{
14+
namespace NintendoSwitch{
15+
namespace PokemonLGPE{
16+
17+
void roll_date_forward_1 (JoyconContext& context);
18+
void roll_date_backward_N (JoyconContext& context, uint8_t skips);
19+
20+
}
21+
22+
}
23+
}
24+
#endif

SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Panels.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "PokemonLGPE_Panels.h"
1010
#include "PokemonLGPE_Settings.h"
1111

12+
#include "Programs/Farming/PokemonLGPE_DailyItemFarmer.h"
1213
#include "Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h"
1314

1415
namespace PokemonAutomation{
@@ -25,7 +26,8 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
2526
ret.emplace_back("---- Settings ----");
2627
ret.emplace_back(make_settings<GameSettings_Descriptor, GameSettingsPanel>());
2728

28-
//ret.emplace_back("---- General ----");
29+
ret.emplace_back("---- General ----");
30+
ret.emplace_back(make_single_switch_program<DailyItemFarmer_Descriptor, DailyItemFarmer>());
2931

3032
ret.emplace_back("---- Shiny Hunting ----");
3133
ret.emplace_back(make_single_switch_program<AlolanTrade_Descriptor, AlolanTrade>());

0 commit comments

Comments
 (0)