From ddafde6be4f62dbfabf1ae78dd22a5b09ae03670 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aida=20Jonikien=C4=97?= <aidas957@gmail.com>
Date: Fri, 26 Jan 2024 23:12:53 +0200
Subject: [PATCH 6/6] ddraw-version-check: Rebase and re-enable.

This rebase seems kind of hacky to me so I won't be surprised
if it doesn't get pushed into wine-staging.

This change also cleans up the patch code a bit.
---
 ...rect-devices-based-off-requested-Dir.patch | 54 ++++++++++---------
 patches/ddraw-version-check/definition        |  1 -
 2 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/patches/ddraw-version-check/0001-ddraw-Return-correct-devices-based-off-requested-Dir.patch b/patches/ddraw-version-check/0001-ddraw-Return-correct-devices-based-off-requested-Dir.patch
index a02889e7..6bae9bf5 100644
--- a/patches/ddraw-version-check/0001-ddraw-Return-correct-devices-based-off-requested-Dir.patch
+++ b/patches/ddraw-version-check/0001-ddraw-Return-correct-devices-based-off-requested-Dir.patch
@@ -1,18 +1,18 @@
-From 16d001f5562c37ac293fa547feef19887e635363 Mon Sep 17 00:00:00 2001
+From da40d204f63147ac421b29761b896ad684f4cb16 Mon Sep 17 00:00:00 2001
 From: Andrew D'Addesio <andrew@fatbag.net>
 Date: Fri, 8 Feb 2019 18:48:33 -1000
 Subject: [PATCH] ddraw: Return correct devices based off requested DirectX
  version.
 
 ---
- dlls/ddraw/ddraw.c | 231 +++++++++++++++++++++++++--------------------
- 1 file changed, 130 insertions(+), 101 deletions(-)
+ dlls/ddraw/ddraw.c | 236 +++++++++++++++++++++++++--------------------
+ 1 file changed, 130 insertions(+), 106 deletions(-)
 
 diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
-index 83eeb33589e..324a149a425 100644
+index 5887854556b..bbe00d72d9e 100644
 --- a/dlls/ddraw/ddraw.c
 +++ b/dlls/ddraw/ddraw.c
-@@ -47,37 +47,80 @@ static const DDDEVICEIDENTIFIER2 deviceidentifier =
+@@ -44,37 +44,80 @@ static const DDDEVICEIDENTIFIER2 deviceidentifier =
      0
  };
  
@@ -28,7 +28,7 @@ index 83eeb33589e..324a149a425 100644
 +    char device_desc[100];
      char device_name[100];
      const GUID *device_guid;
