From 8a6afe6551f53fe0c7f83eaa5c1cb5ebf45aee0a Mon Sep 17 00:00:00 2001 From: diandianxz Date: Mon, 25 May 2026 15:58:26 +0800 Subject: [PATCH 1/3] Update ArcLINK.cs Add a decompression method that decides whether to use BMR or LZSS based on the value of flag & 3 --- ArcFormats/Kaguya/ArcLINK.cs | 56 ++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/ArcFormats/Kaguya/ArcLINK.cs b/ArcFormats/Kaguya/ArcLINK.cs index 9ce87efb9..2f3a6459d 100644 --- a/ArcFormats/Kaguya/ArcLINK.cs +++ b/ArcFormats/Kaguya/ArcLINK.cs @@ -1,4 +1,4 @@ -//! \file ArcLINK.cs +//! \file ArcLINK.cs //! \date Fri Jan 22 18:44:56 2016 //! \brief KaGuYa archive format. // @@ -34,6 +34,7 @@ namespace GameRes.Formats.Kaguya internal class LinkEntry : PackedEntry { public bool IsEncrypted; + public int PackType; } internal class LinkArchive : ArcFile @@ -110,13 +111,28 @@ public override Stream OpenEntry (ArcFile arc, Entry entry) return base.OpenEntry (arc, entry); return larc.Encryption.DecryptEntry (larc, lent); } - using (var input = arc.File.CreateStream (entry.Offset, entry.Size)) - using (var bmr = new BmrDecoder (input)) - { - bmr.Unpack(); - return new BinMemoryStream (bmr.Data, entry.Name); - } - } + using (var input = arc.File.CreateStream (entry.Offset, entry.Size)) + { + if (lent.PackType == 2) + { + using (var bmr = new BmrDecoder (input)) + { + bmr.Unpack(); + return new BinMemoryStream (bmr.Data, entry.Name); + } + } + else if (lent.PackType == 1) //LZSS + { + using (var lz_input = arc.File.CreateStream(entry.Offset + 4, entry.Size - 4, entry.Name)) + using (var lz = new LzReader(lz_input.AsStream, entry.Size - 4, lent.UnpackedSize)) + { + lz.Unpack(); + return new BinMemoryStream (lz.Data, entry.Name); + } + } + } + return base.OpenEntry (arc, entry); + } internal ArcFile ReadOldIndex (ArcView file) { @@ -211,13 +227,22 @@ public List ReadIndex () entry.Size = size - (uint)(entry.Offset - base_offset); if (is_compressed) { - m_input.Read (header, 0, 4); - if (header.AsciiEqual ("BMR")) - { - entry.IsPacked = true; - entry.UnpackedSize = m_input.ReadUInt32(); - } - } + entry.PackType = flags & 3; + if (entry.PackType == 2) // BMR + { + m_input.Read (header, 0, 4); + if (header.AsciiEqual ("BMR")) + { + entry.IsPacked = true; + entry.UnpackedSize = m_input.ReadUInt32(); + } + } + else if (entry.PackType == 1) // LZSS + { + entry.IsPacked = true; + entry.UnpackedSize = m_input.ReadUInt32(); + } + } entry.IsEncrypted = (flags & 4) != 0; m_has_encrypted = m_has_encrypted || entry.IsEncrypted; dir.Add (entry); @@ -466,6 +491,7 @@ public void Dispose () #endregion } + internal abstract class ParamsDeserializer { protected IBinaryStream m_input; From a7fd090082488bd913d75cf43e8cd16f7d1b9405 Mon Sep 17 00:00:00 2001 From: diandianxz Date: Mon, 25 May 2026 22:55:04 +0800 Subject: [PATCH 2/3] test From 0b94b9db4a87160efad52eb97cde07225bf6451b Mon Sep 17 00:00:00 2001 From: diandianxz Date: Mon, 25 May 2026 23:00:48 +0800 Subject: [PATCH 3/3] Update ArcLINK.cs Add LZSS decompression support for PackType=1 Original code hardcoded only BMR (PackType=2), ignoring the control flag. Now both PackType=1 (LZSS) and PackType=2 (BMR) are supported. Tested locally with existing BMR files (no regression) and new LZSS files.