diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index dfa73f38e7..044fd464eb 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -208,6 +208,29 @@ endif() # AsmJit add_subdirectory(asmjit EXCLUDE_FROM_ALL) +# SDL3 +set(SDL3_TARGET 3rdparty_dummy_lib) +if(USE_SDL) + if(USE_SYSTEM_SDL) + find_package(SDL3) + if(SDL3_FOUND AND SDL3_VERSION VERSION_GREATER_EQUAL 3.2.0) + message(STATUS "Using system SDL3 version '${SDL3_VERSION}'") + add_library(3rdparty_sdl3 INTERFACE) + target_compile_definitions(3rdparty_sdl3 INTERFACE -DHAVE_SDL3=1) + target_link_libraries(3rdparty_sdl3 INTERFACE SDL3::SDL3) + set(SDL3_TARGET 3rdparty_sdl3) + else() + message(FATAL_ERROR "SDL3 is not available on this system") + endif() + else() + message(STATUS "Using static SDL3 from 3rdparty") + add_subdirectory(libsdl-org EXCLUDE_FROM_ALL) + target_compile_definitions(SDL3-static INTERFACE -DHAVE_SDL3=1) + set(SDL3_TARGET SDL3-static) + set(SDL3_DIR "${CMAKE_CURRENT_BINARY_DIR}/libsdl-org/SDL" CACHE STRING "") + endif() +endif() + # OpenAL if (NOT ANDROID) add_subdirectory(OpenAL EXCLUDE_FROM_ALL) @@ -222,31 +245,31 @@ if(USE_FAUDIO) # FAudio depends on SDL3 find_package(SDL3) if (USE_SYSTEM_FAUDIO) - if (NOT SDL3_FOUND OR SDL3_VERSION VERSION_LESS 3.2.0) - message(WARNING - "RPCS3: System FAudio requires SDL 3.2.0 or newer. Since a valid SDL3" - ">=3.2.0 version cannot be found, building with FAudio will be skipped.") - set(USE_FAUDIO OFF CACHE BOOL "Disabled using system FAudio with SDL < 3.2.0" FORCE) - else() + if (SDL3_FOUND AND SDL3_VERSION VERSION_GREATER_EQUAL 3.2.0) message(STATUS "RPCS3: Using system FAudio") find_package(FAudio REQUIRED CONFIGS FAudioConfig.cmake FAudio-config.cmake) add_library(3rdparty_FAudio INTERFACE) target_link_libraries(3rdparty_FAudio INTERFACE FAudio) target_compile_definitions(3rdparty_FAudio INTERFACE -DHAVE_FAUDIO) set(FAUDIO_TARGET 3rdparty_FAudio) + else() + message(WARNING + "RPCS3: System FAudio requires SDL 3.2.0 or newer. Since a valid SDL3" + ">=3.2.0 version cannot be found, building with FAudio will be skipped.") + set(USE_FAUDIO OFF CACHE BOOL "Disabled using system FAudio with SDL < 3.2.0" FORCE) endif() else() - if (NOT SDL3_FOUND OR SDL3_VERSION VERSION_LESS 3.2.0) - message(WARNING - "-- RPCS3: 3rdparty FAudio requires SDL 3.2.0 or newer. Since a valid SDL3" - ">=3.2.0 version cannot be found, building with FAudio will be skipped.") - set(USE_FAUDIO OFF CACHE BOOL "Disabled FAudio with SDL < 3.2.0" FORCE) - else() + if (SDL3_FOUND AND SDL3_VERSION VERSION_GREATER_EQUAL 3.2.0) message(STATUS "RPCS3: Using builtin FAudio") set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared library") add_subdirectory(FAudio EXCLUDE_FROM_ALL) target_compile_definitions(FAudio-static INTERFACE -DHAVE_FAUDIO) set(FAUDIO_TARGET FAudio-static) + else() + message(FATAL_ERROR + "-- RPCS3: 3rdparty FAudio requires SDL 3.2.0 or newer. Since a valid SDL3" + ">=3.2.0 version cannot be found, building with FAudio will be skipped.") + set(USE_FAUDIO OFF CACHE BOOL "Disabled FAudio with SDL < 3.2.0" FORCE) endif() endif() endif() @@ -315,29 +338,6 @@ add_subdirectory(wolfssl EXCLUDE_FROM_ALL) # CURL add_subdirectory(curl EXCLUDE_FROM_ALL) -# SDL3 -set(SDL3_TARGET 3rdparty_dummy_lib) -if(USE_SDL) - if(USE_SYSTEM_SDL) - find_package(SDL3) - if(SDL3_FOUND AND NOT SDL3_VERSION VERSION_LESS 3.2.0) - message(STATUS "Using system SDL3 version '${SDL3_VERSION}'") - add_library(3rdparty_sdl3 INTERFACE) - target_compile_definitions(3rdparty_sdl3 INTERFACE -DHAVE_SDL3=1) - target_link_libraries(3rdparty_sdl3 INTERFACE SDL3::SDL3) - set(SDL3_TARGET 3rdparty_sdl3) - else() - message(FATAL_ERROR "SDL3 is not available on this system") - endif() - else() - message(STATUS "Using static SDL3 from 3rdparty") - add_library(3rdparty_sdl3 INTERFACE) - target_compile_definitions(3rdparty_sdl3 INTERFACE -DHAVE_SDL3=1) - add_subdirectory(libsdl-org EXCLUDE_FROM_ALL) - set(SDL3_TARGET 3rdparty_sdl3) - endif() -endif() - # MINIUPNP add_subdirectory(miniupnp EXCLUDE_FROM_ALL) diff --git a/3rdparty/libsdl-org/CMakeLists.txt b/3rdparty/libsdl-org/CMakeLists.txt index d6fb6c8890..ba59cec8f7 100644 --- a/3rdparty/libsdl-org/CMakeLists.txt +++ b/3rdparty/libsdl-org/CMakeLists.txt @@ -1,11 +1,4 @@ -option(SDL2_DISABLE_SDL2MAIN "" ON) -option(SDL2_DISABLE_INSTALL "" ON) -option(SDL2_DISABLE_UNINSTALL "" ON) -option(SDL_SHARED OFF) -set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) -option(SDL_STATIC ON) -set(SDL_STATIC_ENABLED_BY_DEFAULT ON) -option(SDL_TEST OFF) -set(SDL_TEST_ENABLED_BY_DEFAULT OFF) -set(OPT_DEF_LIBC ON) +option(SDL_SHARED "Build a shared version of the library" OFF) +option(SDL_STATIC "Build a static version of the library" ON) +option(SDL_TEST_LIBRARY "Build the SDL3_test library" OFF) add_subdirectory(SDL EXCLUDE_FROM_ALL) diff --git a/rpcs3/Emu/Cell/lv2/sys_net/nt_p2p_port.cpp b/rpcs3/Emu/Cell/lv2/sys_net/nt_p2p_port.cpp index cf7441db35..61039c7856 100644 --- a/rpcs3/Emu/Cell/lv2/sys_net/nt_p2p_port.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_net/nt_p2p_port.cpp @@ -75,16 +75,14 @@ nt_p2p_port::nt_p2p_port(u16 port) else { ::sockaddr_in p2p_ipv4_addr{.sin_family = AF_INET, .sin_port = be_port}; - p2p_ipv4_addr.sin_addr.s_addr = nph.get_bind_ip(); + const u32 bind_ip = nph.get_bind_ip(); + p2p_ipv4_addr.sin_addr.s_addr = bind_ip; - if (ret_bind = ::bind(p2p_socket, reinterpret_cast(&p2p_ipv4_addr), sizeof(p2p_ipv4_addr)); ret_bind == -1) + if (ret_bind = ::bind(p2p_socket, reinterpret_cast(&p2p_ipv4_addr), sizeof(p2p_ipv4_addr)); ret_bind == -1 && bind_ip) { - if (nph.get_bind_ip()) - { - sys_net.error("Failed to bind to %s:%d, falling back to 0.0.0.0:%d", np::ip_to_string(nph.get_bind_ip()), port, port); - p2p_ipv4_addr.sin_addr.s_addr = 0; - ret_bind = ::bind(p2p_socket, reinterpret_cast(&p2p_ipv4_addr), sizeof(p2p_ipv4_addr)); - } + sys_net.error("Failed to bind to %s:%d, falling back to 0.0.0.0:%d", np::ip_to_string(bind_ip), port, port); + p2p_ipv4_addr.sin_addr.s_addr = 0; + ret_bind = ::bind(p2p_socket, reinterpret_cast(&p2p_ipv4_addr), sizeof(p2p_ipv4_addr)); } } diff --git a/rpcs3/Emu/Cell/lv2/sys_net/sys_net_helpers.cpp b/rpcs3/Emu/Cell/lv2/sys_net/sys_net_helpers.cpp index 96a0f62362..6bc03320cd 100644 --- a/rpcs3/Emu/Cell/lv2/sys_net/sys_net_helpers.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_net/sys_net_helpers.cpp @@ -6,6 +6,11 @@ #include "sys_net_helpers.h" #include "network_context.h" +#ifdef _WIN32 +#include "Emu/NP/np_handler.h" +#include "Emu/NP/np_helpers.h" +#endif + LOG_CHANNEL(sys_net); int get_native_error() @@ -159,8 +164,19 @@ sys_net_sockaddr native_addr_to_sys_net_addr(const ::sockaddr_storage& native_ad // Windows doesn't support sending packets to 0.0.0.0 but it works on unixes, send to 127.0.0.1 instead if (native_addr.sin_addr.s_addr == 0x00000000) { - sys_net.warning("[Native] Redirected 0.0.0.0 to 127.0.0.1"); - native_addr.sin_addr.s_addr = std::bit_cast>(0x7F000001); + auto& nph = g_fxo->get>(); + if (const u32 bind_addr = nph.get_bind_ip(); bind_addr != 0) + { + // If bind IP is set 0.0.0.0 was bound to binding_ip so we need to connect to that ip + sys_net.warning("[Native] Redirected 0.0.0.0 to %s", np::ip_to_string(bind_addr)); + native_addr.sin_addr.s_addr = bind_addr; + } + else + { + // Otherwise we connect to localhost which should be bound + sys_net.warning("[Native] Redirected 0.0.0.0 to 127.0.0.1"); + native_addr.sin_addr.s_addr = std::bit_cast>(0x7F000001); + } } #endif diff --git a/rpcs3/Emu/NP/ip_address.cpp b/rpcs3/Emu/NP/ip_address.cpp index 7adb38f113..ce7b460272 100644 --- a/rpcs3/Emu/NP/ip_address.cpp +++ b/rpcs3/Emu/NP/ip_address.cpp @@ -1,4 +1,3 @@ -#include "Emu/Cell/lv2/sys_net/sys_net_helpers.h" #include "stdafx.h" #include "Emu/system_config.h" #include "ip_address.h" diff --git a/rpcs3/Emu/NP/rpcn_client.cpp b/rpcs3/Emu/NP/rpcn_client.cpp index 4d6ce2e2a1..7d80c361a8 100644 --- a/rpcs3/Emu/NP/rpcn_client.cpp +++ b/rpcs3/Emu/NP/rpcn_client.cpp @@ -1078,9 +1078,9 @@ namespace rpcn sockaddr_in sock_addr = {.sin_family = AF_INET}; sock_addr.sin_addr.s_addr = binding_address; - if (::bind(sockfd, reinterpret_cast(&sock_addr), sizeof(sock_addr)) == -1) + if (binding_address != 0 && ::bind(sockfd, reinterpret_cast(&sock_addr), sizeof(sock_addr)) == -1) { - rpcn_log.error("bind: Failed to bind RPCN client socket to binding address!"); + rpcn_log.error("bind: Failed to bind RPCN client socket to binding address(%s): 0x%x!", np::ip_to_string(binding_address), get_native_error()); state = rpcn_state::failure_binding; return false; }