From 4b3fb2ece4609c5b936784cdd505391c345213a1 Mon Sep 17 00:00:00 2001
From: Htylol <dixperm909@yandex.ru>
Date: Thu, 25 Apr 2024 17:27:57 +0500
Subject: [PATCH] Add dgvoodoo2 3d api

---
 data_from_portwine/scripts/functions_helper | 46 +++++++++++++++++++--
 data_from_portwine/scripts/start.sh         | 13 +++---
 data_from_portwine/scripts/var              |  1 +
 3 files changed, 51 insertions(+), 9 deletions(-)

diff --git a/data_from_portwine/scripts/functions_helper b/data_from_portwine/scripts/functions_helper
index 1deba318..90ecbf67 100755
--- a/data_from_portwine/scripts/functions_helper
+++ b/data_from_portwine/scripts/functions_helper
@@ -1013,6 +1013,25 @@ pw_check_and_download_dxvk_and_vkd3d () {
         fi
     fi
 
+    #Download DGVOODOO2
+    if [ ! -d "${PW_VULKAN_DIR}/dgvoodoo2-${DGV2_VER}" ] ; then
+        print_info "Download and install DGVOODOO2 v.${DGV2_VER}"
+        if try_download "https://github.com/lutris/dgvoodoo2/releases/download/${DGV2_VER}/dgvoodoo2-${DGV2_VER}.tar.xz" "${PW_VULKAN_DIR}/dgvoodoo2-${DGV2_VER}.tar.xz" \
+        "${PW_VULKAN_DIR}/dgvoodoo2-${DGV2_VER}.tar.xz"
+        then
+            if unpack_tar_xz "${PW_VULKAN_DIR}/dgvoodoo2-${DGV2_VER}.tar.xz" "${PW_VULKAN_DIR}" ; then
+                try_remove_file "${PW_VULKAN_DIR}/dgvoodoo2-${DGV2_VER}.tar.xz"
+            else
+                try_remove_file "${PW_VULKAN_DIR}/dgvoodoo2-${DGV2_VER}.tar.xz"
+                try_remove_dir "${PW_VULKAN_DIR}/dgvoodoo2-${DGV2_VER}"
+
+                yad_error_download && pw_check_and_download_dxvk_and_vkd3d || exit 1
+            fi
+        else
+            yad_error_download && pw_check_and_download_dxvk_and_vkd3d || exit 1
+        fi
+    fi
+
     return 0
 }
 
