Skip to content

Commit 6e47810

Browse files
committed
non-test starter reset, panels
1 parent f27f31e commit 6e47810

File tree

4 files changed

+282
-4
lines changed

4 files changed

+282
-4
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,8 +1319,14 @@ file(GLOB MAIN_SOURCES
13191319
Source/PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h
13201320
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.cpp
13211321
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.h
1322+
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.cpp
1323+
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h
1324+
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.cpp
1325+
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.h
13221326
Source/PokemonRSE/Programs/TestPrograms/PokemonRSE_SoundListener.cpp
13231327
Source/PokemonRSE/Programs/TestPrograms/PokemonRSE_SoundListener.h
1328+
Source/PokemonRSE/PokemonRSE_Navigation.cpp
1329+
Source/PokemonRSE/PokemonRSE_Navigation.h
13241330
Source/PokemonRSE/PokemonRSE_Panels.cpp
13251331
Source/PokemonRSE/PokemonRSE_Panels.h
13261332
Source/PokemonRSE/PokemonRSE_Settings.cpp

SerialPrograms/Source/PokemonRSE/PokemonRSE_Panels.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
#include "PokemonRSE_Settings.h"
1212

13-
//#include "Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h"
14-
//#include "Programs/ShinyHunting/PokemonRSE_StarterReset.h"
13+
#include "Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h"
14+
#include "Programs/ShinyHunting/PokemonRSE_StarterReset.h"
1515
#include "Programs/TestPrograms/PokemonRSE_SoundListener.h"
1616

1717
namespace PokemonAutomation{
@@ -33,12 +33,12 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
3333
//ret.emplace_back("---- General ----");
3434

3535
ret.emplace_back("---- Shiny Hunting ----");
36-
//ret.emplace_back(make_single_switch_program<AudioStarterReset_Descriptor, AudioStarterReset>());
36+
ret.emplace_back(make_single_switch_program<AudioStarterReset_Descriptor, AudioStarterReset>());
3737

3838

3939
if (PreloadSettings::instance().DEVELOPER_MODE){
4040
ret.emplace_back("---- Test ----");
41-
//ret.emplace_back(make_single_switch_program<StarterReset_Descriptor, StarterReset>()); //outdated early test program
41+
ret.emplace_back(make_single_switch_program<StarterReset_Descriptor, StarterReset>()); //outdated early test program
4242

4343
ret.emplace_back("---- Developer Tools ----");
4444
ret.emplace_back(make_single_switch_program<SoundListener_Descriptor, SoundListener>());
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
/* RS Starter Reset
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
8+
#include "CommonFramework/ProgramStats/StatsTracking.h"
9+
#include "CommonFramework/VideoPipeline/VideoFeed.h"
10+
#include "CommonTools/Async/InferenceRoutines.h"
11+
#include "CommonFramework/Notifications/ProgramNotifications.h"
12+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
13+
#include "Pokemon/Pokemon_Strings.h"
14+
#include "PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h"
15+
#include "PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h"
16+
#include "PokemonRSE/PokemonRSE_Navigation.h"
17+
#include "PokemonRSE_AudioStarterReset.h"
18+
19+
namespace PokemonAutomation{
20+
namespace NintendoSwitch{
21+
namespace PokemonRSE{
22+
23+
AudioStarterReset_Descriptor::AudioStarterReset_Descriptor()
24+
: SingleSwitchProgramDescriptor(
25+
"PokemonRSE:AudioStarterReset",
26+
Pokemon::STRING_POKEMON + " RSE", "Starter Reset (Ruby/Sapphire)",
27+
"ComputerControl/blob/master/Wiki/Programs/PokemonRSE/AudioStarterReset.md",
28+
"Soft reset for a shiny starter. Ruby and Sapphire only.",
29+
FeedbackType::VIDEO_AUDIO,
30+
AllowCommandsWhenRunning::DISABLE_COMMANDS,
31+
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
32+
)
33+
{}
34+
35+
struct AudioStarterReset_Descriptor::Stats : public StatsTracker{
36+
Stats()
37+
: resets(m_stats["Resets"])
38+
, poochyena(m_stats["Shiny Poochyena"])
39+
, shinystarter(m_stats["Shiny Starter"])
40+
{
41+
m_display_order.emplace_back("Resets");
42+
m_display_order.emplace_back("Shiny Poochyena");
43+
m_display_order.emplace_back("Shiny Starter");
44+
}
45+
std::atomic<uint64_t>& resets;
46+
std::atomic<uint64_t>& poochyena;
47+
std::atomic<uint64_t>& shinystarter;
48+
};
49+
std::unique_ptr<StatsTracker> AudioStarterReset_Descriptor::make_stats() const{
50+
return std::unique_ptr<StatsTracker>(new Stats());
51+
}
52+
53+
AudioStarterReset::AudioStarterReset()
54+
: TARGET(
55+
"<b>Starter:</b><br>",
56+
{
57+
{Target::treecko, "treecko", "Treecko"},
58+
{Target::torchic, "torchic", "Torchic"},
59+
{Target::mudkip, "mudkip", "Mudkip"},
60+
},
61+
LockMode::LOCK_WHILE_RUNNING,
62+
Target::treecko
63+
)
64+
, NOTIFICATION_SHINY_POOCH(
65+
"Shiny Poochyena",
66+
false, false, ImageAttachmentMode::JPG,
67+
{"Notifs"}
68+
)
69+
, NOTIFICATION_SHINY_STARTER(
70+
"Shiny Starter",
71+
true, true, ImageAttachmentMode::JPG,
72+
{"Notifs", "Showcase"}
73+
)
74+
, NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600))
75+
, NOTIFICATIONS({
76+
&NOTIFICATION_SHINY_POOCH,
77+
&NOTIFICATION_SHINY_STARTER,
78+
&NOTIFICATION_STATUS_UPDATE,
79+
&NOTIFICATION_PROGRAM_FINISH,
80+
})
81+
{
82+
PA_ADD_OPTION(TARGET);
83+
PA_ADD_OPTION(NOTIFICATIONS);
84+
}
85+
86+
void AudioStarterReset::program(SingleSwitchProgramEnvironment& env, SwitchControllerContext& context){
87+
AudioStarterReset_Descriptor::Stats& stats = env.current_stats<AudioStarterReset_Descriptor::Stats>();
88+
89+
/*
90+
* Settings: Text Speed fast.
91+
* Full screen, no filter? The device I'm using to test has similar looking output, but I don't have switch online+.
92+
* If on a retro handheld, make sure the screen matches that of NSO+.
93+
*
94+
* Setup: Stand in front of the Professor's bag and save the game.
95+
*
96+
* Required to fight, so have to do the SR method instead of run away
97+
* Soft reset programs are only for Ruby/Sapphire, as Emerald has the 0 seed issue.
98+
*
99+
* This also assumes no dry battery.
100+
*/
101+
102+
bool shiny_starter = false;
103+
while (!shiny_starter) {
104+
float shiny_coefficient = 1.0;
105+
ShinySoundDetector pooch_detector(env.console, [&](float error_coefficient) -> bool{
106+
shiny_coefficient = error_coefficient;
107+
return true;
108+
});
109+
110+
env.log("Opening bag and selecting starter.");
111+
pbf_press_button(context, BUTTON_A, 40, 180);
112+
113+
switch (TARGET) {
114+
case Target::treecko:
115+
pbf_press_dpad(context, DPAD_LEFT, 40, 100);
116+
break;
117+
case Target::torchic:
118+
//Default cursor position, do nothing.
119+
break;
120+
case Target::mudkip:
121+
pbf_press_dpad(context, DPAD_RIGHT, 40, 100);
122+
break;
123+
default:
124+
OperationFailedException::fire(
125+
ErrorReport::SEND_ERROR_REPORT,
126+
"AudioStarterReset: Invalid target.",
127+
env.console
128+
);
129+
break;
130+
}
131+
pbf_mash_button(context, BUTTON_A, 540);
132+
context.wait_for_all_requests();
133+
134+
env.log("Starter selected. Checking for shiny Poochyena.");
135+
AdvanceBattleDialogWatcher pooch_appeared(COLOR_YELLOW);
136+
137+
int res = run_until<SwitchControllerContext>(
138+
env.console, context,
139+
[&](SwitchControllerContext& context) {
140+
int ret = wait_until(
141+
env.console, context,
142+
std::chrono::seconds(20),
143+
{{pooch_appeared}}
144+
);
145+
if (ret == 0) {
146+
env.log("Advance arrow detected.");
147+
}
148+
pbf_wait(context, 125);
149+
context.wait_for_all_requests();
150+
},
151+
{{pooch_detector}}
152+
);
153+
pooch_detector.throw_if_no_sound();
154+
if (res == 0){
155+
env.log("Shiny Poochyena detected!");
156+
stats.poochyena++;
157+
env.update_stats();
158+
send_program_notification(env, NOTIFICATION_SHINY_POOCH, COLOR_YELLOW, "Shiny Poochyena found", {}, "", env.console.video().snapshot(), true);
159+
}
160+
else {
161+
env.log("Poochyena is not shiny.");
162+
}
163+
context.wait_for_all_requests();
164+
165+
float shiny_coefficient2 = 1.0;
166+
ShinySoundDetector starter_detector(env.console, [&](float error_coefficient) -> bool{
167+
shiny_coefficient2 = error_coefficient;
168+
return true;
169+
});
170+
171+
BattleMenuWatcher battle_menu(COLOR_RED);
172+
int res2 = run_until<SwitchControllerContext>(
173+
env.console, context,
174+
[&](SwitchControllerContext& context) {
175+
env.log("Sending out selected starter.");
176+
pbf_press_button(context, BUTTON_A, 40, 40);
177+
178+
int ret = wait_until(
179+
env.console, context,
180+
std::chrono::seconds(20),
181+
{{battle_menu}}
182+
);
183+
if (ret == 0) {
184+
env.log("Battle menu detecteed!");
185+
}
186+
pbf_wait(context, 125);
187+
context.wait_for_all_requests();
188+
},
189+
{{starter_detector}}
190+
);
191+
starter_detector.throw_if_no_sound();
192+
context.wait_for_all_requests();
193+
if (res2 == 0){
194+
env.log("Shiny starter detected!");
195+
stats.shinystarter++;
196+
env.update_stats();
197+
send_program_notification(env, NOTIFICATION_SHINY_STARTER, COLOR_YELLOW, "Shiny starter found!", {}, "", env.console.video().snapshot(), true);
198+
shiny_starter = true;
199+
}
200+
else {
201+
env.log("Starter is not shiny.");
202+
env.log("Soft resetting.");
203+
send_program_status_notification(
204+
env, NOTIFICATION_STATUS_UPDATE,
205+
"Soft resetting."
206+
);
207+
stats.resets++;
208+
env.update_stats();
209+
soft_reset(env.program_info(), env.console, context);
210+
}
211+
}
212+
213+
//if system set to nintendo switch, have go home when done option?
214+
215+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
216+
}
217+
218+
}
219+
}
220+
}
221+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* RS Starter Reset
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonRSE_AudioStarterReset_H
8+
#define PokemonAutomation_PokemonRSE_AudioStarterReset_H
9+
10+
#include "Common/Cpp/Options/SimpleIntegerOption.h"
11+
#include "Common/Cpp/Options/TimeExpressionOption.h"
12+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
13+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
14+
15+
namespace PokemonAutomation{
16+
namespace NintendoSwitch{
17+
namespace PokemonRSE{
18+
19+
class AudioStarterReset_Descriptor : public SingleSwitchProgramDescriptor{
20+
public:
21+
AudioStarterReset_Descriptor();
22+
struct Stats;
23+
virtual std::unique_ptr<StatsTracker> make_stats() const override;
24+
};
25+
26+
class AudioStarterReset : public SingleSwitchProgramInstance{
27+
public:
28+
AudioStarterReset();
29+
virtual void program(SingleSwitchProgramEnvironment& env, SwitchControllerContext& context) override;
30+
31+
private:
32+
enum class Target{
33+
treecko,
34+
torchic,
35+
mudkip,
36+
};
37+
EnumDropdownOption<Target> TARGET;
38+
39+
EventNotificationOption NOTIFICATION_SHINY_POOCH;
40+
EventNotificationOption NOTIFICATION_SHINY_STARTER;
41+
EventNotificationOption NOTIFICATION_STATUS_UPDATE;
42+
EventNotificationsOption NOTIFICATIONS;
43+
};
44+
45+
}
46+
}
47+
}
48+
#endif
49+
50+
51+

0 commit comments

Comments
 (0)