-     DWORD remove_caps;
+     DWORD unsupported_caps;
 -} device_list7[] =
 +} device_list[] =
  {
@@ -38,7 +38,7 @@ index 83eeb33589e..324a149a425 100644
 -        "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
 -        "Wine D3D7 T&L HAL",
 -        &IID_IDirect3DTnLHalDevice,
-+        D3D_VERSION(1)|D3D_VERSION(2),
++        D3D_VERSION(1) | D3D_VERSION(2),
 +        "WineD3D Ramp Software Emulation",
 +        "Ramp Emulation",
 +        &IID_IDirect3DRampDevice,
@@ -49,20 +49,20 @@ index 83eeb33589e..324a149a425 100644
 +    /* RGB Emulation (D3D 1-7) */
      {
 -        "WINE Direct3D7 Hardware acceleration using WineD3D",
-+        D3D_VERSION(1)|D3D_VERSION(2)|D3D_VERSION(3)|D3D_VERSION(7),
++        D3D_VERSION(1) | D3D_VERSION(2) | D3D_VERSION(3) | D3D_VERSION(7),
 +        "WineD3D RGB Software Emulation",
 +        "RGB Emulation",
 +        &IID_IDirect3DRGBDevice,
-+        D3DDEVCAPS_HWTRANSFORMANDLIGHT,
++        D3DDEVCAPS_HWTRANSFORMANDLIGHT | D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWRASTERIZATION,
 +    },
 +
 +    /* Direct3D HAL (D3D 1-7) */
 +    {
-+        D3D_VERSION(1)|D3D_VERSION(2)|D3D_VERSION(3)|D3D_VERSION(7),
++        D3D_VERSION(1) | D3D_VERSION(2) | D3D_VERSION(3) | D3D_VERSION(7),
 +        "WineD3D Hardware Acceleration",
          "Direct3D HAL",
          &IID_IDirect3DHALDevice,
-         0,
+         D3DDEVCAPS_HWTRANSFORMANDLIGHT,
      },
  
 -    /* RGB device */
@@ -71,7 +71,7 @@ index 83eeb33589e..324a149a425 100644
 -        "WINE Direct3D7 RGB Software Emulation using WineD3D",
 -        "Wine D3D7 RGB",
 -        &IID_IDirect3DRGBDevice,
--        D3DDEVCAPS_HWTRANSFORMANDLIGHT,
+-        D3DDEVCAPS_HWTRANSFORMANDLIGHT | D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWRASTERIZATION,
 +        D3D_VERSION(2),
 +        "WineD3D MMX Software Emulation",
 +        "MMX Emulation",
@@ -106,7 +106,7 @@ index 83eeb33589e..324a149a425 100644
  };
  
  static void STDMETHODCALLTYPE ddraw_null_wined3d_object_destroyed(void *parent) {}
-@@ -1389,15 +1432,6 @@ HRESULT ddraw_get_d3dcaps(const struct ddraw *ddraw, D3DDEVICEDESC7 *caps)
+@@ -1415,15 +1458,6 @@ HRESULT ddraw_get_d3dcaps(const struct ddraw *ddraw, D3DDEVICEDESC7 *caps)
          D3DPTADDRESSCAPS_WRAP            | D3DPTADDRESSCAPS_MIRROR             | D3DPTADDRESSCAPS_CLAMP              |
          D3DPTADDRESSCAPS_BORDER          | D3DPTADDRESSCAPS_INDEPENDENTUV);
  
@@ -122,7 +122,7 @@ index 83eeb33589e..324a149a425 100644
      /* Fill the missing members, and do some fixup */
      caps->dpcLineCaps.dwSize = sizeof(caps->dpcLineCaps);
      caps->dpcLineCaps.dwTextureBlendCaps = D3DPTBLENDCAPS_ADD
