mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-10 05:28:56 +02:00
[common] unify std::random_device (#3801)
Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3801 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
dd91b41a78
commit
ee2891c55e
18 changed files with 85 additions and 66 deletions
|
|
@ -134,6 +134,8 @@ add_library(
|
||||||
typed_address.h
|
typed_address.h
|
||||||
uint128.h
|
uint128.h
|
||||||
unique_function.h
|
unique_function.h
|
||||||
|
random.cpp
|
||||||
|
random.h
|
||||||
uuid.cpp
|
uuid.cpp
|
||||||
uuid.h
|
uuid.h
|
||||||
vector_math.h
|
vector_math.h
|
||||||
|
|
|
||||||
19
src/common/random.cpp
Normal file
19
src/common/random.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
#include "common/random.h"
|
||||||
|
|
||||||
|
static std::random_device g_random_device;
|
||||||
|
|
||||||
|
namespace Common::Random {
|
||||||
|
[[nodiscard]] u32 Random32(u32 seed) noexcept {
|
||||||
|
return g_random_device();
|
||||||
|
}
|
||||||
|
[[nodiscard]] u64 Random64(u64 seed) noexcept {
|
||||||
|
return g_random_device();
|
||||||
|
}
|
||||||
|
[[nodiscard]] std::mt19937 GetMT19937() noexcept {
|
||||||
|
return std::mt19937(g_random_device());
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/common/random.h
Normal file
13
src/common/random.h
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
namespace Common::Random {
|
||||||
|
[[nodiscard]] u32 Random32(u32 seed) noexcept;
|
||||||
|
[[nodiscard]] u64 Random64(u64 seed) noexcept;
|
||||||
|
[[nodiscard]] std::mt19937 GetMT19937() noexcept;
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
|
|
@ -218,12 +218,6 @@ public:
|
||||||
return t0;
|
return t0;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 GenerateRandomU64() {
|
|
||||||
const u32 lo = this->GenerateRandomU32();
|
|
||||||
const u32 hi = this->GenerateRandomU32();
|
|
||||||
return (u64{hi} << 32) | u64{lo};
|
|
||||||
}
|
|
||||||
|
|
||||||
float GenerateRandomF32() {
|
float GenerateRandomF32() {
|
||||||
// Floats have 24 bits of mantissa.
|
// Floats have 24 bits of mantissa.
|
||||||
constexpr u32 MantissaBits = 24;
|
constexpr u32 MantissaBits = 24;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
|
@ -10,6 +13,7 @@
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/tiny_mt.h"
|
#include "common/tiny_mt.h"
|
||||||
#include "common/uuid.h"
|
#include "common/uuid.h"
|
||||||
|
#include "common/random.h"
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
|
|
@ -175,21 +179,16 @@ u128 UUID::AsU128() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID UUID::MakeRandom() {
|
UUID UUID::MakeRandom() {
|
||||||
std::random_device device;
|
return MakeRandomWithSeed(Common::Random::Random32(0));
|
||||||
|
|
||||||
return MakeRandomWithSeed(device());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID UUID::MakeRandomWithSeed(u32 seed) {
|
UUID UUID::MakeRandomWithSeed(u32 seed) {
|
||||||
// Create and initialize our RNG.
|
// Create and initialize our RNG.
|
||||||
TinyMT rng;
|
TinyMT rng;
|
||||||
rng.Initialize(seed);
|
rng.Initialize(seed);
|
||||||
|
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
|
|
||||||
// Populate the UUID with random bytes.
|
// Populate the UUID with random bytes.
|
||||||
rng.GenerateRandomBytes(uuid.uuid.data(), sizeof(UUID));
|
rng.GenerateRandomBytes(uuid.uuid.data(), sizeof(UUID));
|
||||||
|
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include "common/fs/path_util.h"
|
#include "common/fs/path_util.h"
|
||||||
#include "common/hex_util.h"
|
#include "common/hex_util.h"
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
#include "core/crypto/key_manager.h"
|
#include "core/crypto/key_manager.h"
|
||||||
#include "core/file_sys/card_image.h"
|
#include "core/file_sys/card_image.h"
|
||||||
|
|
@ -490,17 +491,13 @@ std::vector<NcaID> PlaceholderCache::List() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
NcaID PlaceholderCache::Generate() {
|
NcaID PlaceholderCache::Generate() {
|
||||||
std::random_device device;
|
auto gen = Common::Random::GetMT19937();
|
||||||
std::mt19937 gen(device());
|
|
||||||
std::uniform_int_distribution<u64> distribution(1, (std::numeric_limits<u64>::max)());
|
std::uniform_int_distribution<u64> distribution(1, (std::numeric_limits<u64>::max)());
|
||||||
|
|
||||||
NcaID out{};
|
NcaID out{};
|
||||||
|
|
||||||
const auto v1 = distribution(gen);
|
const auto v1 = distribution(gen);
|
||||||
const auto v2 = distribution(gen);
|
const auto v2 = distribution(gen);
|
||||||
std::memcpy(out.data(), &v1, sizeof(u64));
|
std::memcpy(out.data(), &v1, sizeof(u64));
|
||||||
std::memcpy(out.data() + sizeof(u64), &v2, sizeof(u64));
|
std::memcpy(out.data() + sizeof(u64), &v2, sizeof(u64));
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
#include "common/literals.h"
|
#include "common/literals.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
|
|
||||||
#include "core/hle/kernel/board/nintendo/nx/k_system_control.h"
|
#include "core/hle/kernel/board/nintendo/nx/k_system_control.h"
|
||||||
|
|
@ -201,15 +202,8 @@ u64 GenerateUniformRange(u64 min, u64 max, F f) {
|
||||||
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
u64 KSystemControl::GenerateRandomU64() {
|
|
||||||
std::random_device device;
|
|
||||||
std::mt19937 gen(device());
|
|
||||||
std::uniform_int_distribution<u64> distribution(1, (std::numeric_limits<u64>::max)());
|
|
||||||
return distribution(gen);
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 KSystemControl::GenerateRandomRange(u64 min, u64 max) {
|
u64 KSystemControl::GenerateRandomRange(u64 min, u64 max) {
|
||||||
return GenerateUniformRange(min, max, GenerateRandomU64);
|
return GenerateUniformRange(min, max, Common::Random::GetMT19937());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t KSystemControl::CalculateRequiredSecureMemorySize(size_t size, u32 pool) {
|
size_t KSystemControl::CalculateRequiredSecureMemorySize(size_t size, u32 pool) {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
|
@ -33,7 +36,6 @@ public:
|
||||||
|
|
||||||
// Randomness.
|
// Randomness.
|
||||||
static u64 GenerateRandomRange(u64 min, u64 max);
|
static u64 GenerateRandomRange(u64 min, u64 max);
|
||||||
static u64 GenerateRandomU64();
|
|
||||||
|
|
||||||
// Secure Memory.
|
// Secure Memory.
|
||||||
static size_t CalculateRequiredSecureMemorySize(size_t size, u32 pool);
|
static size_t CalculateRequiredSecureMemorySize(size_t size, u32 pool);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include "common/bit_util.h"
|
#include "common/bit_util.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/tiny_mt.h"
|
#include "common/tiny_mt.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "core/hle/kernel/k_system_control.h"
|
#include "core/hle/kernel/k_system_control.h"
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
@ -23,7 +24,7 @@ public:
|
||||||
class RandomBitGenerator {
|
class RandomBitGenerator {
|
||||||
public:
|
public:
|
||||||
RandomBitGenerator() {
|
RandomBitGenerator() {
|
||||||
m_rng.Initialize(static_cast<u32>(KSystemControl::GenerateRandomU64()));
|
m_rng.Initialize(u32(Common::Random::Random64(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 SelectRandomBit(u64 bitmap) {
|
u64 SelectRandomBit(u64 bitmap) {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
#include "common/fiber.h"
|
#include "common/fiber.h"
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/cpu_manager.h"
|
#include "core/cpu_manager.h"
|
||||||
#include "core/hardware_properties.h"
|
#include "core/hardware_properties.h"
|
||||||
|
|
@ -45,8 +46,7 @@ namespace {
|
||||||
|
|
||||||
constexpr inline s32 TerminatingThreadPriority = Kernel::Svc::SystemThreadPriorityHighest - 1;
|
constexpr inline s32 TerminatingThreadPriority = Kernel::Svc::SystemThreadPriorityHighest - 1;
|
||||||
|
|
||||||
static void ResetThreadContext32(Kernel::Svc::ThreadContext& ctx, u64 stack_top, u64 entry_point,
|
static void ResetThreadContext32(Kernel::Svc::ThreadContext& ctx, u64 stack_top, u64 entry_point, u64 arg) {
|
||||||
u64 arg) {
|
|
||||||
ctx = {};
|
ctx = {};
|
||||||
ctx.r[0] = arg;
|
ctx.r[0] = arg;
|
||||||
ctx.r[15] = entry_point;
|
ctx.r[15] = entry_point;
|
||||||
|
|
@ -55,11 +55,10 @@ static void ResetThreadContext32(Kernel::Svc::ThreadContext& ctx, u64 stack_top,
|
||||||
ctx.fpsr = 0;
|
ctx.fpsr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResetThreadContext64(Kernel::Svc::ThreadContext& ctx, u64 stack_top, u64 entry_point,
|
static void ResetThreadContext64(Kernel::Svc::ThreadContext& ctx, u64 stack_top, u64 entry_point, u64 arg) {
|
||||||
u64 arg) {
|
|
||||||
ctx = {};
|
ctx = {};
|
||||||
ctx.r[0] = arg;
|
ctx.r[0] = arg;
|
||||||
ctx.r[18] = Kernel::KSystemControl::GenerateRandomU64() | 1;
|
ctx.r[18] = Common::Random::Random64(0) | 1;
|
||||||
ctx.pc = entry_point;
|
ctx.pc = entry_point;
|
||||||
ctx.sp = stack_top;
|
ctx.sp = stack_top;
|
||||||
ctx.fpcr = 0;
|
ctx.fpcr = 0;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
|
@ -7,6 +10,7 @@
|
||||||
#include <span>
|
#include <span>
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
#include "common/uuid.h"
|
#include "common/uuid.h"
|
||||||
#include "core/hle/service/mii/mii_types.h"
|
#include "core/hle/service/mii/mii_types.h"
|
||||||
|
|
@ -65,11 +69,9 @@ public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static T GetRandomValue(T min, T max) {
|
static T GetRandomValue(T min, T max) {
|
||||||
std::random_device device;
|
std::uniform_int_distribution<u64> distribution{u64(min), u64(max)};
|
||||||
std::mt19937 gen(device());
|
auto gen = Common::Random::GetMT19937();
|
||||||
std::uniform_int_distribution<u64> distribution(static_cast<u64>(min),
|
return T(distribution(gen));
|
||||||
static_cast<u64>(max));
|
|
||||||
return static_cast<T>(distribution(gen));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/file_sys/content_archive.h"
|
#include "core/file_sys/content_archive.h"
|
||||||
|
|
@ -229,7 +230,7 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
|
||||||
// TODO: this is bad form of ASLR, it sucks
|
// TODO: this is bad form of ASLR, it sucks
|
||||||
size_t aslr_offset = ((::Settings::values.rng_seed_enabled.GetValue()
|
size_t aslr_offset = ((::Settings::values.rng_seed_enabled.GetValue()
|
||||||
? ::Settings::values.rng_seed.GetValue()
|
? ::Settings::values.rng_seed.GetValue()
|
||||||
: std::rand()) * 0x734287f27) & 0xfff000;
|
: Common::Random::Random64(0)) * 0x734287f27) & 0xfff000;
|
||||||
|
|
||||||
// Setup the process code layout
|
// Setup the process code layout
|
||||||
if (process.LoadFromMetadata(metadata, code_size, fastmem_base, aslr_offset, is_hbl).IsError()) {
|
if (process.LoadFromMetadata(metadata, code_size, fastmem_base, aslr_offset, is_hbl).IsError()) {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "core/file_sys/kernel_executable.h"
|
#include "core/file_sys/kernel_executable.h"
|
||||||
#include "core/file_sys/program_metadata.h"
|
#include "core/file_sys/program_metadata.h"
|
||||||
#include "core/hle/kernel/code_set.h"
|
#include "core/hle/kernel/code_set.h"
|
||||||
|
|
@ -90,7 +91,7 @@ AppLoader::LoadResult AppLoader_KIP::Load(Kernel::KProcess& process,
|
||||||
// TODO: this is bad form of ASLR, it sucks
|
// TODO: this is bad form of ASLR, it sucks
|
||||||
size_t aslr_offset = ((::Settings::values.rng_seed_enabled.GetValue()
|
size_t aslr_offset = ((::Settings::values.rng_seed_enabled.GetValue()
|
||||||
? ::Settings::values.rng_seed.GetValue()
|
? ::Settings::values.rng_seed.GetValue()
|
||||||
: std::rand()) * 0x734287f27) & 0xfff000;
|
: Common::Random::Random64(0)) * 0x734287f27) & 0xfff000;
|
||||||
|
|
||||||
// Setup the process code layout
|
// Setup the process code layout
|
||||||
if (process.LoadFromMetadata(FileSys::ProgramMetadata::GetDefault(), codeset.memory.size(), 0, aslr_offset, false).IsError()) {
|
if (process.LoadFromMetadata(FileSys::ProgramMetadata::GetDefault(), codeset.memory.size(), 0, aslr_offset, false).IsError()) {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/file_sys/control_metadata.h"
|
#include "core/file_sys/control_metadata.h"
|
||||||
|
|
@ -243,7 +244,7 @@ static bool LoadNroImpl(Core::System& system, Kernel::KProcess& process,
|
||||||
// TODO: this is bad form of ASLR, it sucks
|
// TODO: this is bad form of ASLR, it sucks
|
||||||
size_t aslr_offset = ((::Settings::values.rng_seed_enabled.GetValue()
|
size_t aslr_offset = ((::Settings::values.rng_seed_enabled.GetValue()
|
||||||
? ::Settings::values.rng_seed.GetValue()
|
? ::Settings::values.rng_seed.GetValue()
|
||||||
: std::rand()) * 0x734287f27) & 0xfff000;
|
: Common::Random::Random64(0)) * 0x734287f27) & 0xfff000;
|
||||||
|
|
||||||
// Setup the process code layout
|
// Setup the process code layout
|
||||||
if (process
|
if (process
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,21 @@
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <frozen/string.h>
|
#include <frozen/string.h>
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "settings_generator.h"
|
#include "settings_generator.h"
|
||||||
|
|
||||||
namespace FrontendCommon {
|
namespace FrontendCommon {
|
||||||
|
|
||||||
void GenerateSettings() {
|
void GenerateSettings() {
|
||||||
static std::random_device rd;
|
auto gen = Common::Random::GetMT19937();
|
||||||
|
|
||||||
// Web Token
|
// Web Token
|
||||||
if (Settings::values.eden_token.GetValue().empty()) {
|
if (Settings::values.eden_token.GetValue().empty()) {
|
||||||
static constexpr const size_t token_length = 48;
|
static constexpr const size_t token_length = 48;
|
||||||
static constexpr const frozen::string token_set = "abcdefghijklmnopqrstuvwxyz";
|
static constexpr const frozen::string token_set = "abcdefghijklmnopqrstuvwxyz";
|
||||||
static std::uniform_int_distribution<int> token_dist(0, token_set.size() - 1);
|
static std::uniform_int_distribution<int> token_dist(0, token_set.size() - 1);
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
for (size_t i = 0; i < token_length; ++i) {
|
for (size_t i = 0; i < token_length; ++i) {
|
||||||
size_t idx = token_dist(rd);
|
size_t idx = token_dist(gen);
|
||||||
result += token_set[idx];
|
result += token_set[idx];
|
||||||
}
|
}
|
||||||
Settings::values.eden_token.SetValue(result);
|
Settings::values.eden_token.SetValue(result);
|
||||||
|
|
@ -27,8 +26,6 @@ void GenerateSettings() {
|
||||||
|
|
||||||
// Randomly generated number because, well, we fill the rest automagically ;)
|
// Randomly generated number because, well, we fill the rest automagically ;)
|
||||||
// Other serial parts are filled by Region_Index
|
// Other serial parts are filled by Region_Index
|
||||||
std::random_device device;
|
|
||||||
std::mt19937 gen(device());
|
|
||||||
std::uniform_int_distribution<u32> distribution(1, (std::numeric_limits<u32>::max)());
|
std::uniform_int_distribution<u32> distribution(1, (std::numeric_limits<u32>::max)());
|
||||||
if (Settings::values.serial_unit.GetValue() == 0)
|
if (Settings::values.serial_unit.GetValue() == 0)
|
||||||
Settings::values.serial_unit.SetValue(distribution(gen));
|
Settings::values.serial_unit.SetValue(distribution(gen));
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
|
#include "common/random.h"
|
||||||
#include "common/input.h"
|
#include "common/input.h"
|
||||||
#include "hid_core/frontend/input_converter.h"
|
#include "hid_core/frontend/input_converter.h"
|
||||||
|
|
||||||
|
|
@ -119,15 +123,14 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
|
||||||
.properties = properties,
|
.properties = properties,
|
||||||
};
|
};
|
||||||
if (TransformToButton(callback).value) {
|
if (TransformToButton(callback).value) {
|
||||||
std::random_device device;
|
|
||||||
std::mt19937 gen(device());
|
|
||||||
std::uniform_int_distribution<s16> distribution(-5000, 5000);
|
std::uniform_int_distribution<s16> distribution(-5000, 5000);
|
||||||
status.accel.x.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
|
auto gen = Common::Random::GetMT19937();
|
||||||
status.accel.y.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
|
status.accel.x.raw_value = f32(distribution(gen)) * 0.001f;
|
||||||
status.accel.z.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
|
status.accel.y.raw_value = f32(distribution(gen)) * 0.001f;
|
||||||
status.gyro.x.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
|
status.accel.z.raw_value = f32(distribution(gen)) * 0.001f;
|
||||||
status.gyro.y.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
|
status.gyro.x.raw_value = f32(distribution(gen)) * 0.001f;
|
||||||
status.gyro.z.raw_value = static_cast<f32>(distribution(gen)) * 0.001f;
|
status.gyro.y.raw_value = f32(distribution(gen)) * 0.001f;
|
||||||
|
status.gyro.z.raw_value = f32(distribution(gen)) * 0.001f;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
#include "common/param_package.h"
|
#include "common/param_package.h"
|
||||||
|
#include "common/random.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "input_common/drivers/udp_client.h"
|
#include "input_common/drivers/udp_client.h"
|
||||||
#include "input_common/helpers/udp_protocol.h"
|
#include "input_common/helpers/udp_protocol.h"
|
||||||
|
|
@ -31,7 +32,7 @@ public:
|
||||||
|
|
||||||
explicit Socket(const std::string& host, u16 port, SocketCallback callback_)
|
explicit Socket(const std::string& host, u16 port, SocketCallback callback_)
|
||||||
: callback(std::move(callback_)), timer(io_context),
|
: callback(std::move(callback_)), timer(io_context),
|
||||||
socket(io_context, udp::endpoint(udp::v4(), 0)), client_id(GenerateRandomClientId()) {
|
socket(io_context, udp::endpoint(udp::v4(), 0)), client_id(Common::Random::Random32(0)) {
|
||||||
boost::system::error_code ec{};
|
boost::system::error_code ec{};
|
||||||
auto ipv4 = boost::asio::ip::make_address_v4(host, ec);
|
auto ipv4 = boost::asio::ip::make_address_v4(host, ec);
|
||||||
if (ec.value() != boost::system::errc::success) {
|
if (ec.value() != boost::system::errc::success) {
|
||||||
|
|
@ -64,11 +65,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u32 GenerateRandomClientId() const {
|
|
||||||
std::random_device device;
|
|
||||||
return device();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleReceive(const boost::system::error_code&, std::size_t bytes_transferred) {
|
void HandleReceive(const boost::system::error_code&, std::size_t bytes_transferred) {
|
||||||
if (auto type = Response::Validate(receive_buffer.data(), bytes_transferred)) {
|
if (auto type = Response::Validate(receive_buffer.data(), bytes_transferred)) {
|
||||||
switch (*type) {
|
switch (*type) {
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@ namespace Network {
|
||||||
|
|
||||||
class Room::RoomImpl {
|
class Room::RoomImpl {
|
||||||
public:
|
public:
|
||||||
std::mt19937 random_gen; ///< Random number generator. Used for GenerateFakeIPAddress
|
|
||||||
|
|
||||||
ENetHost* server = nullptr; ///< Network interface.
|
ENetHost* server = nullptr; ///< Network interface.
|
||||||
|
|
||||||
std::atomic<State> state{State::Closed}; ///< Current state of the room.
|
std::atomic<State> state{State::Closed}; ///< Current state of the room.
|
||||||
|
|
@ -51,7 +49,7 @@ public:
|
||||||
IPBanList ip_ban_list; ///< List of banned IP addresses
|
IPBanList ip_ban_list; ///< List of banned IP addresses
|
||||||
mutable std::mutex ban_list_mutex; ///< Mutex for the ban lists
|
mutable std::mutex ban_list_mutex; ///< Mutex for the ban lists
|
||||||
|
|
||||||
RoomImpl() : random_gen(std::random_device()()) {}
|
RoomImpl() {}
|
||||||
|
|
||||||
/// Thread that receives and dispatches network packets
|
/// Thread that receives and dispatches network packets
|
||||||
std::optional<std::jthread> room_thread;
|
std::optional<std::jthread> room_thread;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue