implemented LIN2 archives.

This commit is contained in:
morkt 2016-10-23 15:45:56 +04:00
parent 2e9a3f240b
commit ab87c63ff5
4 changed files with 168 additions and 3 deletions

View File

@ -129,6 +129,7 @@
<Compile Include="Ivory\ImageMMD.cs" />
<Compile Include="Ivory\ImageMOE.cs" />
<Compile Include="Ivory\ImageSG.cs" />
<Compile Include="Kaguya\ArcLIN2.cs" />
<Compile Include="Kiss\ArcARC.cs" />
<Compile Include="KScript\ArcKPC.cs" />
<Compile Include="KScript\ImageKGP.cs" />

View File

@ -0,0 +1,144 @@
//! \file ArcLIN2.cs
//! \date Sun Oct 23 09:57:27 2016
//! \brief KaGuYa archive format.
//
// Copyright (C) 2016 by morkt
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using GameRes.Utility;
namespace GameRes.Formats.Kaguya
{
[Export(typeof(ArchiveFormat))]
public class Lin2Opener : ArchiveFormat
{
public override string Tag { get { return "ARC/LIN2"; } }
public override string Description { get { return "KaGuYa script engine resource archive"; } }
public override uint Signature { get { return 0x324E494C; } } // 'LIN2'
public override bool IsHierarchic { get { return false; } }
public override bool CanWrite { get { return false; } }
public override ArcFile TryOpen (ArcView file)
{
int count = file.View.ReadInt32 (4);
if (!IsSaneCount (count))
return null;
uint index_offset = 8;
var name_buffer = new byte[0x100];
var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i)
{
ushort name_length = file.View.ReadUInt16 (index_offset);
if (name_length > name_buffer.Length)
name_buffer = new byte[name_length];
file.View.Read (index_offset+2, name_buffer, 0, name_length);
for (int j = 0; j < name_length; ++j)
name_buffer[j] ^= 0xFF;
var name = Binary.GetCString (name_buffer, 0, name_length);
if (string.IsNullOrEmpty (name))
return null;
index_offset += 2u + name_length;
var entry = FormatCatalog.Instance.Create<PackedEntry> (name);
entry.Offset = file.View.ReadUInt32 (index_offset);
entry.Size = file.View.ReadUInt32 (index_offset+4);
if (!entry.CheckPlacement (file.MaxOffset))
return null;
int type = file.View.ReadInt16 (index_offset+8);
if (1 == type)
entry.IsPacked = true;
else if (2 == type)
entry.Type = "audio";
dir.Add (entry);
index_offset += 10;
}
return new ArcFile (file, this, dir);
}
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
var pent = entry as PackedEntry;
if (null == pent || !pent.IsPacked)
return base.OpenEntry (arc, entry);
if (0 == pent.UnpackedSize)
pent.UnpackedSize = arc.File.View.ReadUInt32 (entry.Offset);
using (var input = arc.File.CreateStream (entry.Offset+4, entry.Size-4))
{
var data = UnpackLzss (input, pent.UnpackedSize);
return new BinMemoryStream (data, entry.Name);
}
}
byte[] UnpackLzss (IBinaryStream input, uint unpacked_size)
{
var output = new byte[unpacked_size];
var frame = new byte[0x100];
int frame_pos = 0xEF;
int dst = 0;
int ctl = 0;
int bit = 0;
int prev_count = 0x100;
while (dst < output.Length)
{
bit >>= 1;
if (0 == bit)
{
ctl = input.ReadByte();
if (-1 == ctl)
break;
bit = 0x80;
}
if (0 != (ctl & bit))
{
byte v = input.ReadUInt8();
frame[frame_pos++ & 0xFF] = v;
output[dst++] = v;
}
else
{
int offset = input.ReadUInt8();
int count;
if (-1 == prev_count)
{
prev_count = input.ReadUInt8();
count = prev_count & 0xF;
}
else
{
count = prev_count >> 4;
prev_count = -1;
}
count += 2;
while (count --> 0 && dst < output.Length)
{
byte v = frame[offset++ & 0xFF];
frame[frame_pos++ & 0xFF] = v;
output[dst++] = v;
}
}
}
return output;
}
}
}

View File

