| 1 |
|
| 2 |
|
| 3 |
#pragma once |
| 4 |
|
| 5 |
#include <array> |
| 6 |
#include <cstddef> |
| 7 |
|
| 8 |
#include "Common/CommonTypes.h" |
| 9 |
|
| 10 |
namespace DiscIO |
| 11 |
{ |
| 12 |
class LaggedFibonacciGenerator |
| 13 |
{ |
| 14 |
public: |
| 15 |
static constexpr size_t SEED_SIZE = 17; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
static size_t GetSeed(const u8* data, size_t size, size_t data_offset, u32 seed_out[SEED_SIZE]); |
| 21 |
|
| 22 |
|
| 23 |
void SetSeed(const u32 seed[SEED_SIZE]); |
| 24 |
void SetSeed(const u8 seed[SEED_SIZE * sizeof(u32)]); |
| 25 |
|
| 26 |
|
| 27 |
void GetBytes(size_t count, u8* out); |
| 28 |
u8 GetByte(); |
| 29 |
|
| 30 |
|
| 31 |
void Forward(size_t count); |
| 32 |
|
| 33 |
private: |
| 34 |
static bool GetSeed(const u32* data, size_t size, size_t data_offset, |
| 35 |
LaggedFibonacciGenerator* lfg, u32 seed_out[SEED_SIZE]); |
| 36 |
|
| 37 |
void Forward(); |
| 38 |
void Backward(size_t start_word = 0, size_t end_word = LFG_K); |
| 39 |
|
| 40 |
bool Reinitialize(u32 seed_out[SEED_SIZE]); |
| 41 |
bool Initialize(bool check_existing_data); |
| 42 |
|
| 43 |
static constexpr size_t LFG_K = 521; |
| 44 |
static constexpr size_t LFG_J = 32; |
| 45 |
|
| 46 |
std::array<u32, LFG_K> m_buffer{}; |
| 47 |
|
| 48 |
size_t m_position_bytes = 0; |
| 49 |
}; |
| 50 |
|
| 51 |
} |