mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-10 15:14:55 +00:00
Fix 0.9 bfres with scene animations. Add toggle for direct x tex decoder
This commit is contained in:
parent
141be9ff4f
commit
47ca70a015
15 changed files with 182 additions and 42 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -72,10 +72,12 @@ namespace FirstPlugin
|
||||||
|
|
||||||
public MenuExt()
|
public MenuExt()
|
||||||
{
|
{
|
||||||
|
// toolExt[0] = new STToolStripItem("Models");
|
||||||
|
// toolExt[0].DropDownItems.Add(new STToolStripItem("Batch Export (BFRES)", Export));
|
||||||
|
|
||||||
editExt[0] = new STToolStripItem("Use Advanced Editor As Default", AdvancedEditor);
|
editExt[0] = new STToolStripItem("Use Advanced Editor As Default", AdvancedEditor);
|
||||||
newFileExt[0] = new STToolStripItem("BFRES (Switch)", NewSwitchBfres);
|
newFileExt[0] = new STToolStripItem("BFRES (Switch)", NewSwitchBfres);
|
||||||
newFileExt[1] = new STToolStripItem("BFRES (Wii U)", NewWiiUBfres);
|
newFileExt[1] = new STToolStripItem("BFRES (Wii U)", NewWiiUBfres);
|
||||||
|
|
||||||
editExt[0].Checked = !PluginRuntime.UseSimpleBfresEditor;
|
editExt[0].Checked = !PluginRuntime.UseSimpleBfresEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +144,71 @@ namespace FirstPlugin
|
||||||
debugInfo.Show();
|
debugInfo.Show();
|
||||||
debugInfo.PrintDebugInfo(ofd.FileName);
|
debugInfo.PrintDebugInfo(ofd.FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Export(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
string formats = FileFilters.FMDL_EXPORT;
|
||||||
|
|
||||||
|
string[] forms = formats.Split('|');
|
||||||
|
|
||||||
|
List<string> Formats = new List<string>();
|
||||||
|
for (int i = 0; i < forms.Length; i++)
|
||||||
|
{
|
||||||
|
if (i > 1 || i == (forms.Length - 1)) //Skip lines with all extensions
|
||||||
|
{
|
||||||
|
if (!forms[i].StartsWith("*"))
|
||||||
|
Formats.Add(forms[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BatchFormatExport form = new BatchFormatExport(Formats);
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
string Extension = form.GetSelectedExtension();
|
||||||
|
|
||||||
|
OpenFileDialog ofd = new OpenFileDialog();
|
||||||
|
ofd.Multiselect = true;
|
||||||
|
ofd.Filter = Utils.GetAllFilters(new Type[] { typeof(BFRES), typeof(SARC) });
|
||||||
|
|
||||||
|
if (ofd.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
FolderSelectDialog folderDialog = new FolderSelectDialog();
|
||||||
|
if (folderDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
foreach (string file in ofd.FileNames)
|
||||||
|
{
|
||||||
|
var FileFormat = STFileLoader.OpenFileFormat(file, new Type[] { typeof(BFRES), typeof(SARC) });
|
||||||
|
if (FileFormat == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SearchBinary(FileFormat, folderDialog.SelectedPath, Extension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SearchBinary(IFileFormat FileFormat, string Folder, string Extension)
|
||||||
|
{
|
||||||
|
if (FileFormat is SARC)
|
||||||
|
{
|
||||||
|
foreach (var file in ((SARC)FileFormat).Files)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{FileFormat.FileName} {file.Text}");
|
||||||
|
var archiveFile = STFileLoader.OpenFileFormat(file.FullName, new Type[] { typeof(BFRES), typeof(SARC) }, file.Data);
|
||||||
|
if (archiveFile == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SearchBinary(archiveFile, Folder, Extension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (FileFormat is BFRES)
|
||||||
|
{
|
||||||
|
// ((BFRES)FileFormat).Export(Path.Combine(Folder, $"{FileFormat.FileName}{Extension}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
FileFormat.Unload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] CreateNewBFRESSwitch(string Name)
|
private static byte[] CreateNewBFRESSwitch(string Name)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -231,6 +231,9 @@ namespace Switch_Toolbox.Library
|
||||||
case "FrameCamera":
|
case "FrameCamera":
|
||||||
bool.TryParse(node.InnerText, out Runtime.FrameCamera);
|
bool.TryParse(node.InnerText, out Runtime.FrameCamera);
|
||||||
break;
|
break;
|
||||||
|
case "UseDirectXTexDecoder":
|
||||||
|
bool.TryParse(node.InnerText, out Runtime.UseDirectXTexDecoder);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,6 +356,7 @@ namespace Switch_Toolbox.Library
|
||||||
XmlNode mainSettingsNode = doc.CreateElement("MAINFORM");
|
XmlNode mainSettingsNode = doc.CreateElement("MAINFORM");
|
||||||
parentNode.AppendChild(mainSettingsNode);
|
parentNode.AppendChild(mainSettingsNode);
|
||||||
|
|
||||||
|
mainSettingsNode.AppendChild(createNode(doc, "UseDirectXTexDecoder", Runtime.UseDirectXTexDecoder.ToString()));
|
||||||
mainSettingsNode.AppendChild(createNode(doc, "DisplayViewport", Runtime.DisplayViewport.ToString()));
|
mainSettingsNode.AppendChild(createNode(doc, "DisplayViewport", Runtime.DisplayViewport.ToString()));
|
||||||
mainSettingsNode.AppendChild(createNode(doc, "UseOpenGL", Runtime.UseOpenGL.ToString()));
|
mainSettingsNode.AppendChild(createNode(doc, "UseOpenGL", Runtime.UseOpenGL.ToString()));
|
||||||
mainSettingsNode.AppendChild(createNode(doc, "UseDebugDomainExceptionHandler", Runtime.UseDebugDomainExceptionHandler.ToString()));
|
mainSettingsNode.AppendChild(createNode(doc, "UseDebugDomainExceptionHandler", Runtime.UseDebugDomainExceptionHandler.ToString()));
|
||||||
|
|
|
@ -237,13 +237,11 @@ namespace Switch_Toolbox.Library
|
||||||
int W = (width + 3) / 4;
|
int W = (width + 3) / 4;
|
||||||
int H = (height + 3) / 4;
|
int H = (height + 3) / 4;
|
||||||
|
|
||||||
|
|
||||||
byte[] Output = new byte[W * H * 64];
|
byte[] Output = new byte[W * H * 64];
|
||||||
|
|
||||||
for (int Y = 0; Y < H; Y++)
|
for (int Y = 0; Y < H; Y++)
|
||||||
{
|
{
|
||||||
for (int X = 0; X < W; X++)
|
for (int X = 0; X < W; X++)
|
||||||
|
|
||||||
{
|
{
|
||||||
int IOffs = (Y * W + X) * 16;
|
int IOffs = (Y * W + X) * 16;
|
||||||
byte[] Red = new byte[8];
|
byte[] Red = new byte[8];
|
||||||
|
|
|
@ -377,10 +377,16 @@ namespace Switch_Toolbox.Library
|
||||||
case TEX_FORMAT.ETC1_A4:
|
case TEX_FORMAT.ETC1_A4:
|
||||||
return BitmapExtension.GetBitmap(ETC1.ETC1Decompress(data, (int)width, (int)height, true),
|
return BitmapExtension.GetBitmap(ETC1.ETC1Decompress(data, (int)width, (int)height, true),
|
||||||
(int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
(int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||||
default:
|
|
||||||
return BitmapExtension.GetBitmap(DecodeBlock(data, width, height, Format),
|
|
||||||
(int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Runtime.UseDirectXTexDecoder)
|
||||||
|
{
|
||||||
|
return BitmapExtension.GetBitmap(DecodeBlock(data, width, height, Format),
|
||||||
|
(int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return DecodeNotDirectXTex(data, width, height, Format);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -388,29 +394,7 @@ namespace Switch_Toolbox.Library
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Format == TEX_FORMAT.BC1_UNORM)
|
return DecodeNotDirectXTex(data, width, height, Format);
|
||||||
return DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, false);
|
|
||||||
else if (Format == TEX_FORMAT.BC1_UNORM_SRGB)
|
|
||||||
return DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, true);
|
|
||||||
else if (Format == TEX_FORMAT.BC3_UNORM_SRGB)
|
|
||||||
return DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, false);
|
|
||||||
else if (Format == TEX_FORMAT.BC3_UNORM)
|
|
||||||
return DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, true);
|
|
||||||
else if (Format == TEX_FORMAT.BC4_UNORM)
|
|
||||||
return DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, false);
|
|
||||||
else if (Format == TEX_FORMAT.BC4_SNORM)
|
|
||||||
return DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, true);
|
|
||||||
else if (Format == TEX_FORMAT.BC5_UNORM)
|
|
||||||
return DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, false);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Runtime.UseOpenGL)
|
|
||||||
{
|
|
||||||
Runtime.OpenTKInitialized = true;
|
|
||||||
LoadOpenGLTexture();
|
|
||||||
return RenderableTex.GLTextureToBitmap(RenderableTex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -421,6 +405,40 @@ namespace Switch_Toolbox.Library
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Bitmap DecodeNotDirectXTex(byte[] data, uint Width, uint Height, TEX_FORMAT Format)
|
||||||
|
{
|
||||||
|
if (Format == TEX_FORMAT.BC1_UNORM)
|
||||||
|
return DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, false);
|
||||||
|
else if (Format == TEX_FORMAT.BC1_UNORM_SRGB)
|
||||||
|
return DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, true);
|
||||||
|
else if (Format == TEX_FORMAT.BC3_UNORM_SRGB)
|
||||||
|
return DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, false);
|
||||||
|
else if (Format == TEX_FORMAT.BC3_UNORM)
|
||||||
|
return DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, true);
|
||||||
|
else if (Format == TEX_FORMAT.BC4_UNORM)
|
||||||
|
return DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, false);
|
||||||
|
else if (Format == TEX_FORMAT.BC4_SNORM)
|
||||||
|
return DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, true);
|
||||||
|
else if (Format == TEX_FORMAT.BC5_UNORM)
|
||||||
|
return DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, false);
|
||||||
|
else if (Format == TEX_FORMAT.BC7_UNORM)
|
||||||
|
return BitmapExtension.GetBitmap(CSharpImageLibrary.DDS.Dxt.DecompressBc7(data, (int)Width, (int)Height), (int)Width, (int)Height);
|
||||||
|
else if (Format == TEX_FORMAT.BC7_UNORM_SRGB)
|
||||||
|
return BitmapExtension.GetBitmap(CSharpImageLibrary.DDS.Dxt.DecompressBc7(data, (int)Width, (int)Height), (int)Width, (int)Height);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Runtime.UseOpenGL)
|
||||||
|
{
|
||||||
|
Runtime.OpenTKInitialized = true;
|
||||||
|
if (RenderableTex == null || !RenderableTex.GLInitialized)
|
||||||
|
LoadOpenGLTexture();
|
||||||
|
|
||||||
|
return RenderableTex.ToBitmap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static Bitmap DecodeBlockGetBitmap(byte[] data, uint Width, uint Height, TEX_FORMAT Format)
|
public static Bitmap DecodeBlockGetBitmap(byte[] data, uint Width, uint Height, TEX_FORMAT Format)
|
||||||
{
|
{
|
||||||
Bitmap bitmap = BitmapExtension.GetBitmap(DecodeBlock(data, Width, Height, Format),
|
Bitmap bitmap = BitmapExtension.GetBitmap(DecodeBlock(data, Width, Height, Format),
|
||||||
|
|
|
@ -66,17 +66,21 @@ namespace Switch_Toolbox.Library.Rendering
|
||||||
case TEX_FORMAT.BC4_SNORM:
|
case TEX_FORMAT.BC4_SNORM:
|
||||||
//Convert to rgb to prevent red output
|
//Convert to rgb to prevent red output
|
||||||
//While shaders could prevent this, converting is easier and works fine across all editors
|
//While shaders could prevent this, converting is easier and works fine across all editors
|
||||||
data = STGenericTexture.DecodeBlock(data,
|
if (Runtime.UseDirectXTexDecoder)
|
||||||
|
{
|
||||||
|
data = STGenericTexture.DecodeBlock(data,
|
||||||
GenericTexture.Width,
|
GenericTexture.Width,
|
||||||
GenericTexture.Height,
|
GenericTexture.Height,
|
||||||
GenericTexture.Format,
|
GenericTexture.Format,
|
||||||
GenericTexture.PlatformSwizzle);
|
GenericTexture.PlatformSwizzle);
|
||||||
|
pixelInternalFormat = PixelInternalFormat.Rgba;
|
||||||
pixelInternalFormat = PixelInternalFormat.Rgba;
|
pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
|
||||||
pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
|
}
|
||||||
|
else
|
||||||
// pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1;
|
{
|
||||||
// pixelInternalFormat = PixelInternalFormat.CompressedSignedRedRgtc1;
|
pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1;
|
||||||
|
pixelInternalFormat = PixelInternalFormat.CompressedSignedRedRgtc1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case TEX_FORMAT.BC5_SNORM:
|
case TEX_FORMAT.BC5_SNORM:
|
||||||
pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2;
|
pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2;
|
||||||
|
@ -110,14 +114,17 @@ namespace Switch_Toolbox.Library.Rendering
|
||||||
pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
|
pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
data = STGenericTexture.DecodeBlock(data,
|
if (Runtime.UseDirectXTexDecoder)
|
||||||
|
{
|
||||||
|
data = STGenericTexture.DecodeBlock(data,
|
||||||
GenericTexture.Width,
|
GenericTexture.Width,
|
||||||
GenericTexture.Height,
|
GenericTexture.Height,
|
||||||
GenericTexture.Format,
|
GenericTexture.Format,
|
||||||
GenericTexture.PlatformSwizzle);
|
GenericTexture.PlatformSwizzle);
|
||||||
|
|
||||||
pixelInternalFormat = PixelInternalFormat.Rgba;
|
pixelInternalFormat = PixelInternalFormat.Rgba;
|
||||||
pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
|
pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
GLInitialized = true;
|
GLInitialized = true;
|
||||||
|
|
|
@ -33,6 +33,8 @@ namespace Switch_Toolbox.Library.IO
|
||||||
|
|
||||||
public static IFileFormat OpenFileFormat(string FileName, Type[] FileTypes, byte[] data = null)
|
public static IFileFormat OpenFileFormat(string FileName, Type[] FileTypes, byte[] data = null)
|
||||||
{
|
{
|
||||||
|
CheckCompression(FileName, data);
|
||||||
|
|
||||||
Stream stream;
|
Stream stream;
|
||||||
if (data != null)
|
if (data != null)
|
||||||
stream = new MemoryStream(data);
|
stream = new MemoryStream(data);
|
||||||
|
@ -56,6 +58,8 @@ namespace Switch_Toolbox.Library.IO
|
||||||
|
|
||||||
public static IFileFormat OpenFileFormat(string FileName, Type FileType, byte[] data = null)
|
public static IFileFormat OpenFileFormat(string FileName, Type FileType, byte[] data = null)
|
||||||
{
|
{
|
||||||
|
CheckCompression(FileName, data);
|
||||||
|
|
||||||
Stream stream;
|
Stream stream;
|
||||||
if (data != null)
|
if (data != null)
|
||||||
stream = new MemoryStream(data);
|
stream = new MemoryStream(data);
|
||||||
|
@ -71,6 +75,46 @@ namespace Switch_Toolbox.Library.IO
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CheckCompression(string FileName, byte[] data)
|
||||||
|
{
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
using (var reader = new FileReader(data))
|
||||||
|
{
|
||||||
|
DecompressData(reader, FileName, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
using (var reader = new FileReader(FileName))
|
||||||
|
{
|
||||||
|
DecompressData(reader, FileName, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DecompressData(FileReader reader, string FileName, byte[] data)
|
||||||
|
{
|
||||||
|
reader.ByteOrder = ByteOrder.BigEndian;
|
||||||
|
uint MagicHex = reader.ReadUInt32();
|
||||||
|
string Magic = reader.ReadMagic(0, 4);
|
||||||
|
reader.Position = 0;
|
||||||
|
|
||||||
|
if (Magic == "Yaz0")
|
||||||
|
{
|
||||||
|
if (data != null)
|
||||||
|
data = EveryFileExplorer.YAZ0.Decompress(data);
|
||||||
|
else
|
||||||
|
data = EveryFileExplorer.YAZ0.Decompress(FileName);
|
||||||
|
}
|
||||||
|
if (MagicHex == 0x28B52FFD || MagicHex == 0xFD2FB528)
|
||||||
|
{
|
||||||
|
if (data != null)
|
||||||
|
data = STLibraryCompression.ZSTD.Decompress(data);
|
||||||
|
else
|
||||||
|
data = STLibraryCompression.ZSTD.Decompress(File.ReadAllBytes(FileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="IFileFormat"/> from a file or byte array.
|
/// Gets the <see cref="IFileFormat"/> from a file or byte array.
|
||||||
|
|
|
@ -15,6 +15,8 @@ namespace Switch_Toolbox.Library
|
||||||
|
|
||||||
public class Runtime
|
public class Runtime
|
||||||
{
|
{
|
||||||
|
public static bool UseDirectXTexDecoder = true;
|
||||||
|
|
||||||
public static bool DEVELOPER_DEBUG_MODE = false;
|
public static bool DEVELOPER_DEBUG_MODE = false;
|
||||||
|
|
||||||
public static class ResourceTables
|
public static class ResourceTables
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue