Skip to content

Commit 360b67c

Browse files
committed
working highlight RNG
1 parent 3424527 commit 360b67c

File tree

6 files changed

+313
-87
lines changed

6 files changed

+313
-87
lines changed

SerialPrograms/Source/Pokemon/Pokemon_Xoroshiro128Plus.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ std::vector<bool> Xoroshiro128Plus::generate_last_bit_sequence(size_t max_advanc
7777
return sequence;
7878
}
7979

80+
81+
std::pair<bool, uint64_t> Xoroshiro128Plus::advances_to_state(Xoroshiro128PlusState other_state, uint64_t max_advances) {
82+
Xoroshiro128Plus temp_rng(get_state());
83+
uint64_t advances = 0;
84+
85+
while (advances <= max_advances) {
86+
Xoroshiro128PlusState temp_state = temp_rng.get_state();
87+
if (temp_state.s0 == other_state.s0 && temp_state.s1 == other_state.s1) {
88+
return { true, advances };
89+
}
90+
temp_rng.next();
91+
advances++;
92+
}
93+
return { false, advances };
94+
}
95+
8096
// The generic solution to the system of equations to calculate the initial state from the last bits of 128 consecutive Xoroshiro128+ results.
8197
uint64_t Xoroshiro128Plus::last_bits_reverse_matrix[128][2] = {
8298
/*s0 bit 0*/ {0b0101001100100001111011111110111001010011111110101011100011001101, 0b0111010111110111000101010100001111101001111001011111001011010111} ,

SerialPrograms/Source/Pokemon/Pokemon_Xoroshiro128Plus.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ class Xoroshiro128Plus{
3131
Xoroshiro128PlusState get_state();
3232
std::vector<bool> generate_last_bit_sequence(size_t max_advances);
3333

34+
// Calculates how many advances are required to reach the given state.
35+
// The given state must be reachable within max_advances advances.
36+
// Returns a pair:
37+
// first: true if the state is reachable within max_advances, false otherwise
38+
// second: the number of advances required (if first is true)
39+
std::pair<bool, uint64_t> advances_to_state(Xoroshiro128PlusState other_state, uint64_t max_advances = 100000);
40+
3441
static Xoroshiro128Plus xoroshiro128plus_from_last_bits(std::pair<uint64_t, uint64_t> last_bits);
3542

3643

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ Xoroshiro128PlusState find_rng_state(
6666
return rng.get_state();
6767
}
6868

69-
7069
Xoroshiro128PlusState refind_rng_state(
7170
VideoStream& stream,
7271
ProControllerContext& context,
@@ -75,6 +74,18 @@ Xoroshiro128PlusState refind_rng_state(
7574
size_t max_advances,
7675
bool save_screenshots,
7776
bool log_image_values
77+
) {
78+
return refind_rng_state_and_animations(stream, context, last_known_state, min_advances, max_advances, save_screenshots, log_image_values).first;
79+
}
80+
81+
std::pair<Xoroshiro128PlusState, uint64_t> refind_rng_state_and_animations(
82+
VideoStream& stream,
83+
ProControllerContext& context,
84+
Xoroshiro128PlusState last_known_state,
85+
size_t min_advances,
86+
size_t max_advances,
87+
bool save_screenshots,
88+
bool log_image_values
7889
)
7990
{
8091
Xoroshiro128Plus rng(last_known_state.s0, last_known_state.s1);
@@ -140,7 +151,7 @@ Xoroshiro128PlusState refind_rng_state(
140151
stream.log("RNG: state[0] = " + tostr_hex(rng.get_state().s0));
141152
stream.log("RNG: state[1] = " + tostr_hex(rng.get_state().s1));
142153

143-
return rng.get_state();
154+
return { rng.get_state(), sequence.size() };
144155
}
145156

146157

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
99
#include "Pokemon/Pokemon_Xoroshiro128Plus.h"
1010

11+
#include <optional>
12+
1113
namespace PokemonAutomation{
1214
namespace NintendoSwitch{
1315
namespace PokemonSwSh{
@@ -33,6 +35,20 @@ Xoroshiro128PlusState refind_rng_state(
3335
bool log_values
3436
);
3537

38+
// Performs Orbeetle attack animations until only one possible state is left.
39+
// Returns a pair:
40+
// first: current RNG state
41+
// second: the number of animations required to find the state
42+
std::pair<Xoroshiro128PlusState, uint64_t> refind_rng_state_and_animations(
43+
VideoStream& stream,
44+
ProControllerContext& context,
45+
Xoroshiro128PlusState last_known_state,
46+
size_t min_advances,
47+
size_t max_advances,
48+
bool save_screenshots,
49+
bool log_values
50+
);
51+
3652
void do_rng_advances(
3753
VideoStream& stream, ProControllerContext& context,
3854
Xoroshiro128Plus& rng,

0 commit comments

Comments
 (0)