From 27de2235416868ee22a8d51fcfc7541258a31cb6 Mon Sep 17 00:00:00 2001 From: JacksonAbney Date: Sun, 6 Apr 2025 15:00:23 -0800 Subject: [PATCH 1/3] Fixes "Mipmap not found in texture" exception for textures with a height that isn't a multiple of 4 but is compressed. --- CodeWalker.Core/GameFiles/Resources/Texture.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CodeWalker.Core/GameFiles/Resources/Texture.cs b/CodeWalker.Core/GameFiles/Resources/Texture.cs index 36c558ee9..2061ef4a4 100644 --- a/CodeWalker.Core/GameFiles/Resources/Texture.cs +++ b/CodeWalker.Core/GameFiles/Resources/Texture.cs @@ -707,6 +707,8 @@ public int CalcDataSize() len += slicePitch; div *= 2; } + + Console.WriteLine(len * Depth); return len * Depth; } public ushort CalculateStride() @@ -1099,6 +1101,13 @@ public override void Read(ResourceDataReader reader, params object[] parameters) int Levels = Convert.ToInt32(parameters[3]); int Stride = Convert.ToInt32(parameters[4]); + bool compressed = DDSIO.DXTex.IsCompressed(DDSIO.GetDXGIFormat((TextureFormat)format)); + + if (compressed && Height % 4 != 0) + { + Height = Math.Max(1, (Height + 3) & ~3); + } + int fullLength = 0; int length = Stride * Height; for (int i = 0; i < Levels; i++) From bbd0998e13a06b946b7cc168e11126069be8ec40 Mon Sep 17 00:00:00 2001 From: JacksonAbney Date: Sun, 6 Apr 2025 15:06:25 -0800 Subject: [PATCH 2/3] Remove extra logging that was left in from initially debugging the issue. --- CodeWalker.Core/GameFiles/Resources/Texture.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/CodeWalker.Core/GameFiles/Resources/Texture.cs b/CodeWalker.Core/GameFiles/Resources/Texture.cs index 2061ef4a4..d441bba0e 100644 --- a/CodeWalker.Core/GameFiles/Resources/Texture.cs +++ b/CodeWalker.Core/GameFiles/Resources/Texture.cs @@ -708,7 +708,6 @@ public int CalcDataSize() div *= 2; } - Console.WriteLine(len * Depth); return len * Depth; } public ushort CalculateStride() From c26824be968b6975185ef28ce8c96c58eeec5fc4 Mon Sep 17 00:00:00 2001 From: JacksonAbney Date: Sun, 6 Apr 2025 15:41:13 -0800 Subject: [PATCH 3/3] Change Math.Max(1 to Math.Max(4 as minimum dimension should be 4 not 1. --- CodeWalker.Core/GameFiles/Resources/Texture.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodeWalker.Core/GameFiles/Resources/Texture.cs b/CodeWalker.Core/GameFiles/Resources/Texture.cs index d441bba0e..088acf0b1 100644 --- a/CodeWalker.Core/GameFiles/Resources/Texture.cs +++ b/CodeWalker.Core/GameFiles/Resources/Texture.cs @@ -1104,7 +1104,7 @@ public override void Read(ResourceDataReader reader, params object[] parameters) if (compressed && Height % 4 != 0) { - Height = Math.Max(1, (Height + 3) & ~3); + Height = Math.Max(4, (Height + 3) & ~3); } int fullLength = 0;