From 6f3bd580c270e0009339a0a1cecd8f6ab0d26ba1 Mon Sep 17 00:00:00 2001
From: FunkyFr3sh <cc.red.alert.1@googlemail.com>
Date: Mon, 2 Aug 2021 18:56:06 +0200
Subject: [PATCH] export all dinput functions

---
 ddraw.def         |  5 ++++-
 src/directinput.c | 26 +++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/ddraw.def b/ddraw.def
index 096d061..60d496f 100644
--- a/ddraw.def
+++ b/ddraw.def
@@ -13,6 +13,9 @@ EXPORTS
     DirectDrawEnumerateExW                    @13
     DirectDrawEnumerateW                      @14
     ReleaseDDThreadLock                       @21
-    DirectInputCreateEx = fake_DirectInputCreateEx @22
+    DirectInputCreateA = fake_DirectInputCreateA
+    DirectInputCreateW = fake_DirectInputCreateW
+    DirectInputCreateEx = fake_DirectInputCreateEx
+    DirectInput8Create = fake_DirectInput8Create
     GameHandlesClose                          DATA
     pvBmpBits = FakePrimarySurface            DATA
diff --git a/src/directinput.c b/src/directinput.c
index 4a7848e..5102ad1 100644
--- a/src/directinput.c
+++ b/src/directinput.c
@@ -180,6 +180,12 @@ HRESULT WINAPI fake_DirectInputCreateA(
     {
         real_DirectInputCreateA =
             (DIRECTINPUTCREATEAPROC)GetProcAddress(GetModuleHandle("dinput.dll"), "DirectInputCreateA");
+
+        if (real_DirectInputCreateA == fake_DirectInputCreateW)
+        {
+            real_DirectInputCreateA =
+                (DIRECTINPUTCREATEAPROC)GetProcAddress(LoadLibraryA("system32\\dinput.dll"), "DirectInputCreateA");
+        }
     }
 
     if (!real_DirectInputCreateA)
@@ -208,6 +214,12 @@ HRESULT WINAPI fake_DirectInputCreateW(
     {
         real_DirectInputCreateW =
             (DIRECTINPUTCREATEWPROC)GetProcAddress(GetModuleHandle("dinput.dll"), "DirectInputCreateW");
+
+        if (real_DirectInputCreateW == fake_DirectInputCreateW)
+        {
+            real_DirectInputCreateW =
+                (DIRECTINPUTCREATEWPROC)GetProcAddress(LoadLibraryA("system32\\dinput.dll"), "DirectInputCreateW");
+        }
     }
 
     if (!real_DirectInputCreateW)
@@ -236,7 +248,13 @@ HRESULT WINAPI fake_DirectInputCreateEx(
     if (!real_DirectInputCreateEx)
     {
         real_DirectInputCreateEx =
-            (DIRECTINPUTCREATEEXPROC)GetProcAddress(LoadLibraryA("system32\\dinput.dll"), "DirectInputCreateEx");
+            (DIRECTINPUTCREATEEXPROC)GetProcAddress(GetModuleHandle("dinput.dll"), "DirectInputCreateEx");
+
+        if (real_DirectInputCreateEx == fake_DirectInputCreateEx)
+        {
+            real_DirectInputCreateEx =
+                (DIRECTINPUTCREATEEXPROC)GetProcAddress(LoadLibraryA("system32\\dinput.dll"), "DirectInputCreateEx");
+        }
     }
 
     if (!real_DirectInputCreateEx)
@@ -275,6 +293,12 @@ HRESULT WINAPI fake_DirectInput8Create(
     {
         real_DirectInput8Create =
             (DIRECTINPUT8CREATEPROC)GetProcAddress(GetModuleHandle("dinput8.dll"), "DirectInput8Create");
+
+        if (real_DirectInput8Create == fake_DirectInput8Create)
+        {
+            real_DirectInput8Create =
+                (DIRECTINPUT8CREATEPROC)GetProcAddress(LoadLibraryA("system32\\dinput8.dll"), "DirectInput8Create");
+        }
     }
 
     if (!real_DirectInput8Create)