Skip to content

Commit 66f5bb7

Browse files
authored
Merge pull request #583 from kichithewolf/LGPE-snorlax
LGPE Snorlax
2 parents 9c077d9 + 0e059f2 commit 66f5bb7

13 files changed

+703
-0
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,10 @@ file(GLOB MAIN_SOURCES
13751375
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h
13761376
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.cpp
13771377
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.h
1378+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.cpp
1379+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h
1380+
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.cpp
1381+
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h
13781382
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp
13791383
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h
13801384
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.cpp
@@ -1385,6 +1389,10 @@ file(GLOB MAIN_SOURCES
13851389
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_FossilRevival.h
13861390
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.cpp
13871391
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.h
1392+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.cpp
1393+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h
1394+
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.cpp
1395+
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.h
13881396
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp
13891397
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h
13901398
Source/PokemonLGPE/PokemonLGPE_Panels.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,15 @@ SOURCES += \
674674
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.cpp \
675675
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.cpp \
676676
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.cpp \
677+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.cpp \
678+
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.cpp \
677679
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp \
678680
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.cpp \
679681
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp \
680682
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_FossilRevival.cpp \
681683
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.cpp \
684+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.cpp \
685+
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.cpp \
682686
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp \
683687
Source/PokemonLGPE/PokemonLGPE_Panels.cpp \
684688
Source/PokemonLGPE/PokemonLGPE_Settings.cpp \
@@ -1869,11 +1873,15 @@ HEADERS += \
18691873
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.h \
18701874
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h \
18711875
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.h \
1876+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h \
1877+
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h \
18721878
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h \
18731879
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.h \
18741880
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h \
18751881
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_FossilRevival.h \
18761882
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.h \
1883+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h \
1884+
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.h \
18771885
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h \
18781886
Source/PokemonLGPE/PokemonLGPE_Panels.h \
18791887
Source/PokemonLGPE/PokemonLGPE_Settings.h \
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* Battle Arrow Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
8+
#include "Kernels/Waterfill/Kernels_Waterfill_Session.h"
9+
#include "CommonFramework/Globals.h"
10+
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
11+
#include "CommonTools/Images/BinaryImage_FilterRgb32.h"
12+
#include "CommonTools/ImageMatch/ExactImageMatcher.h"
13+
#include "PokemonLGPE_BattleArrowDetector.h"
14+
15+
//#include <iostream>
16+
//using std::cout;
17+
//using std::endl;
18+
19+
namespace PokemonAutomation{
20+
namespace NintendoSwitch{
21+
namespace PokemonLGPE{
22+
23+
const ImageMatch::ExactImageMatcher& BATTLE_ARROW(){
24+
static ImageMatch::ExactImageMatcher matcher(RESOURCE_PATH() + "PokemonLGPE/BattleArrow.png");
25+
return matcher;
26+
}
27+
28+
BattleArrowDetector::BattleArrowDetector(Color color, const ImageFloatBox& box)
29+
: m_color(color)
30+
, m_box(box)
31+
{}
32+
void BattleArrowDetector::make_overlays(VideoOverlaySet& items) const{
33+
items.add(m_color, m_box);
34+
}
35+
bool BattleArrowDetector::detect(const ImageViewRGB32& screen) const{
36+
using namespace Kernels::Waterfill;
37+
38+
ImageViewRGB32 region = extract_box_reference(screen, m_box);
39+
40+
const ImageMatch::ExactImageMatcher& matcher = BATTLE_ARROW();
41+
42+
auto matrix = compress_rgb32_to_binary_range(region, 0xffc0c0c0, 0xffffffff);
43+
auto session = make_WaterfillSession(matrix);
44+
auto iter = session->make_iterator(100);
45+
WaterfillObject object;
46+
47+
//static int c = 0;
48+
while (iter->find_next(object, false)){
49+
double aspect_ratio = object.aspect_ratio();
50+
if (aspect_ratio < 1.0 || aspect_ratio > 1.3){
51+
continue;
52+
}
53+
ImageViewRGB32 cropped = extract_box_reference(region, object);
54+
//cropped.save("test-object-" + std::to_string(c++) + ".png");
55+
double rmsd = matcher.rmsd(cropped);
56+
//cout << rmsd << endl;
57+
if (rmsd < 110){
58+
return true;
59+
}
60+
}
61+
62+
return false;
63+
}
64+
65+
66+
67+
}
68+
}
69+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Battle Arrow Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLGPE_BattleArrowDetector_H
8+
#define PokemonAutomation_PokemonLGPE_BattleArrowDetector_H
9+
10+
#include <chrono>
11+
#include <atomic>
12+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
13+
#include "Common/Cpp/Color.h"
14+
#include "CommonFramework/ImageTools/ImageBoxes.h"
15+
#include "CommonTools/VisualDetector.h"
16+
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
17+
18+
namespace PokemonAutomation{
19+
namespace NintendoSwitch{
20+
namespace PokemonLGPE{
21+
22+
class BattleArrowDetector : public StaticScreenDetector{
23+
public:
24+
/*
25+
|Fight|Pokemon|Bag|Run| for wild battle
26+
|---|Fight|Pokemon|Bag| for trainer battle
27+
(align right)
28+
Don't know what changes for a double battle.
29+
*/
30+
//Arrow bounces back and forth.
31+
BattleArrowDetector(Color color, const ImageFloatBox& box);
32+
33+
virtual void make_overlays(VideoOverlaySet& items) const override;
34+
virtual bool detect(const ImageViewRGB32& screen) const override;
35+
36+
protected:
37+
Color m_color;
38+
ImageFloatBox m_box;
39+
};
40+
class BattleArrowWatcher : public DetectorToFinder<BattleArrowDetector>{
41+
public:
42+
BattleArrowWatcher(Color color = COLOR_RED, ImageFloatBox box = {0.546, 0.863, 0.045, 0.068})
43+
: DetectorToFinder("BattleArrowWatcher", std::chrono::milliseconds(100), color, box)
44+
{}
45+
};
46+
47+
48+
49+
}
50+
}
51+
}
52+
53+
#endif
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* Shiny Sound Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonTools/Audio/AudioTemplateCache.h"
8+
#include "CommonTools/Audio/SpectrogramMatcher.h"
9+
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
10+
#include "PokemonLGPE/PokemonLGPE_Settings.h"
11+
#include "PokemonLGPE_ShinySoundDetector.h"
12+
13+
namespace PokemonAutomation{
14+
namespace NintendoSwitch{
15+
namespace PokemonLGPE{
16+
17+
18+
ShinySoundDetector::ShinySoundDetector(Logger& logger, DetectedCallback detected_callback)
19+
// Use a yellow as the detection color because the shiny animation is yellow.
20+
: AudioPerSpectrumDetectorBase(
21+
logger,
22+
"ShinySoundDetector",
23+
"Shiny sound",
24+
COLOR_YELLOW,
25+
detected_callback
26+
)
27+
{}
28+
29+
30+
float ShinySoundDetector::get_score_threshold() const{
31+
return (float)GameSettings::instance().SHINY_SOUND_THRESHOLD;
32+
}
33+
34+
std::unique_ptr<SpectrogramMatcher> ShinySoundDetector::build_spectrogram_matcher(size_t sample_rate){
35+
return std::make_unique<SpectrogramMatcher>(
36+
"Shiny Sound",
37+
AudioTemplateCache::instance().get_throw("PokemonLGPE/ShinySound", sample_rate),
38+
SpectrogramMatcher::Mode::SPIKE_CONV, sample_rate,
39+
GameSettings::instance().SHINY_SOUND_LOW_FREQUENCY
40+
);
41+
}
42+
43+
44+
45+
}
46+
}
47+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* Shiny Sound Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLGPE_ShinySoundDetector_H
8+
#define PokemonAutomation_PokemonLGPE_ShinySoundDetector_H
9+
10+
#include "CommonTools/Audio/AudioPerSpectrumDetectorBase.h"
11+
12+
namespace PokemonAutomation{
13+
namespace NintendoSwitch{
14+
namespace PokemonLGPE{
15+
16+
17+
class ShinySoundDetector : public AudioPerSpectrumDetectorBase{
18+
public:
19+
// Warning: The callback will be called from the audio inference thread.
20+
ShinySoundDetector(Logger& logger, DetectedCallback detected_callback);
21+
22+
// Implement AudioPerSpectrumDetectorBase::get_score_threshold()
23+
virtual float get_score_threshold() const override;
24+
25+
protected:
26+
// Implement AudioPerSpectrumDetectorBase::build_spectrogram_matcher()
27+
virtual std::unique_ptr<SpectrogramMatcher> build_spectrogram_matcher(size_t sample_rate) override;
28+
};
29+
30+
31+
32+
33+
}
34+
}
35+
}
36+
#endif

SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Panels.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include "Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h"
1414
#include "Programs/ShinyHunting/PokemonLGPE_FossilRevival.h"
1515
#include "Programs/ShinyHunting/PokemonLGPE_GiftReset.h"
16+
#include "Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h"
17+
18+
#include "Programs/TestPrograms/PokemonLGPE_SoundListener.h"
1619

1720
namespace PokemonAutomation{
1821
namespace NintendoSwitch{
@@ -35,6 +38,14 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
3538
ret.emplace_back(make_single_switch_program<AlolanTrade_Descriptor, AlolanTrade>());
3639
ret.emplace_back(make_single_switch_program<FossilRevival_Descriptor, FossilRevival>());
3740
ret.emplace_back(make_single_switch_program<GiftReset_Descriptor, GiftReset>());
41+
if (IS_BETA_VERSION || PreloadSettings::instance().DEVELOPER_MODE) {
42+
ret.emplace_back(make_single_switch_program<LegendaryReset_Descriptor, LegendaryReset>());
43+
}
44+
45+
if (PreloadSettings::instance().DEVELOPER_MODE){
46+
ret.emplace_back("---- Developer Tools ----");
47+
ret.emplace_back(make_single_switch_program<SoundListener_Descriptor, SoundListener>());
48+
}
3849

3950
return ret;
4051
}

SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Settings.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ GameSettings::GameSettings()
4848
LockMode::LOCK_WHILE_RUNNING,
4949
"15 s"
5050
)
51+
, m_shiny_audio_settings("<font size=4><b>Shiny Audio Settings:</b></font>")
52+
, SHINY_SOUND_THRESHOLD(
53+
"<b>Shiny Sound Threshold:</b><br>Maximum error coefficient to trigger a shiny detection.",
54+
LockMode::LOCK_WHILE_RUNNING,
55+
0.95, 0, 1.0
56+
)
57+
, SHINY_SOUND_LOW_FREQUENCY(
58+
"<b>Shiny Sound Low Frequency (Hz):</b><br>High pass filter frequency for shiny sound.",
59+
LockMode::LOCK_WHILE_RUNNING,
60+
1000, 0, 48000
61+
)
5162
{
5263
PA_ADD_STATIC(m_general);
5364

@@ -59,6 +70,10 @@ GameSettings::GameSettings()
5970
PA_ADD_OPTION(START_GAME_WAIT1);
6071
PA_ADD_OPTION(ENTER_GAME_MASH0);
6172
PA_ADD_OPTION(ENTER_GAME_WAIT0);
73+
74+
PA_ADD_STATIC(m_shiny_audio_settings);
75+
PA_ADD_OPTION(SHINY_SOUND_THRESHOLD);
76+
PA_ADD_OPTION(SHINY_SOUND_LOW_FREQUENCY);
6277
}
6378

6479

SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class GameSettings : public BatchOption{
3232
MillisecondsOption START_GAME_WAIT1;
3333
MillisecondsOption ENTER_GAME_MASH0;
3434
MillisecondsOption ENTER_GAME_WAIT0;
35+
36+
SectionDividerOption m_shiny_audio_settings;
37+
FloatingPointOption SHINY_SOUND_THRESHOLD;
38+
FloatingPointOption SHINY_SOUND_LOW_FREQUENCY;
3539
};
3640

3741

0 commit comments

Comments
 (0)