diff --git a/.vs/Switch_Toolbox/v15/.suo b/.vs/Switch_Toolbox/v15/.suo index b7a753bc..1bb0f9a2 100644 Binary files a/.vs/Switch_Toolbox/v15/.suo and b/.vs/Switch_Toolbox/v15/.suo differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide index 3555f1be..82677333 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal index 3f85759d..58d7e924 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal differ diff --git a/Switch_FileFormatsMain/FileFormats/Texture/GTXFile.cs b/Switch_FileFormatsMain/FileFormats/Texture/GTXFile.cs index 4f780979..3b9ea1e1 100644 --- a/Switch_FileFormatsMain/FileFormats/Texture/GTXFile.cs +++ b/Switch_FileFormatsMain/FileFormats/Texture/GTXFile.cs @@ -151,9 +151,9 @@ namespace FirstPlugin public byte[] Save() { //Get each block type for saving except alignment - var TextureInfoBlocks = blocks.Where(i => i.BlockType == BlockType.ImageInfo); - var TextureDataBlocks = blocks.Where(i => i.BlockType == BlockType.ImageData); - var TextureMipDataBlocks = blocks.Where(i => i.BlockType == BlockType.MipData); + // var TextureInfoBlocks = blocks.Where(i => i.BlockType == BlockType.ImageInfo); + // var TextureDataBlocks = blocks.Where(i => i.BlockType == BlockType.ImageData); + // var TextureMipDataBlocks = blocks.Where(i => i.BlockType == BlockType.MipData); System.IO.MemoryStream mem = new System.IO.MemoryStream(); using (FileWriter writer = new FileWriter(mem)) @@ -180,21 +180,26 @@ namespace FirstPlugin else throw new Exception($"Unsupported GTX version {header.MajorVersion}"); - int imageInfoIndex = 0; - int imageBlockIndex = 0; - int imageMipBlockIndex = 0; + int imageInfoIndex = -1; + int imageBlockIndex = -1; + int imageMipBlockIndex = -1; writer.Seek(header.HeaderSize, System.IO.SeekOrigin.Begin); foreach (var block in blocks) { if ((uint)block.BlockType == surfBlockType) { - block.data = textures[imageInfoIndex++].surface.Write(); + imageInfoIndex++; + imageBlockIndex++; + imageMipBlockIndex++; + + block.data = textures[imageInfoIndex].surface.Write(); block.Write(writer); + } else if ((uint)block.BlockType == dataBlockType) { - var tex = textures[imageBlockIndex++]; + var tex = textures[imageBlockIndex]; var pos = writer.Position; uint Alignment = tex.surface.alignment; @@ -208,7 +213,7 @@ namespace FirstPlugin } else if ((uint)block.BlockType == mipBlockType) { - var tex = textures[imageMipBlockIndex++]; + var tex = textures[imageMipBlockIndex]; var pos = writer.Position; uint Alignment = tex.surface.alignment; @@ -217,6 +222,8 @@ namespace FirstPlugin GTXDataBlock dataAlignBlock = new GTXDataBlock(BlockType.AlignData, dataAlignment, 0, 0); dataAlignBlock.Write(writer); + if (tex.surface.mipData == null || tex.surface.mipData.Length <= 0) + throw new Exception("Invalid mip data!"); block.data = tex.surface.mipData; block.Write(writer);