From 214ba1d68ab6018fb61ebec5a1cce8c4e9b637ec Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 10 Sep 2018 13:29:56 +1000
Subject: Fix build for Haiku


diff --git a/common/arch_def.h b/common/arch_def.h
index 9e8a5fc..d67db5d 100644
--- a/common/arch_def.h
+++ b/common/arch_def.h
@@ -48,6 +48,12 @@
 #	define	PLATFORM_WINDOWS	1
 #   endif
 
+#elif defined(__HAIKU__)
+
+#   if !defined(PLATFORM_HAIKU)
+#	define	PLATFORM_HAIKU		1
+#   endif
+
 #elif defined(__APPLE__) && defined(__MACH__)		/* Mac OS X */
 
 #   if !defined(PLATFORM_OSX)
@@ -85,7 +91,7 @@
     defined(__sun) || defined(sun)				|| \
     defined(__sgi) || defined(sgi) || defined(__sgi__)		|| \
     defined(__GNU__) /* GNU/Hurd */				|| \
-    defined(__QNX__) || defined(__QNXNTO__)
+    defined(__QNX__) || defined(__QNXNTO__) || defined(__HAIKU__)
 #   if !defined(PLATFORM_UNIX)
 #	define	PLATFORM_UNIX		1
 #   endif
@@ -145,6 +151,8 @@
 #	define	PLATFORM_STRING	"AmigaOS"
 #elif defined(__QNX__) || defined(__QNXNTO__)
 #	define	PLATFORM_STRING	"QNX"
+#elif defined(PLATFORM_HAIKU)
+#	define	PLATFORM_STRING	"Haiku"
 #elif defined(PLATFORM_OSX)
 #	define	PLATFORM_STRING	"MacOSX"
 #elif defined(PLATFORM_MAC)
diff --git a/common/net_sys.h b/common/net_sys.h
index 9b69bd3..80dc6ce 100644
--- a/common/net_sys.h
+++ b/common/net_sys.h
@@ -50,7 +50,7 @@
 #endif	/* BSD, sockaddr */
 
 /* unix includes and compatibility macros */
-#if defined(PLATFORM_UNIX) || defined(PLATFORM_RISCOS)
+#if defined(PLATFORM_UNIX) || defined(PLATFORM_RISCOS) || defined(PLATFORM_HAIKU)
 
 #include <sys/param.h>
 #include <sys/ioctl.h>
diff --git a/common/q_stdinc.h b/common/q_stdinc.h
index 41bc316..0333319 100644
--- a/common/q_stdinc.h
+++ b/common/q_stdinc.h
@@ -86,8 +86,12 @@
 /* Make sure the types really have the right
  * sizes: These macros are from SDL headers.
  */
+#ifdef __HAIKU__
+#define	COMPILE_TIME_ASSERT(name, x)
+#else
 #define	COMPILE_TIME_ASSERT(name, x)	\
 	typedef int dummy_ ## name[(x) * 2 - 1]
+#endif
 
 COMPILE_TIME_ASSERT(char, sizeof(char) == 1);
 COMPILE_TIME_ASSERT(float, sizeof(float) == 4);
diff --git a/engine/hexen2/Makefile b/engine/hexen2/Makefile
index 66e4dd3..971c888 100644
--- a/engine/hexen2/Makefile
+++ b/engine/hexen2/Makefile
@@ -412,6 +412,9 @@ endif
 ifeq ($(HOST_OS),qnx)
 SYSLIBS += -lsocket
 endif
+ifeq ($(HOST_OS),haiku)
+SYSLIBS += -lnetwork
+endif
 ifeq ($(HOST_OS),sunos)
 SYSLIBS += -lsocket -lnsl -lresolv
 endif
diff --git a/engine/hexen2/net_udp.c b/engine/hexen2/net_udp.c
index 48e313b..804cad5 100644
--- a/engine/hexen2/net_udp.c
+++ b/engine/hexen2/net_udp.c
@@ -55,6 +55,7 @@ struct Library	*SocketBase;
 
 static int udp_scan_iface (sys_socket_t socketfd)
 {
+#ifndef __HAIKU__
 	struct ifconf	ifc;
 	struct ifreq	*ifr;
 	char		buf[8192];
@@ -93,7 +94,7 @@ static int udp_scan_iface (sys_socket_t socketfd)
 			return 0;
 		}
 	}
-
+#endif
 	return -1;
 }
 
-- 
2.16.4


From e1983a5560414a664dd2058e4618f8054b2cdf32 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 10 Sep 2018 21:05:00 +1000
Subject: Fix cursor scancodes


diff --git a/engine/h2shared/in_sdl.c b/engine/h2shared/in_sdl.c
index bd264d1..3a7a2e9 100644
--- a/engine/h2shared/in_sdl.c
+++ b/engine/h2shared/in_sdl.c
@@ -887,6 +887,20 @@ void IN_SendKeyEvents (void)
 				}
 				/* else: it's an international character */
 			}
+			switch (sym) {
+				case 28:
+					sym = 276;
+					break;
+				case 29:
+					sym = 275;
+					break;
+				case 31:
+					sym = 274;
+					break;
+				case 30:
+					sym = 273;
+					break;
+			}
 			/*printf("You pressed %s (%d) (%c)\n", SDL_GetKeyName(sym), sym, sym);*/
 
 			switch (sym)
-- 
2.16.4


From 91983190d764f5f0e6946282afea61de8ae0868d Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 10 Sep 2018 21:46:52 +1000
Subject: Fix settings dir


diff --git a/engine/h2shared/userdir.h b/engine/h2shared/userdir.h
index f821df5..1e13bc8 100644
--- a/engine/h2shared/userdir.h
+++ b/engine/h2shared/userdir.h
@@ -40,6 +40,8 @@
 
 #if defined(PLATFORM_OSX)
 #define	AOT_USERDIR		SYS_USERDIR_OSX
+#elif defined(PLATFORM_HAIKU)
+#define	AOT_USERDIR		"config/settings/hexen2"
 #else	/* unix: */
 #define	AOT_USERDIR		SYS_USERDIR_UNIX
 #endif
-- 
2.16.4


From 3c566975035cebb10a70f68470875048b5b84055 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 10 Sep 2018 21:47:17 +1000
Subject: Set current dir to application floder


diff --git a/engine/hexen2/sys_unix.c b/engine/hexen2/sys_unix.c
index e387e32..22ab279 100644
--- a/engine/hexen2/sys_unix.c
+++ b/engine/hexen2/sys_unix.c
@@ -683,6 +683,16 @@ int main (int argc, char **argv)
 	int			i;
 	double		time, oldtime, newtime;
 
+#ifdef PLATFORM_HAIKU
+	char *binpath = realpath(argv[0], NULL);
+	if (binpath != NULL) {
+		char *appdir = strrchr(binpath, '/');
+		*appdir = '\0';
+		chdir(binpath);
+		free(binpath);
+	}
+#endif
+
 	PrintVersion();
 
 	if (argc > 1)
-- 
2.16.4

