Browse Source
Also includes a few manual tweaks to comments and newlines for better results. Co-authored-by: Anders Jenbo <anders@jenbo.dk>pull/3607/head
111 changed files with 486 additions and 464 deletions
@ -1,29 +1,30 @@
|
||||
#include <3ds.h> |
||||
#include <SDL.h> |
||||
#include <fmt/core.h> |
||||
#include "utils/sdl2_to_1_2_backports.h" |
||||
|
||||
int SDL_ShowSimpleMessageBox(Uint32 flags, |
||||
const char *title, |
||||
const char *message, |
||||
SDL_Surface *window) |
||||
{ |
||||
if (SDL_ShowCursor(SDL_DISABLE) <= -1) |
||||
SDL_Log("%s", SDL_GetError()); |
||||
|
||||
bool init = !gspHasGpuRight(); |
||||
auto text = fmt::format("{}\n\n{}", title, message); |
||||
|
||||
if (init) |
||||
gfxInitDefault(); |
||||
|
||||
errorConf error; |
||||
errorInit(&error, ERROR_TEXT, CFG_LANGUAGE_EN); |
||||
errorText(&error, text.c_str()); |
||||
errorDisp(&error); |
||||
|
||||
if (init) |
||||
gfxExit(); |
||||
|
||||
return 0; |
||||
} |
||||
#include <3ds.h> |
||||
#include <SDL.h> |
||||
#include <fmt/core.h> |
||||
|
||||
#include "utils/sdl2_to_1_2_backports.h" |
||||
|
||||
int SDL_ShowSimpleMessageBox(Uint32 flags, |
||||
const char *title, |
||||
const char *message, |
||||
SDL_Surface *window) |
||||
{ |
||||
if (SDL_ShowCursor(SDL_DISABLE) <= -1) |
||||
SDL_Log("%s", SDL_GetError()); |
||||
|
||||
bool init = !gspHasGpuRight(); |
||||
auto text = fmt::format("{}\n\n{}", title, message); |
||||
|
||||
if (init) |
||||
gfxInitDefault(); |
||||
|
||||
errorConf error; |
||||
errorInit(&error, ERROR_TEXT, CFG_LANGUAGE_EN); |
||||
errorText(&error, text.c_str()); |
||||
errorDisp(&error); |
||||
|
||||
if (init) |
||||
gfxExit(); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
@ -1,66 +1,70 @@
|
||||
#include <malloc.h> |
||||
#include <3ds.h> |
||||
#include "utils/log.hpp" |
||||
|
||||
namespace devilution { |
||||
|
||||
constexpr auto SOC_ALIGN = 0x1000; |
||||
constexpr auto SOC_BUFFERSIZE = 0x100000; |
||||
static u32 *socBuffer; |
||||
static bool initialized; |
||||
|
||||
static bool waitForWifi() |
||||
{ |
||||
// 100 ms
|
||||
constexpr s64 sleepNano = 100 * 1000 * 1000; |
||||
|
||||
// 5 sec
|
||||
constexpr int loopCount = 5 * 1000 / 100; |
||||
|
||||
uint32_t wifi = 0; |
||||
for (int i = 0; i < loopCount; ++i) { |
||||
if (R_SUCCEEDED(ACU_GetWifiStatus(&wifi)) && wifi) |
||||
return true; |
||||
|
||||
svcSleepThread(sleepNano); |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
void n3ds_socExit() |
||||
{ |
||||
if (socBuffer == nullptr) |
||||
return; |
||||
|
||||
socExit(); |
||||
free(socBuffer); |
||||
socBuffer = nullptr; |
||||
} |
||||
|
||||
void n3ds_socInit() |
||||
{ |
||||
if (!waitForWifi()) { |
||||
LogError("n3ds_socInit: Wifi off"); |
||||
return; |
||||
} |
||||
|
||||
socBuffer = (u32 *)memalign(SOC_ALIGN, SOC_BUFFERSIZE); |
||||
if (socBuffer == nullptr) { |
||||
LogError("n3ds_socInit: memalign() failed"); |
||||
return; |
||||
} |
||||
|
||||
Result result = socInit(socBuffer, SOC_BUFFERSIZE); |
||||
if (!R_SUCCEEDED(result)) { |
||||
LogError("n3ds_socInit: socInit() failed"); |
||||
free(socBuffer); |
||||
return; |
||||
} |
||||
|
||||
if (!initialized) |
||||
atexit([]() { n3ds_socExit(); }); |
||||
initialized = true; |
||||
} |
||||
|
||||
} // namespace devilution
|
||||
#include "platform/ctr/sockets.hpp" |
||||
|
||||
#include <malloc.h> |
||||
|
||||
#include <3ds.h> |
||||
|
||||
#include "utils/log.hpp" |
||||
|
||||
namespace devilution { |
||||
|
||||
constexpr auto SOC_ALIGN = 0x1000; |
||||
constexpr auto SOC_BUFFERSIZE = 0x100000; |
||||
static u32 *socBuffer; |
||||
static bool initialized; |
||||
|
||||
static bool waitForWifi() |
||||
{ |
||||
// 100 ms
|
||||
constexpr s64 sleepNano = 100 * 1000 * 1000; |
||||
|
||||
// 5 sec
|
||||
constexpr int loopCount = 5 * 1000 / 100; |
||||
|
||||
uint32_t wifi = 0; |
||||
for (int i = 0; i < loopCount; ++i) { |
||||
if (R_SUCCEEDED(ACU_GetWifiStatus(&wifi)) && wifi) |
||||
return true; |
||||
|
||||
svcSleepThread(sleepNano); |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
void n3ds_socExit() |
||||
{ |
||||
if (socBuffer == nullptr) |
||||
return; |
||||
|
||||
socExit(); |
||||
free(socBuffer); |
||||
socBuffer = nullptr; |
||||
} |
||||
|
||||
void n3ds_socInit() |
||||
{ |
||||
if (!waitForWifi()) { |
||||
LogError("n3ds_socInit: Wifi off"); |
||||
return; |
||||
} |
||||
|
||||
socBuffer = (u32 *)memalign(SOC_ALIGN, SOC_BUFFERSIZE); |
||||
if (socBuffer == nullptr) { |
||||
LogError("n3ds_socInit: memalign() failed"); |
||||
return; |
||||
} |
||||
|
||||
Result result = socInit(socBuffer, SOC_BUFFERSIZE); |
||||
if (!R_SUCCEEDED(result)) { |
||||
LogError("n3ds_socInit: socInit() failed"); |
||||
free(socBuffer); |
||||
return; |
||||
} |
||||
|
||||
if (!initialized) |
||||
atexit([]() { n3ds_socExit(); }); |
||||
initialized = true; |
||||
} |
||||
|
||||
} // namespace devilution
|
||||
|
||||
@ -1,54 +1,57 @@
|
||||
#include <sys/types.h> |
||||
#include <sodium.h> |
||||
|
||||
extern "C" { |
||||
#include <switch/sf/service.h> |
||||
#include <switch/services/csrng.h> |
||||
} |
||||
|
||||
static const char *randombytes_switchrandom_implementation_name() |
||||
{ |
||||
return "switchrandom"; |
||||
} |
||||
|
||||
static bool randombytes_switchrandom_tryfill(void *const buf, const size_t size) |
||||
{ |
||||
Result res; |
||||
Service *csrngService = csrngGetServiceSession(); |
||||
if (!serviceIsActive(csrngService)) { |
||||
res = csrngInitialize(); |
||||
if (!R_SUCCEEDED(res)) |
||||
return false; |
||||
} |
||||
res = csrngGetRandomBytes(buf, size); |
||||
return R_SUCCEEDED(res); |
||||
} |
||||
|
||||
static uint32_t randombytes_switchrandom() |
||||
{ |
||||
uint32_t num; |
||||
if (!randombytes_switchrandom_tryfill(&num, sizeof(uint32_t))) |
||||
sodium_misuse(); |
||||
return num; |
||||
} |
||||
|
||||
static void randombytes_switchrandom_buf(void *const buf, const size_t size) |
||||
{ |
||||
if (!randombytes_switchrandom_tryfill(buf, size)) |
||||
sodium_misuse(); |
||||
} |
||||
|
||||
struct randombytes_implementation randombytes_switchrandom_implementation = { |
||||
randombytes_switchrandom_implementation_name, |
||||
randombytes_switchrandom, |
||||
nullptr, |
||||
nullptr, |
||||
randombytes_switchrandom_buf, |
||||
nullptr |
||||
}; |
||||
|
||||
void randombytes_switchrandom_init() |
||||
{ |
||||
randombytes_set_implementation(&randombytes_switchrandom_implementation); |
||||
atexit(csrngExit); |
||||
} |
||||
#include "platform/switch/random.hpp" |
||||
|
||||
#include <sys/types.h> |
||||
|
||||
#include <sodium.h> |
||||
|
||||
extern "C" { |
||||
#include <switch/services/csrng.h> |
||||
#include <switch/sf/service.h> |
||||
} |
||||
|
||||
static const char *randombytes_switchrandom_implementation_name() |
||||
{ |
||||
return "switchrandom"; |
||||
} |
||||
|
||||
static bool randombytes_switchrandom_tryfill(void *const buf, const size_t size) |
||||
{ |
||||
Result res; |
||||
Service *csrngService = csrngGetServiceSession(); |
||||
if (!serviceIsActive(csrngService)) { |
||||
res = csrngInitialize(); |
||||
if (!R_SUCCEEDED(res)) |
||||
return false; |
||||
} |
||||
res = csrngGetRandomBytes(buf, size); |
||||
return R_SUCCEEDED(res); |
||||
} |
||||
|
||||
static uint32_t randombytes_switchrandom() |
||||
{ |
||||
uint32_t num; |
||||
if (!randombytes_switchrandom_tryfill(&num, sizeof(uint32_t))) |
||||
sodium_misuse(); |
||||
return num; |
||||
} |
||||
|
||||
static void randombytes_switchrandom_buf(void *const buf, const size_t size) |
||||
{ |
||||
if (!randombytes_switchrandom_tryfill(buf, size)) |
||||
sodium_misuse(); |
||||
} |
||||
|
||||
struct randombytes_implementation randombytes_switchrandom_implementation = { |
||||
randombytes_switchrandom_implementation_name, |
||||
randombytes_switchrandom, |
||||
nullptr, |
||||
nullptr, |
||||
randombytes_switchrandom_buf, |
||||
nullptr |
||||
}; |
||||
|
||||
void randombytes_switchrandom_init() |
||||
{ |
||||
randombytes_set_implementation(&randombytes_switchrandom_implementation); |
||||
atexit(csrngExit); |
||||
} |
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue