Skip to content

Commit 6f81f45

Browse files
committed
refactor out rng state prediction after menu close, implicit cram-o-matic fix
1 parent 7566c46 commit 6f81f45

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ void do_rng_advances(
180180
pbf_wait(context, 1000ms);
181181
}
182182

183+
Xoroshiro128PlusState predict_state_after_menu_close(Xoroshiro128PlusState current_state, uint8_t num_npcs) {
184+
Xoroshiro128Plus rng(current_state);
185+
186+
for (size_t i = 0; i < num_npcs; i++) {
187+
rng.nextInt(91);
188+
}
189+
rng.next();
190+
rng.nextInt(61);
191+
192+
return rng.get_state();
193+
}
194+
183195

184196
}
185197
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ void do_rng_advances(
5757
Milliseconds release_duration
5858
);
5959

60+
Xoroshiro128PlusState predict_state_after_menu_close(Xoroshiro128PlusState current_state, uint8_t num_npcs);
61+
6062

6163

6264
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,9 @@ CramomaticTarget CramomaticRNG::calculate_target(SingleSwitchProgramEnvironment&
194194
// priority_advances only starts counting up after the first good result is found
195195
while (priority_advances <= MAX_PRIORITY_ADVANCES){
196196
// calculate the result for the current temp_rng state
197-
Xoroshiro128Plus temp_rng(rng.get_state());
197+
Xoroshiro128PlusState temp_state = predict_state_after_menu_close(rng.get_state(), NUM_NPCS);
198+
Xoroshiro128Plus temp_rng(temp_state);
198199

199-
for (size_t i = 0; i < NUM_NPCS; i++){
200-
temp_rng.nextInt(91);
201-
}
202-
temp_rng.next();
203-
temp_rng.nextInt(60);
204200

205201
/*uint64_t item_roll =*/ temp_rng.nextInt(4);
206202
uint64_t ball_roll = temp_rng.nextInt(100);

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -249,25 +249,14 @@ uint8_t DailyHighlightRNG::calibrate_num_npc_from_party(SingleSwitchProgramEnvir
249249
const uint8_t MAX_NPCS = 6; // Usually either 1 or 2, sometimes 3 or 4, maybe 5 or 6 -> high numbers suggest bad npc state
250250
std::vector<Xoroshiro128PlusState> rng_states;
251251

252-
for (size_t i = 0; i <= MAX_NPCS; i++) {
253-
Xoroshiro128Plus temp_rng(rng.get_state());
254-
255-
for (size_t j = 0; j < i; j++) {
256-
temp_rng.nextInt(91);
257-
}
258-
temp_rng.next();
259-
temp_rng.nextInt(61);
252+
for (size_t npcs = 0; npcs <= MAX_NPCS; npcs++) {
253+
Xoroshiro128PlusState temp_state = predict_state_after_menu_close(rng.get_state(), npcs);
254+
Xoroshiro128Plus temp_rng(temp_state);
260255

261256
// Do advances that were needed to find current state
262-
for (size_t j = 0; j < additional_advances; j++) {
257+
for (size_t i = 0; i < additional_advances; i++) {
263258
temp_rng.next();
264259
}
265-
266-
env.console.log(std::to_string(i));
267-
env.console.log(std::to_string(additional_advances));
268-
env.console.log(tostr_hex(temp_rng.get_state().s0));
269-
env.console.log(tostr_hex(temp_rng.get_state().s1));
270-
271260
rng_states.push_back(temp_rng.get_state());
272261
}
273262

@@ -305,12 +294,8 @@ size_t DailyHighlightRNG::calculate_target(SingleSwitchProgramEnvironment& env,
305294
while (!found_advance_amount) {
306295
// Calculate the result for the current temp_rng state
307296

308-
Xoroshiro128Plus temp_rng(rng.get_state());
309-
for (size_t i = 0; i < num_npcs; i++) {
310-
temp_rng.nextInt(91);
311-
}
312-
temp_rng.next();
313-
temp_rng.nextInt(61);
297+
Xoroshiro128PlusState temp_state = predict_state_after_menu_close(rng.get_state(), num_npcs);
298+
Xoroshiro128Plus temp_rng(temp_state);
314299

315300
uint64_t highlight_roll = temp_rng.nextInt(1000);
316301

0 commit comments

Comments
 (0)