Fix: seed srand on launch and fix spoiler log for seed testing generation (#2902)

This commit is contained in:
Adam Bird 2023-05-20 16:25:29 -04:00 committed by GitHub
parent 0b47a19c2c
commit cf42057842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 14 deletions

View File

@ -518,7 +518,7 @@ std::string GenerateRandomizer(std::unordered_map<RandomizerSettingKey, uint8_t>
srand(time(NULL)); srand(time(NULL));
// if a blank seed was entered, make a random one // if a blank seed was entered, make a random one
if (seedString.empty()) { if (seedString.empty()) {
Settings::seed = rand() & 0xFFFFFFFF; seedString = std::to_string(rand() % 0xFFFFFFFF);
} else if (seedString.rfind("seed_testing_count", 0) == 0 && seedString.length() > 18) { } else if (seedString.rfind("seed_testing_count", 0) == 0 && seedString.length() > 18) {
int count; int count;
try { try {
@ -530,16 +530,11 @@ std::string GenerateRandomizer(std::unordered_map<RandomizerSettingKey, uint8_t>
} }
Playthrough::Playthrough_Repeat(cvarSettings, excludedLocations, count); Playthrough::Playthrough_Repeat(cvarSettings, excludedLocations, count);
return ""; return "";
} else { }
try {
uint32_t seedHash = boost::hash_32<std::string>{}(seedString);
int seed = seedHash & 0xFFFFFFFF;
Settings::seed = seed;
Settings::seedString = seedString; Settings::seedString = seedString;
} catch (...) { uint32_t seedHash = boost::hash_32<std::string>{}(Settings::seedString);
return ""; Settings::seed = seedHash & 0xFFFFFFFF;
}
}
int ret = Playthrough::Playthrough_Init(Settings::seed, cvarSettings, excludedLocations); int ret = Playthrough::Playthrough_Init(Settings::seed, cvarSettings, excludedLocations);
if (ret < 0) { if (ret < 0) {

View File

@ -87,8 +87,9 @@ int Playthrough_Repeat(std::unordered_map<RandomizerSettingKey, uint8_t> cvarSet
printf("\x1b[0;0HGENERATING %d SEEDS", count); printf("\x1b[0;0HGENERATING %d SEEDS", count);
uint32_t repeatedSeed = 0; uint32_t repeatedSeed = 0;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
repeatedSeed = rand() % 0xFFFFFFFF; Settings::seedString = std::to_string(rand() % 0xFFFFFFFF);
Settings::seed = repeatedSeed; repeatedSeed = boost::hash_32<std::string>{}(Settings::seedString);
Settings::seed = repeatedSeed % 0xFFFFFFFF;
CitraPrint("testing seed: " + std::to_string(Settings::seed)); CitraPrint("testing seed: " + std::to_string(Settings::seed));
ClearProgress(); ClearProgress();
Playthrough_Init(Settings::seed, cvarSettings, excludedLocations); Playthrough_Init(Settings::seed, cvarSettings, excludedLocations);

View File

@ -3192,7 +3192,7 @@ void DrawRandoEditor(bool& open) {
UIWidgets::Spacer(0); UIWidgets::Spacer(0);
if (ImGui::Button("Generate Randomizer")) { if (ImGui::Button("Generate Randomizer")) {
GenerateRandomizer(CVarGetInteger("gRandoManualSeedEntry", 0) ? seedString : std::to_string(rand() & 0xFFFFFFFF).c_str()); GenerateRandomizer(CVarGetInteger("gRandoManualSeedEntry", 0) ? seedString : "");
} }
UIWidgets::Spacer(0); UIWidgets::Spacer(0);

View File

@ -782,6 +782,8 @@ extern "C" void InitOTR() {
} else { } else {
CVarClear("gLetItSnow"); CVarClear("gLetItSnow");
} }
srand(now);
#ifdef ENABLE_CROWD_CONTROL #ifdef ENABLE_CROWD_CONTROL
CrowdControl::Instance = new CrowdControl(); CrowdControl::Instance = new CrowdControl();
CrowdControl::Instance->Init(); CrowdControl::Instance->Init();