Skip to content

Commit e76a40e

Browse files
authored
add FRLG SeedsDatabase and simplify RNG program UI (#1339)
1 parent 0598730 commit e76a40e

16 files changed

Lines changed: 527 additions & 363 deletions

SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp

Lines changed: 38 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ EggRng::EggRng()
143143
LockMode::LOCK_WHILE_RUNNING,
144144
GameVersion::firered
145145
)
146+
, SOUND(
147+
"<b>Sound:</b><br>"
148+
"Your in-game sound setting. This affects the possible seeds.",
149+
{
150+
{SoundSetting::Mono, "mono", "Mono"},
151+
{SoundSetting::Stereo, "stereo", "Stereo"}
152+
},
153+
LockMode::LOCK_WHILE_RUNNING,
154+
SoundSetting::Mono
155+
)
146156
, m_target_settings("Target Settings")
147157
, EGG_SPECIES(
148158
"<b>Egg Species:</b>",
@@ -166,42 +176,6 @@ EggRng::EggRng()
166176
"70FE", "70FE",
167177
true
168178
)
169-
, HELD_SEED_LIST(
170-
"<b>Nearby Held Seeds:</b><br>"
171-
"This box should contain a list of seeds (in order) around and including your held seed, with one seed on each line",
172-
LockMode::LOCK_WHILE_RUNNING,
173-
"D000\n199A\n77A1\nAABC\n280C\n70FE\nB573\n02F2\n8084\nA533\nED1E",
174-
"D000\n199A\n77A1\nAABC\n280C\n70FE\nB573\n02F2\n8084\nA533\nED1E",
175-
true
176-
)
177-
, HELD_SEED_BUTTON(
178-
"<b>Held Seed Button:</b><br>",
179-
{
180-
{SeedButton::A, "A", "A"},
181-
{SeedButton::Start, "Start", "Start"},
182-
{SeedButton::L, "L", "L (L=A)"},
183-
},
184-
LockMode::LOCK_WHILE_RUNNING,
185-
SeedButton::A
186-
)
187-
, HELD_EXTRA_BUTTON(
188-
"<b>Held Seed Extra Button:</b><br>"
189-
"Additional button presses that affect the seed.",
190-
{
191-
{BlackoutButton::None, "None", "None"},
192-
{BlackoutButton::L, "L", "Blackout L"},
193-
{BlackoutButton::R, "R", "Blackout R"},
194-
},
195-
LockMode::LOCK_WHILE_RUNNING,
196-
BlackoutButton::None
197-
)
198-
, HELD_SEED_DELAY(
199-
"<b>Held Seed Delay Time (ms):</b><br>"
200-
"The delay between starting the game and advancing past the title screen. Set this to match your held seed.<br>"
201-
"<i>If using Ten Lines, select <b>Nintendo Switch 1</b> as your console even if using a Switch 2.</i>",
202-
LockMode::LOCK_WHILE_RUNNING,
203-
31338, 30400 // default, min
204-
)
205179
, HELD_ADVANCES(
206180
"<b>Held Advances:</b><br>The total number of RNG advances for your held target.",
207181
LockMode::LOCK_WHILE_RUNNING,
@@ -215,48 +189,18 @@ EggRng::EggRng()
215189
"70FE", "70FE",
216190
true
217191
)
218-
, PICKUP_SEED_LIST(
219-
"<b>Nearby Pickup Seeds:</b><br>"
220-
"This box should contain a list of seeds (in order) around and including your held seed, with one seed on each line",
221-
LockMode::LOCK_WHILE_RUNNING,
222-
"D000\n199A\n77A1\nAABC\n280C\n70FE\nB573\n02F2\n8084\nA533\nED1E",
223-
"D000\n199A\n77A1\nAABC\n280C\n70FE\nB573\n02F2\n8084\nA533\nED1E",
224-
true
225-
)
226-
, PICKUP_SEED_BUTTON(
227-
"<b>Pickup Seed Button:</b><br>",
228-
{
229-
{SeedButton::A, "A", "A"},
230-
{SeedButton::Start, "Start", "Start"},
231-
{SeedButton::L, "L", "L (L=A)"},
232-
},
233-
LockMode::LOCK_WHILE_RUNNING,
234-
SeedButton::A
235-
)
236-
, PICKUP_EXTRA_BUTTON(
237-
"<b>Pickup Seed Extra Button:</b><br>"
238-
"Additional button presses that affect the seed.",
239-
{
240-
{BlackoutButton::None, "None", "None"},
241-
{BlackoutButton::L, "L", "Blackout L"},
242-
{BlackoutButton::R, "R", "Blackout R"},
243-
},
244-
LockMode::LOCK_WHILE_RUNNING,
245-
BlackoutButton::None
246-
)
247-
, PICKUP_SEED_DELAY(
248-
"<b>Pickup Seed Delay Time (ms):</b><br>"
249-
"The delay between starting the game and advancing past the title screen. Set this to match your held seed.<br>"
250-
"<i>If using Ten Lines, select <b>Nintendo Switch 1</b> as your console even if using a Switch 2.</i>",
251-
LockMode::LOCK_WHILE_RUNNING,
252-
31338, 30400 // default, min
253-
)
254192
, PICKUP_ADVANCES(
255193
"<b>Pickup Advances:</b><br>The total number of RNG advances for your pickup target.",
256194
LockMode::LOCK_WHILE_RUNNING,
257195
10000, 700, 1000000000 // default, min
258196
)
259197
, m_program_settings("Program Settings")
198+
, SEED_RADIUS(
199+
"<b>Nearby Seed Radius:</b><br>"
200+
"The number of nearby seeds on each side of the target to search when identifying which seed was hit.",
201+
LockMode::LOCK_WHILE_RUNNING,
202+
5, 1 // default, min
203+
)
260204
, STARTING_POINT(
261205
"<b>Starting Point:</b>",
262206
{
@@ -319,25 +263,19 @@ EggRng::EggRng()
319263
PA_ADD_OPTION(m_game_info);
320264
PA_ADD_OPTION(LANGUAGE);
321265
PA_ADD_OPTION(GAME_VERSION);
266+
PA_ADD_OPTION(SOUND);
322267
PA_ADD_OPTION(m_target_settings);
323268
PA_ADD_OPTION(EGG_SPECIES);
324269
PA_ADD_OPTION(COMPATIBILITY);
325270
PA_ADD_OPTION(PARENT_IVS);
326271
PA_ADD_OPTION(m_held_settings);
327272
PA_ADD_OPTION(HELD_SEED);
328-
PA_ADD_OPTION(HELD_SEED_LIST);
329-
PA_ADD_OPTION(HELD_SEED_BUTTON);
330-
PA_ADD_OPTION(HELD_EXTRA_BUTTON);
331-
PA_ADD_OPTION(HELD_SEED_DELAY);
332273
PA_ADD_OPTION(HELD_ADVANCES);
333274
PA_ADD_OPTION(m_pickup_settings);
334275
PA_ADD_OPTION(PICKUP_SEED);
335-
PA_ADD_OPTION(PICKUP_SEED_LIST);
336-
PA_ADD_OPTION(PICKUP_SEED_BUTTON);
337-
PA_ADD_OPTION(PICKUP_EXTRA_BUTTON);
338-
PA_ADD_OPTION(PICKUP_SEED_DELAY);
339276
PA_ADD_OPTION(PICKUP_ADVANCES);
340277
PA_ADD_OPTION(m_program_settings);
278+
PA_ADD_OPTION(SEED_RADIUS);
341279
PA_ADD_OPTION(STARTING_POINT);
342280
PA_ADD_OPTION(MAX_RESETS);
343281
PA_ADD_OPTION(MAX_BALL_THROWS);
@@ -404,6 +342,8 @@ bool EggRng::reset_and_check_seed(
404342
const uint64_t& SEED_DELAY = frame_target.seed_delay;
405343
const std::vector<uint16_t>& SEED_VALUES = frame_target.seed_values;
406344
const int16_t& SEED_POSITION = frame_target.seed_position;
345+
const SeedButton& SEED_BUTTON = frame_target.seed_button;
346+
const BlackoutButton& EXTRA_BUTTON = frame_target.extra_button;
407347

408348
static const int64_t FIXED_SEED_OFFSET = -845; // ms, approximate
409349
const int64_t FIXED_ADVANCES_OFFSET = pickup_frame ? -246 : 135; // frames, approximate
@@ -439,9 +379,8 @@ bool EggRng::reset_and_check_seed(
439379
// Step 1: reset and perform blind sequence
440380
env.log("Resetting Game...");
441381
reset_and_perform_blind_sequence(
442-
env.console, context, target,
443-
pickup_frame ? PICKUP_SEED_BUTTON : HELD_SEED_BUTTON,
444-
pickup_frame ? PICKUP_EXTRA_BUTTON : HELD_EXTRA_BUTTON,
382+
env.console, context, target,
383+
SEED_BUTTON, EXTRA_BUTTON,
445384
timings, launch_delay, false, PROFILE
446385
);
447386
stats.resets++;
@@ -792,35 +731,37 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
792731
SPECIES_LIST.emplace(slot.species);
793732
}
794733

734+
const SeedsDatabase seeds_db(seeds_json_path(GAME_VERSION == GameVersion::firered, LANGUAGE));
735+
795736
// held timings
796737
const uint16_t TARGET_HELD_SEED = parse_seed(env.console, HELD_SEED);
797-
const std::vector<uint16_t> HELD_SEED_VALUES = parse_seed_list(env.console, HELD_SEED_LIST);
798-
const int16_t HELD_SEED_POSITION = seed_position_in_list(TARGET_HELD_SEED, HELD_SEED_VALUES);
799-
if (HELD_SEED_POSITION == -1){
738+
const SeedMatch held_match = seeds_db.find_seed(TARGET_HELD_SEED, SOUND, SEED_RADIUS);
739+
if (!held_match.found){
800740
OperationFailedException::fire(
801741
ErrorReport::SEND_ERROR_REPORT,
802-
"EggRng(): Held Seed is missing from the list of nearby seeds.",
742+
"EggRng(): Held Seed was not found in the seed database for this game version, language, and sound setting.",
803743
env.console
804-
);
744+
);
805745
}
806-
env.log("Target Held Seed Value: " + to_hex_string(TARGET_HELD_SEED));
746+
env.log("Target Held Seed Value: " + to_hex_string(TARGET_HELD_SEED)
747+
+ " (delay " + std::to_string(held_match.seed_delay) + "ms, button mode " + held_match.button_mode + ")");
807748

808749
// pickup timings
809750
const uint16_t TARGET_PICKUP_SEED = parse_seed(env.console, PICKUP_SEED);
810-
const std::vector<uint16_t> PICKUP_SEED_VALUES = parse_seed_list(env.console, PICKUP_SEED_LIST);
811-
const int16_t PICKUP_SEED_POSITION = seed_position_in_list(TARGET_PICKUP_SEED, PICKUP_SEED_VALUES);
812-
if (PICKUP_SEED_POSITION == -1){
751+
const SeedMatch pickup_match = seeds_db.find_seed(TARGET_PICKUP_SEED, SOUND, SEED_RADIUS);
752+
if (!pickup_match.found){
813753
OperationFailedException::fire(
814754
ErrorReport::SEND_ERROR_REPORT,
815-
"EggRng(): Pickup Seed is missing from the list of nearby seeds.",
755+
"EggRng(): Pickup Seed was not found in the seed database for this game version, language, and sound setting.",
816756
env.console
817-
);
757+
);
818758
}
819-
env.log("Target Pickup Seed Value: " + to_hex_string(TARGET_PICKUP_SEED));
759+
env.log("Target Pickup Seed Value: " + to_hex_string(TARGET_PICKUP_SEED)
760+
+ " (delay " + std::to_string(pickup_match.seed_delay) + "ms, button mode " + pickup_match.button_mode + ")");
820761

821762
EggFrameTargets frame_targets{
822-
{ HELD_SEED_DELAY, HELD_SEED_VALUES, HELD_SEED_POSITION },
823-
{ PICKUP_SEED_DELAY, PICKUP_SEED_VALUES, PICKUP_SEED_POSITION }
763+
{ held_match.seed_delay, held_match.seed_values, held_match.seed_position, held_match.seed_button, held_match.extra_button },
764+
{ pickup_match.seed_delay, pickup_match.seed_values, pickup_match.seed_position, pickup_match.seed_button, pickup_match.extra_button }
824765
};
825766

826767
// searchers

SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "PokemonFRLG_RngStatsDatabase.h"
2424
#include "PokemonFRLG_RngDisplays.h"
2525
#include "PokemonFRLG_RngLoopRoutines.h"
26+
#include "PokemonFRLG_SeedsDatabase.h"
2627

2728
namespace PokemonAutomation{
2829
namespace NintendoSwitch{
@@ -146,29 +147,23 @@ class EggRng : public SingleSwitchProgramInstance, public ConfigOption::Listener
146147
SectionDividerOption m_game_info;
147148
OCR::LanguageOCROption LANGUAGE;
148149
EnumDropdownOption<GameVersion> GAME_VERSION;
150+
EnumDropdownOption<SoundSetting> SOUND;
149151

150152
SectionDividerOption m_target_settings;
151153
PokemonNameSelectOption EGG_SPECIES;
152154
EnumDropdownOption<AdvEggCompatibility> COMPATIBILITY;
153155
ParentIVsTable PARENT_IVS;
154156

155157
SectionDividerOption m_held_settings;
156-
StringOption HELD_SEED;
157-
TextEditOption HELD_SEED_LIST;
158-
EnumDropdownOption<SeedButton> HELD_SEED_BUTTON;
159-
EnumDropdownOption<BlackoutButton> HELD_EXTRA_BUTTON;
160-
SimpleIntegerOption<uint64_t> HELD_SEED_DELAY;
158+
StringOption HELD_SEED;
161159
SimpleIntegerOption<uint64_t>HELD_ADVANCES;
162160

163161
SectionDividerOption m_pickup_settings;
164-
StringOption PICKUP_SEED;
165-
TextEditOption PICKUP_SEED_LIST;
166-
EnumDropdownOption<SeedButton> PICKUP_SEED_BUTTON;
167-
EnumDropdownOption<BlackoutButton> PICKUP_EXTRA_BUTTON;
168-
SimpleIntegerOption<uint64_t> PICKUP_SEED_DELAY;
162+
StringOption PICKUP_SEED;
169163
SimpleIntegerOption<uint64_t>PICKUP_ADVANCES;
170164

171165
SectionDividerOption m_program_settings;
166+
SimpleIntegerOption<uint16_t> SEED_RADIUS;
172167
EnumDropdownOption<EggProgramState> STARTING_POINT;
173168
SimpleIntegerOption<uint64_t> MAX_RESETS;
174169
SimpleIntegerOption<uint64_t> MAX_RARE_CANDIES;

SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ GiftRng::GiftRng()
6767
, m_game_info(
6868
"<font size=4><b>Game Information</b></font>"
6969
)
70+
, GAME_VERSION(
71+
"<b>Game Version:</b>",
72+
{
73+
{GameVersion::firered, "firered", "FireRed"},
74+
{GameVersion::leafgreen, "leafgreen", "LeafGreen"}
75+
},
76+
LockMode::LOCK_WHILE_RUNNING,
77+
GameVersion::firered
78+
)
7079
, LANGUAGE(
7180
"<b>Game Language:</b>",
7281
{
@@ -80,6 +89,16 @@ GiftRng::GiftRng()
8089
LockMode::LOCK_WHILE_RUNNING,
8190
true
8291
)
92+
, SOUND(
93+
"<b>Sound:</b><br>"
94+
"Your in-game sound setting. This affects the possible seeds.",
95+
{
96+
{SoundSetting::Mono, "mono", "Mono"},
97+
{SoundSetting::Stereo, "stereo", "Stereo"}
98+
},
99+
LockMode::LOCK_WHILE_RUNNING,
100+
SoundSetting::Mono
101+
)
83102
, m_target_settings(
84103
"<font size=4><b>Target Settings</b></font> — Get these from an RNG search tool"
85104
)
@@ -113,43 +132,6 @@ GiftRng::GiftRng()
113132
"70FE", "70FE",
114133
true
115134
)
116-
, SEED_LIST(
117-
"<b>Nearby Seeds:</b><br>"
118-
"This box should contain a list of seeds (in order) around and including your target seed, with one seed on each line",
119-
LockMode::LOCK_WHILE_RUNNING,
120-
"D000\n199A\n77A1\nAABC\n280C\n70FE\nB573\n02F2\n8084\nA533\nED1E",
121-
"D000\n199A\n77A1\nAABC\n280C\n70FE\nB573\n02F2\n8084\nA533\nED1E",
122-
true
123-
)
124-
, SEED_BUTTON(
125-
"<b>Seed Button:</b>",
126-
{
127-
{SeedButton::A, "A", "A"},
128-
{SeedButton::Start, "Start", "Start"},
129-
{SeedButton::L, "L", "L (L=A)"},
130-
},
131-
LockMode::LOCK_WHILE_RUNNING,
132-
SeedButton::A
133-
)
134-
, EXTRA_BUTTON(
135-
"<b>Extra Button:</b><br>"
136-
"Additional button presses that affect the seed.",
137-
{
138-
{BlackoutButton::None, "None", "None"},
139-
{BlackoutButton::L, "L", "Blackout L"},
140-
{BlackoutButton::R, "R", "Blackout R"},
141-
},
142-
LockMode::LOCK_WHILE_RUNNING,
143-
BlackoutButton::None
144-
)
145-
, SEED_DELAY(
146-
"<b>Seed Delay Time (ms):</b><br>"
147-
"The delay between starting the game and advancing past the title screen. Set this to match your target seed.<br>"
148-
"<i>If using Ten Lines for seed info, select <b>Nintendo Switch 1</b> as your console even if using a Switch 2.</i><br>"
149-
"<b>Warning: values close to 30500ms can sometimes cause problems, and you may need to manually increase your initial seed calibration or pick a new target.</b>",
150-
LockMode::LOCK_WHILE_RUNNING,
151-
31338, 30400 // default, min
152-
)
153135
, ADVANCES(
154136
"<b>Advances:</b><br>The total number of RNG advances for your target.",
155137
LockMode::LOCK_WHILE_RUNNING,
@@ -165,6 +147,12 @@ GiftRng::GiftRng()
165147
LockMode::LOCK_WHILE_RUNNING,
166148
false // default
167149
)
150+
, SEED_RADIUS(
151+
"<b>Nearby Seed Radius:</b><br>"
152+
"The number of nearby seeds on each side of the target to search when identifying which seed was hit.",
153+
LockMode::LOCK_WHILE_RUNNING,
154+
5, 1 // default, min
155+
)
168156
, MAX_RESETS(
169157
"<b>Max Resets:</b>",
170158
LockMode::UNLOCK_WHILE_RUNNING,
@@ -207,17 +195,16 @@ GiftRng::GiftRng()
207195
PA_ADD_OPTION(RNG_FILTERS);
208196
PA_ADD_OPTION(RNG_CALIBRATION);
209197
PA_ADD_OPTION(m_game_info);
198+
PA_ADD_OPTION(GAME_VERSION);
210199
PA_ADD_OPTION(LANGUAGE);
200+
PA_ADD_OPTION(SOUND);
211201
PA_ADD_OPTION(m_target_settings);
212202
PA_ADD_OPTION(TARGET);
213203
PA_ADD_OPTION(SEED);
214-
PA_ADD_OPTION(SEED_LIST);
215-
PA_ADD_OPTION(SEED_BUTTON);
216-
PA_ADD_OPTION(EXTRA_BUTTON);
217-
PA_ADD_OPTION(SEED_DELAY);
218204
PA_ADD_OPTION(ADVANCES);
219205
PA_ADD_OPTION(m_program_settings);
220206
PA_ADD_OPTION(USE_TEACHY_TV);
207+
PA_ADD_OPTION(SEED_RADIUS);
221208
PA_ADD_OPTION(MAX_RESETS);
222209
PA_ADD_OPTION(MAX_RARE_CANDIES);
223210
PA_ADD_OPTION(PROFILE);
@@ -241,12 +228,18 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
241228
RNG_CALIBRATION.reset_hits();
242229

243230
const uint16_t TARGET_SEED = parse_seed(env.console, SEED);
244-
const std::vector<uint16_t> SEED_VALUES = parse_seed_list(env.console, SEED_LIST);
245-
const int16_t SEED_POSITION = seed_position_in_list(TARGET_SEED, SEED_VALUES);
246-
247-
if (SEED_POSITION == -1){
248-
throw UserSetupError(env.console, "The target Seed is missing from the list of nearby seeds.");
231+
SeedsDatabase seeds_db(seeds_json_path(GAME_VERSION == GameVersion::firered, LANGUAGE));
232+
const SeedMatch seed_match = seeds_db.find_seed(TARGET_SEED, SOUND, SEED_RADIUS);
233+
if (!seed_match.found){
234+
throw UserSetupError(env.console, "The target Seed was not found in the seed database for this game version, language, and sound setting.");
249235
}
236+
const std::vector<uint16_t> SEED_VALUES = seed_match.seed_values;
237+
const int16_t SEED_POSITION = seed_match.seed_position;
238+
const uint64_t SEED_DELAY = seed_match.seed_delay;
239+
const SeedButton SEED_BUTTON = seed_match.seed_button;
240+
const BlackoutButton EXTRA_BUTTON = seed_match.extra_button;
241+
env.log("Seed delay: " + std::to_string(SEED_DELAY) + "ms, button mode: " + seed_match.button_mode
242+
+ ", column: " + seed_match.column_name);
250243

251244
BaseStats BASE_STATS;
252245
int16_t GENDER_THRESHOLD = -1;

0 commit comments

Comments
 (0)