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/Source/CommonTools/OCR/OCR_Routines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ const std::vector<TextColorRange>& BLUE_TEXT_FILTERS(){
};
return filters;
}
const std::vector<TextColorRange>& LIME_TEXT_FILTERS(){
static std::vector<TextColorRange> filters{
{0xff6FA60D, 0xffBEEF36},
{0xff5E9400, 0xffC9F95C},
{0xff4D8100, 0xffD3FB7E},
};
return filters;
}



Expand Down
1 change: 1 addition & 0 deletions SerialPrograms/Source/CommonTools/OCR/OCR_Routines.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const std::vector<TextColorRange>& BLACK_TEXT_FILTERS();
const std::vector<TextColorRange>& WHITE_TEXT_FILTERS();
const std::vector<TextColorRange>& BLACK_OR_WHITE_TEXT_FILTERS();
const std::vector<TextColorRange>& BLUE_TEXT_FILTERS();
const std::vector<TextColorRange>& LIME_TEXT_FILTERS();



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* IV Judge Reader
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "PokemonLZA_IvJudgeReader.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{


const IvJudgeReader& IV_READER(){
const static Pokemon::IvJudgeReader reader("PokemonLZA/IVCheckerOCR.json");
return reader;
}




IvJudgeReaderScope::IvJudgeReaderScope(VideoOverlay& overlay, Language language)
: m_language(language)
, m_box0(overlay, {0.765000, 0.255000, 0.085000, 0.045000})
, m_box1(overlay, {0.850000, 0.335000, 0.085000, 0.045000})
, m_box2(overlay, {0.855000, 0.435000, 0.085000, 0.045000})
, m_box3(overlay, {0.675000, 0.335000, 0.085000, 0.045000})
, m_box4(overlay, {0.675000, 0.435000, 0.085000, 0.045000})
, m_box5(overlay, {0.765000, 0.510000, 0.085000, 0.045000})
{}




IvJudgeValue IvJudgeReaderScope::read(Logger& logger, const ImageViewRGB32& frame, const OverlayBoxScope& box){
ImageViewRGB32 image = extract_box_reference(frame, box);
OCR::StringMatchResult result = IV_READER().read_substring(
logger, m_language, image,
OCR::LIME_TEXT_FILTERS()
);
result.clear_beyond_log10p(IvJudgeReader::MAX_LOG10P);
if (result.results.size() != 1){
return IvJudgeValue::UnableToDetect;
}
return IV_JUDGE_VALUE_STRINGS().get_enum(result.results.begin()->second.token);
}
IvJudgeReader::Results IvJudgeReaderScope::read(Logger& logger, const ImageViewRGB32& frame){
IvJudgeReader::Results results;
if (m_language != Language::None){
results.hp = read(logger, frame, m_box0);
results.attack = read(logger, frame, m_box1);
results.defense = read(logger, frame, m_box2);
results.spatk = read(logger, frame, m_box3);
results.spdef = read(logger, frame, m_box4);
results.speed = read(logger, frame, m_box5);
}
return results;
}

std::vector<ImageViewRGB32> IvJudgeReaderScope::dump_images(const ImageViewRGB32& frame){
std::vector<ImageViewRGB32> images;
images.emplace_back(extract_box_reference(frame, m_box0));
images.emplace_back(extract_box_reference(frame, m_box1));
images.emplace_back(extract_box_reference(frame, m_box2));
images.emplace_back(extract_box_reference(frame, m_box3));
images.emplace_back(extract_box_reference(frame, m_box4));
images.emplace_back(extract_box_reference(frame, m_box5));
return images;
}



}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* IV Judge Reader
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonLZA_IvJudgeReader_H
#define PokemonAutomation_PokemonLZA_IvJudgeReader_H

#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "Pokemon/Inference/Pokemon_IvJudgeReader.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{
using namespace Pokemon;


const IvJudgeReader& IV_READER();


class IvJudgeReaderScope{
public:
IvJudgeReaderScope(VideoOverlay& overlay, Language language);

IvJudgeReader::Results read(Logger& logger, const ImageViewRGB32& frame);

std::vector<ImageViewRGB32> dump_images(const ImageViewRGB32& frame);

private:
IvJudgeValue read(Logger& logger, const ImageViewRGB32& frame, const OverlayBoxScope& box);

private:
Language m_language;
OverlayBoxScope m_box0;
OverlayBoxScope m_box1;
OverlayBoxScope m_box2;
OverlayBoxScope m_box3;
OverlayBoxScope m_box4;
OverlayBoxScope m_box5;
};



}
}
}
#endif
8 changes: 7 additions & 1 deletion SerialPrograms/Source/PokemonLZA/PokemonLZA_Panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include "Programs/ShinyHunting/PokemonLZA_AutoFossil.h"
#include "Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.h"

// Non-Shiny Hunting
#include "Programs/NonShinyHunting/PokemonLZA_StatsReset.h"

// Developer
#include "Programs/TestPrograms/PokemonLZA_OverworldWatcher.h"
#include "Programs/TestPrograms/PokemonLZA_MoveBoxArrow.h"
Expand Down Expand Up @@ -73,11 +76,14 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
if (IS_BETA_VERSION){
ret.emplace_back(make_single_switch_program<AutoFossil_Descriptor, AutoFossil>());
}

if (PreloadSettings::instance().DEVELOPER_MODE){
ret.emplace_back(make_single_switch_program<BeldumHunter_Descriptor, BeldumHunter>());
}

if (IS_BETA_VERSION){
ret.emplace_back("---- Non-Shiny Hunting ----");
ret.emplace_back(make_single_switch_program<StatsReset_Descriptor, StatsReset>());
}