@@ -1978,7 +1997,7 @@ start_portwine () {
         if [[ "${XDG_SESSION_TYPE}" != "wayland" ]] || [[ "${PW_USE_GAMESCOPE}" != 1 ]] ; then
             export LIBGL_KOPPER_DRI2=1
         fi
-    elif [[ "${PW_VULKAN_USE}" == "5" ]] ; then
+    elif [[ "${PW_VULKAN_USE}" == "6" ]] ; then
         print_info "Use DAMAVAND (DirectX to wined3d vulkan)"
         export WINE_D3D_CONFIG='renderer=vulkan'
     else
@@ -2004,6 +2023,24 @@ start_portwine () {
             export PATH_TO_VKD3D_FILES="${PW_VULKAN_DIR}/vkd3d-proton-${VKD3D_GIT_VER}"
             print_info "DXVK v.${DXVK_GIT_VER} in use"
             print_info "VKD3D-PROTON v.${VKD3D_GIT_VER} in use"
+        elif [[ "${PW_VULKAN_USE}" == "5" ]] ; then
+            export PATH_TO_DXVK_FILES="${PW_VULKAN_DIR}/dxvk-${DXVK_STABLE_VER}"
+            export PATH_TO_DGV2_FILES="${PW_VULKAN_DIR}/dgvoodoo2-${DGV2_VER}"
+            print_info "DXVK v.${DXVK_STABLE_VER} in use"
+            print_info "DGVOODOO2 ${DGV2_VER} in use"
+            try_copy_file "$PATH_TO_DGV2_FILES/x32/d3dimm.dll" "${PATH_TO_GAME}"
+            try_copy_file "$PATH_TO_DGV2_FILES/x32/ddraw.dll" "${PATH_TO_GAME}"
+            try_copy_file "$PATH_TO_DGV2_FILES/x32/glide.dll" "${PATH_TO_GAME}"
+            try_copy_file "$PATH_TO_DGV2_FILES/x32/glide2x.dll" "${PATH_TO_GAME}"
+            try_copy_file "$PATH_TO_DGV2_FILES/x32/glide3x.dll" "${PATH_TO_GAME}"
+            echo "[General]
+OutputAPI                            = d3d11_fl11_0
+[Glide]
+3DfxWatermark                       = false
+3DfxSplashScreen                    = false
+[DirectX]
+dgVoodooWatermark                   = false" > "${PATH_TO_GAME}/dgVoodoo.conf"
+            var_winedlloverride_update ddraw=n
         fi
         PATH_TO_D8VK_FILES="${PW_VULKAN_DIR}/d8vk-${D8VK_VER}"
         print_info "D8VK v.${D8VK_VER} in use"
@@ -2639,9 +2676,7 @@ pw_gui_for_edit_db () {
     PW_RESTORE_RESOLUTION_INFO=$(eval_gettext 'Remember the screen resolution when starting the game and return it when closing (useful for games that change the screen resolution when closing)')
     PW_USE_SYSTEM_VK_LAYERS_INFO=$(eval_gettext 'Use system mangohud, vkBasalt, obs-vkcapture and other applications using vulkan layers')
     PW_USE_OBS_VKCAPTURE_INFO=$(eval_gettext 'Enable the ability to write to OBS Studio using obs-vkcapture (ATTENTION: the forced use of system mangohud, vkBasalt, obs-vkcapture and other applications using vulkan layers will be enabled)')
-    PW_DISABLE_COMPOSITING_INFO=$(eval_gettext 'Disable desktop compositing (effects). It often improves performance.')
-    PW_USE_GAMESCOPE_INFO=$(eval_gettext "
-<b>Super + F :</b> Toggle fullscreen
+    PW_USE_GAMESCOPE_INFO=$(eval_gettext "<b>Super + F :</b> Toggle fullscreen
 <b>Super + N :</b> Toggle nearest neighbour filtering
 <b>Super + U :</b> Toggle FSR upscaling
 <b>Super + Y :</b> Toggle NIS upscaling
@@ -2650,6 +2685,7 @@ pw_gui_for_edit_db () {
 <b>Super + S :</b> Take screenshot (currently goes to /tmp/gamescope_DATE.png)
 <b>Super + G :</b> Toggle keyboard grab
 <b>Super + C :</b> Update clipboard")
+    PW_DISABLE_COMPOSITING_INFO=$(eval_gettext 'Disable desktop compositing (effects). It often improves performance.')
 
     edit_db_field_add () {
         for int_to_boole in $@ ; do
@@ -3591,6 +3627,8 @@ portwine_start_debug () {
     elif [[ "${PW_VULKAN_USE}" = "4" ]] ; then
         echo "PW_VULKAN_USE=${PW_VULKAN_USE} - OpenGL on MESA vulkan drivers" >> "${PORT_WINE_PATH}/PortProton.log"
     elif [[ "${PW_VULKAN_USE}" = "5" ]] ; then
+        echo "PW_VULKAN_USE=${PW_VULKAN_USE} - DGVOODOO2 (DirectX 1-7, Glide 3dfx wrapper)" >> "${PORT_WINE_PATH}/PortProton.log"
+    elif [[ "${PW_VULKAN_USE}" = "6" ]] ; then
         echo "PW_VULKAN_USE=${PW_VULKAN_USE} - DirectX to wined3d vulkan" >> "${PORT_WINE_PATH}/PortProton.log"
     else
         echo "PW_VULKAN_USE=${PW_VULKAN_USE}" >> "${PORT_WINE_PATH}/PortProton.log"
diff --git a/data_from_portwine/scripts/start.sh b/data_from_portwine/scripts/start.sh
index 47b9fb15..e8826402 100755
--- a/data_from_portwine/scripts/start.sh
+++ b/data_from_portwine/scripts/start.sh
@@ -348,13 +348,15 @@ SORT_STABLE="$(eval_gettext "Stable") DXVK ${DXVK_STABLE_VER}, VKD3D ${VKD3D_STA
 SORT_NEWEST="$(eval_gettext "Newest") DXVK ${DXVK_GIT_VER}, VKD3D ${VKD3D_GIT_VER}"
 SORT_G_NINE="$(eval_gettext "GALLIUM_NINE (DX9 for MESA)")"
 SORT_G_ZINK="$(eval_gettext "GALLIUM_ZINK (OpenGL for VULKAN)")"
+SORT_DGV2="$(eval_gettext "DGVOODOO2 (DirectX 1-7, Glide 3dfx wrapper)")"
 
 case "${PW_VULKAN_USE}" in
-    0) PW_DEFAULT_VULKAN_USE="$SORT_OPENGL!$SORT_STABLE!$SORT_NEWEST!$SORT_G_NINE!$SORT_G_ZINK" ;;
-    1) PW_DEFAULT_VULKAN_USE="$SORT_STABLE!$SORT_NEWEST!$SORT_OPENGL!$SORT_G_NINE!$SORT_G_ZINK" ;;
-    3) PW_DEFAULT_VULKAN_USE="$SORT_G_NINE!$SORT_STABLE!$SORT_NEWEST!$SORT_OPENGL!$SORT_G_ZINK" ;;
-    4) PW_DEFAULT_VULKAN_USE="$SORT_G_ZINK!$SORT_OPENGL!$SORT_STABLE!$SORT_NEWEST!$SORT_G_NINE" ;;
-    *) PW_DEFAULT_VULKAN_USE="$SORT_NEWEST!$SORT_STABLE!$SORT_OPENGL!$SORT_G_NINE!$SORT_G_ZINK" ;;
+    0) PW_DEFAULT_VULKAN_USE="$SORT_OPENGL!$SORT_STABLE!$SORT_NEWEST!$SORT_G_NINE!$SORT_G_ZINK!$SORT_DGV2" ;;
+    1) PW_DEFAULT_VULKAN_USE="$SORT_STABLE!$SORT_NEWEST!$SORT_OPENGL!$SORT_G_NINE!$SORT_G_ZINK!$SORT_DGV2" ;;
+    3) PW_DEFAULT_VULKAN_USE="$SORT_G_NINE!$SORT_STABLE!$SORT_NEWEST!$SORT_OPENGL!$SORT_G_ZINK!$SORT_DGV2" ;;
+    4) PW_DEFAULT_VULKAN_USE="$SORT_G_ZINK!$SORT_STABLE!$SORT_NEWEST!$SORT_OPENGL!$SORT_G_NINE!$SORT_DGV2" ;;
+    5) PW_DEFAULT_VULKAN_USE="$SORT_DGV2!$SORT_STABLE!$SORT_NEWEST!$SORT_OPENGL!$SORT_G_NINE!$SORT_G_ZINK" ;;
+    *) PW_DEFAULT_VULKAN_USE="$SORT_NEWEST!$SORT_STABLE!$SORT_OPENGL!$SORT_G_NINE!$SORT_G_ZINK!$SORT_DGV2" ;;
 esac
 
 if [[ ! -z "${PORTWINE_DB_FILE}" ]] ; then
@@ -597,6 +599,7 @@ case "${VULKAN_MOD}" in
     "$SORT_NEWEST" )     export PW_VULKAN_USE="2" ;;
     "$SORT_G_NINE" )     export PW_VULKAN_USE="3" ;;
     "$SORT_G_ZINK" )     export PW_VULKAN_USE="4" ;;
+    "$SORT_DGV2" )       export PW_VULKAN_USE="5" ;;
 esac
 
 init_wine_ver
diff --git a/data_from_portwine/scripts/var b/data_from_portwine/scripts/var
index d825bb38..b7a8fbc0 100755
--- a/data_from_portwine/scripts/var
+++ b/data_from_portwine/scripts/var
@@ -50,6 +50,7 @@ export PW_WINE_FULLSCREEN_FSR="1"
 ###DXVK_AND_VKD3D###
 export VKD3D_LIMIT_TESS_FACTORS="64"
 export D8VK_VER="1.7.1-2367"
+export DGV2_VER="v2.8.2"
 export DXVK_STABLE_VER="1.10.3-28"
 export DXVK_GIT_VER="2.3.1-9"
 export VKD3D_STABLE_VER="1.1-2602"