From feeb8b7cc0367568e61b47c6e2058df06f65a6ba Mon Sep 17 00:00:00 2001 From: MayNL Date: Tue, 14 Apr 2026 20:48:19 -0400 Subject: [PATCH] Added validate check for skin and cape textures --- PCK-Studio/Controls/Editor/PckEditor.cs | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/PCK-Studio/Controls/Editor/PckEditor.cs b/PCK-Studio/Controls/Editor/PckEditor.cs index 9743c650..5fb7d69c 100644 --- a/PCK-Studio/Controls/Editor/PckEditor.cs +++ b/PCK-Studio/Controls/Editor/PckEditor.cs @@ -1752,6 +1752,41 @@ namespace PckStudio.Controls ofd.Filter = $"{asset.Type} (*{fileExt}{extra_extensions})|*{fileExt}{extra_extensions}"; if (ofd.ShowDialog(this) == DialogResult.OK) { + byte[] fileData = File.ReadAllBytes(ofd.FileName); + bool isSkin = asset.Type == PckAssetType.SkinFile; + bool isCape = asset.Type == PckAssetType.CapeFile; + + if (Settings.Default.ValidateImageDimension && (isSkin || isCape)) + { + try + { + Image texture = Image.FromStream(new MemoryStream(fileData)); + + bool isEqualDimensions = texture.Width == texture.Height; + bool isHalfHeight = texture.Height == (texture.Width / 2); + + Console.WriteLine($"{texture.Width} {texture.Height}"); + + if (isSkin && !isEqualDimensions && !isHalfHeight) + { + MessageBox.Show("The selected image does not suit a skin texture.", "Invalid image dimensions.", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (isCape && !isHalfHeight) + { + MessageBox.Show("The selected image does not suit a cape texture.", "Invalid image dimensions.", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + texture.Dispose(); + } + catch + { + MessageBox.Show("The selected file is not a valid image.", "Invalid image.", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + string newFileExt = Path.GetExtension(ofd.FileName); asset.SetData(File.ReadAllBytes(ofd.FileName)); asset.Filename = asset.Filename.Replace(fileExt, newFileExt);