diff --git a/CMakeLists.txt b/CMakeLists.txt index 8105e4002..78dec846f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ option(FASTER "Enable FASTER in engine" ON) option(BINARY_RELEASE "Enable options for binary release" OFF) option(NIGHTLY_BUILD "Enable options for nightly build" OFF) option(USE_SDL1 "Use SDL1.2 instead of SDL2" OFF) +option(NONET "Disable network" OFF) if(BINARY_RELEASE) set(CMAKE_BUILD_TYPE "Release") @@ -62,7 +63,9 @@ set(CMAKE_THREAD_PREFER_PTHREAD ON) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -find_package(sodium REQUIRED) +if(NOT NONET) + find_package(sodium REQUIRED) +endif() if(USE_SDL1) find_package(SDL REQUIRED) @@ -176,7 +179,7 @@ add_library(devilution STATIC Source/trigs.cpp Source/wave.cpp) -add_executable(devilutionx MACOSX_BUNDLE +set(devilutionx_SRCS SourceX/dx.cpp SourceX/miniwin/misc.cpp SourceX/miniwin/misc_io.cpp @@ -194,9 +197,6 @@ add_executable(devilutionx MACOSX_BUNDLE SourceX/dvlnet/packet.cpp SourceX/dvlnet/base.cpp SourceX/dvlnet/frame_queue.cpp - SourceX/dvlnet/tcp_client.cpp - SourceX/dvlnet/tcp_server.cpp - SourceX/dvlnet/udp_p2p.cpp SourceX/DiabloUI/art.cpp SourceX/DiabloUI/credits.cpp SourceX/DiabloUI/diabloui.cpp @@ -212,6 +212,15 @@ add_executable(devilutionx MACOSX_BUNDLE ./Packaging/macOS/AppIcon.icns ./Packaging/resources/CharisSILB.ttf) +if(NOT NONET) + list(APPEND devilutionx_SRCS + SourceX/dvlnet/tcp_client.cpp + SourceX/dvlnet/tcp_server.cpp + SourceX/dvlnet/udp_p2p.cpp) +endif() + +add_executable(devilutionx MACOSX_BUNDLE ${devilutionx_SRCS}) + configure_file(SourceS/config.h.in config.h @ONLY) target_include_directories(devilution PUBLIC Source SourceS ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(devilutionx PRIVATE @@ -226,8 +235,11 @@ target_link_libraries(devilutionx PRIVATE PKWare StormLib smacker - Radon - sodium) + Radon) + +if(NOT NONET) + target_link_libraries(devilutionx PRIVATE sodium) +endif() target_compile_definitions(devilution PRIVATE DEVILUTION_ENGINE) target_compile_definitions(devilution PUBLIC @@ -249,6 +261,10 @@ foreach(target devilution devilutionx) SDL2::SDL2_mixer) endif() + if(NONET) + target_compile_definitions(${target} PRIVATE NONET) + endif() + if(ASAN) target_compile_options(${target} PUBLIC -fsanitize=address -fsanitize-recover=address) target_link_libraries(${target} PUBLIC -fsanitize=address -fsanitize-recover=address) diff --git a/README.md b/README.md index 41707b4e6..b31b68958 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,8 @@ make -j$(nproc) ### General The default build type is `Debug`. This can be changed with `-DBINARY_RELEASE=ON`. Independently of this, the debug mode of the Diablo engine is always enabled by default. It can be disabled with `-DDEBUG=OFF`. Finally, in debug builds the address sanitizer is enabled by default. This can be disabled with `-DASAN=OFF`. You can also generate 32bit builds on 64bit platforms by setting `-DCMAKE_TOOLCHAIN_FILE=../CMake/32bit.cmake` (remember to use the `linux32` command if on Linux). +Network support can be deiabled using `-DNONET`, this also removes the need for the ASIO and Sodium dependencies + ### mingw32 Use `-DCROSS_PREFIX=/path/to/prefix` if the `i686-w64-mingw32` directory is not in `/usr`. ### Use SDL v1 instead of SDL v2. diff --git a/SourceX/DiabloUI/selconn.cpp b/SourceX/DiabloUI/selconn.cpp index 38be91f5a..9d4a521eb 100644 --- a/SourceX/DiabloUI/selconn.cpp +++ b/SourceX/DiabloUI/selconn.cpp @@ -19,9 +19,13 @@ DWORD provider; UiText SELCONNECT_DIALOG_DESCRIPTION(selconn_Description, { 35, 275, 205, 66 }); UiListItem SELCONN_DIALOG_ITEMS[] = { +#ifndef NONET { "Client-Server (TCP)", 0 }, { "Peer-to-Peer (UDP)", 1 }, { "Loopback", 2 }, +#else + { "Loopback", 0 }, +#endif }; UiItem SELCONNECT_DIALOG[] = { UiImage(&ArtBackground, { 0, 0, 640, 480 }), diff --git a/SourceX/dvlnet/abstract_net.cpp b/SourceX/dvlnet/abstract_net.cpp index 62be06d64..b28dc81cf 100644 --- a/SourceX/dvlnet/abstract_net.cpp +++ b/SourceX/dvlnet/abstract_net.cpp @@ -1,8 +1,10 @@ #include "dvlnet/abstract_net.h" #include "stubs.h" +#ifndef NONET #include "dvlnet/tcp_client.h" #include "dvlnet/udp_p2p.h" +#endif #include "dvlnet/loopback.h" namespace dvl { @@ -14,6 +16,9 @@ abstract_net::~abstract_net() std::unique_ptr abstract_net::make_net(provider_t provider) { +#ifdef NONET + return std::unique_ptr(new loopback); +#else if (provider == 'TCPN') { return std::unique_ptr(new tcp_client); } else if (provider == 'UDPN') { @@ -23,6 +28,7 @@ std::unique_ptr abstract_net::make_net(provider_t provider) } else { ABORT(); } +#endif } } // namespace net diff --git a/SourceX/dvlnet/packet.cpp b/SourceX/dvlnet/packet.cpp index 172e33f94..8c822879c 100644 --- a/SourceX/dvlnet/packet.cpp +++ b/SourceX/dvlnet/packet.cpp @@ -3,7 +3,9 @@ namespace dvl { namespace net { +#ifndef NONET static constexpr bool disable_encryption = false; +#endif const buffer_t &packet::data() { @@ -102,6 +104,7 @@ void packet_in::decrypt() ABORT(); if (have_decrypted) return; +#ifndef NONET if (!disable_encryption) { if (encrypted_buffer.size() < crypto_secretbox_NONCEBYTES + crypto_secretbox_MACBYTES @@ -119,7 +122,9 @@ void packet_in::decrypt() encrypted_buffer.data(), key.data())) throw packet_exception(); - } else { + } else +#endif + { if (encrypted_buffer.size() < sizeof(packet_type) + 2 * sizeof(plr_t)) throw packet_exception(); decrypted_buffer = encrypted_buffer; @@ -139,6 +144,7 @@ void packet_out::encrypt() process_data(); +#ifndef NONET if (!disable_encryption) { auto len_cleartext = encrypted_buffer.size(); encrypted_buffer.insert(encrypted_buffer.begin(), @@ -155,11 +161,13 @@ void packet_out::encrypt() key.data())) ABORT(); } +#endif have_encrypted = true; } packet_factory::packet_factory(std::string pw) { +#ifndef NONET if (sodium_init() < 0) ABORT(); pw.resize(std::min(pw.size(), crypto_pwhash_argon2id_PASSWD_MAX)); @@ -173,6 +181,7 @@ packet_factory::packet_factory(std::string pw) crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE, crypto_pwhash_ALG_ARGON2ID13)) ABORT(); +#endif } } // namespace net diff --git a/SourceX/dvlnet/packet.h b/SourceX/dvlnet/packet.h index 8aec6667a..9eb512aa9 100644 --- a/SourceX/dvlnet/packet.h +++ b/SourceX/dvlnet/packet.h @@ -4,7 +4,9 @@ #include #include #include +#ifndef NONET #include +#endif #include "dvlnet/abstract_net.h" #include "stubs.h" @@ -25,7 +27,9 @@ typedef uint8_t plr_t; typedef uint32_t cookie_t; typedef int turn_t; // change int to something else in devilution code later typedef int leaveinfo_t; // also change later +#ifndef NONET typedef std::array key_t; +#endif static constexpr plr_t PLR_MASTER = 0xFE; static constexpr plr_t PLR_BROADCAST = 0xFF;