diff --git a/TextureExtraction tool/Data/TextureExtractor.cs b/TextureExtraction tool/Data/TextureExtractor.cs index aa9af88a..4c6d6e37 100644 --- a/TextureExtraction tool/Data/TextureExtractor.cs +++ b/TextureExtraction tool/Data/TextureExtractor.cs @@ -35,6 +35,11 @@ public class ExtractorOptions : Options /// public bool Force = false; + /// + /// Tries to Imitate dolphin mipmap detection. + /// + public bool DolphinMipDetection = true; + /// /// Sorts the textures and removes unnecessary folders. /// @@ -350,7 +355,7 @@ private void Save(JUTTexture texture, in string subdirectory) { string path = GetFullSaveDirectory(subdirectory); Directory.CreateDirectory(path); - tex[i].Save(Path.Combine(path, tex.GetDolphinTextureHash(i) + ".png"), System.Drawing.Imaging.ImageFormat.Png); + tex[i].Save(Path.Combine(path, tex.GetDolphinTextureHash(i, false, ((ExtractorOptions)Option).DolphinMipDetection) + ".png"), System.Drawing.Imaging.ImageFormat.Png); //skip mips? if (!((ExtractorOptions)Option).Mips) break; diff --git a/TextureExtraction tool/Program.cs b/TextureExtraction tool/Program.cs index d33faa71..82a2c0fa 100644 --- a/TextureExtraction tool/Program.cs +++ b/TextureExtraction tool/Program.cs @@ -87,6 +87,8 @@ static void Main(string[] args) options.Raw = ConsoleEx.WriteBoolPrint(ConsoleEx.ReadBool(false, ConsoleKey.T, ConsoleKey.F), "True", "\tFalse", ConsoleColor.Green, ConsoleColor.Red); Console.WriteLine($"Tries to extract textures from unknown file formats, may cause errors. \tTrue or (False)"); options.Force = ConsoleEx.WriteBoolPrint(ConsoleEx.ReadBool(false, ConsoleKey.T, ConsoleKey.F), "True", "\tFalse", ConsoleColor.Green, ConsoleColor.Red); + Console.Write($"Tries to Imitate dolphin mipmap detection. \t(True) or False"); + options.DolphinMipDetection = ConsoleEx.WriteBoolPrint(ConsoleEx.ReadBool(true, ConsoleKey.T, ConsoleKey.F), "True", "\tFalse", ConsoleColor.Green, ConsoleColor.Red); Console.Write($"Clean up folder structure. \t(True) or False"); options.Cleanup = ConsoleEx.WriteBoolPrint(ConsoleEx.ReadBool(true, ConsoleKey.T, ConsoleKey.F), "True", "\tFalse", ConsoleColor.Green, ConsoleColor.Red); Console.WriteLine($"High performance mode.(Multithreading) \t(True) or False"); @@ -203,9 +205,14 @@ static void Main(string[] args) options.Cleanup = true; break; case "-cleanup:none": + case "-c:none": case "-c:n": options.Cleanup = false; break; + case "-dolphinmipdetection": + case "-dm": + options.Cleanup = false; + break; case "-tasks": case "-t": i++; @@ -306,6 +313,7 @@ private static void PrintHelp() Console.WriteLine("\tOption:\t -f -force\tTries to extract unknown files, may cause errors."); Console.WriteLine("\tOption:\t -c -cleanup\tuses the default folder cleanup."); Console.WriteLine("\tOption:\t -c:n -cleanup:none\tretains the original folder structure."); + Console.WriteLine("\tOption:\t -dmd -dolphinmipdetection\tTries to imitate dolphin mipmap detection."); Console.WriteLine("\tOption:\t -t -tasks \"i\"\tsets the maximum number of concurrent tasks."); Console.WriteLine($"\t\ti:\t integer that represents the maximum degree of parallelism. default:{options.Parallel.MaxDegreeOfParallelism}"); Console.WriteLine(); @@ -367,6 +375,8 @@ static void PrintOptions(TextureExtractor.ExtractorOptions options) ConsoleEx.WriteBoolPrint(options.Raw, ConsoleColor.Green, ConsoleColor.Red); Console.Write($"Force extract textures from unknown formats: "); ConsoleEx.WriteBoolPrint(options.Force, ConsoleColor.Green, ConsoleColor.Red); + Console.Write($"Imitate dolphin mipmap detection: "); + ConsoleEx.WriteBoolPrint(options.DolphinMipDetection, ConsoleColor.Green, ConsoleColor.Red); Console.Write($"Clean up folder structure: "); ConsoleEx.WriteBoolPrint(options.Cleanup, ConsoleColor.Green, ConsoleColor.Red); Console.Write($"High performance mode (Multithreading): "); diff --git a/TextureExtraction tool/Properties/AssemblyInfo.cs b/TextureExtraction tool/Properties/AssemblyInfo.cs index 01a1c7aa..4afc4846 100644 --- a/TextureExtraction tool/Properties/AssemblyInfo.cs +++ b/TextureExtraction tool/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.8.2.4")] -[assembly: AssemblyFileVersion("0.8.2.4")] +[assembly: AssemblyVersion("0.8.2.6")] +[assembly: AssemblyFileVersion("0.8.2.6")] diff --git a/lib/AuroraLip/Texture/Formats/HXTB.cs b/lib/AuroraLip/Texture/Formats/HXTB.cs index da6657eb..fc5c6dae 100644 --- a/lib/AuroraLip/Texture/Formats/HXTB.cs +++ b/lib/AuroraLip/Texture/Formats/HXTB.cs @@ -44,7 +44,7 @@ protected override void Read(Stream stream) stream.Seek(header_offset, SeekOrigin.Begin); uint data_offset = stream.ReadUInt32(Endian.Big); GXImageFormat format = (GXImageFormat)stream.ReadByte(); - byte image_count = (byte)stream.ReadByte(); + byte image_count = (byte)stream.ReadByte(); // max_LOD? ushort unknown3 = stream.ReadUInt16(Endian.Big); ushort width = stream.ReadUInt16(Endian.Big); ushort height = stream.ReadUInt16(Endian.Big); @@ -83,7 +83,7 @@ protected override void Read(Stream stream) WrapT = GXWrapMode.CLAMP, EnableEdgeLOD = false, MinLOD = 0, - MaxLOD = 0 + MaxLOD = image_count }; Add(current); } diff --git a/lib/AuroraLip/Texture/Formats/NUTC.cs b/lib/AuroraLip/Texture/Formats/NUTC.cs index 3bf1b6e9..3a52c84a 100644 --- a/lib/AuroraLip/Texture/Formats/NUTC.cs +++ b/lib/AuroraLip/Texture/Formats/NUTC.cs @@ -36,6 +36,9 @@ protected override void Read(Stream stream) ushort texturesCount = stream.ReadUInt16(Endian.Big); stream.Position = 0x20; + if (FormatVersion != 32770) + Console.WriteLine("NUTC Version: " + FormatVersion); + for (int i = 0; i < texturesCount; i++) { @@ -84,7 +87,7 @@ protected override void Read(Stream stream) WrapT = GXWrapMode.CLAMP, EnableEdgeLOD = false, MinLOD = 0, - MaxLOD = 0 + MaxLOD = TotalImageCount-1 }; Add(current); } diff --git a/lib/AuroraLip/Texture/Formats/PTLG.cs b/lib/AuroraLip/Texture/Formats/PTLG.cs index cbab05ed..2389ddc6 100644 --- a/lib/AuroraLip/Texture/Formats/PTLG.cs +++ b/lib/AuroraLip/Texture/Formats/PTLG.cs @@ -85,7 +85,7 @@ protected override void Read(Stream stream) WrapT = GXWrapMode.CLAMP, EnableEdgeLOD = false, MinLOD = 0, - MaxLOD = 0 + MaxLOD = Images-1 }; Add(current); diff --git a/lib/AuroraLip/Texture/Formats/REFT.cs b/lib/AuroraLip/Texture/Formats/REFT.cs index d3fa0a8a..464f7df0 100644 --- a/lib/AuroraLip/Texture/Formats/REFT.cs +++ b/lib/AuroraLip/Texture/Formats/REFT.cs @@ -103,7 +103,6 @@ private void ReadREFTfile(Stream stream) int Palettes = stream.ReadUInt16(Endian.Big); uint PaletteSize = stream.ReadUInt32(Endian.Big); byte images = (byte)stream.ReadByte(); - if (images > 0) --images; byte MinFilter = (byte)stream.ReadByte(); byte MaxFilter = (byte)stream.ReadByte(); byte Unknown2 = (byte)stream.ReadByte(); @@ -118,7 +117,7 @@ private void ReadREFTfile(Stream stream) PaletteData = stream.Read((int)PaletteSize); } stream.Position = ImageAddress; - TexEntry current = new TexEntry(stream, PaletteData, Format, PaletteFormat, Palettes, ImageWidth, ImageHeight, images) + TexEntry current = new TexEntry(stream, PaletteData, Format, PaletteFormat, Palettes, ImageWidth, ImageHeight, images -1) { LODBias = LODBias, MagnificationFilter = (GXFilterMode)MaxFilter, diff --git a/lib/AuroraLip/Texture/Formats/TEX.cs b/lib/AuroraLip/Texture/Formats/TEX.cs index 3078e11d..164eb0cd 100644 --- a/lib/AuroraLip/Texture/Formats/TEX.cs +++ b/lib/AuroraLip/Texture/Formats/TEX.cs @@ -60,7 +60,7 @@ protected override void Read(Stream stream) WrapT = GXWrapMode.CLAMP, EnableEdgeLOD = false, MinLOD = 0, - MaxLOD = 0 + MaxLOD = MipMaps }; Add(current); } diff --git a/lib/AuroraLip/Texture/Formats/TXTR.cs b/lib/AuroraLip/Texture/Formats/TXTR.cs index 87db0f3b..13b73b86 100644 --- a/lib/AuroraLip/Texture/Formats/TXTR.cs +++ b/lib/AuroraLip/Texture/Formats/TXTR.cs @@ -39,11 +39,11 @@ protected override void Read(Stream stream) PaletteFormat = (GXPaletteFormat)stream.ReadUInt32(Endian.Big); int CWidth = stream.ReadUInt16(Endian.Big); int CHeight = stream.ReadUInt16(Endian.Big); - ColorsCount = CHeight* CWidth; - palettedata = stream.Read(ColorsCount*2); + ColorsCount = CHeight * CWidth; + palettedata = stream.Read(ColorsCount * 2); } - TexEntry current = new TexEntry(stream, palettedata, Format, PaletteFormat, ColorsCount, ImageWidth, ImageHeight, (int)Images-1) + TexEntry current = new TexEntry(stream, palettedata, Format, PaletteFormat, ColorsCount, ImageWidth, ImageHeight, (int)Images - 1) { LODBias = 0, MagnificationFilter = GXFilterMode.Nearest, @@ -52,7 +52,7 @@ protected override void Read(Stream stream) WrapT = GXWrapMode.CLAMP, EnableEdgeLOD = false, MinLOD = 0, - MaxLOD = 0 + MaxLOD = Images - 1 }; Add(current); } diff --git a/lib/AuroraLip/Texture/J3D/TexEntry.cs b/lib/AuroraLip/Texture/J3D/TexEntry.cs index 5045dda8..4915f049 100644 --- a/lib/AuroraLip/Texture/J3D/TexEntry.cs +++ b/lib/AuroraLip/Texture/J3D/TexEntry.cs @@ -150,11 +150,17 @@ public TexEntry(Bitmap Image, GXImageFormat ImageFormat = GXImageFormat.CMPR, GX EnableEdgeLOD = EdgeLoD; } - public string GetDolphinTextureHash(int mipmap = 0, bool UseTlut = false) + public string GetDolphinTextureHash(int mipmap = 0, bool UseTlut = false, bool DolphinMipDetection = true) { + bool HasMips = this.Count != 1; + //dolphin seems to use the MaxLOD value to decide if it is a mipmap Texture. + //https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/VideoCommon/TextureInfo.cpp#L80 + if (!HasMips && DolphinMipDetection) + HasMips = MaxLOD != 0; + return "tex1_" + this[0].Width + 'x' + this[0].Height + '_' //Has mipmaps - + (this.Count != 1 + + (HasMips ? "m_" : string.Empty) // Hash + Hash.ToString("x").PadLeft(16, '0') + '_'