Skip to content

Commit dbc3164

Browse files
committed
Fix RNG programs for SBB.
1 parent 172539e commit dbc3164

File tree

5 files changed

+39
-23
lines changed

5 files changed

+39
-23
lines changed

SerialPrograms/Source/PokemonSwSh/Programs/RNG/PokemonSwSh_BasicRNG.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,25 @@ void do_rng_advances(
148148
VideoStream& stream, ProControllerContext& context,
149149
Xoroshiro128Plus& rng,
150150
size_t advances,
151-
uint16_t press_duration,
152-
uint16_t release_duration
151+
Milliseconds press_duration,
152+
Milliseconds release_duration
153153
){
154+
Milliseconds tv = context->timing_variation();
154155
for (size_t i = 0; i < advances; i++){
155156
if ((i + 1) % 10 == 0){
156157
std::string text = std::to_string(i + 1) + "/" + std::to_string(advances);
157158
stream.log("RNG advance: " + text);
158159
stream.overlay().add_log("Advancing: " + text, COLOR_GREEN);
159160
}
160-
pbf_press_button(context, BUTTON_RCLICK, press_duration, release_duration);
161+
pbf_press_button(
162+
context,
163+
BUTTON_RCLICK,
164+
press_duration + tv,
165+
release_duration + tv
166+
);
161167
rng.next();
162168
}
163-
pbf_wait(context, 1 * TICKS_PER_SECOND);
169+
pbf_wait(context, 1000ms);
164170
}
165171

166172

SerialPrograms/Source/PokemonSwSh/Programs/RNG/PokemonSwSh_BasicRNG.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ void do_rng_advances(
3737
VideoStream& stream, ProControllerContext& context,
3838
Xoroshiro128Plus& rng,
3939
size_t advances,
40-
uint16_t press_duration = 10,
41-
uint16_t release_duration = 10
40+
Milliseconds press_duration,
41+
Milliseconds release_duration
4242
);
4343

4444

SerialPrograms/Source/PokemonSwSh/Programs/RNG/PokemonSwSh_CramomaticRNG.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "CommonTools/Images/SolidColorTest.h"
2121
#include "CommonTools/Async/InferenceRoutines.h"
2222
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
23+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
2324
#include "NintendoSwitch/NintendoSwitch_Settings.h"
2425
#include "Pokemon/Pokemon_Strings.h"
2526
#include "Pokemon/Inference/Pokemon_PokeballNameReader.h"
@@ -48,7 +49,8 @@ CramomaticRNG_Descriptor::CramomaticRNG_Descriptor()
4849
"Perform RNG manipulation to get rare balls from the Cram-o-matic.",
4950
FeedbackType::REQUIRED,
5051
AllowCommandsWhenRunning::DISABLE_COMMANDS,
51-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
52+
{ControllerFeature::NintendoSwitch_ProController},
53+
FasterIfTickPrecise::MUCH_FASTER
5254
)
5355
{}
5456

