mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-12-29 11:06:07 +00:00
core: Implement sceRandomGetRandomNumber (#350)
This commit is contained in:
parent
a7f2f09a44
commit
0fe766db6c
|
@ -222,6 +222,10 @@ set(PLAYGO_LIB src/core/libraries/playgo/playgo.cpp
|
|||
src/core/libraries/playgo/playgo_types.h
|
||||
)
|
||||
|
||||
set(RANDOM_LIB src/core/libraries/random/random.cpp
|
||||
src/core/libraries/random/random.h
|
||||
)
|
||||
|
||||
set(USBD_LIB src/core/libraries/usbd/usbd.cpp
|
||||
src/core/libraries/usbd/usbd.h
|
||||
)
|
||||
|
@ -334,6 +338,7 @@ set(CORE src/core/aerolib/stubs.cpp
|
|||
${NP_LIBS}
|
||||
${PNG_LIB}
|
||||
${PLAYGO_LIB}
|
||||
${RANDOM_LIB}
|
||||
${USBD_LIB}
|
||||
${MISC_LIBS}
|
||||
${DIALOGS_LIB}
|
||||
|
|
|
@ -73,6 +73,7 @@ enum class Class : u8 {
|
|||
Lib_DiscMap, ///< The LibSceDiscMap implementation.
|
||||
Lib_Png, ///< The LibScePng implementation.
|
||||
Lib_PlayGo, ///< The LibScePlayGo implementation.
|
||||
Lib_Random, ///< The libSceRandom implementation.
|
||||
Lib_Usbd, ///< The LibSceUsbd implementation.
|
||||
Lib_Ajm, ///< The LibSceAjm implementation.
|
||||
Lib_ErrorDialog, ///< The LibSceErrorDialog implementation.
|
||||
|
|
|
@ -233,6 +233,9 @@ constexpr int SCE_KERNEL_ERROR_ESDKVERSION = 0x80020063;
|
|||
constexpr int SCE_KERNEL_ERROR_ESTART = 0x80020064;
|
||||
constexpr int SCE_KERNEL_ERROR_ESTOP = 0x80020065;
|
||||
|
||||
// libSceRandom error codes
|
||||
constexpr int SCE_RANDOM_ERROR_INVALID = 0x817C0016;
|
||||
|
||||
// videoOut
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; // invalid argument
|
||||
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002; // invalid addresses
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "core/libraries/np_trophy/np_trophy.h"
|
||||
#include "core/libraries/pad/pad.h"
|
||||
#include "core/libraries/playgo/playgo.h"
|
||||
#include "core/libraries/random/random.h"
|
||||
#include "core/libraries/rtc/rtc.h"
|
||||
#include "core/libraries/save_data/savedata.h"
|
||||
#include "core/libraries/screenshot/screenshot.h"
|
||||
|
@ -71,6 +72,7 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) {
|
|||
Libraries::AppContent::RegisterlibSceAppContent(sym);
|
||||
Libraries::PngDec::RegisterlibScePngDec(sym);
|
||||
Libraries::PlayGo::RegisterlibScePlayGo(sym);
|
||||
Libraries::Random::RegisterlibSceRandom(sym);
|
||||
Libraries::Usbd::RegisterlibSceUsbd(sym);
|
||||
Libraries::Pad::RegisterlibScePad(sym);
|
||||
Libraries::Ajm::RegisterlibSceAjm(sym);
|
||||
|
|
27
src/core/libraries/random/random.cpp
Normal file
27
src/core/libraries/random/random.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/logging/log.h"
|
||||
#include "core/libraries/error_codes.h"
|
||||
#include "core/libraries/libs.h"
|
||||
#include "random.h"
|
||||
|
||||
namespace Libraries::Random {
|
||||
|
||||
s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, size_t size) {
|
||||
LOG_TRACE(Lib_Random, "called");
|
||||
if (size > SCE_RANDOM_MAX_SIZE) {
|
||||
return SCE_RANDOM_ERROR_INVALID;
|
||||
}
|
||||
|
||||
for (auto i = 0; i < size; ++i) {
|
||||
buf[i] = std::rand() & 0xFF;
|
||||
}
|
||||
return ORBIS_OK;
|
||||
}
|
||||
|
||||
void RegisterlibSceRandom(Core::Loader::SymbolsResolver* sym) {
|
||||
LIB_FUNCTION("PI7jIZj4pcE", "libSceRandom", 1, "libSceRandom", 1, 1, sceRandomGetRandomNumber);
|
||||
};
|
||||
|
||||
} // namespace Libraries::Random
|
17
src/core/libraries/random/random.h
Normal file
17
src/core/libraries/random/random.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
#include "common/types.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
}
|
||||
|
||||
namespace Libraries::Random {
|
||||
constexpr int32_t SCE_RANDOM_MAX_SIZE = 64;
|
||||
|
||||
s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, size_t size);
|
||||
|
||||
void RegisterlibSceRandom(Core::Loader::SymbolsResolver* sym);
|
||||
} // namespace Libraries::Random
|
Loading…
Reference in a new issue