diff --git a/soh/soh/Enhancements/Graphics/AgeDependentEquipment.cpp b/soh/soh/Enhancements/Graphics/AgeDependentEquipment.cpp index e8b0d127043..7dbe81a5d86 100644 --- a/soh/soh/Enhancements/Graphics/AgeDependentEquipment.cpp +++ b/soh/soh/Enhancements/Graphics/AgeDependentEquipment.cpp @@ -1,9 +1,9 @@ #include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" #include "soh/ShipInit.hpp" +#include "soh/ResourceManagerHelpers.h" extern "C" { #include "macros.h" -#include "soh/ResourceManagerHelpers.h" #include "objects/object_link_boy/object_link_boy.h" #include "objects/object_link_child/object_link_child.h" extern SaveContext gSaveContext; diff --git a/soh/soh/Enhancements/randomizer/3drando/random.cpp b/soh/soh/Enhancements/randomizer/3drando/random.cpp index 257fa0c1289..73b97f6b642 100644 --- a/soh/soh/Enhancements/randomizer/3drando/random.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/random.cpp @@ -1,10 +1,5 @@ #include "random.hpp" -#include -#include -#include - -static bool init = false; uint64_t rando_state = 0; const uint64_t multiplier = 6364136223846793005ULL; const uint64_t increment = 11634580027462260723ULL; diff --git a/soh/soh/Extractor/Extract.cpp b/soh/soh/Extractor/Extract.cpp index 558a3f74d79..024edda43b2 100644 --- a/soh/soh/Extractor/Extract.cpp +++ b/soh/soh/Extractor/Extract.cpp @@ -7,6 +7,7 @@ #include "Extract.h" #include "portable-file-dialogs.h" #include +#include "soh/ShipUtils.h" #include "variables.h" #ifdef unix @@ -46,7 +47,6 @@ #include #include #include -#include #include extern "C" uint32_t CRC32C(unsigned char* data, size_t dataSize); @@ -619,13 +619,10 @@ std::string Extractor::Mkdtemp() { // create 6 random alphanumeric characters static const char charset[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dist(0, sizeof(charset) - 1); char randchr[7]; for (int i = 0; i < 6; i++) { - randchr[i] = charset[dist(gen)]; + randchr[i] = charset[ShipUtils::Random(0, sizeof(charset))]; } randchr[6] = '\0'; diff --git a/soh/soh/ShipUtils.cpp b/soh/soh/ShipUtils.cpp index 9fd4d1be619..b11b6ef8ca7 100644 --- a/soh/soh/ShipUtils.cpp +++ b/soh/soh/ShipUtils.cpp @@ -98,14 +98,13 @@ extern "C" void* Ship_GetCharFontTexture(u8 character) { return (void*)fontTbl[adjustedChar]; } -static bool rand_init = false; +static bool default_init = false; uint64_t default_state = 0; const uint64_t multiplier = 6364136223846793005ULL; const uint64_t increment = 11634580027462260723ULL; // Initialize with seed specified void ShipUtils::RandInit(uint64_t seed, uint64_t* state) { - rand_init = true; if (state == nullptr) { state = &default_state; } @@ -115,16 +114,16 @@ void ShipUtils::RandInit(uint64_t seed, uint64_t* state) { uint32_t ShipUtils::next32(uint64_t* state) { if (state == nullptr) { state = &default_state; - } - - if (!rand_init) { - // No seed given, get a random number from device to seed + if (!default_init) { + // No seed given, get a random number from device to seed #if !defined(__SWITCH__) && !defined(__WIIU__) - uint64_t seed = static_cast(std::random_device{}()); + uint64_t seed = static_cast(std::random_device{}()); #else - uint64_t seed = static_cast(rand()); + uint64_t seed = static_cast(rand()); #endif - ShipUtils::RandInit(seed, state); + default_init = true; + ShipUtils::RandInit(seed, state); + } } *state = *state * multiplier + increment; diff --git a/soh/soh/SohGui/UIWidgets.cpp b/soh/soh/SohGui/UIWidgets.cpp index 3fedea85d81..e338344b0f8 100644 --- a/soh/soh/SohGui/UIWidgets.cpp +++ b/soh/soh/SohGui/UIWidgets.cpp @@ -1,10 +1,8 @@ #include "UIWidgets.hpp" #define IMGUI_DEFINE_MATH_OPERATORS #include -#include #include #include -#include #include #include #include