@@ -133,12 +135,12 @@ CramomaticRNG::CramomaticRNG()
133135
, ADVANCE_PRESS_DURATION(
134136
"<b>Advance Press Duration:</b><br>Hold the button down for this long to advance once.",
135137
LockMode::LOCK_WHILE_RUNNING,
136-
10
138+
"80 ms"
137139
)
138140
, ADVANCE_RELEASE_DURATION(
139141
"<b>Advance Release Duration:</b><br>After releasing the button, wait this long before pressing it again.",
140142
LockMode::LOCK_WHILE_RUNNING,
141-
10
143+
"80 ms"
142144
)
143145
, SAVE_SCREENSHOTS(
144146
"<b>Save Debug Screenshots:</b>",
@@ -174,8 +176,8 @@ CramomaticRNG::CramomaticRNG()
174176

175177
void CramomaticRNG::navigate_to_party(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
176178
pbf_press_button(context, BUTTON_X, 10, 125);
177-
pbf_press_button(context, BUTTON_A, 10, 10);
178-
pbf_wait(context, 2 * TICKS_PER_SECOND);
179+
pbf_press_button(context, BUTTON_A, 20, 10);
180+
pbf_wait(context, 2000ms);
179181
}
180182

181183
CramomaticTarget CramomaticRNG::calculate_target(SingleSwitchProgramEnvironment& env, Xoroshiro128PlusState state, std::vector<CramomaticSelection> selected_balls){
@@ -281,7 +283,7 @@ CramomaticTarget CramomaticRNG::calculate_target(SingleSwitchProgramEnvironment&
281283
}
282284

283285
void CramomaticRNG::leave_to_overworld_and_interact(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
284-
pbf_press_button(context, BUTTON_B, 2 * TICKS_PER_SECOND, 5);
286+
pbf_press_button(context, BUTTON_B, 2000ms, 40ms);
285287
pbf_press_button(context, BUTTON_B, 10, 70);
286288

287289
pbf_mash_button(context, BUTTON_A, 320);
@@ -305,7 +307,7 @@ void CramomaticRNG::choose_apricorn(SingleSwitchProgramEnvironment& env, ProCont
305307
}
306308

307309
// select the apricorn(s)
308-
pbf_wait(context, 1 * TICKS_PER_SECOND);
310+
pbf_wait(context, 1000ms);
309311
pbf_press_button(context, BUTTON_A, 10, 30);
310312
if (sport){
311313
pbf_press_dpad(context, DPAD_DOWN, 20, 10);
@@ -317,7 +319,7 @@ void CramomaticRNG::choose_apricorn(SingleSwitchProgramEnvironment& env, ProCont
317319
}
318320
pbf_press_button(context, BUTTON_A, 10, 30);
319321

320-
pbf_mash_button(context, BUTTON_A, 5 * TICKS_PER_SECOND);
322+
pbf_mash_button(context, BUTTON_A, 5000ms);
321323
}
322324

323325
std::pair<bool, std::string> CramomaticRNG::receive_ball(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
@@ -367,16 +369,16 @@ std::pair<bool, std::string> CramomaticRNG::receive_ball(SingleSwitchProgramEnvi
367369
arrow_detected = true;
368370
}
369371
}
370-
pbf_press_button(context, BUTTON_B, 10, TICKS_PER_SECOND);
372+
pbf_press_button(context, BUTTON_B, 80ms, 1000ms);
371373
return {arrow_detected, best_ball};
372374
}
373375

374376
void CramomaticRNG::recover_from_wrong_state(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
375377
// Mash the B button to exit potential menus or dialog boxes
376-
pbf_mash_button(context, BUTTON_B, 30 * TICKS_PER_SECOND);
378+
pbf_mash_button(context, BUTTON_B, 30s);
377379

378380
// take a step in case Hyde repositioned the player
379-
pbf_move_left_joystick(context, 128, 0, TICKS_PER_SECOND, 10);
381+
pbf_move_left_joystick(context, 128, 0, 1000ms, 80ms);
380382

381383
context.wait_for_all_requests();
382384
}
@@ -436,7 +438,7 @@ void CramomaticRNG::program(SingleSwitchProgramEnvironment& env, ProControllerCo
436438
// Touch the date.
437439
if (TOUCH_DATE_INTERVAL.ok_to_touch_now()){
438440
env.log("Touching date to prevent rollover.");
439-
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY_SAFE0);
441+
ssf_press_button(context, BUTTON_HOME, GameSettings::instance().GAME_TO_HOME_DELAY_SAFE0, 160ms);
440442
touch_date_from_home(context, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
441443
resume_game_no_interact(env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
442444
}
@@ -482,7 +484,13 @@ void CramomaticRNG::program(SingleSwitchProgramEnvironment& env, ProControllerCo
482484
num_apricorn_one -= sport ? 2 : 4;
483485
num_apricorn_two -= sport ? 2 : 0;
484486

485-
do_rng_advances(env.console, context, rng, target.needed_advances, ADVANCE_PRESS_DURATION, ADVANCE_RELEASE_DURATION);
487+
do_rng_advances(
488+
env.console, context,
489+
rng,
490+
target.needed_advances,
491+
ADVANCE_PRESS_DURATION,
492+
ADVANCE_RELEASE_DURATION
493+
);
486494
leave_to_overworld_and_interact(env, context);
487495

488496
try{

SerialPrograms/Source/PokemonSwSh/Programs/RNG/PokemonSwSh_CramomaticRNG.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
#ifndef PokemonAutomation_PokemonSwSh_CramomaticRNG_H
88
#define PokemonAutomation_PokemonSwSh_CramomaticRNG_H
99

10+
#include "Common/Cpp/Options/StaticTextOption.h"
1011
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
1112
#include "Common/Cpp/Options/SimpleIntegerOption.h"
12-
#include "Common/Cpp/Options/StaticTextOption.h"
13+
#include "Common/Cpp/Options/TimeDurationOption.h"
1314
#include "CommonFramework/Notifications/EventNotificationsTable.h"
1415
#include "CommonTools/Options/LanguageOCROption.h"
1516
#include "NintendoSwitch/Options/NintendoSwitch_StartInGripMenuOption.h"
@@ -59,8 +60,8 @@ class CramomaticRNG : public SingleSwitchProgramInstance{
5960
SectionDividerOption m_advanced_options;
6061
SimpleIntegerOption<uint16_t> MAX_PRIORITY_ADVANCES;
6162
SimpleIntegerOption<uint16_t> MAX_UNKNOWN_ADVANCES;
62-
SimpleIntegerOption<uint16_t> ADVANCE_PRESS_DURATION;
63-
SimpleIntegerOption<uint16_t> ADVANCE_RELEASE_DURATION;
63+
MillisecondsOption ADVANCE_PRESS_DURATION;
64+
MillisecondsOption ADVANCE_RELEASE_DURATION;
6465
BooleanCheckBoxOption SAVE_SCREENSHOTS;
6566
BooleanCheckBoxOption LOG_VALUES;
6667

SerialPrograms/Source/PokemonSwSh/Programs/RNG/PokemonSwSh_SeedFinder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ SeedFinder_Descriptor::SeedFinder_Descriptor()
2828
"Finds the current state to be used for manual RNG manipulation.",
2929
FeedbackType::REQUIRED,
3030
AllowCommandsWhenRunning::DISABLE_COMMANDS,
31-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
31+
{ControllerFeature::NintendoSwitch_ProController},
32+
FasterIfTickPrecise::NOT_FASTER
3233
)
3334
{}
3435

0 commit comments

Comments
 (0)