Skip to content
Open
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
5 changes: 5 additions & 0 deletions SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
//#include "Programs/Glitches/PokemonBDSP_CloneItemsBoxCopy.h"
//#include "Programs/Glitches/PokemonBDSP_CloneItemsMenuOverlap.h"

#include "Programs/RngManipulation/PokemonBDSP_BedroomSeedFinder.h"
#include "Programs/RngManipulation/PokemonBDSP_IntroSeedFinder.h"

#include "Programs/TestPrograms/PokemonBDSP_ShinyEncounterTester.h"
#include "Programs/TestPrograms/PokemonBDSP_SoundListener.h"
#include "Programs/TestPrograms/PokemonBDSP_SummaryReaderTester.h"
Expand Down Expand Up @@ -99,6 +102,8 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{

if (IS_BETA_VERSION || STATIC_GLOBALS.DEVELOPER_MODE){
ret.emplace_back("---- Untested/Beta/WIP ----");
ret.emplace_back(make_single_switch_program<IntroSeedFinder_Descriptor, IntroSeedFinder>());
ret.emplace_back(make_single_switch_program<BedroomSeedFinder_Descriptor, BedroomSeedFinder>());
}
if (STATIC_GLOBALS.DEVELOPER_MODE){
ret.emplace_back("---- Developer Tools ----");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* BDSP Bedroom Seed Finder
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/PrettyPrint.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "Pokemon/Pokemon_Strings.h"
#include "PokemonBDSP/Inference/Rng/PokemonBDSP_BlinkScenes.h"
#include "PokemonBDSP/Inference/Rng/PokemonBDSP_EyeBlinkDetector.h"
#include "PokemonBDSP_BedroomSeedFinder.h"
#include "PokemonBDSP_BlinkRecovery.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{
using namespace Pokemon;



BedroomSeedFinder_Descriptor::BedroomSeedFinder_Descriptor()
: SingleSwitchProgramDescriptor(
"PokemonBDSP:BedroomSeedFinder",
STRING_POKEMON + " BDSP", "Bedroom Seed Finder",
"",
"Recover the RNG seed by watching the player character's blinks in their bedroom.",
ProgramControllerClass::StandardController_NoRestrictions,
FeedbackType::REQUIRED,
AllowCommandsWhenRunning::ENABLE_COMMANDS,
{}
)
{}


BedroomSeedFinder::BedroomSeedFinder()
: GO_HOME_WHEN_DONE(false)
{
PA_ADD_OPTION(PLAYER_MODEL);
PA_ADD_OPTION(COLLECTION_DISPLAY);
PA_ADD_OPTION(STATE_DISPLAY);
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
}


void BedroomSeedFinder::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
STATE_DISPLAY.reset();
COLLECTION_DISPLAY.reset();

std::vector<BdspEyeTemplate> setups = bedroom_eye_templates(PLAYER_MODEL.model_number());
std::vector<ImageRGB32> eyes = load_eye_templates(setups);

std::vector<std::unique_ptr<EyeBlinkWatcher>> watchers;
std::vector<PeriodicInferenceCallback> callbacks;
make_blink_watchers(setups, eyes, watchers, callbacks);

env.log(
"Watching the player blink. The overlay box should be sitting on the player's eye."
);

BlinkRecoveryConfig config;
config.npcs = 1;

BlinkRecovery recovery = recover_state_from_blinks(
env, context, watchers, callbacks, COLLECTION_DISPLAY, config
);
if (!recovery.success){
throw UserSetupError(env.logger(),
"Gave up: " + recovery.failure_reason + ". Check the overlay box is on the "
"player's eye, that the character model above matches the one in game, and that "
"the log shows blinks arriving every few seconds."
);
}

uint64_t seed0 = 0;
uint64_t seed1 = 0;
xorshift128_state_to_seed_pair(recovery.state, seed0, seed1);

env.log("--------");
env.log("State confirmed over " + std::to_string(recovery.events) + " rolls.", COLOR_BLUE);
env.log("State: " + recovery.state.to_string(), COLOR_BLUE);
env.log("PokeFinder seeds: " + tostr_hex_padded(16, seed0)
+ " " + tostr_hex_padded(16, seed1), COLOR_BLUE);

STATE_DISPLAY.set_state(recovery.state, recovery.events);
STATE_DISPLAY.set_confidence_unique();

GO_HOME_WHEN_DONE.run_end_of_program(context);
}




}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* BDSP Bedroom Seed Finder
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonBDSP_BedroomSeedFinder_H
#define PokemonAutomation_PokemonBDSP_BedroomSeedFinder_H

#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
#include "PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.h"
#include "PokemonBDSP_RngDisplays.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{


class BedroomSeedFinder_Descriptor : public SingleSwitchProgramDescriptor{
public:
BedroomSeedFinder_Descriptor();
};


class BedroomSeedFinder : public SingleSwitchProgramInstance{
public:
BedroomSeedFinder();

virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;

private:

PlayerModelOption PLAYER_MODEL;

BlinkCollectionDisplay COLLECTION_DISPLAY;
RngStateDisplay STATE_DISPLAY;

GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
};


}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,7 @@ BlinkRecovery recover_state_from_blinks(
+ std::to_string(config.liveness_timeout.count() / 60) + " minutes";
return ret;
}
try{
subcontext.wait_until(current_time() + config.poll_interval);
}catch (OperationCancelledException&){}
subcontext.throw_if_cancelled_with_exception();
context.throw_if_cancelled();
subcontext.wait_until(current_time() + config.poll_interval);

keep_awake_if_due(context, next_nudge, config.keep_awake_interval);

Expand Down Expand Up @@ -509,13 +505,9 @@ void hold_and_reanchor(
// the press is timed off this anchor, so this is the most valuable check
bool leaving = current_time() >= leave_at;
if (!leaving){
try{
subcontext.wait_until(std::min({
leave_at, next_reanchor, current_time() + config.poll_interval
}));
}catch (OperationCancelledException&){}
subcontext.throw_if_cancelled_with_exception();
context.throw_if_cancelled();
subcontext.wait_until(std::min({
leave_at, next_reanchor, current_time() + config.poll_interval
}));
keep_awake_if_due(context, next_nudge, config.keep_awake_interval);
}

Expand Down
Loading
Loading