From df4b5960f7e77168479e7789d2470d61a42b0465 Mon Sep 17 00:00:00 2001 From: morkt Date: Mon, 22 Feb 2016 17:39:17 +0400 Subject: [PATCH] (AgfFormat): correctly read [non]compressed file sections. --- ArcFormats/Eushully/ImageAGF.cs | 34 ++++++++++++++++----------------- supported.html | 2 ++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ArcFormats/Eushully/ImageAGF.cs b/ArcFormats/Eushully/ImageAGF.cs index 42af8085..68b41ce3 100644 --- a/ArcFormats/Eushully/ImageAGF.cs +++ b/ArcFormats/Eushully/ImageAGF.cs @@ -62,14 +62,9 @@ namespace GameRes.Formats.Eushully int type = LittleEndian.ToInt32 (header, 4); if (type != 1 && type != 2) return null; - uint unpacked_size = LittleEndian.ToUInt32 (header, 0x10); - uint packed_size = LittleEndian.ToUInt32 (header, 0x14); - Stream unpacked; - if (unpacked_size != packed_size) - unpacked = new LzssStream (stream, LzssMode.Decompress, true); - else - unpacked = new StreamRegion (stream, stream.Position, packed_size, true); - using (unpacked) + int unpacked_size = LittleEndian.ToInt32 (header, 0x10); + int packed_size = LittleEndian.ToInt32 (header, 0x14); + using (var unpacked = AgfReader.OpenSection (stream, unpacked_size, packed_size)) using (var reader = new BinaryReader (unpacked)) { if (0x20 != reader.Read (header, 0, 0x20)) @@ -80,7 +75,7 @@ namespace GameRes.Formats.Eushully Height = LittleEndian.ToUInt32 (header, 0x18), BPP = 1 == type ? 24 : 32, SourceBPP = LittleEndian.ToInt16 (header, 0x1E), - DataOffset = 0x18 + packed_size, + DataOffset = 0x18 + (uint)packed_size, }; if (0 == info.SourceBPP) return null; @@ -108,11 +103,7 @@ namespace GameRes.Formats.Eushully public override ImageData Read (Stream stream, ImageMetaData info) { - var meta = info as AgfMetaData; - if (null == meta) - throw new ArgumentException ("AgfFormat.Read should be supplied with AgfMetaData", "info"); - - using (var reader = new AgfReader (stream, meta)) + using (var reader = new AgfReader (stream, (AgfMetaData)info)) { reader.Unpack(); return ImageData.Create (info, reader.Format, null, reader.Data); @@ -151,6 +142,14 @@ namespace GameRes.Formats.Eushully m_palette = info.Palette; } + public static Stream OpenSection (Stream stream, int unpacked_size, int packed_size) + { + if (unpacked_size != packed_size) + return new LzssStream (stream, LzssMode.Decompress, true); + else + return new StreamRegion (stream, stream.Position, packed_size, true); + } + public void Unpack () { m_input.ReadInt32(); @@ -158,11 +157,9 @@ namespace GameRes.Formats.Eushully int packed_size = m_input.ReadInt32(); var data_pos = m_input.BaseStream.Position; var bmp_data = new byte[data_size]; - using (var unpacked = new LzssStream (m_input.BaseStream, LzssMode.Decompress, true)) - { + using (var unpacked = OpenSection (m_input.BaseStream, data_size, packed_size)) if (data_size != unpacked.Read (bmp_data, 0, data_size)) throw new EndOfStreamException(); - } byte[] alpha = null; if (32 == m_bpp) { @@ -230,10 +227,11 @@ namespace GameRes.Formats.Eushully if (!Binary.AsciiEqual (header, 0, "ACIF")) return null; int unpacked_size = LittleEndian.ToInt32 (header, 0x1C); + int packed_size = LittleEndian.ToInt32 (header, 0x20); if (m_width*m_height != unpacked_size) return null; var alpha = new byte[unpacked_size]; - using (var unpacked = new LzssStream (m_input.BaseStream, LzssMode.Decompress, true)) + using (var unpacked = OpenSection (m_input.BaseStream, unpacked_size, packed_size)) if (unpacked_size != unpacked.Read (alpha, 0, unpacked_size)) return null; return alpha; diff --git a/supported.html b/supported.html index a0b5b892..f6eff8d9 100644 --- a/supported.html +++ b/supported.html @@ -324,6 +324,7 @@ Ore-tachi ni Tsubasa wa Nai
Rikorisu ~Lycoris Radiata~
Sakura Synchronicity
Shinsetsu Ryouki no Ori Dai 2 Shou
+Shuffle! Essence+
*.elgELGNo *.arcARC\x1a
ARCNoAZ System @@ -536,6 +537,7 @@ Tetsuwan Gacchu!
Gigai no Alruna
sys4ini.bin
sys3ini.bin
*.alfS4IC
S3ICNoEushully +Kuutei Senki ~Tasogare ni Shizumu Kusabi~
Soukai no Oujo-tachi
Soukai no Valkyria