Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,10 @@ file(GLOB MAIN_SOURCES
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.cpp
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.h
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.cpp
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.cpp
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.cpp
Expand All @@ -1385,6 +1389,10 @@ file(GLOB MAIN_SOURCES
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_FossilRevival.h
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.cpp
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.h
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.cpp
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.cpp
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.h
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h
Source/PokemonLGPE/PokemonLGPE_Panels.cpp
Expand Down
8 changes: 8 additions & 0 deletions SerialPrograms/SerialPrograms.pro
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,15 @@ SOURCES += \
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.cpp \
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.cpp \
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.cpp \
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.cpp \
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.cpp \
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp \
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.cpp \
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp \
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_FossilRevival.cpp \
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.cpp \
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.cpp \
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.cpp \
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp \
Source/PokemonLGPE/PokemonLGPE_Panels.cpp \
Source/PokemonLGPE/PokemonLGPE_Settings.cpp \
Expand Down Expand Up @@ -1869,11 +1873,15 @@ HEADERS += \
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.h \
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h \
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.h \
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h \
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h \
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h \
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.h \
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h \
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_FossilRevival.h \
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.h \
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h \
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.h \
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h \
Source/PokemonLGPE/PokemonLGPE_Panels.h \
Source/PokemonLGPE/PokemonLGPE_Settings.h \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Battle Arrow Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "Kernels/Waterfill/Kernels_Waterfill_Session.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonTools/Images/BinaryImage_FilterRgb32.h"
#include "CommonTools/ImageMatch/ExactImageMatcher.h"
#include "PokemonLGPE_BattleArrowDetector.h"

//#include <iostream>
//using std::cout;
//using std::endl;

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLGPE{

const ImageMatch::ExactImageMatcher& BATTLE_ARROW(){
static ImageMatch::ExactImageMatcher matcher(RESOURCE_PATH() + "PokemonLGPE/BattleArrow.png");
return matcher;
}

BattleArrowDetector::BattleArrowDetector(Color color, const ImageFloatBox& box)
: m_color(color)
, m_box(box)
{}
void BattleArrowDetector::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_box);
}
bool BattleArrowDetector::detect(const ImageViewRGB32& screen) const{
using namespace Kernels::Waterfill;

ImageViewRGB32 region = extract_box_reference(screen, m_box);

const ImageMatch::ExactImageMatcher& matcher = BATTLE_ARROW();

auto matrix = compress_rgb32_to_binary_range(region, 0xffc0c0c0, 0xffffffff);
auto session = make_WaterfillSession(matrix);
auto iter = session->make_iterator(100);
WaterfillObject object;

//static int c = 0;
while (iter->find_next(object, false)){
double aspect_ratio = object.aspect_ratio();
if (aspect_ratio < 1.0 || aspect_ratio > 1.3){
continue;
}
ImageViewRGB32 cropped = extract_box_reference(region, object);
//cropped.save("test-object-" + std::to_string(c++) + ".png");
double rmsd = matcher.rmsd(cropped);
//cout << rmsd << endl;
if (rmsd < 110){
return true;
}
}

return false;
}



}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Battle Arrow Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonLGPE_BattleArrowDetector_H
#define PokemonAutomation_PokemonLGPE_BattleArrowDetector_H

#include <chrono>
#include <atomic>
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "Common/Cpp/Color.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonTools/VisualDetector.h"
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLGPE{

class BattleArrowDetector : public StaticScreenDetector{
public:
/*
|Fight|Pokemon|Bag|Run| for wild battle
|---|Fight|Pokemon|Bag| for trainer battle
(align right)
Don't know what changes for a double battle.
*/
//Arrow bounces back and forth.
BattleArrowDetector(Color color, const ImageFloatBox& box);

virtual void make_overlays(VideoOverlaySet& items) const override;
virtual bool detect(const ImageViewRGB32& screen) const override;

protected:
Color m_color;
ImageFloatBox m_box;
};
class BattleArrowWatcher : public DetectorToFinder<BattleArrowDetector>{
public:
BattleArrowWatcher(Color color = COLOR_RED, ImageFloatBox box = {0.546, 0.863, 0.045, 0.068})
: DetectorToFinder("BattleArrowWatcher", std::chrono::milliseconds(100), color, box)
{}
};



}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Shiny Sound Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonTools/Audio/AudioTemplateCache.h"
#include "CommonTools/Audio/SpectrogramMatcher.h"
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
#include "PokemonLGPE/PokemonLGPE_Settings.h"
#include "PokemonLGPE_ShinySoundDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLGPE{


