support_kaguya_PL_arc

This commit is contained in:
rewjx
2022-02-13 00:55:33 +08:00
parent 6b65a173fb
commit 01a2b34c5d
4 changed files with 355 additions and 207 deletions

View File

@@ -215,6 +215,8 @@
<Compile Include="Interheart\ArcFPK2.cs" /> <Compile Include="Interheart\ArcFPK2.cs" />
<Compile Include="Interheart\ImageCandy.cs" /> <Compile Include="Interheart\ImageCandy.cs" />
<Compile Include="Ivory\ArcSG.cs" /> <Compile Include="Ivory\ArcSG.cs" />
<Compile Include="Kaguya\ArcPL00.cs" />
<Compile Include="Kaguya\ArcPL10.cs" />
<Compile Include="Key\ArcPAK.cs" /> <Compile Include="Key\ArcPAK.cs" />
<Compile Include="Key\AudioOGGPAK.cs" /> <Compile Include="Key\AudioOGGPAK.cs" />
<Compile Include="Key\ImageCZ.cs" /> <Compile Include="Key\ImageCZ.cs" />

View File

@@ -649,6 +649,7 @@ namespace GameRes.Formats.Kaguya
{ {
table.Add (new Tuple<string, Decryptor> ("AN00", (a, e) => DecryptAn00 (a, e))); table.Add (new Tuple<string, Decryptor> ("AN00", (a, e) => DecryptAn00 (a, e)));
table.Add (new Tuple<string, Decryptor> ("AN21", (a, e) => DecryptAn21 (a, e))); table.Add (new Tuple<string, Decryptor> ("AN21", (a, e) => DecryptAn21 (a, e)));
table.Add (new Tuple<string, Decryptor> ("PL00", (a, e) => DecryptPL00 (a, e)));
table.Add (new Tuple<string, Decryptor> ("PL10", (a, e) => DecryptPL10 (a, e))); table.Add (new Tuple<string, Decryptor> ("PL10", (a, e) => DecryptPL10 (a, e)));
} }
m_type_table = table.ToArray(); m_type_table = table.ToArray();
@@ -719,6 +720,25 @@ namespace GameRes.Formats.Kaguya
return new BinMemoryStream (data, entry.Name); return new BinMemoryStream (data, entry.Name);
} }
Stream DecryptPL00(LinkArchive arc, LinkEntry entry)
{
var data = arc.File.View.ReadBytes(entry.Offset, entry.Size);
int count = data.ToUInt16(4);
int offset = 22;
for(int i = 0; i < count; ++i)
{
offset += 8;
int w = data.ToInt32(offset);
int h = data.ToInt32(offset + 4);
int channels = data.ToInt32(offset + 8);
int size = channels * w * h;
offset += 12;
DecryptData(data, offset, size);
offset += size;
}
return new BinMemoryStream(data, entry.Name);
}
Stream DecryptPL10(LinkArchive arc, LinkEntry entry) Stream DecryptPL10(LinkArchive arc, LinkEntry entry)
{ {
var data = arc.File.View.ReadBytes(entry.Offset, entry.Size); var data = arc.File.View.ReadBytes(entry.Offset, entry.Size);

View File

@@ -0,0 +1,126 @@
//! \file ArcAN21.cs
//! \date Sun Apr 30 21:04:25 2017
//! \brief KaGuYa script engine animation resource.
//
// Copyright (C) 2017 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;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Windows.Media;
namespace GameRes.Formats.Kaguya
{
class PL00Entry : PackedEntry
{
public int FrameIndex;
public ImageMetaData ImageInfo;
}
[Export(typeof(ArchiveFormat))]
public class PL00Opener : ArchiveFormat
{
public override string Tag { get { return "PL00/KAGUYA"; } }
public override string Description { get { return "KaGuYa script engine animation resource"; } }
public override uint Signature { get { return 0x30304C50; } } // 'PL00'
public override bool IsHierarchic { get { return false; } }
public override bool CanWrite { get { return false; } }
public PL00Opener()
{
Extensions = new string[] { "plt" };
}
public override ArcFile TryOpen(ArcView file)
{
uint current_offset = 4;
int frame_count = file.View.ReadUInt16(current_offset);
if (!IsSaneCount(frame_count))
return null;
current_offset += 2;
string base_name = Path.GetFileNameWithoutExtension(file.Name);
var dir = new List<Entry>(frame_count);
var info = new ImageMetaData
{
OffsetX = file.View.ReadInt32(current_offset),
OffsetY = file.View.ReadInt32(current_offset + 4),
Width = file.View.ReadUInt32(current_offset + 8),
Height = file.View.ReadUInt32(current_offset + 12),
};
int channels = file.View.ReadInt32(38);
info.BPP = channels * 8;
current_offset += 16;
for (int i = 0; i < frame_count; ++i)
{
int offsetx = file.View.ReadInt32(current_offset);
int offsety = file.View.ReadInt32(current_offset + 4);
uint width = file.View.ReadUInt32(current_offset + 8);
uint height = file.View.ReadUInt32(current_offset + 12);
channels = file.View.ReadInt32(current_offset + 16);
uint size = (uint)(width * height * channels);
current_offset += 20;
var entry = new PL00Entry
{
FrameIndex = i,
Name = string.Format("{0}#{1:D2}", base_name, i),
Type = "image",
Offset = current_offset,
Size = size,
IsPacked = false,
ImageInfo = new ImageMetaData
{
OffsetX = offsetx,
OffsetY = offsety,
Width = width,
Height = height,
BPP = channels * 8,
}
};
dir.Add(entry);
current_offset += size;
}
return new PL00Archive(file, this, dir, info);
}
public override IImageDecoder OpenImage(ArcFile arc, Entry entry)
{
var anent = (PL00Entry)entry;
var input = arc.File.CreateStream(entry.Offset, entry.Size);
var pixels = input.ReadBytes((int)anent.Size);
return new BitmapDecoder(pixels, anent.ImageInfo);
}
}
class PL00Archive : ArcFile
{
public readonly ImageMetaData ImageInfo;
public PL00Archive(ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, ImageMetaData base_info)
: base(arc, impl, dir)
{
ImageInfo = base_info;
}
}
}

View File

@@ -1,207 +1,207 @@
//! \file ArcAN21.cs //! \file ArcAN21.cs
//! \date Sun Apr 30 21:04:25 2017 //! \date Sun Apr 30 21:04:25 2017
//! \brief KaGuYa script engine animation resource. //! \brief KaGuYa script engine animation resource.
// //
// Copyright (C) 2017 by morkt // Copyright (C) 2017 by morkt
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the // deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // 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 // sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: // furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in // The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software. // all copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // 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 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE. // IN THE SOFTWARE.
// //
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Windows.Media; using System.Windows.Media;
namespace GameRes.Formats.Kaguya namespace GameRes.Formats.Kaguya
{ {
class PL10Entry : PackedEntry class PL10Entry : PackedEntry
{ {
public int FrameIndex; public int FrameIndex;
public int RleStep; public int RleStep;
} }
[Export(typeof(ArchiveFormat))] [Export(typeof(ArchiveFormat))]
public class PL10Opener : ArchiveFormat public class PL10Opener : ArchiveFormat
{ {
public override string Tag { get { return "PL10/KAGUYA"; } } public override string Tag { get { return "PL10/KAGUYA"; } }
public override string Description { get { return "KaGuYa script engine animation resource"; } } public override string Description { get { return "KaGuYa script engine animation resource"; } }
public override uint Signature { get { return 0x30314C50; } } // 'PL10' public override uint Signature { get { return 0x30314C50; } } // 'PL10'
public override bool IsHierarchic { get { return false; } } public override bool IsHierarchic { get { return false; } }
public override bool CanWrite { get { return false; } } public override bool CanWrite { get { return false; } }
public PL10Opener() public PL10Opener()
{ {
Extensions = new string[] { "plt" }; Extensions = new string[] { "plt" };
} }
public override ArcFile TryOpen(ArcView file) public override ArcFile TryOpen(ArcView file)
{ {
uint current_offset = 4; uint current_offset = 4;
int frame_count = file.View.ReadUInt16(current_offset); int frame_count = file.View.ReadUInt16(current_offset);
if (!IsSaneCount(frame_count)) if (!IsSaneCount(frame_count))
return null; return null;
current_offset += 0x12; current_offset += 0x12;
string base_name = Path.GetFileNameWithoutExtension(file.Name); string base_name = Path.GetFileNameWithoutExtension(file.Name);
var dir = new List<Entry>(frame_count); var dir = new List<Entry>(frame_count);
var info = new ImageMetaData var info = new ImageMetaData
{ {
OffsetX = file.View.ReadInt32(current_offset), OffsetX = file.View.ReadInt32(current_offset),
OffsetY = file.View.ReadInt32(current_offset + 4), OffsetY = file.View.ReadInt32(current_offset + 4),
Width = file.View.ReadUInt32(current_offset + 8), Width = file.View.ReadUInt32(current_offset + 8),
Height = file.View.ReadUInt32(current_offset + 12), Height = file.View.ReadUInt32(current_offset + 12),
}; };
int channels = file.View.ReadInt32(current_offset + 0x10); int channels = file.View.ReadInt32(current_offset + 0x10);
info.BPP = channels * 8; info.BPP = channels * 8;
current_offset += 0x14; current_offset += 0x14;
var entry = new PL10Entry var entry = new PL10Entry
{ {
FrameIndex = 0, FrameIndex = 0,
Name = string.Format("{0}#{1:D2}", base_name, 0), Name = string.Format("{0}#{1:D2}", base_name, 0),
Type = "image", Type = "image",
Offset = current_offset, Offset = current_offset,
Size = (uint)channels * info.Width * info.Height, Size = (uint)channels * info.Width * info.Height,
IsPacked = false, IsPacked = false,
}; };
dir.Add(entry); dir.Add(entry);
current_offset += entry.Size; current_offset += entry.Size;
for (int i = 1; i < frame_count; ++i) for (int i = 1; i < frame_count; ++i)
{ {
int step = file.View.ReadByte(current_offset++); int step = file.View.ReadByte(current_offset++);
if (0 == step) if (0 == step)
return null; return null;
uint packed_size = file.View.ReadUInt32(current_offset); uint packed_size = file.View.ReadUInt32(current_offset);
uint unpacked_size = (uint)(channels * (info.OffsetX + (int)info.Width) uint unpacked_size = (uint)(channels * (info.OffsetX + (int)info.Width)
* (info.OffsetY + (int)info.Height)); * (info.OffsetY + (int)info.Height));
current_offset += 4; current_offset += 4;
entry = new PL10Entry entry = new PL10Entry
{ {
FrameIndex = i, FrameIndex = i,
Name = string.Format("{0}#{1:D2}", base_name, i), Name = string.Format("{0}#{1:D2}", base_name, i),
Type = "image", Type = "image",
Offset = current_offset, Offset = current_offset,
Size = packed_size, Size = packed_size,
UnpackedSize = unpacked_size, UnpackedSize = unpacked_size,
IsPacked = true, IsPacked = true,
RleStep = step, RleStep = step,
}; };
dir.Add(entry); dir.Add(entry);
current_offset += packed_size; current_offset += packed_size;
} }
return new PL10Archive(file, this, dir, info); return new PL10Archive(file, this, dir, info);
} }
public override Stream OpenEntry(ArcFile arc, Entry entry) public override Stream OpenEntry(ArcFile arc, Entry entry)
{ {
var anent = entry as PL10Entry; var anent = entry as PL10Entry;
var input = arc.File.CreateStream(entry.Offset, entry.Size); var input = arc.File.CreateStream(entry.Offset, entry.Size);
if (null == anent || !anent.IsPacked) if (null == anent || !anent.IsPacked)
return input; return input;
using (input) using (input)
{ {
var data = DecompressRLE(input, anent.UnpackedSize, anent.RleStep); var data = DecompressRLE(input, anent.UnpackedSize, anent.RleStep);
return new BinMemoryStream(data); return new BinMemoryStream(data);
} }
} }
public override IImageDecoder OpenImage(ArcFile arc, Entry entry) public override IImageDecoder OpenImage(ArcFile arc, Entry entry)
{ {
var anarc = (PL10Archive)arc; var anarc = (PL10Archive)arc;
var anent = (PL10Entry)entry; var anent = (PL10Entry)entry;
var pixels = anarc.GetFrame(anent.FrameIndex); var pixels = anarc.GetFrame(anent.FrameIndex);
return new BitmapDecoder(pixels, anarc.ImageInfo); return new BitmapDecoder(pixels, anarc.ImageInfo);
} }
internal static byte[] DecompressRLE(IBinaryStream input, uint unpacked_size, int rle_step) internal static byte[] DecompressRLE(IBinaryStream input, uint unpacked_size, int rle_step)
{ {
var output = new byte[unpacked_size]; var output = new byte[unpacked_size];
for (int i = 0; i < rle_step; ++i) for (int i = 0; i < rle_step; ++i)
{ {
byte v1 = input.ReadUInt8(); byte v1 = input.ReadUInt8();
output[i] = v1; output[i] = v1;
int dst = i + rle_step; int dst = i + rle_step;
while (dst < output.Length) while (dst < output.Length)
{ {
byte v2 = input.ReadUInt8(); byte v2 = input.ReadUInt8();
output[dst] = v2; output[dst] = v2;
dst += rle_step; dst += rle_step;
if (v2 == v1) if (v2 == v1)
{ {
int count = input.ReadUInt8(); int count = input.ReadUInt8();
if (0 != (count & 0x80)) if (0 != (count & 0x80))
count = input.ReadUInt8() + ((count & 0x7F) << 8) + 128; count = input.ReadUInt8() + ((count & 0x7F) << 8) + 128;
while (count-- > 0 && dst < output.Length) while (count-- > 0 && dst < output.Length)
{ {
output[dst] = v2; output[dst] = v2;
dst += rle_step; dst += rle_step;
} }
if (dst < output.Length) if (dst < output.Length)
{ {
v2 = input.ReadUInt8(); v2 = input.ReadUInt8();
output[dst] = v2; output[dst] = v2;
dst += rle_step; dst += rle_step;
} }
} }
v1 = v2; v1 = v2;
} }
} }
return output; return output;
} }
} }
class PL10Archive : ArcFile class PL10Archive : ArcFile
{ {
byte[][] Frames; byte[][] Frames;
public readonly ImageMetaData ImageInfo; public readonly ImageMetaData ImageInfo;
public PL10Archive(ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, ImageMetaData base_info) public PL10Archive(ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, ImageMetaData base_info)
: base(arc, impl, dir) : base(arc, impl, dir)
{ {
Frames = new byte[dir.Count][]; Frames = new byte[dir.Count][];
ImageInfo = base_info; ImageInfo = base_info;
} }
public byte[] GetFrame(int index) public byte[] GetFrame(int index)
{ {
if (index >= Frames.Length) if (index >= Frames.Length)
throw new ArgumentException("index"); throw new ArgumentException("index");
if (null != Frames[index]) if (null != Frames[index])
return Frames[index]; return Frames[index];
var entry = Dir.ElementAt(index); var entry = Dir.ElementAt(index);
byte[] pixels; byte[] pixels;
using (var stream = OpenEntry(entry)) using (var stream = OpenEntry(entry))
{ {
pixels = new byte[stream.Length]; pixels = new byte[stream.Length];
stream.Read(pixels, 0, pixels.Length); stream.Read(pixels, 0, pixels.Length);
} }
if (index > 0) if (index > 0)
{ {
var prev_frame = GetFrame(index - 1); var prev_frame = GetFrame(index - 1);
for (int i = 0; i < pixels.Length; ++i) for (int i = 0; i < pixels.Length; ++i)
pixels[i] += prev_frame[i]; pixels[i] += prev_frame[i];
} }
Frames[index] = pixels; Frames[index] = pixels;
return pixels; return pixels;
} }
} }
} }