From 22e4c5cc26fbd437b2762d1a070d54937520c558 Mon Sep 17 00:00:00 2001 From: Robert Jordan Date: Wed, 19 May 2021 18:04:17 -0400 Subject: [PATCH] (HG3): fix img_jpg RGB swap and img_al null-terminator check * `"img_jpg"` tag format unpack operation was swapping RGB -> BGR when already in BGR format. * `"img_al"` tag name had two null-terminator checks. And apparently CatSystem 2 does not guarantee anything after the first null-terminator in a fixed-length string *(yikes)*. This can be observed with a few assets in the `cs2_full_v301` toolset, like `be01S_0000001.hg3`: `69 6D 67 5F 61 6C 00 B5` : `"img_al.5"` --- ArcFormats/CatSystem/ImageHG3.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ArcFormats/CatSystem/ImageHG3.cs b/ArcFormats/CatSystem/ImageHG3.cs index 0f7d0f2c8..cb4924072 100644 --- a/ArcFormats/CatSystem/ImageHG3.cs +++ b/ArcFormats/CatSystem/ImageHG3.cs @@ -306,16 +306,16 @@ byte[] UnpackJpeg () int dst = 0; for (uint i = 0; i < total; ++i) { - output[dst++] = pixels[src+2]; - output[dst++] = pixels[src+1]; output[dst++] = pixels[src]; + output[dst++] = pixels[src+1]; + output[dst++] = pixels[src+2]; output[dst++] = 0xFF; src += src_pixel_size; } m_input.Position = next_section; var section_header = m_input.ReadBytes (8); - if (!Binary.AsciiEqual (section_header, "img_al\0\0")) + if (!Binary.AsciiEqual (section_header, "img_al\0")) return output; m_input.Seek (8, SeekOrigin.Current); int alpha_size = m_input.ReadInt32();