Add NXDK (Xbox) support

This commit is contained in:
ReenigneArcher
2026-04-04 22:38:08 -04:00
committed by Cameron Gutman
parent 2600beaf13
commit 40d87314d0
7 changed files with 65 additions and 42 deletions
+34 -17
View File
@@ -1,6 +1,6 @@
#pragma once
#ifdef _WIN32
#if defined(_WIN32) && !defined(NXDK)
// Prevent bogus definitions of error codes
// that are incompatible with Winsock errors.
#define _CRT_NO_POSIX_ERROR_CODES
@@ -13,11 +13,23 @@
#include <string.h>
#include <stdint.h>
#ifdef _WIN32
#if defined(_WIN32) && !defined(NXDK)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#elif defined(NXDK)
// nxdk exposes Win32-style threading primitives, but its network stack is
// lwIP with POSIX/BSD socket compatibility headers. Pull in the socket-facing
// headers from the POSIX side so moonlight-common-c uses the Unix backend.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <fcntl.h>
#elif defined(__APPLE__)
#include <mach/mach_time.h>
#include <unistd.h>
@@ -64,15 +76,19 @@
#endif
#ifdef LC_WINDOWS
# if !defined(NXDK)
// Windows doesn't have strtok_r() but it has the same
// function named strtok_s().
#define strtok_r strtok_s
# endif
# if defined(WINAPI_FAMILY) && WINAPI_FAMILY==WINAPI_FAMILY_APP
# define LC_UWP
# else
# define LC_WINDOWS_DESKTOP
#endif
# if !defined(NXDK)
# if defined(WINAPI_FAMILY) && WINAPI_FAMILY==WINAPI_FAMILY_APP
# define LC_UWP
# else
# define LC_WINDOWS_DESKTOP
# endif
# endif
#endif
@@ -83,7 +99,7 @@
if (ListenerCallbacks.logMessage) \
ListenerCallbacks.logMessage(s, ##__VA_ARGS__)
#if defined(LC_WINDOWS)
#if defined(LC_WINDOWS) && !defined(__clang__)
#include <crtdbg.h>
#ifdef LC_DEBUG
#define LC_ASSERT(x) __analysis_assume(x); \
@@ -116,21 +132,22 @@
#define LC_ASSERT_VT(x) LC_ASSERT(x)
#endif
#ifdef _MSC_VER
#if defined(__has_builtin) && __has_builtin(__builtin_bswap16)
#define LC_HAS_BUILTIN_BSWAP
#endif
#if defined(LC_HAS_BUILTIN_BSWAP) || \
(defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
#define BSWAP16(x) __builtin_bswap16(x)
#define BSWAP32(x) __builtin_bswap32(x)
#define BSWAP64(x) __builtin_bswap64(x)
#elif defined(_MSC_VER)
#pragma intrinsic(_byteswap_ushort)
#define BSWAP16(x) _byteswap_ushort(x)
#pragma intrinsic(_byteswap_ulong)
#define BSWAP32(x) _byteswap_ulong(x)
#pragma intrinsic(_byteswap_uint64)
#define BSWAP64(x) _byteswap_uint64(x)
#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
#define BSWAP16(x) __builtin_bswap16(x)
#define BSWAP32(x) __builtin_bswap32(x)
#define BSWAP64(x) __builtin_bswap64(x)
#elif defined(__has_builtin) && __has_builtin(__builtin_bswap16)
#define BSWAP16(x) __builtin_bswap16(x)
#define BSWAP32(x) __builtin_bswap32(x)
#define BSWAP64(x) __builtin_bswap64(x)
#else
#error Please define your platform byteswap macros!
#endif