Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ GameSettings::GameSettings()
LockMode::LOCK_WHILE_RUNNING,
"3000 ms"
)
, m_rng_settings("<font size=4><b>RNG Settings:</b></font>")
, HANDLE_ONLINE_LICENSE_CHECK(
"<b>Handle Online License Check:</b><br>"
"Turn this on if your console checks the game's license online when it starts the game: "
Expand All @@ -73,6 +74,12 @@ GameSettings::GameSettings()
LockMode::LOCK_WHILE_RUNNING,
false // default
)
, RUN_RNG_START_CHECKS(
"<b>Run Start Checks:</b><br>"
"Run pre-program validation checks, e.g. that your party has enough free slots.",
LockMode::LOCK_WHILE_RUNNING,
true // default
)
, 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.",
Expand All @@ -98,7 +105,9 @@ GameSettings::GameSettings()
PA_ADD_OPTION(SELECT_BUTTON_MASH0);
PA_ADD_OPTION(ENTER_GAME_WAIT0);
PA_ADD_OPTION(ENTER_GAME_MASH0);
PA_ADD_STATIC(m_rng_settings);
PA_ADD_OPTION(HANDLE_ONLINE_LICENSE_CHECK);
PA_ADD_OPTION(RUN_RNG_START_CHECKS);
PA_ADD_STATIC(m_shiny_audio_settings);
PA_ADD_OPTION(SHINY_SOUND_THRESHOLD);
PA_ADD_OPTION(SHINY_SOUND_LOW_FREQUENCY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ class GameSettings : public BatchOption, private ConfigOption::Listener{
MillisecondsOption SELECT_BUTTON_MASH0;
MillisecondsOption ENTER_GAME_WAIT0;
MillisecondsOption ENTER_GAME_MASH0;

SectionDividerOption m_rng_settings;
BooleanCheckBoxOption HANDLE_ONLINE_LICENSE_CHECK;
BooleanCheckBoxOption RUN_RNG_START_CHECKS;

SectionDividerOption m_shiny_audio_settings;
FloatingPointOption SHINY_SOUND_THRESHOLD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,10 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
/*
* Settings: Text Speed fast
*/
run_precheck(env, context);

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

home_black_border_check(env.console, context);

// prepare database of base stats and gender thresholds
RngStatsDatabase STATS_DATA("PokemonFRLG/BaseStats.json");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "CommonFramework/Options/LabelCellOption.h"
#include "CommonTools/Options/LanguageOCROption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
#include "Pokemon/Options/Pokemon_NameSelectOption.h"
#include "Pokemon/Pokemon_AdvRng.h"
#include "PokemonFRLG_BlindNavigation.h"
#include "PokemonFRLG_RngCalibration.h"
#include "PokemonFRLG_RngProgram.h"
#include "PokemonFRLG_RngStatsDatabase.h"
#include "PokemonFRLG_RngDisplays.h"
#include "PokemonFRLG_RngLoopRoutines.h"
Expand Down Expand Up @@ -56,9 +56,16 @@ class EggRng_Descriptor : public SingleSwitchProgramDescriptor{
virtual std::unique_ptr<StatsTracker> make_stats() const override;
};

class EggRng : public SingleSwitchProgramInstance, public ConfigOption::Listener{
// Calibrates timings to hit an RNG target for a daycare egg.
class EggRng : public RngProgramInstance, public ConfigOption::Listener{
public:
using Descriptor = EggRng_Descriptor;
virtual size_t free_party_slots_needed() const override{
if (STARTING_POINT == EggProgramState::pickup_calibration){
return 2;
}
return 3;
}
~EggRng();
EggRng();
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,10 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
/*
* Settings: Text Speed fast
*/
run_precheck(env, context);

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

home_black_border_check(env.console, context);

RNG_FILTERS.reset();
RNG_CALIBRATION.reset_hits();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include "Common/Cpp/Options/StaticTextOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "CommonTools/Options/LanguageOCROption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
#include "PokemonFRLG_BlindNavigation.h"
#include "PokemonFRLG_RngDisplays.h"
#include "PokemonFRLG_RngProgram.h"
#include "PokemonFRLG_SeedsDatabase.h"

namespace PokemonAutomation{
Expand All @@ -29,9 +29,11 @@ class GiftRng_Descriptor : public SingleSwitchProgramDescriptor{
virtual std::unique_ptr<StatsTracker> make_stats() const override;
};

class GiftRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{
// Calibrates timings to hit an RNG target for a gift Pokemon.
class GiftRng : public RngProgramInstance, private ConfigOption::Listener{
public:
using Descriptor = GiftRng_Descriptor;
virtual size_t free_party_slots_needed() const override{ return 1; }
~GiftRng();
GiftRng();
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,10 @@ void RngHelper::program(SingleSwitchProgramEnvironment& env, ProControllerContex
/*
* Settings: Text Speed fast
*/
run_precheck(env, context);

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

home_black_border_check(env.console, context);

bool shiny_found = false;

static const int64_t FIXED_SEED_OFFSET = -845; // milliseconds, approximate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include "Common/Cpp/Options/StaticTextOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "CommonTools/Options/LanguageOCROption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
#include "PokemonFRLG_BlindNavigation.h"
#include "PokemonFRLG_RngProgram.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -28,9 +28,12 @@ class RngHelper_Descriptor : public SingleSwitchProgramDescriptor{
virtual std::unique_ptr<StatsTracker> make_stats() const override;
};

class RngHelper : public SingleSwitchProgramInstance{
// Soft resets with given timings to hit a target seed and frame.
class RngHelper : public RngProgramInstance{
public:
using Descriptor = RngHelper_Descriptor;
// The manual tool: the user sets the target and the party, so no check.
virtual size_t free_party_slots_needed() const override{ return 0; }
RngHelper();
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override;
virtual void start_program_border_check(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* RNG Program
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <string>
#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "Pokemon/Pokemon_Strings.h"
#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h"
#include "PokemonFRLG_RngProgram.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


namespace{

std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_needed){
if (free_slots_needed == 1){
return std::format(
"Your party is full. Leave a party slot free so the program can check the {} it catches or receives.",
Pokemon::STRING_POKEMON
);
}
return std::format(
"Your party has {} {}. Leave at least {} party slots free for the {} the program catches or receives.",
party_size, Pokemon::STRING_POKEMON, free_slots_needed, Pokemon::STRING_POKEMON
);
}

} // namespace


void RngProgramInstance::check_free_party_slots(
SingleSwitchProgramEnvironment& env,
ProControllerContext& context
){
const size_t free_slots_needed = free_party_slots_needed();
if (free_slots_needed == 0){
return;
}
Logger& logger = env.console.logger();
logger.log("Checking for " + std::to_string(free_slots_needed) + " free party slot(s)...");
try{
open_party_menu_from_overworld(env.console, context);
}catch (OperationFailedException&){
logger.log("Unable to open the party menu. Skipping the free party slot check.", COLOR_RED);
return;
}
context.wait_for_all_requests();
constexpr size_t MAX_PARTY_SIZE = 6;
const size_t party_size = static_cast<size_t>(detect_last_occupied_party_slot(env.console)) + 1;
if (MAX_PARTY_SIZE - party_size < free_slots_needed){
throw UserSetupError(logger, not_enough_free_slots_message(party_size, free_slots_needed));
}
logger.log("Party has enough free slots.");
}

void RngProgramInstance::run_precheck(
SingleSwitchProgramEnvironment& env,
ProControllerContext& context
){
home_black_border_check(env.console, context);
if (!GameSettings::instance().RUN_RNG_START_CHECKS){
env.console.log("Start checks are off in the FRLG Game Settings. Skipping them.");
return;
}
check_free_party_slots(env, context);
}

} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* RNG Program
*
* From: https://github.com/PokemonAutomation/
*
* Base class for the FRLG RNG programs. Each program states what the game
* must look like when it starts, and checks it first thing, so a setup
* mistake stops the run at once instead of failing in a misleading way many
* resets later.
*
*/

#ifndef PokemonAutomation_PokemonFRLG_RngProgram_H
#define PokemonAutomation_PokemonFRLG_RngProgram_H

#include <cstddef>
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


// Base class of the RNG programs.
class RngProgramInstance : public SingleSwitchProgramInstance{
public:
using SingleSwitchProgramInstance::SingleSwitchProgramInstance;

// How many free party slots the program needs: one for each Pokemon it
// catches or receives and then reads from the end of the party. In a full
// party that Pokemon would go to the PC instead.
virtual size_t free_party_slots_needed() const = 0;

protected:
// Call first in program(), with the game on the overworld where the
// player saved: checks the party has the free slots
// free_party_slots_needed() asks for, then goes Home for the black
// border check. Throws UserSetupError if a check fails.
void run_precheck(
SingleSwitchProgramEnvironment& env,
ProControllerContext& context
);

private:
void check_free_party_slots(
SingleSwitchProgramEnvironment& env,
ProControllerContext& context
);
};


} // namespace PokemonFRLG
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,10 @@ void RoamingLegendaryRng::program(SingleSwitchProgramEnvironment& env, ProContro
/*
* Settings: Text Speed fast
*/
run_precheck(env, context);

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

home_black_border_check(env.console, context);

RNG_FILTERS.reset();
RNG_CALIBRATION.reset_hits();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include "Common/Cpp/Options/StaticTextOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "CommonTools/Options/LanguageOCROption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
#include "PokemonFRLG_BlindNavigation.h"
#include "PokemonFRLG_RngDisplays.h"
#include "PokemonFRLG_RngProgram.h"
#include "PokemonFRLG_SeedsDatabase.h"

namespace PokemonAutomation{
Expand All @@ -29,9 +29,11 @@ class RoamingLegendaryRng_Descriptor : public SingleSwitchProgramDescriptor{
virtual std::unique_ptr<StatsTracker> make_stats() const override;
};

class RoamingLegendaryRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{
// Calibrates timings to hit an RNG target for a roaming legendary.
class RoamingLegendaryRng : public RngProgramInstance, private ConfigOption::Listener{
public:
using Descriptor = RoamingLegendaryRng_Descriptor;
virtual size_t free_party_slots_needed() const override{ return 1; }
~RoamingLegendaryRng();
RoamingLegendaryRng();
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,10 @@ void StarterRng::program(SingleSwitchProgramEnvironment& env, ProControllerConte
/*
* Settings: Text Speed fast
*/
run_precheck(env, context);

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

home_black_border_check(env.console, context);

RNG_FILTERS.reset();
RNG_CALIBRATION.reset_hits();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#include "Common/Cpp/Options/StaticTextOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "CommonTools/Options/LanguageOCROption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
#include "Pokemon/Pokemon_StatsCalculation.h"
#include "Pokemon/Pokemon_AdvRng.h"
#include "PokemonFRLG_RngDisplays.h"
#include "PokemonFRLG_RngProgram.h"
#include "PokemonFRLG_SeedsDatabase.h"

namespace PokemonAutomation{
Expand All @@ -30,9 +30,12 @@ class StarterRng_Descriptor : public SingleSwitchProgramDescriptor{
virtual std::unique_ptr<StatsTracker> make_stats() const override;
};

class StarterRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{
// Calibrates timings to hit an RNG target for a starter.
class StarterRng : public RngProgramInstance, private ConfigOption::Listener{
public:
using Descriptor = StarterRng_Descriptor;
// The party is empty before the starter, so there is nothing to check.
virtual size_t free_party_slots_needed() const override{ return 0; }
~StarterRng();
StarterRng();
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ void StaticRng::program(SingleSwitchProgramEnvironment& env, ProControllerContex
/*
* Settings: Text Speed fast
*/
run_precheck(env, context);

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

home_black_border_check(env.console, context);

RNG_FILTERS.reset();
RNG_CALIBRATION.reset_hits();

Expand Down
Loading
Loading