Skip to content

Commit 0b2b030

Browse files
committed
shiny reset, battle menu+shiny number detect
1 parent c62ae24 commit 0b2b030

File tree

8 files changed

+514
-1
lines changed

8 files changed

+514
-1
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
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* Dialog Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "CommonFramework/ImageTools/SolidColorTest.h"
8+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
9+
#include "PokemonRSE_DialogDetector.h"
10+
11+
namespace PokemonAutomation{
12+
namespace NintendoSwitch{
13+
namespace PokemonRSE{
14+
15+
/*
16+
DialogDetector::DialogDetector(Color color)
17+
: m_left_box(0.155, 0.727, 0.015, 0.168)
18+
, m_right_box(0.837, 0.729, 0.008, 0.161)
19+
{}
20+
void DialogDetector::make_overlays(VideoOverlaySet& items) const{
21+
items.add(COLOR_RED, m_left_box);
22+
items.add(COLOR_RED, m_right_box);
23+
}
24+
bool DialogDetector::detect(const ImageViewRGB32& screen) const{
25+
ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box);
26+
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
27+
if (is_solid(left_image, { 0.335, 0.331, 0.332 }) && is_solid(right_image, { 0.335, 0.331, 0.332 })){
28+
return true;
29+
}
30+
return false;
31+
}
32+
33+
34+
BattleDialogDetector::BattleDialogDetector(Color color)
35+
: m_left_box(0.155, 0.727, 0.015, 0.168)
36+
, m_right_box(0.837, 0.729, 0.008, 0.161)
37+
{}
38+
void BattleDialogDetector::make_overlays(VideoOverlaySet& items) const{
39+
items.add(COLOR_RED, m_left_box);
40+
items.add(COLOR_RED, m_right_box);
41+
}
42+
bool BattleDialogDetector::detect(const ImageViewRGB32& screen) const{
43+
ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box);
44+
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
45+
if (is_solid(left_image, { 0.25, 0.38, 0.369 }) && is_solid(right_image, { 0.25, 0.38, 0.369 })){
46+
return true;
47+
}
48+
return false;
49+
}
50+
*/
51+
52+
BattleMenuDetector::BattleMenuDetector(Color color)
53+
: m_left_box(0.155, 0.727, 0.015, 0.168)
54+
, m_right_box(0.821, 0.725, 0.030, 0.181)
55+
{}
56+
void BattleMenuDetector::make_overlays(VideoOverlaySet& items) const{
57+
items.add(COLOR_RED, m_left_box);
58+
items.add(COLOR_RED, m_right_box);
59+
}
60+
bool BattleMenuDetector::detect(const ImageViewRGB32& screen) const{
61+
ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box);
62+
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
63+
if (is_solid(left_image, { 0.335, 0.331, 0.332 }) && is_solid(right_image, { 0.25, 0.38, 0.369 })){
64+
return true;
65+
}
66+
return false;
67+
}
68+
69+
70+
71+
}
72+
}
73+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* Dialog Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonRSE_DialogDetector_H
8+
#define PokemonAutomation_PokemonRSE_DialogDetector_H
9+
10+
#include <chrono>
11+
#include <atomic>
12+
//#include "CommonFramework/Logging/Logger.h"
13+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
14+
#include "Common/Cpp/Color.h"
15+
#include "CommonFramework/ImageTools/ImageBoxes.h"
16+
#include "CommonFramework/InferenceInfra/VisualInferenceCallback.h"
17+
#include "CommonFramework/Inference/VisualDetector.h"
18+
19+
namespace PokemonAutomation{
20+
class CancellableScope;
21+
class VideoFeed;
22+
namespace NintendoSwitch{
23+
namespace PokemonRSE{
24+
25+
/*
26+
// Detect that a dialog box is on screen by looking for the white of the box
27+
class DialogDetector : public StaticScreenDetector{
28+
public:
29+
DialogDetector(Color color);
30+
31+
virtual void make_overlays(VideoOverlaySet& items) const override;
32+
virtual bool detect(const ImageViewRGB32& screen) const override;
33+
34+
private:
35+
ImageFloatBox m_left_box;
36+
ImageFloatBox m_right_box;
37+
};
38+
class DialogWatcher : public DetectorToFinder<DialogDetector>{
39+
public:
40+
DialogWatcher(Color color)
41+
: DetectorToFinder("DialogWatcher", std::chrono::milliseconds(250), color)
42+
{}
43+
};
44+
45+
46+
47+
// Battle dialog boxes are teal
48+
class BattleDialogDetector : public StaticScreenDetector{
49+
public:
50+
BattleDialogDetector(Color color);
51+
52+
virtual void make_overlays(VideoOverlaySet& items) const override;
53+
virtual bool detect(const ImageViewRGB32& screen) const override;
54+
55+
private:
56+
ImageFloatBox m_left_box;
57+
ImageFloatBox m_right_box;
58+
};
59+
class BattleDialogWatcher : public DetectorToFinder<BattleDialogDetector>{
60+
public:
61+
BattleDialogWatcher(Color color)
62+
: DetectorToFinder("BattleDialogWatcher", std::chrono::milliseconds(250), color)
63+
{}
64+
};
65+
*/
66+
67+
68+
// Battle menu is up when it is white on the left and teal on the right
69+
class BattleMenuDetector : public StaticScreenDetector{
70+
public:
71+
BattleMenuDetector(Color color);
72+
73+
virtual void make_overlays(VideoOverlaySet& items) const override;
74+
virtual bool detect(const ImageViewRGB32& screen) const override;
75+
76+
private:
77+
ImageFloatBox m_left_box;
78+
ImageFloatBox m_right_box;
79+
};
80+
class BattleMenuWatcher : public DetectorToFinder<BattleMenuDetector>{
81+
public:
82+
BattleMenuWatcher(Color color)
83+
: DetectorToFinder("BattleMenuWatcher", std::chrono::milliseconds(250), color)
84+
{}
85+
};
86+
87+
88+
89+
// advancedialogdetector Detect that the dialog arrow is in the dialog box by filtering for the red arrow
90+
91+
// when given a choice popup, there is no advance arrow
92+
93+
94+
95+
}
96+
}
97+
}
98+
99+
#endif
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* Shiny Number Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "Common/Cpp/Color.h"
8+
#include "CommonFramework/ImageTools/ImageBoxes.h"
9+
#include "CommonFramework/ImageTools/ImageFilter.h"
10+
#include "CommonFramework/ImageTypes/ImageRGB32.h"
11+
#include "CommonFramework/ImageTools/ImageStats.h"
12+
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
13+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
14+
#include "PokemonRSE_ShinyNumberDetector.h"
15+
16+
#include <iostream>
17+
using std::cout;
18+
using std::endl;
19+
20+
namespace PokemonAutomation{
21+
namespace NintendoSwitch{
22+
namespace PokemonRSE{
23+
24+
ShinyNumberDetector::ShinyNumberDetector()
25+
: m_box_number(0.136, 0.156, 0.123, 0.072)
26+
{}
27+
28+
bool ShinyNumberDetector::read(Logger& logger, const ImageViewRGB32& frame){
29+
const bool replace_color_within_range = true;
30+
31+
//Filter out background
32+
ImageRGB32 filtered_region = filter_rgb32_range(
33+
extract_box_reference(frame, m_box_number),
34+
combine_rgb(138, 97, 221), combine_rgb(200, 181, 239), Color(0), replace_color_within_range
35+
);
36+
ImageStats stats = image_stats(filtered_region);
37+
38+
/*
39+
filtered_region.save("./filtered_only.png");
40+
cout << stats.average.r << endl;
41+
cout << stats.average.g << endl;
42+
cout << stats.average.b << endl;
43+
*/
44+
45+
/*
46+
Shiny:
47+
R: 196.632, G: 196.771, B: 145.863
48+
Not shiny:
49+
R: 181.862, G: 180.686, B: 193.999
50+
*/
51+
52+
if (stats.average.b + 20 < stats.average.r){
53+
return true;
54+
}
55+
return false;
56+
}
57+
58+
59+
}
60+
}
61+
}
62+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* Shiny Number Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonRSE_ShinyNumberDetector_H
8+
#define PokemonAutomation_PokemonRSE_ShinyNumberDetector_H
9+
10+
#include "Common/Cpp/AbstractLogger.h"
11+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
12+
13+
namespace PokemonAutomation{
14+
namespace NintendoSwitch{
15+
namespace PokemonRSE{
16+
17+
// In the summary screen, the dex number will be yellow if a shiny, white if not.
18+
// Additionally, the background behind the sprite will be white if shiny, grey if not.
19+
// Number is easier to check as background as scan lines.
20+
class ShinyNumberDetector{
21+
public:
22+
ShinyNumberDetector();
23+
24+
bool read(Logger& logger, const ImageViewRGB32& frame);
25+
26+
private:
27+
ImageFloatBox m_box_number;
28+
};
29+
30+
31+
32+
}
33+
}
34+
}
35+
#endif

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)