-@@ -3713,8 +3747,7 @@ static HRESULT WINAPI ddraw1_DuplicateSurface(IDirectDraw *iface, IDirectDrawSur
+@@ -3746,8 +3780,7 @@ static HRESULT WINAPI ddraw1_DuplicateSurface(IDirectDraw *iface, IDirectDrawSur
  /*****************************************************************************
   * IDirect3D7::EnumDevices
   *
@@ -132,8 +132,8 @@ index 83eeb33589e..324a149a425 100644
   *
   * Params:
   *  callback: Function to call for each enumerated device
-@@ -3747,14 +3780,17 @@ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBA
- 
+@@ -3779,13 +3812,16 @@ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBA
+     }
      dev_caps = device_desc7.dwDevCaps;
  
 -    for (i = 0; i < ARRAY_SIZE(device_list7); i++)
@@ -142,19 +142,18 @@ index 83eeb33589e..324a149a425 100644
          HRESULT ret;
  
 -        device_desc7.deviceGUID = *device_list7[i].device_guid;
--        device_desc7.dwDevCaps  = dev_caps & ~device_list7[i].remove_caps;
+-        device_desc7.dwDevCaps = dev_caps & ~device_list7[i].unsupported_caps;
+-        ret = callback(device_list7[i].interface_name, device_list7[i].device_name, &device_desc7, context);
 +        if (!(device_list[i].version_mask & D3D_VERSION(ddraw->d3dversion)))
 +            continue;
 +
 +        device_desc7.deviceGUID = *device_list[i].device_guid;
-+        device_desc7.dwDevCaps  = dev_caps & ~device_list[i].remove_caps;
- 
--        ret = callback(device_list7[i].interface_name, device_list7[i].device_name, &device_desc7, context);
++        device_desc7.dwDevCaps = dev_caps & ~device_list[i].unsupported_caps;
 +        ret = callback(device_list[i].device_name, device_list[i].device_name, &device_desc7, context);
          if (ret != DDENUMRET_OK)
          {
              TRACE("Application cancelled the enumeration.\n");
-@@ -3770,11 +3806,21 @@ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBA
+@@ -3801,11 +3837,21 @@ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBA
      return D3D_OK;
  }
  
@@ -178,7 +177,7 @@ index 83eeb33589e..324a149a425 100644
   *
   * Versions 1, 2 and 3
   *
-@@ -3789,18 +3835,18 @@ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBA
+@@ -3820,18 +3866,18 @@ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBA
   *****************************************************************************/
  static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBACK callback, void *context)
  {
@@ -206,7 +205,7 @@ index 83eeb33589e..324a149a425 100644
  
      TRACE("iface %p, callback %p, context %p.\n", iface, callback, context);
  
-@@ -3809,52 +3855,58 @@ static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBA
+@@ -3840,55 +3886,58 @@ static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBA
  
      wined3d_mutex_lock();
  
@@ -261,6 +260,9 @@ index 83eeb33589e..324a149a425 100644
 -        hal_desc.dcmColorModel = 0;
 -        /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
 -        hal_desc.dwFlags = 0;
+-        /* RGB, REF, RAMP and MMX devices don't report hardware transform and lighting capability */
+-        hal_desc.dwDevCaps &= ~(D3DDEVCAPS_HWTRANSFORMANDLIGHT | D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWRASTERIZATION);
+-        hel_desc.dwDevCaps &= ~(D3DDEVCAPS_HWTRANSFORMANDLIGHT | D3DDEVCAPS_DRAWPRIMITIVES2EX | D3DDEVCAPS_HWRASTERIZATION);
 -
 -        hr = callback((GUID *)&IID_IDirect3DRGBDevice, reference_description,
 -                device_name, &hal_desc, &hel_desc, context);
@@ -304,7 +306,7 @@ index 83eeb33589e..324a149a425 100644
          {
              TRACE("Application cancelled the enumeration.\n");
              wined3d_mutex_unlock();
-@@ -3862,29 +3914,6 @@ static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBA
+@@ -3896,31 +3945,6 @@ static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBA
          }
      }
  
@@ -321,6 +323,8 @@ index 83eeb33589e..324a149a425 100644
 -            | D3DPTEXTURECAPS_NONPOW2CONDITIONAL | D3DPTEXTURECAPS_PERSPECTIVE);
 -    /* HAL devices have a HEL dcmColorModel of 0 */
 -    hel_desc.dcmColorModel = 0;
+-    /* HAL devices report hardware transform and lighting capability, but not in hel */
+-    hel_desc.dwDevCaps &= ~(D3DDEVCAPS_HWTRANSFORMANDLIGHT | D3DDEVCAPS_DRAWPRIMITIVES2EX);
 -
 -    hr = callback((GUID *)&IID_IDirect3DHALDevice, wined3d_description,
 -            device_name, &hal_desc, &hel_desc, context);
@@ -335,5 +339,5 @@ index 83eeb33589e..324a149a425 100644
  
      wined3d_mutex_unlock();
 -- 
-2.20.1
+2.43.0
 
diff --git a/patches/ddraw-version-check/definition b/patches/ddraw-version-check/definition
index c67bf740..a1b0659b 100644
--- a/patches/ddraw-version-check/definition
+++ b/patches/ddraw-version-check/definition
@@ -8,4 +8,3 @@
 #   The Sims Online
 Fixes: [19153] Resident Evil 1 fails to start (needs IDirect3D3::EnumDevices() to return a device named "RGB Emulation")
 Depends: ddraw-Device_Caps
-Disabled: True
-- 
2.43.0

