Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 41 additions & 15 deletions ArcFormats/Kaguya/ArcLINK.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! \file ArcLINK.cs
//! \file ArcLINK.cs
//! \date Fri Jan 22 18:44:56 2016
//! \brief KaGuYa archive format.
//
Expand Down Expand Up @@ -34,6 +34,7 @@ namespace GameRes.Formats.Kaguya
internal class LinkEntry : PackedEntry
{
public bool IsEncrypted;
public int PackType;
}

internal class LinkArchive : ArcFile
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -211,13 +227,22 @@ public List<Entry> 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);
Expand Down Expand Up @@ -466,6 +491,7 @@ public void Dispose ()
#endregion
}


internal abstract class ParamsDeserializer
{
protected IBinaryStream m_input;
Expand Down