From 3d5d02fc15197eac5a663f5c79db21ff88cae5a4 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 3 Mar 2019 19:58:01 -0500 Subject: [PATCH 01/10] Error if the lump is a PNG lump --- src/w_wad.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/w_wad.c b/src/w_wad.c index 88e89974a..9ca4e0ff0 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1175,6 +1175,29 @@ void zerr(int ret) } #endif +#define NO_PNG_LUMPS + +#ifdef NO_PNG_LUMPS +static void ErrorIfPNG(void *d, size_t s, char *f, char *l) +{ + if (s < 67) // http://garethrees.org/2007/11/14/pngcrush/ + return; +#define sigcheck ((UINT8 *)d) + if (sigcheck[0] == 0x89 + && sigcheck[1] == 0x50 + && sigcheck[2] == 0x4e + && sigcheck[3] == 0x47 + && sigcheck[4] == 0x0d + && sigcheck[5] == 0x0a + && sigcheck[6] == 0x1a + && sigcheck[7] == 0x0a) + { + I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .PNG - please convert to either Doom or Flat (raw) image format.", l, f); + } +#undef sigcheck +} +#endif + /** Reads bytes from the head of a lump. * Note: If the lump is compressed, the whole thing has to be read anyway. * @@ -1214,7 +1237,15 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si switch(wadfiles[wad]->lumpinfo[lump].compression) { case CM_NOCOMPRESSION: // If it's uncompressed, we directly write the data into our destination, and return the bytes read. +#ifdef NO_PNG_LUMPS + { + size_t bytesread = fread(dest, 1, size, handle); + ErrorIfPNG(dest, bytesread, wadfiles[wad]->filename, l->name2); + return bytesread; + } +#else return fread(dest, 1, size, handle); +#endif case CM_LZF: // Is it LZF compressed? Used by ZWADs. { #ifdef ZWAD @@ -1249,11 +1280,15 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si M_Memcpy(dest, decData + offset, size); Z_Free(rawData); Z_Free(decData); +#ifdef NO_PNG_LUMPS + ErrorIfPNG(dest, size, wadfiles[wad]->filename, l->name2); +#endif return size; #else //I_Error("ZWAD files not supported on this platform."); return 0; #endif + } #ifdef HAVE_ZLIB case CM_DEFLATE: // Is it compressed via DEFLATE? Very common in ZIPs/PK3s, also what most doom-related editors support. @@ -1307,6 +1342,9 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si Z_Free(rawData); Z_Free(decData); +#ifdef NO_PNG_LUMPS + ErrorIfPNG(dest, size, wadfiles[wad]->filename, l->name2); +#endif return size; } #endif From 15323328c5659ebee4c5b740c52b1968167e0f56 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 3 Mar 2019 22:43:21 -0500 Subject: [PATCH 02/10] Check using memcmp() --- src/w_wad.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 9ca4e0ff0..b5aa95fac 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1183,14 +1183,10 @@ static void ErrorIfPNG(void *d, size_t s, char *f, char *l) if (s < 67) // http://garethrees.org/2007/11/14/pngcrush/ return; #define sigcheck ((UINT8 *)d) - if (sigcheck[0] == 0x89 - && sigcheck[1] == 0x50 - && sigcheck[2] == 0x4e - && sigcheck[3] == 0x47 - && sigcheck[4] == 0x0d - && sigcheck[5] == 0x0a - && sigcheck[6] == 0x1a - && sigcheck[7] == 0x0a) + // Check for PNG file signature using memcmp + // As it may be faster on CPUs with slow unaligned memory access + // Ref: http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-signature + if (memcmp(&sigcheck[0], "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", 8) == 0) { I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .PNG - please convert to either Doom or Flat (raw) image format.", l, f); } From 9542a47f7fee56f6078b9973233b911370476ef3 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 3 Mar 2019 22:57:09 -0500 Subject: [PATCH 03/10] New -noxinput and -nohidapi command line parameters. --- src/sdl/i_system.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index b5597784e..517c183ee 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1402,7 +1402,13 @@ static int joy_open2(const char *fname) void I_InitJoystick(void) { I_ShutdownJoystick(); - SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + + if (M_CheckParm("-noxinput")) + SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + + if (M_CheckParm("-nohidapi")) + SDL_SetHintWithPriority("SDL_JOYSTICK_HIDAPI", "0", SDL_HINT_OVERRIDE); + if (!strcmp(cv_usejoystick.string, "0") || M_CheckParm("-nojoy")) return; if (joy_open(cv_usejoystick.string) != -1) @@ -1418,7 +1424,13 @@ void I_InitJoystick(void) void I_InitJoystick2(void) { I_ShutdownJoystick2(); - SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + + if (M_CheckParm("-noxinput")) + SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + + if (M_CheckParm("-nohidapi")) + SDL_SetHintWithPriority("SDL_JOYSTICK_HIDAPI", "0", SDL_HINT_OVERRIDE); + if (!strcmp(cv_usejoystick2.string, "0") || M_CheckParm("-nojoy")) return; if (joy_open2(cv_usejoystick2.string) != -1) From 6d751ff30257ce2f24b8f1aadb848438786b2949 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Fri, 15 Mar 2019 18:46:25 -0400 Subject: [PATCH 04/10] Remove the define. --- src/w_wad.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 4f0142081..c4f9ceca8 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1182,19 +1182,17 @@ void zerr(int ret) #define NO_PNG_LUMPS #ifdef NO_PNG_LUMPS -static void ErrorIfPNG(void *d, size_t s, char *f, char *l) +static void ErrorIfPNG(UINT8 *d, size_t s, char *f, char *l) { if (s < 67) // http://garethrees.org/2007/11/14/pngcrush/ return; -#define sigcheck ((UINT8 *)d) // Check for PNG file signature using memcmp // As it may be faster on CPUs with slow unaligned memory access // Ref: http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-signature - if (memcmp(&sigcheck[0], "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", 8) == 0) + if (memcmp(&d[0], "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", 8) == 0) { I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .PNG - please convert to either Doom or Flat (raw) image format.", l, f); } -#undef sigcheck } #endif From d03c53930bfa9f0265ec27223a6a4baa20bb0a73 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Mon, 18 Mar 2019 16:50:17 -0400 Subject: [PATCH 05/10] Update CMakeLists.txt, remove CMAKE_SIZEOF_VOID_P check --- CMakeLists.txt | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6eb065d04..11898db5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,14 +54,6 @@ macro(copy_files_to_build_dir target dlllist_var) endif() endmacro() -# 64-bit check -if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) - message(STATUS "Target is 64-bit") - set(SRB2_SYSTEM_BITS 64) -else() - set(SRB2_SYSTEM_BITS 32) -endif() - # OS macros if (UNIX) add_definitions(-DUNIXCOMMON) @@ -73,9 +65,6 @@ endif() if(${CMAKE_SYSTEM} MATCHES "Linux") add_definitions(-DLINUX) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - add_definitions(-DLINUX64) - endif() endif() if(${CMAKE_SYSTEM} MATCHES "Darwin") From 6142becb4d88e638326c136982e6191aaa6a137d Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Mon, 18 Mar 2019 23:58:31 -0400 Subject: [PATCH 06/10] Revert "Update CMakeLists.txt, remove CMAKE_SIZEOF_VOID_P check" This reverts commit d03c53930bfa9f0265ec27223a6a4baa20bb0a73. --- CMakeLists.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11898db5c..6eb065d04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,14 @@ macro(copy_files_to_build_dir target dlllist_var) endif() endmacro() +# 64-bit check +if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) + message(STATUS "Target is 64-bit") + set(SRB2_SYSTEM_BITS 64) +else() + set(SRB2_SYSTEM_BITS 32) +endif() + # OS macros if (UNIX) add_definitions(-DUNIXCOMMON) @@ -65,6 +73,9 @@ endif() if(${CMAKE_SYSTEM} MATCHES "Linux") add_definitions(-DLINUX) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + add_definitions(-DLINUX64) + endif() endif() if(${CMAKE_SYSTEM} MATCHES "Darwin") From 49dddf54ab4ee6ad41dd5c3b00d2f4af33cd9fe8 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Tue, 19 Mar 2019 00:04:14 -0400 Subject: [PATCH 07/10] CMake: check if CMAKE_SIZEOF_VOID_P is defined on Mac? --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6eb065d04..75aa82f32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,8 @@ macro(copy_files_to_build_dir target dlllist_var) endmacro() # 64-bit check -if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) +message(STATUS "CMAKE_SIZEOF_VOID_P=" ${CMAKE_SIZEOF_VOID_P}) +if(CMAKE_SIZEOF_VOID_P EQUAL 8) message(STATUS "Target is 64-bit") set(SRB2_SYSTEM_BITS 64) else() From 1c55daef2a5612bca39d47d490f82987cface0a9 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Tue, 19 Mar 2019 09:10:25 -0400 Subject: [PATCH 08/10] CMake: have funny check for empty CMAKE_SIZEOF_VOID_P --- CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75aa82f32..0a5507b92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,14 +54,19 @@ macro(copy_files_to_build_dir target dlllist_var) endif() endmacro() -# 64-bit check -message(STATUS "CMAKE_SIZEOF_VOID_P=" ${CMAKE_SIZEOF_VOID_P}) +# bitness check +set(SRB2_SYSTEM_BITS 0) if(CMAKE_SIZEOF_VOID_P EQUAL 8) message(STATUS "Target is 64-bit") set(SRB2_SYSTEM_BITS 64) -else() +endif() +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + message(STATUS "Target is 32-bit") set(SRB2_SYSTEM_BITS 32) endif() +if(${SRB2_SYSTEM_BITS} EQUAL 0) + message(STATUS "Target bitness is unknown") +endif() # OS macros if (UNIX) From f139ffd1dc6c757806c506f0925f2b5a612ab475 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 20 Mar 2019 19:20:34 -0700 Subject: [PATCH 09/10] Let localhost connections --- src/i_tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index f8a65b754..37e355579 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -612,7 +612,7 @@ static boolean SOCK_Get(void) if (c != ERRSOCKET) { // find remote node number - for (j = 0; j <= MAXNETNODES; j++) //include LAN + for (j = 1; j <= MAXNETNODES; j++) //include LAN { if (SOCK_cmpaddr(&fromaddress, &clientaddress[j], 0)) { From ed0f8fd96765fec8ac9b6407db7118669b07ddde Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 20 Mar 2019 20:05:45 -0700 Subject: [PATCH 10/10] Actually allow connecting to "localhost" Because IPv6 doesn't seem to work anyway. --- src/i_tcp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 37e355579..11a84ceba 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -1340,8 +1340,12 @@ static SINT8 SOCK_NetMakeNodewPort(const char *address, const char *port) while (runp != NULL) { // find ip of the server - memcpy(&clientaddress[newnode], runp->ai_addr, runp->ai_addrlen); - runp = NULL; + if (sendto(mysockets[0], NULL, 0, 0, runp->ai_addr, runp->ai_addrlen) == 0) + { + memcpy(&clientaddress[newnode], runp->ai_addr, runp->ai_addrlen); + break; + } + runp = runp->ai_next; } I_freeaddrinfo(ai); return newnode;