cheats: don't use rand()
This commit is contained in:
parent
a6d92ed8fe
commit
37c5c6f049
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user