diff --git a/sysmodules/rosalina/include/menus/cheats.h b/sysmodules/rosalina/include/menus/cheats.h index 163609a..9ce7f22 100644 --- a/sysmodules/rosalina/include/menus/cheats.h +++ b/sysmodules/rosalina/include/menus/cheats.h @@ -33,4 +33,5 @@ #define CHEATS_PER_MENU_PAGE 18 void RosalinaMenu_Cheats(void); -void Cheat_ApplyCheats(); +void Cheat_SeedRng(u64 seed); +void Cheat_ApplyCheats(void); diff --git a/sysmodules/rosalina/source/main.c b/sysmodules/rosalina/source/main.c index b4b4b5a..f8869da 100644 --- a/sysmodules/rosalina/source/main.c +++ b/sysmodules/rosalina/source/main.c @@ -37,6 +37,7 @@ #include "menus/miscellaneous.h" #include "menus/debugger.h" #include "menus/screen_filters.h" +#include "menus/cheats.h" #include "task_runner.h" @@ -193,6 +194,8 @@ int main(void) if(R_FAILED(svcCreateEvent(&terminationRequestEvent, RESET_STICKY))) svcBreak(USERBREAK_ASSERT); + Cheat_SeedRng(svcGetSystemTick()); + MyThread *menuThread = menuCreateThread(); MyThread *taskRunnerThread = taskRunnerCreateThread(); MyThread *errDispThread = errDispCreateThread(); diff --git a/sysmodules/rosalina/source/menus/cheats.c b/sysmodules/rosalina/source/menus/cheats.c index 718d366..d29f6d7 100644 --- a/sysmodules/rosalina/source/menus/cheats.c +++ b/sysmodules/rosalina/source/menus/cheats.c @@ -96,6 +96,7 @@ typedef struct CheatState CheatState cheat_state = { 0 }; u8 cheatCount = 0; u64 cheatTitleInfo = -1ULL; +u64 cheatRngState = 0; static inline u32* activeOffset() { @@ -114,6 +115,12 @@ static inline u32* activeStorage(CheatDescription* desc) char failureReason[64]; +static u32 Cheat_GetRandomNumber(void) +{ + cheatRngState = 0x5D588B656C078965ULL * cheatRngState + 0x0000000000269EC3ULL; + return (u32)(cheatRngState >> 32); +} + static bool Cheat_IsValidAddress(const Handle processHandle, u32 address, u32 size) { MemInfo info; @@ -1477,7 +1484,7 @@ static u32 Cheat_ApplyCheat(const Handle processHandle, CheatDescription* const case 0xF: { u32 range = arg1 - (arg0 & 0xFFFFFF); - u32 number = rand() % range; + u32 number = Cheat_GetRandomNumber() % range; *activeData() = (arg0 & 0xFFFFFF) + number; } break; @@ -1862,6 +1869,11 @@ static u32 Cheat_GetCurrentTitleId(u64* titleId) return res; } +void Cheat_SeedRng(u64 seed) +{ + cheatRngState = seed; +} + void Cheat_ApplyCheats(void) { if (!cheatCount)