Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion soh/soh/Enhancements/Graphics/AgeDependentEquipment.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 0 additions & 5 deletions soh/soh/Enhancements/randomizer/3drando/random.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#include "random.hpp"

#include <bit>
#include <random>
#include <cassert>

static bool init = false;
uint64_t rando_state = 0;
const uint64_t multiplier = 6364136223846793005ULL;
const uint64_t increment = 11634580027462260723ULL;
Expand Down
7 changes: 2 additions & 5 deletions soh/soh/Extractor/Extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Extract.h"
#include "portable-file-dialogs.h"
#include <ship/utils/binarytools/BitConverter.h>
#include "soh/ShipUtils.h"
#include "variables.h"

#ifdef unix
Expand Down Expand Up @@ -46,7 +47,6 @@
#include <fstream>
#include <filesystem>
#include <unordered_map>
#include <random>
#include <string>

extern "C" uint32_t CRC32C(unsigned char* data, size_t dataSize);
Expand Down Expand Up @@ -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';

Expand Down
17 changes: 8 additions & 9 deletions soh/soh/ShipUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<uint64_t>(std::random_device{}());
uint64_t seed = static_cast<uint64_t>(std::random_device{}());
#else
uint64_t seed = static_cast<uint64_t>(rand());
uint64_t seed = static_cast<uint64_t>(rand());
#endif
ShipUtils::RandInit(seed, state);
default_init = true;
ShipUtils::RandInit(seed, state);
}
}

*state = *state * multiplier + increment;
Expand Down
2 changes: 0 additions & 2 deletions soh/soh/SohGui/UIWidgets.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "UIWidgets.hpp"
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h>
#include <sstream>
#include <libultraship/libultraship.h>
#include <string>
#include <random>
#include <math.h>
#include <unordered_map>
#include <libultraship/libultra/types.h>
Expand Down
Loading