From 259f6819409465cbe5f52e081079157cc6a8ac81 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Thu, 2 Apr 2020 14:48:25 -0400 Subject: [PATCH] NUTEXB : Also pad image data for images edited in tool --- .../FileFormats/Texture/NUTEXB.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/File_Format_Library/FileFormats/Texture/NUTEXB.cs b/File_Format_Library/FileFormats/Texture/NUTEXB.cs index 5f9cc15a..6b2bc760 100644 --- a/File_Format_Library/FileFormats/Texture/NUTEXB.cs +++ b/File_Format_Library/FileFormats/Texture/NUTEXB.cs @@ -312,12 +312,7 @@ namespace FirstPlugin data.Add(array[0]); var output = Utils.CombineByteArray(data.ToArray()); - if (output.Length < ImageData.Length) { - var paddingSize = ImageData.Length - output.Length; - output = Utils.CombineByteArray(output, new byte[paddingSize]); - } - - ImageData = output; + ImageData = SetImageData(output); data.Clear(); surfacesNew.Clear(); @@ -326,6 +321,18 @@ namespace FirstPlugin UpdateEditor(); } + private byte[] SetImageData(byte[] output) + { + if (output.Length < ImageData.Length && LimitFileSize) + { + var paddingSize = ImageData.Length - output.Length; + output = Utils.CombineByteArray(output, new byte[paddingSize]); + } + + Console.WriteLine($"output {output.Length} ImageData {ImageData.Length}"); + return output; + } + private void SaveAction(object sender, EventArgs args) { SaveFileDialog sfd = new SaveFileDialog(); @@ -493,7 +500,6 @@ namespace FirstPlugin { MipCount = GenerateMipCount(bitmap.Width, bitmap.Height); ImageData = GenerateMipsAndCompress(bitmap, MipCount, Format); - return; } @@ -531,7 +537,11 @@ namespace FirstPlugin var mipmaps = TextureImporterSettings.SwizzleSurfaceMipMaps(tex, GenerateMipsAndCompress(bitmap, MipCount, Format), MipCount); - ImageData = Utils.CombineByteArray(mipmaps.ToArray()); + byte[] output = Utils.CombineByteArray(mipmaps.ToArray()); + if (useSizeRestrictions.Checked && output.Length > ImageData.Length) + throw new Exception("Image must be the same size or smaller!"); + + ImageData = SetImageData(output); } public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)