@ -50,7 +50,7 @@ namespace GameRes.Formats.Kaguya
[Export(typeof(ArchiveFormat))]
public class LinkOpener : ArchiveFormat
{
public override string Tag { get { return "LINK/KAGUYA"; } }
public override string Tag { get { return "ARC/LINK"; } }
public override string Description { get { return "KaGuYa script engine resource archive"; } }
public override uint Signature { get { return 0x4B4E494C; } } // 'LINK'
public override bool IsHierarchic { get { return false; } }

View File

@ -81,6 +81,7 @@ Saimin Gakuen<br/>
Grisaia no Kajitsu<br/>
Happiness! Re:Lucks<br/>
Kamikaze ☆ Explorer!<br/>
Koko kara Natsu no Innocence!<br/>
Makai Tenshi Djibril -Episode 4-<br/>
Sakigake ⇒ Generation!<br/>
Sengoku Tenshi Djibril<br/>
@ -139,7 +140,9 @@ White ~blanche comme la lune~<br/>
<tr><td>*.dat</td><td><tt>NEKOPACK</tt></td><td>No</td><td>Rosebleu<br/>Lime</td><td>
Inpyuri -Hito to Anata to Ayakashi to-<br/>
Nostradamus ni Kiitemiro♪<br/>
Tiny Dungeon ~BIRTH for YOURS~<br/>
Tiny Dungeon ~BLACK and WHITE~<br/>
Tiny Dungeon ~BLESS of DRAGON~<br/>
Tiny Dungeon ~Brave or Slave~<br/>
</td></tr>
<tr class="odd"><td>*.dat</td><td>-</td><td>No</td><td>Meteor<br/>Silver Bullet</td><td>
@ -392,6 +395,7 @@ Michibikareshi Mono-tachi no Rakuen ~BEDLAM~<br/>
Onsen Kankou Yukemuri Chijou<br/>
Oshiete! Bloomer Sensei<br/>
Ryoujoku Costume Play<br/>
Ryoushuu ~Kinki no Mesuniku Jikken Chousho~<br/>
Seikoujo Claudia<br/>
Shinshoku<br/>
Sweet and Sweet<br/>
@ -430,6 +434,7 @@ Itsuka, Dokoka de ~Ano Ameoto no Kioku~<span class="footnote">2.36 or 2.37</span
Kichiku Nakadashi Suieibu<span class="footnote">ShiinaRio v2.41</span><br/>
Mahou Shoujo no Taisetsu na Koto <span class="footnote">ShiinaRio v2.47</span><br/>
Maki Fes! <span class="footnote">ShiinaRio v2.50</span><br/>
Mikoko <span class="footnote">ShiinaRio v2.46</span><br/>
Mimi o Sumaseba <span class="footnote">ShiinaRio v2.47</span><br/>
Nagagutsu wo Haita Deco <span class="footnote">ShiinaRio v2.39</span><br/>
Najimi no Oba-chan <span class="footnote">ShiinaRio v2.47</span><br/>
@ -765,6 +770,7 @@ Sakimidare<br/>
Gigai no Alruna<br/>
</td></tr>
<tr class="odd"><td>sys4ini.bin<br/>sys3ini.bin<br/>*.alf</td><td><tt>S4IC</tt><br/><tt>S3IC</tt></td><td>No</td><td rowspan="2">Eushully</td><td rowspan="2">
Himegari Dungeon Meister<br/>
Kuutei Senki ~Tasogare ni Shizumu Kusabi~<br/>
Mahou ga Sekai o Sukuimasu<br/>
Meishoku no Reiki<br/>
@ -779,6 +785,7 @@ Hyakki Yakou<br/>
Mahou Senshi Extra Stage 2 ~Gakuen Kangoku~<br/>
Saikyou Goshujin-sama! -Mighty My Master-<br/>
Saiminjutsu Re<br/>
Summoner Princess Artemina 2 -Tatakae! Apologue-<br/>
Wizard Links<br/>
</td></tr>
<tr class="last"><td>*.med</td><td><tt>MD</tt></td><td>No</td></tr>
@ -806,6 +813,7 @@ Shitai o Arau<br/>
Hanikami Clover<br/>
Katakoi no Tsuki<br/>
Katakoi no Tsuki Extra<br/>
Magica Ride<br/>
Shukufuku no Kane no Oto wa, Sakurairo no Kaze to Tomo ni<br/>
</td></tr>
<tr class="odd"><td>*.bsa</td><td><tt>BSArc</tt></td><td>No</td><td rowspan="2">Bishop</td><td rowspan="2">
@ -858,6 +866,7 @@ Genrin no Kishougun<br/>
</td></tr>
<tr class="odd"><td>*.mpk</td><td>-</td><td>No</td><td rowspan="2">propeller</td><td rowspan="2">
Bullet Butlers<br/>
Kitto, Sumiwataru Asairo Yori mo,<br/>
</td></tr>
<tr class="odd last"><td>*.mgr</td><td>-</td><td>No</td></tr>
<tr><td>*.dat</td><td><tt>PAK0</tt></td><td>No</td><td>Studio e.go!</td><td>
@ -945,11 +954,14 @@ Eien no Aselia -The Spirit of Eternity Sword-
Ayakashi<br/>
Ayakashi H<br/>
</td></tr>
<tr class="odd"><td>*.arc</td><td><tt>LINK3</tt></td><td>No</td><td rowspan="3">KaGuYa</td><td rowspan="3">
<tr class="odd"><td>*.arc</td><td><tt>LIN2</tt><br/><tt>LINK3</tt><br/><tt>LINK5</tt><br/><tt>LINK6</tt></td><td>No</td><td rowspan="3">KaGuYa</td><td rowspan="3">
Dokidoki Onee-san<br/>
Harami Tama<br/>
Mahokoi ~Ecchi na Mahou de Koi x Koi Shichau~<br/>
Mainichi ga M!<br/>
Ningyou no Yakata<br/>
</td></tr>
<tr class="odd"><td>*.alp</td><td><tt>AP-2</tt></td><td>No</td></tr>
<tr class="odd"><td>*.alp</td><td><tt>AP-0</tt><br/><tt>AP-2</tt></td><td>No</td></tr>
<tr class="odd last"><td>*.anm</td><td><tt>AN00</tt></td><td>No</td></tr>
<tr><td>*.pcs</td><td><tt>PCCS</tt></td><td>No</td><td>C's ware</td><td>
Kuro to Kuro to Kuro no Saidan ~Kodoku~<br/>
@ -966,6 +978,7 @@ Houmon Hanbai ~Otona no Omocha Irimasen ka?~<br/>
</td></tr>
<tr class="odd"><td>*.pac</td><td>-<br/><tt>PAC</tt></td><td>No</td><td rowspan="2">Unison Shift<br/>Softpal</td><td rowspan="2">
Maruhi Jinjibu Ryoujokuka<br/>
M.E.s -Doukyuusei Maid Choukyou-<br/>
Natsuiro Kokoro Log<br/>
Shikotama Slave ~Aruji de Shimai na Tenshi to Akuma~<br/>
Unity Marriage ~Futari no Hanayome~<br/>
@ -1090,6 +1103,7 @@ In'youchuu Goku ~Ryoujoku Jigoku Taimaroku~<br/>
In'youchuu Kyou ~Ryoujoku Byoutou Taimaroku~<br/>
In'youchuu Rei ~Ryoujoku Shiro Taima Emaki~<br/>
In'youchuu Shoku ~Ryoushokutou Taimaroku~<br/>
Kairaku Izonshou<br/>
Koitsuma Biyori ~Yukino-san wa Hitozuma Kanrinin~<br/>
Kowaku no Toki<br/>
Kuraibito<br/>
@ -1099,7 +1113,9 @@ Onna Kyoushi Suzune<br/>
Ore Maou! ~Kudake Chitta Tamashii<br/>
Oshioki ~Gakuen Reijou Kousei Keikaku~<br/>
Ouma no Shoku ~Sei ni Tsukaeshi Yami no Guuzou~<br/>
Shukubo no Uzuki ~Hitozuma Miboujin no Nareta Karada to Amai Toiki~<br/>
Volley Coaching!<br/>
Yumekoi Tensei<br/>
Zoku Etsuraku no Tane<br/>
</td></tr>
<tr class="odd"><td>*.bin</td><td><tt>OZ</tt></td><td>No</td><td>Patisserie</td><td>
@ -1197,6 +1213,10 @@ Tiara<br/>
<tr><td>*.paz</td><td>-</td><td>No</td><td>Musica</td><td>
Tsumi no Hikari Rendezvous<br/>
</td></tr>
<tr class="odd"><td>arc.dat</td><td>-</td><td>No</td><td rowspan="2">AdvSys3</td><td rowspan="2">
Okami Tsuma ~Ryokan Baito de no Himitsu~<br/>
</td></tr>
<tr class="odd last"><td>*.gwd</td><td><tt>GWD</tt></td><td>No</td></tr>
</table>
<p><a name="note-1" class="footnote">1</a> Non-encrypted only</p>
</body>