From d63bb19338503e05dad263ae786326e365be99aa Mon Sep 17 00:00:00 2001 From: morkt Date: Mon, 23 May 2016 22:55:04 +0400 Subject: [PATCH] (GraFormat): recognize images without 'gra' signature. --- ArcFormats/MnoViolet/ImageGRA.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/ArcFormats/MnoViolet/ImageGRA.cs b/ArcFormats/MnoViolet/ImageGRA.cs index 6e4e2d08..97bf9f8b 100644 --- a/ArcFormats/MnoViolet/ImageGRA.cs +++ b/ArcFormats/MnoViolet/ImageGRA.cs @@ -35,6 +35,7 @@ namespace GameRes.Formats.MnoViolet { public int PackedSize; public int UnpackedSize; + public long DataOffset; } [Export(typeof(ImageFormat))] @@ -46,7 +47,7 @@ namespace GameRes.Formats.MnoViolet public GraFormat () { - Signatures = new uint[] { 0x00617267, 0x0073616d }; // 'gra', 'mas' + Signatures = new uint[] { 0x00617267, 0x0073616d, 0 }; // 'gra', 'mas' } public override void Write (Stream file, ImageData image) @@ -61,6 +62,19 @@ namespace GameRes.Formats.MnoViolet uint sign = input.ReadUInt32(); uint width = input.ReadUInt32(); uint height = input.ReadUInt32(); + if (0 == width || width > 0x8000 || 0 == height || height > 0x8000) + return null; + int bpp; + if (0x617267 == sign) // 'gra' + bpp = 24; + else if (0x73616D == sign) // 'mas' + bpp = 8; + else if (1 == sign) + bpp = input.ReadInt32(); + else + return null; + if (bpp != 32 && bpp != 24 && bpp != 8) + return null; int packed_size = input.ReadInt32(); int data_size = input.ReadInt32(); return new GraMetaData @@ -69,7 +83,8 @@ namespace GameRes.Formats.MnoViolet Height = height, PackedSize = packed_size, UnpackedSize = data_size, - BPP = 0x617267 == sign ? 24 : 8, + BPP = bpp, + DataOffset = stream.Position, }; } } @@ -77,13 +92,15 @@ namespace GameRes.Formats.MnoViolet public override ImageData Read (Stream stream, ImageMetaData info) { var meta = (GraMetaData)info; - stream.Position = 0x14; + stream.Position = meta.DataOffset; using (var reader = new LzssReader (stream, meta.PackedSize, meta.UnpackedSize)) { reader.Unpack(); int stride = ((int)info.Width*info.BPP/8 + 3) & ~3; PixelFormat format; - if (24 == info.BPP) + if (32 == info.BPP) + format = PixelFormats.Bgra32; + else if (24 == info.BPP) format = PixelFormats.Bgr24; else format = PixelFormats.Gray8;