ShinySoundDetector::ShinySoundDetector(Logger& logger, DetectedCallback detected_callback)
// Use a yellow as the detection color because the shiny animation is yellow.
: AudioPerSpectrumDetectorBase(
logger,
"ShinySoundDetector",
"Shiny sound",
COLOR_YELLOW,
detected_callback
)
{}


float ShinySoundDetector::get_score_threshold() const{
return (float)GameSettings::instance().SHINY_SOUND_THRESHOLD;
}

std::unique_ptr<SpectrogramMatcher> ShinySoundDetector::build_spectrogram_matcher(size_t sample_rate){
return std::make_unique<SpectrogramMatcher>(
"Shiny Sound",
AudioTemplateCache::instance().get_throw("PokemonLGPE/ShinySound", sample_rate),
SpectrogramMatcher::Mode::SPIKE_CONV, sample_rate,
GameSettings::instance().SHINY_SOUND_LOW_FREQUENCY
);
}



}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Shiny Sound Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonLGPE_ShinySoundDetector_H
#define PokemonAutomation_PokemonLGPE_ShinySoundDetector_H

#include "CommonTools/Audio/AudioPerSpectrumDetectorBase.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLGPE{


class ShinySoundDetector : public AudioPerSpectrumDetectorBase{
public:
// Warning: The callback will be called from the audio inference thread.
ShinySoundDetector(Logger& logger, DetectedCallback detected_callback);

// Implement AudioPerSpectrumDetectorBase::get_score_threshold()
virtual float get_score_threshold() const override;

protected:
// Implement AudioPerSpectrumDetectorBase::build_spectrogram_matcher()
virtual std::unique_ptr<SpectrogramMatcher> build_spectrogram_matcher(size_t sample_rate) override;
};




}
}
}
#endif
11 changes: 11 additions & 0 deletions SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h"
#include "Programs/ShinyHunting/PokemonLGPE_FossilRevival.h"
#include "Programs/ShinyHunting/PokemonLGPE_GiftReset.h"
#include "Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h"

#include "Programs/TestPrograms/PokemonLGPE_SoundListener.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -35,6 +38,14 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
ret.emplace_back(make_single_switch_program<AlolanTrade_Descriptor, AlolanTrade>());
ret.emplace_back(make_single_switch_program<FossilRevival_Descriptor, FossilRevival>());
ret.emplace_back(make_single_switch_program<GiftReset_Descriptor, GiftReset>());
if (IS_BETA_VERSION || PreloadSettings::instance().DEVELOPER_MODE) {
ret.emplace_back(make_single_switch_program<LegendaryReset_Descriptor, LegendaryReset>());
}

if (PreloadSettings::instance().DEVELOPER_MODE){
ret.emplace_back("---- Developer Tools ----");
ret.emplace_back(make_single_switch_program<SoundListener_Descriptor, SoundListener>());
}

return ret;
}
Expand Down
15 changes: 15 additions & 0 deletions SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ GameSettings::GameSettings()
LockMode::LOCK_WHILE_RUNNING,
"15 s"
)
, m_shiny_audio_settings("<font size=4><b>Shiny Audio Settings:</b></font>")
, SHINY_SOUND_THRESHOLD(
"<b>Shiny Sound Threshold:</b><br>Maximum error coefficient to trigger a shiny detection.",
LockMode::LOCK_WHILE_RUNNING,
0.95, 0, 1.0
)
, SHINY_SOUND_LOW_FREQUENCY(
"<b>Shiny Sound Low Frequency (Hz):</b><br>High pass filter frequency for shiny sound.",
LockMode::LOCK_WHILE_RUNNING,
1000, 0, 48000
)
{
PA_ADD_STATIC(m_general);

Expand All @@ -59,6 +70,10 @@ GameSettings::GameSettings()
PA_ADD_OPTION(START_GAME_WAIT1);
PA_ADD_OPTION(ENTER_GAME_MASH0);
PA_ADD_OPTION(ENTER_GAME_WAIT0);

PA_ADD_STATIC(m_shiny_audio_settings);
PA_ADD_OPTION(SHINY_SOUND_THRESHOLD);
PA_ADD_OPTION(SHINY_SOUND_LOW_FREQUENCY);
}


Expand Down
4 changes: 4 additions & 0 deletions SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class GameSettings : public BatchOption{
MillisecondsOption START_GAME_WAIT1;
MillisecondsOption ENTER_GAME_MASH0;
MillisecondsOption ENTER_GAME_WAIT0;

SectionDividerOption m_shiny_audio_settings;
FloatingPointOption SHINY_SOUND_THRESHOLD;
FloatingPointOption SHINY_SOUND_LOW_FREQUENCY;
};


Expand Down
Loading