diff --git a/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFBMDL.cs b/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFBMDL.cs index 0d81afcb..78bc3bd4 100644 --- a/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFBMDL.cs +++ b/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFBMDL.cs @@ -182,7 +182,7 @@ namespace FirstPlugin { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Supported Formats|*.dae;*.json;"; - sfd.FileName = Text; + sfd.FileName = Path.GetFileNameWithoutExtension(Text); sfd.DefaultExt = "dae"; if (sfd.ShowDialog() == DialogResult.OK) { diff --git a/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMeshBufferHelper.cs b/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMeshBufferHelper.cs index f70b618b..b0f9c8f8 100644 --- a/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMeshBufferHelper.cs +++ b/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMeshBufferHelper.cs @@ -28,6 +28,7 @@ namespace FirstPlugin public static byte[] CreateVertexDataBuffer(STGenericObject mesh, List SkinningIndices, IList attributes) { + var stride = GetTotalBufferStride(attributes); var mem = new System.IO.MemoryStream(); using (var writer = new FileWriter(mem)) @@ -35,6 +36,8 @@ namespace FirstPlugin //Generate a buffer based on the attributes used for (int v = 0; v < mesh.vertices.Count; v++) { + writer.SeekBegin(v * stride); + for (int a = 0; a < attributes.Count; a++) { uint numAttributes = attributes[a].ElementCount; @@ -51,7 +54,7 @@ namespace FirstPlugin values.Add(mesh.vertices[v].nrm.X); values.Add(mesh.vertices[v].nrm.Y); values.Add(mesh.vertices[v].nrm.Z); - values.Add(0); + values.Add(mesh.vertices[v].normalW); // values.Add(((GFLXMesh.GFLXVertex)mesh.vertices[v]).NormalW); break; case VertexType.Color1: @@ -128,12 +131,12 @@ namespace FirstPlugin return mem.ToArray(); } - public static uint GetTotalBufferStride(Mesh mesh) + public static uint GetTotalBufferStride(IList attributes) { uint VertBufferStride = 0; - for (int i = 0; i < mesh.Attributes?.Count; i++) + for (int i = 0; i < attributes?.Count; i++) { - var attribute = mesh.Attributes[i]; + var attribute = attributes[i]; switch ((VertexType)attribute.VertexType) { case VertexType.Position: @@ -210,7 +213,7 @@ namespace FirstPlugin { List Vertices = new List(); - uint VertBufferStride = GetTotalBufferStride(mesh); + uint VertBufferStride = GetTotalBufferStride(mesh.Attributes); using (var reader = new FileReader(mesh.Data.ToArray())) { @@ -417,9 +420,9 @@ namespace FirstPlugin } - private static void WriteBuffer(FileWriter writer, uint ElementCount, float[] value, BufferFormat Format, VertexType AttributeType) + private static void WriteBuffer(FileWriter writer, uint elementCount, float[] value, BufferFormat Format, VertexType AttributeType) { - for (int i = 0; i < ElementCount; i++) + for (int i = 0; i < elementCount; i++) { switch (Format) { diff --git a/Switch_Toolbox_Library/Helpers/TreeHelper.cs b/Switch_Toolbox_Library/Helpers/TreeHelper.cs index 6a29ea1d..d822889c 100644 --- a/Switch_Toolbox_Library/Helpers/TreeHelper.cs +++ b/Switch_Toolbox_Library/Helpers/TreeHelper.cs @@ -93,18 +93,25 @@ namespace Toolbox.Library var Collection = TreeViewExtensions.Collect(Nodes); int Curfile = 0; - foreach (TreeNode file in Collection) + foreach (TreeNode node in Collection) { - if (file is ArchiveFileWrapper) + ArchiveFileInfo file = null; + + if (node.Tag != null && node.Tag is ArchiveFileInfo) + file = (ArchiveFileInfo)node.Tag; + else if (node is ArchiveFileWrapper) + file = ((ArchiveFileWrapper)node).ArchiveFileInfo; + + if (file != null) { - string FilePath = ((ArchiveFileWrapper)file).ArchiveFileInfo.FileName; + string FilePath = file.FileName; string FolderPath = Path.GetDirectoryName(FilePath.RemoveIllegaleFolderNameCharacters()); string FolderPathDir = Path.Combine(overridePath, FolderPath); if (!Directory.Exists(FolderPathDir)) Directory.CreateDirectory(FolderPathDir); - string FileName = file.Text.RemoveIllegaleFileNameCharacters(); + string FileName = Path.GetFileName(file.FileName).RemoveIllegaleFileNameCharacters(); FilePath = Path.Combine(FolderPath, FileName); @@ -118,19 +125,18 @@ namespace Toolbox.Library progressBar.Refresh(); CreateDirectoryIfExists($"{path}"); - if (file is ArchiveFileWrapper) - { - filesExtracted.Add($"{path}"); + filesExtracted.Add($"{path}"); - if (((ArchiveFileWrapper)file).ArchiveFileInfo.FileDataStream != null) - { - ((ArchiveFileWrapper)file).ArchiveFileInfo.FileDataStream.ExportToFile(path); - } - else - { - File.WriteAllBytes($"{path}", - ((ArchiveFileWrapper)file).ArchiveFileInfo.FileData); - } + if (file.FileFormat != null && file.FileFormat.CanSave) + file.SaveFileFormat(); + + if (file.FileDataStream != null) + { + file.FileDataStream.ExportToFile(path); + } + else + { + File.WriteAllBytes($"{path}", file.FileData); } } }