From 8a99b5e0ad90fdf48858adde40489fa325ee0328 Mon Sep 17 00:00:00 2001
From: FunkyFr3sh <cc.red.alert.1@googlemail.com>
Date: Sun, 15 Oct 2023 02:44:31 +0200
Subject: [PATCH] improve mingw build

---
 src/hook.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/hook.c b/src/hook.c
index 1b654d0..224e411 100644
--- a/src/hook.c
+++ b/src/hook.c
@@ -326,14 +326,22 @@ void hook_patch_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks, BOOL is_loc
                                     continue;
 
                                 /* avoid exceptions with obfuscated binaries in debug build */
-#if defined(_DEBUG)
+#if defined(_DEBUG) || defined(__GNUC__)
                                 MEMORY_BASIC_INFORMATION mbi = { 0 };
-                                if (VirtualQuery((void*)import->Name, & mbi, sizeof(mbi)))
+                                if (VirtualQuery((void*)import->Name, &mbi, sizeof(mbi)))
                                 {
-                                    DWORD mask = (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY);
+                                    DWORD mask = (
+                                        PAGE_READONLY | 
+                                        PAGE_READWRITE | 
+                                        PAGE_WRITECOPY | 
+                                        PAGE_EXECUTE_READ | 
+                                        PAGE_EXECUTE_READWRITE | 
+                                        PAGE_EXECUTE_WRITECOPY);
+                                    
                                     BOOL b = !(mbi.Protect & mask);
-                                    // check the page is not a guard page
-                                    if (mbi.Protect & (PAGE_GUARD | PAGE_NOACCESS)) b = TRUE;
+
+                                    if (mbi.Protect & (PAGE_GUARD | PAGE_NOACCESS)) 
+                                        b = TRUE;
 
                                     if (b)
                                         continue;
@@ -603,6 +611,13 @@ void hook_init(BOOL initial_hook)
             /* Switch to 3 if we can be sure that ddraw.dll will not be unloaded from the process */
             g_config.hook = 3;
         }
+
+#if defined(__GNUC__)
+        if (g_config.hook == 4)
+        {
+            g_config.hook = 3;
+        }
+#endif
     }
 
     if (!g_hook_active || g_config.hook == 3 || g_config.hook == 4)