if (PreloadSettings::instance().DEVELOPER_MODE){
ret.emplace_back("---- Developer Tools ----");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/* Stats Reset
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/ProgramStats/StatsTracking.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
#include "CommonTools/Async/InferenceRoutines.h"
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
#include "Pokemon/Pokemon_Strings.h"
#include "PokemonLZA/Inference/Boxes/PokemonLZA_IvJudgeReader.h"
#include "PokemonLZA_StatsReset.h"
#include "PokemonLZA/Programs/PokemonLZA_GameEntry.h"
#include "PokemonLZA/Programs/PokemonLZA_MenuNavigation.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{


StatsReset_Descriptor::StatsReset_Descriptor()
: SingleSwitchProgramDescriptor(
"PokemonLZA:StatsReset",
STRING_POKEMON + " LZA", "Stats Reset",
"Programs/PokemonLZA/StatsReset.html",
"Repeatedly receive gift " + STRING_POKEMON + " until you get the stats you want.",
ProgramControllerClass::StandardController_NoRestrictions,
FeedbackType::REQUIRED,
AllowCommandsWhenRunning::DISABLE_COMMANDS
)
{}
struct StatsReset_Descriptor::Stats : public StatsTracker{
Stats()
: attempts(m_stats["Attempts"])
, errors(m_stats["Errors"])
, matches(m_stats["Matches"])
{
m_display_order.emplace_back(Stat("Attempts"));
m_display_order.emplace_back(Stat("Errors"));
m_display_order.emplace_back(Stat("Matches"));
}

std::atomic<uint64_t>& attempts;
std::atomic<uint64_t>& errors;
std::atomic<uint64_t>& matches;
};
std::unique_ptr<StatsTracker> StatsReset_Descriptor::make_stats() const{
return std::unique_ptr<StatsTracker>(new Stats());
}



StatsReset::StatsReset()
: GO_HOME_WHEN_DONE(true)
, LANGUAGE(
"<b>Game Language:</b>",
IV_READER().languages(),
LockMode::LOCK_WHILE_RUNNING
)
, POKEMON(
"<b>Gift " + STRING_POKEMON + ":</b>",
{
{GiftPokemon::FLOETTE, "floette", "Floette"},
},
LockMode::LOCK_WHILE_RUNNING,
GiftPokemon::FLOETTE
)
, HP("<b>HP:</b>")
, ATTACK("<b>Attack:</b>", IvJudgeFilter::NoGood)
, DEFENSE("<b>Defense:</b>")
, SPATK("<b>Sp. Atk:</b>")
, SPDEF("<b>Sp. Def:</b>")
, SPEED("<b>Speed:</b>")
, NOTIFICATION_PROGRAM_FINISH("Program Finished", true, true, ImageAttachmentMode::JPG)
, NOTIFICATIONS({
&NOTIFICATION_PROGRAM_FINISH,
&NOTIFICATION_ERROR_FATAL,
})
{
PA_ADD_OPTION(GO_HOME_WHEN_DONE);

PA_ADD_OPTION(LANGUAGE);
PA_ADD_OPTION(POKEMON);
PA_ADD_OPTION(HP);
PA_ADD_OPTION(ATTACK);
PA_ADD_OPTION(DEFENSE);
PA_ADD_OPTION(SPATK);
PA_ADD_OPTION(SPDEF);
PA_ADD_OPTION(SPEED);

PA_ADD_OPTION(NOTIFICATIONS);
}



void StatsReset::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){

StatsReset_Descriptor::Stats& stats = env.current_stats<StatsReset_Descriptor::Stats>();

VideoSnapshot screen;
while (true){
env.update_stats();
context.wait_for_all_requests();

overworld_to_main_menu(env.console, context);
pbf_press_button(context, BUTTON_PLUS, 500ms, 500ms);
pbf_move_right_joystick(context, 128, 0, 500ms, 500ms);
pbf_move_right_joystick(context, 128, 0, 500ms, 500ms);
pbf_move_left_joystick(context, 50, 128, 100ms, 500ms);
pbf_mash_button(context, BUTTON_A, 5000ms);

pbf_move_left_joystick(context, 128, 0, 10s, 500ms);
pbf_mash_button(context, BUTTON_A, 30s);

context.wait_for_all_requests();
{
BlackScreenOverWatcher detector;
int result = run_until<ProControllerContext>(
env.console, context,
[this](ProControllerContext& context){
if (POKEMON == GiftPokemon::FLOETTE){
pbf_mash_button(context, BUTTON_A, 60s);
}else{
pbf_mash_button(context, BUTTON_A, 30s);
}
},
{{detector}}
);
if (result == 0){
env.log(STRING_POKEMON + " dialog finished.", COLOR_PURPLE);
}else{
env.log(STRING_POKEMON + " dialog timed out.", COLOR_RED);
}
}

overworld_to_box_system(env.console, context);
pbf_press_button(context, BUTTON_RCLICK, 500ms, 500ms);
stats.attempts++;
context.wait_for_all_requests();

{
IvJudgeReaderScope reader(env.console, LANGUAGE);
screen = env.console.video().snapshot();
IvJudgeReader::Results results = reader.read(env.console, screen);
bool ok = true;
ok &= HP.matches(stats.errors, results.hp);
ok &= ATTACK.matches(stats.errors, results.attack);
ok &= DEFENSE.matches(stats.errors, results.defense);
ok &= SPATK.matches(stats.errors, results.spatk);
ok &= SPDEF.matches(stats.errors, results.spdef);
ok &= SPEED.matches(stats.errors, results.speed);
if (ok){
break;
}
}

pbf_mash_button(context, BUTTON_B, 3s);
go_home(env.console, context);
reset_game_from_home(env, env.console, context, true);
}

stats.matches++;
env.update_stats();
env.log("Result Found!", COLOR_BLUE);

pbf_wait(context, 5000ms);
pbf_press_button(context, BUTTON_CAPTURE, 2000ms, 5000ms);

send_program_finished_notification(
env, NOTIFICATION_PROGRAM_FINISH,
"Found a match!",
screen, false
);
GO_HOME_WHEN_DONE.run_end_of_program(context);
}


}
}
}

Loading