Skip to content

Commit 83f4265

Browse files
committed
shiny reset, battle menu+shiny number detect
1 parent c08cf59 commit 83f4265

File tree

8 files changed

+271
-99
lines changed

8 files changed

+271
-99
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,10 +1291,16 @@ file(GLOB MAIN_SOURCES
12911291
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.h
12921292
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.cpp
12931293
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h
1294+
Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.cpp
1295+
Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h
12941296
Source/PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.cpp
12951297
Source/PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h
1298+
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.cpp
1299+
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.h
12961300
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.cpp
12971301
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h
1302+
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.cpp
1303+
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.h
12981304
Source/PokemonRSE/Programs/TestPrograms/PokemonRSE_SoundListener.cpp
12991305
Source/PokemonRSE/Programs/TestPrograms/PokemonRSE_SoundListener.h
13001306
Source/PokemonRSE/PokemonRSE_Navigation.cpp

SerialPrograms/Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.cpp

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,10 @@
44
*
55
*/
66

7-
#include "CommonTools/Images/SolidColorTest.h"
8-
#include "CommonTools/Images/ImageFilter.h"
9-
#include "CommonFramework/ImageTools/ImageBoxes.h"
10-
#include "CommonFramework/ImageTypes/ImageRGB32.h"
11-
#include "CommonFramework/ImageTools/ImageStats.h"
12-
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
7+
#include "CommonFramework/ImageTools/SolidColorTest.h"
138
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
149
#include "PokemonRSE_DialogDetector.h"
1510

16-
#include <iostream>
17-
using std::cout;
18-
using std::endl;
19-
2011
namespace PokemonAutomation{
2112
namespace NintendoSwitch{
2213
namespace PokemonRSE{
@@ -38,11 +29,11 @@ bool DialogDetector::detect(const ImageViewRGB32& screen) const{
3829
}
3930
return false;
4031
}
41-
*/
32+
4233
4334
BattleDialogDetector::BattleDialogDetector(Color color)
44-
: m_left_box(0.158, 0.725, 0.011, 0.176)
45-
, m_right_box(0.827, 0.722, 0.013, 0.178)
35+
: m_left_box(0.155, 0.727, 0.015, 0.168)
36+
, m_right_box(0.837, 0.729, 0.008, 0.161)
4637
{}
4738
void BattleDialogDetector::make_overlays(VideoOverlaySet& items) const{
4839
items.add(COLOR_RED, m_left_box);
@@ -51,15 +42,15 @@ void BattleDialogDetector::make_overlays(VideoOverlaySet& items) const{
5142
bool BattleDialogDetector::detect(const ImageViewRGB32& screen) const{
5243
ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box);
5344
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
54-
if (is_solid(left_image, { 0.335, 0.331, 0.332 }) && is_solid(right_image, { 0.335, 0.331, 0.332 })){
45+
if (is_solid(left_image, { 0.25, 0.38, 0.369 }) && is_solid(right_image, { 0.25, 0.38, 0.369 })){
5546
return true;
5647
}
5748
return false;
5849
}
59-
50+
*/
6051

6152
BattleMenuDetector::BattleMenuDetector(Color color)
62-
: m_left_box(0.439, 0.717, 0.021, 0.192)
53+
: m_left_box(0.155, 0.727, 0.015, 0.168)
6354
, m_right_box(0.821, 0.725, 0.030, 0.181)
6455
{}
6556
void BattleMenuDetector::make_overlays(VideoOverlaySet& items) const{
@@ -76,48 +67,6 @@ bool BattleMenuDetector::detect(const ImageViewRGB32& screen) const{
7667
}
7768

7869

79-
AdvanceBattleDialogDetector::AdvanceBattleDialogDetector(Color color)
80-
: m_dialog_box(0.156, 0.715, 0.686, 0.193)
81-
, m_left_box(0.156, 0.724, 0.010, 0.176)
82-
, m_right_box(0.836, 0.717, 0.008, 0.189)
83-
{}
84-
void AdvanceBattleDialogDetector::make_overlays(VideoOverlaySet& items) const{
85-
items.add(COLOR_RED, m_dialog_box);
86-
items.add(COLOR_RED, m_left_box);
87-
items.add(COLOR_RED, m_right_box);
88-
}
89-
bool AdvanceBattleDialogDetector::detect(const ImageViewRGB32& screen) const{
90-
const bool replace_color_within_range = false;
91-
92-
//Filter out background
93-
ImageRGB32 filtered_region = filter_rgb32_range(
94-
extract_box_reference(screen, m_dialog_box),
95-
combine_rgb(185, 0, 1), combine_rgb(255, 32, 33), Color(0), replace_color_within_range
96-
);
97-
ImageStats stats = image_stats(filtered_region);
98-
99-
/*
100-
filtered_region.save("./filtered_only.png");
101-
cout << stats.average.r << endl;
102-
cout << stats.average.g << endl;
103-
cout << stats.average.b << endl;
104-
*/
105-
106-
ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box);
107-
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
108-
109-
if (is_solid(left_image, { 0.335, 0.331, 0.332 })
110-
&& is_solid(right_image, { 0.335, 0.331, 0.332 })
111-
&& (stats.average.r > stats.average.b + 200)
112-
&& (stats.average.r > stats.average.g + 200)
113-
)
114-
{
115-
return true;
116-
}
117-
return false;
118-
}
119-
120-
12170

12271
}
12372
}

SerialPrograms/Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99

1010
#include <chrono>
1111
#include <atomic>
12+
//#include "CommonFramework/Logging/Logger.h"
1213
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
1314
#include "Common/Cpp/Color.h"
1415
#include "CommonFramework/ImageTools/ImageBoxes.h"
15-
#include "CommonTools/VisualDetector.h"
16-
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
16+
#include "CommonFramework/InferenceInfra/VisualInferenceCallback.h"
17+
#include "CommonFramework/Inference/VisualDetector.h"
1718

1819
namespace PokemonAutomation{
1920
class CancellableScope;
@@ -22,7 +23,7 @@ namespace NintendoSwitch{
2223
namespace PokemonRSE{
2324

2425
/*
25-
// TODO: Detect that a dialog box is on screen by looking for the white of the box
26+
// Detect that a dialog box is on screen by looking for the white of the box
2627
class DialogDetector : public StaticScreenDetector{
2728
public:
2829
DialogDetector(Color color);
@@ -40,7 +41,8 @@ class DialogWatcher : public DetectorToFinder<DialogDetector>{
4041
: DetectorToFinder("DialogWatcher", std::chrono::milliseconds(250), color)
4142
{}
4243
};
43-
*/
44+
45+
4446
4547
// Battle dialog boxes are teal
4648
class BattleDialogDetector : public StaticScreenDetector{
@@ -60,10 +62,10 @@ class BattleDialogWatcher : public DetectorToFinder<BattleDialogDetector>{
6062
: DetectorToFinder("BattleDialogWatcher", std::chrono::milliseconds(250), color)
6163
{}
6264
};
65+
*/
6366

6467

65-
// Battle menu is up when it is white on the right and teal on the left
66-
// For emerald the text is more flush to the left, so we target the right of the battle menu box
68+
// Battle menu is up when it is white on the left and teal on the right
6769
class BattleMenuDetector : public StaticScreenDetector{
6870
public:
6971
BattleMenuDetector(Color color);
@@ -84,30 +86,10 @@ class BattleMenuWatcher : public DetectorToFinder<BattleMenuDetector>{
8486

8587

8688

87-
// Detect the red advancement arrow by filtering for red.
88-
// This works for now, I don't think there's colored text?
89-
// TODO: Change this to detect that the dialog arrow is in the dialog box by filtering for the red arrow
90-
class AdvanceBattleDialogDetector : public StaticScreenDetector{
91-
public:
92-
AdvanceBattleDialogDetector(Color color);
93-
94-
virtual void make_overlays(VideoOverlaySet& items) const override;
95-
virtual bool detect(const ImageViewRGB32& screen) const override;
89+
// advancedialogdetector Detect that the dialog arrow is in the dialog box by filtering for the red arrow
9690

97-
private:
98-
ImageFloatBox m_dialog_box;
99-
ImageFloatBox m_left_box;
100-
ImageFloatBox m_right_box;
101-
};
102-
class AdvanceBattleDialogWatcher : public DetectorToFinder<AdvanceBattleDialogDetector>{
103-
public:
104-
AdvanceBattleDialogWatcher(Color color)
105-
: DetectorToFinder("AdvanceBattleDialogWatcher", std::chrono::milliseconds(250), color)
106-
{}
107-
};
91+
// when given a choice popup, there is no advance arrow
10892

109-
// Future note: when given a choice popup, there is no advance arrow.
110-
// FRLG doesn't have an advance arrow, that's a future issue.
11193

11294

11395
}

SerialPrograms/Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@
66

77
#include "Common/Cpp/Color.h"
88
#include "CommonFramework/ImageTools/ImageBoxes.h"
9-
#include "CommonFramework/ImageTools/ImageStats.h"
9+
#include "CommonFramework/ImageTools/ImageFilter.h"
1010
#include "CommonFramework/ImageTypes/ImageRGB32.h"
11+
#include "CommonFramework/ImageTools/ImageStats.h"
1112
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
1213
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
13-
#include "CommonTools/Images/ImageFilter.h"
1414
#include "PokemonRSE_ShinyNumberDetector.h"
1515

16-
//#include <iostream>
17-
//using std::cout;
18-
//using std::endl;
16+
#include <iostream>
17+
using std::cout;
18+
using std::endl;
1919

2020
namespace PokemonAutomation{
2121
namespace NintendoSwitch{
2222
namespace PokemonRSE{
2323

24-
ShinyNumberDetector::ShinyNumberDetector(Color color)
24+
ShinyNumberDetector::ShinyNumberDetector()
2525
: m_box_number(0.136, 0.156, 0.123, 0.072)
2626
{}
27-
void ShinyNumberDetector::make_overlays(VideoOverlaySet& items) const{
28-
items.add(COLOR_RED, m_box_number);
29-
}
27+
3028
bool ShinyNumberDetector::read(Logger& logger, const ImageViewRGB32& frame){
3129
const bool replace_color_within_range = true;
3230

SerialPrograms/Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ namespace PokemonRSE{
1616

1717
// In the summary screen, the dex number will be yellow if a shiny, white if not.
1818
// Additionally, the background behind the sprite will be white if shiny, grey if not.
19-
// Number is easier to check as the background is scan lines.
19+
// Number is easier to check as background as scan lines.
2020
class ShinyNumberDetector{
2121
public:
22-
ShinyNumberDetector(Color color);
22+
ShinyNumberDetector();
2323

24-
virtual void make_overlays(VideoOverlaySet& items) const;
2524
bool read(Logger& logger, const ImageViewRGB32& frame);
2625

2726
private:

SerialPrograms/Source/PokemonRSE/PokemonRSE_Panels.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "PokemonRSE_Settings.h"
1212

1313
#include "Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h"
14+
#include "Programs/ShinyHunting/PokemonRSE_StarterReset.h"
1415
#include "Programs/TestPrograms/PokemonRSE_SoundListener.h"
1516

1617
namespace PokemonAutomation{
@@ -31,7 +32,8 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
3132

3233
//ret.emplace_back("---- General ----");
3334

34-
//ret.emplace_back("---- Shiny Hunting ----");
35+
ret.emplace_back("---- Shiny Hunting ----");
36+
ret.emplace_back(make_single_switch_program<StarterReset_Descriptor, StarterReset>());
3537

3638

3739
if (PreloadSettings::instance().DEVELOPER_MODE){

0 commit comments

Comments
 (0)