From 595bb9a375c67807cf02893870b713ac5bc7aa8e Mon Sep 17 00:00:00 2001 From: gg781 <142070467+gg781@users.noreply.github.com> Date: Wed, 23 Aug 2023 11:26:48 +0800 Subject: [PATCH] Add Support for D3DFMT_X8R8G8B8 (#214) This would "fix" the exported xml from having "22" in the embedded texture's format block. In before this 22 prevents the xml file from importing into blender via Sollumz, caused the common error "KeyError:22" when some people editing weird-making mods. --- CodeWalker.Core/GameFiles/Resources/Texture.cs | 1 + CodeWalker.Core/GameFiles/Utils/DDSIO.cs | 6 ++++++ CodeWalker/GameFiles/TextureFormats.cs | 2 ++ 3 files changed, 9 insertions(+) diff --git a/CodeWalker.Core/GameFiles/Resources/Texture.cs b/CodeWalker.Core/GameFiles/Resources/Texture.cs index 76faa84..f27a96a 100644 --- a/CodeWalker.Core/GameFiles/Resources/Texture.cs +++ b/CodeWalker.Core/GameFiles/Resources/Texture.cs @@ -659,6 +659,7 @@ namespace CodeWalker.GameFiles public enum TextureFormat : uint { D3DFMT_A8R8G8B8 = 21, + D3DFMT_X8R8G8B8 = 22, D3DFMT_A1R5G5B5 = 25, D3DFMT_A8 = 28, D3DFMT_A8B8G8R8 = 32, diff --git a/CodeWalker.Core/GameFiles/Utils/DDSIO.cs b/CodeWalker.Core/GameFiles/Utils/DDSIO.cs index e99f363..3542699 100644 --- a/CodeWalker.Core/GameFiles/Utils/DDSIO.cs +++ b/CodeWalker.Core/GameFiles/Utils/DDSIO.cs @@ -185,6 +185,10 @@ namespace CodeWalker.Utils px = imgdata; swaprb = false; break; + case DXGI_FORMAT.DXGI_FORMAT_B8G8R8X8_UNORM: // TextureFormat.D3DFMT_X8R8G8B8 + px = imgdata; + swaprb = false; + break; default: break; //shouldn't get here... } @@ -491,6 +495,7 @@ namespace CodeWalker.Utils case DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM: format = TextureFormat.D3DFMT_A8B8G8R8; break; case DXGI_FORMAT.DXGI_FORMAT_R8_UNORM: format = TextureFormat.D3DFMT_L8; break; case DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM: format = TextureFormat.D3DFMT_A8R8G8B8; break; + case DXGI_FORMAT.DXGI_FORMAT_B8G8R8X8_UNORM: format = TextureFormat.D3DFMT_X8R8G8B8; break; } return format; } @@ -514,6 +519,7 @@ namespace CodeWalker.Utils case TextureFormat.D3DFMT_A8B8G8R8: format = DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM; break; case TextureFormat.D3DFMT_L8: format = DXGI_FORMAT.DXGI_FORMAT_R8_UNORM; break; case TextureFormat.D3DFMT_A8R8G8B8: format = DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM; break; + case TextureFormat.D3DFMT_X8R8G8B8: format = DXGI_FORMAT.DXGI_FORMAT_B8G8R8X8_UNORM; break; } return format; } diff --git a/CodeWalker/GameFiles/TextureFormats.cs b/CodeWalker/GameFiles/TextureFormats.cs index 008baf5..7afbe4e 100644 --- a/CodeWalker/GameFiles/TextureFormats.cs +++ b/CodeWalker/GameFiles/TextureFormats.cs @@ -30,6 +30,7 @@ namespace CodeWalker.GameFiles case TextureFormat.D3DFMT_A8B8G8R8: format = Format.R8G8B8A8_UNorm; break; case TextureFormat.D3DFMT_L8: format = Format.R8_UNorm; break; case TextureFormat.D3DFMT_A8R8G8B8: format = Format.B8G8R8A8_UNorm; break; + case TextureFormat.D3DFMT_X8R8G8B8: format = Format.B8G8R8X8_UNorm; break; } return format; } @@ -52,6 +53,7 @@ namespace CodeWalker.GameFiles case TextureFormat.D3DFMT_A8B8G8R8: return 32;// R8G8B8A8_UNorm case TextureFormat.D3DFMT_L8: return 8;// R8_UNorm case TextureFormat.D3DFMT_A8R8G8B8: return 32;// B8G8R8A8_UNorm + case TextureFormat.D3DFMT_X8R8G8B8: return 32;// B8G8R8X8_UNorm default: return 0; }