mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
Compare commits
22 Commits
GARbro-Mod
...
GARbro-Mod
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eeceb8bf1d | ||
|
|
d2ea724c07 | ||
|
|
069e05bf13 | ||
|
|
aa7714be18 | ||
|
|
7530e5e6a3 | ||
|
|
02a12bbe48 | ||
|
|
a547f0282b | ||
|
|
0f827a9eba | ||
|
|
736fe8aeea | ||
|
|
bce3c1ff5b | ||
|
|
45013e79d3 | ||
|
|
43dfeca924 | ||
|
|
cc78b2d42d | ||
|
|
a160e2174a | ||
|
|
ed639136b0 | ||
|
|
75a06b1885 | ||
|
|
958ac3438d | ||
|
|
726b416160 | ||
|
|
d982b65de4 | ||
|
|
01a2b34c5d | ||
|
|
6b65a173fb | ||
|
|
debd814596 |
@@ -224,12 +224,15 @@
|
|||||||
<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" />
|
||||||
<Compile Include="Kid\ArcDAT.cs" />
|
<Compile Include="Kid\ArcDAT.cs" />
|
||||||
<Compile Include="Kid\AudioWAF.cs" />
|
<Compile Include="Kid\AudioWAF.cs" />
|
||||||
<Compile Include="Kid\ImagePRT.cs" />
|
<Compile Include="Kid\ImagePRT.cs" />
|
||||||
|
<Compile Include="KiriKiri\HxCrypt.cs" />
|
||||||
<Compile Include="KiriKiri\MoreCrypt.cs" />
|
<Compile Include="KiriKiri\MoreCrypt.cs" />
|
||||||
<Compile Include="KiriKiri\YuzCrypt.cs" />
|
<Compile Include="KiriKiri\YuzCrypt.cs" />
|
||||||
<Compile Include="Lambda\ArcLAX.cs" />
|
<Compile Include="Lambda\ArcLAX.cs" />
|
||||||
|
|||||||
@@ -648,7 +648,10 @@ namespace GameRes.Formats.Kaguya
|
|||||||
if (anm_encrypted)
|
if (anm_encrypted)
|
||||||
{
|
{
|
||||||
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> ("AN20", (a, e) => DecryptAn20 (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)));
|
||||||
}
|
}
|
||||||
m_type_table = table.ToArray();
|
m_type_table = table.ToArray();
|
||||||
}
|
}
|
||||||
@@ -688,6 +691,42 @@ namespace GameRes.Formats.Kaguya
|
|||||||
frame_offset += size + 8;
|
frame_offset += size + 8;
|
||||||
}
|
}
|
||||||
return new BinMemoryStream (data, entry.Name);
|
return new BinMemoryStream (data, entry.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream DecryptAn20(LinkArchive arc, LinkEntry entry)
|
||||||
|
{
|
||||||
|
var data = arc.File.View.ReadBytes(entry.Offset, entry.Size);
|
||||||
|
int count = data.ToUInt16(4);
|
||||||
|
int offset = 8;
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
switch (data[offset++])
|
||||||
|
{
|
||||||
|
case 0: break;
|
||||||
|
case 1: offset += 8; break;
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
case 5: offset += 4; break;
|
||||||
|
default: return new BinMemoryStream(data, entry.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count = data.ToUInt16(offset);
|
||||||
|
offset += 2 + count * 8;
|
||||||
|
int frame_count = data.ToInt16(offset);
|
||||||
|
offset += 18;
|
||||||
|
for(int i = 0; i < frame_count; ++i)
|
||||||
|
{
|
||||||
|
offset += 8;
|
||||||
|
int w = data.ToInt32(offset);
|
||||||
|
int h = data.ToInt32(offset + 4);
|
||||||
|
int channels = data.ToInt32(offset + 8);
|
||||||
|
int frame_size = channels * w * h;
|
||||||
|
offset += 12;
|
||||||
|
DecryptData(data, offset, frame_size);
|
||||||
|
offset += frame_size;
|
||||||
|
}
|
||||||
|
return new BinMemoryStream(data, entry.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream DecryptAn21 (LinkArchive arc, LinkEntry entry)
|
Stream DecryptAn21 (LinkArchive arc, LinkEntry entry)
|
||||||
@@ -716,6 +755,37 @@ namespace GameRes.Formats.Kaguya
|
|||||||
offset += 12;
|
offset += 12;
|
||||||
DecryptData (data, offset, channels * w * h);
|
DecryptData (data, offset, channels * w * h);
|
||||||
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)
|
||||||
|
{
|
||||||
|
var data = arc.File.View.ReadBytes(entry.Offset, entry.Size);
|
||||||
|
int offset = 30;
|
||||||
|
int w = data.ToInt32(offset);
|
||||||
|
int h = data.ToInt32(offset + 4);
|
||||||
|
int channels = data.ToInt32(offset + 8);
|
||||||
|
offset += 12;
|
||||||
|
DecryptData(data, offset, channels * w * h);
|
||||||
|
return new BinMemoryStream(data, entry.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecryptData (byte[] data, int index, int length)
|
void DecryptData (byte[] data, int index, int length)
|
||||||
|
|||||||
126
ArcFormats/Kaguya/ArcPL00.cs
Normal file
126
ArcFormats/Kaguya/ArcPL00.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
207
ArcFormats/Kaguya/ArcPL10.cs
Normal file
207
ArcFormats/Kaguya/ArcPL10.cs
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
//! \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 PL10Entry : PackedEntry
|
||||||
|
{
|
||||||
|
public int FrameIndex;
|
||||||
|
public int RleStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Export(typeof(ArchiveFormat))]
|
||||||
|
public class PL10Opener : ArchiveFormat
|
||||||
|
{
|
||||||
|
public override string Tag { get { return "PL10/KAGUYA"; } }
|
||||||
|
public override string Description { get { return "KaGuYa script engine animation resource"; } }
|
||||||
|
public override uint Signature { get { return 0x30314C50; } } // 'PL10'
|
||||||
|
public override bool IsHierarchic { get { return false; } }
|
||||||
|
public override bool CanWrite { get { return false; } }
|
||||||
|
|
||||||
|
public PL10Opener()
|
||||||
|
{
|
||||||
|
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 += 0x12;
|
||||||
|
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(current_offset + 0x10);
|
||||||
|
info.BPP = channels * 8;
|
||||||
|
current_offset += 0x14;
|
||||||
|
var entry = new PL10Entry
|
||||||
|
{
|
||||||
|
FrameIndex = 0,
|
||||||
|
Name = string.Format("{0}#{1:D2}", base_name, 0),
|
||||||
|
Type = "image",
|
||||||
|
Offset = current_offset,
|
||||||
|
Size = (uint)channels * info.Width * info.Height,
|
||||||
|
IsPacked = false,
|
||||||
|
};
|
||||||
|
dir.Add(entry);
|
||||||
|
current_offset += entry.Size;
|
||||||
|
for (int i = 1; i < frame_count; ++i)
|
||||||
|
{
|
||||||
|
int step = file.View.ReadByte(current_offset++);
|
||||||
|
if (0 == step)
|
||||||
|
return null;
|
||||||
|
uint packed_size = file.View.ReadUInt32(current_offset);
|
||||||
|
uint unpacked_size = (uint)(channels * (info.OffsetX + (int)info.Width)
|
||||||
|
* (info.OffsetY + (int)info.Height));
|
||||||
|
current_offset += 4;
|
||||||
|
entry = new PL10Entry
|
||||||
|
{
|
||||||
|
FrameIndex = i,
|
||||||
|
Name = string.Format("{0}#{1:D2}", base_name, i),
|
||||||
|
Type = "image",
|
||||||
|
Offset = current_offset,
|
||||||
|
Size = packed_size,
|
||||||
|
UnpackedSize = unpacked_size,
|
||||||
|
IsPacked = true,
|
||||||
|
RleStep = step,
|
||||||
|
};
|
||||||
|
dir.Add(entry);
|
||||||
|
current_offset += packed_size;
|
||||||
|
}
|
||||||
|
return new PL10Archive(file, this, dir, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Stream OpenEntry(ArcFile arc, Entry entry)
|
||||||
|
{
|
||||||
|
var anent = entry as PL10Entry;
|
||||||
|
var input = arc.File.CreateStream(entry.Offset, entry.Size);
|
||||||
|
if (null == anent || !anent.IsPacked)
|
||||||
|
return input;
|
||||||
|
using (input)
|
||||||
|
{
|
||||||
|
var data = DecompressRLE(input, anent.UnpackedSize, anent.RleStep);
|
||||||
|
return new BinMemoryStream(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IImageDecoder OpenImage(ArcFile arc, Entry entry)
|
||||||
|
{
|
||||||
|
var anarc = (PL10Archive)arc;
|
||||||
|
var anent = (PL10Entry)entry;
|
||||||
|
var pixels = anarc.GetFrame(anent.FrameIndex);
|
||||||
|
return new BitmapDecoder(pixels, anarc.ImageInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static byte[] DecompressRLE(IBinaryStream input, uint unpacked_size, int rle_step)
|
||||||
|
{
|
||||||
|
var output = new byte[unpacked_size];
|
||||||
|
for (int i = 0; i < rle_step; ++i)
|
||||||
|
{
|
||||||
|
byte v1 = input.ReadUInt8();
|
||||||
|
output[i] = v1;
|
||||||
|
int dst = i + rle_step;
|
||||||
|
while (dst < output.Length)
|
||||||
|
{
|
||||||
|
byte v2 = input.ReadUInt8();
|
||||||
|
output[dst] = v2;
|
||||||
|
dst += rle_step;
|
||||||
|
if (v2 == v1)
|
||||||
|
{
|
||||||
|
int count = input.ReadUInt8();
|
||||||
|
if (0 != (count & 0x80))
|
||||||
|
count = input.ReadUInt8() + ((count & 0x7F) << 8) + 128;
|
||||||
|
while (count-- > 0 && dst < output.Length)
|
||||||
|
{
|
||||||
|
output[dst] = v2;
|
||||||
|
dst += rle_step;
|
||||||
|
}
|
||||||
|
if (dst < output.Length)
|
||||||
|
{
|
||||||
|
v2 = input.ReadUInt8();
|
||||||
|
output[dst] = v2;
|
||||||
|
dst += rle_step;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v1 = v2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PL10Archive : ArcFile
|
||||||
|
{
|
||||||
|
byte[][] Frames;
|
||||||
|
|
||||||
|
public readonly ImageMetaData ImageInfo;
|
||||||
|
|
||||||
|
public PL10Archive(ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, ImageMetaData base_info)
|
||||||
|
: base(arc, impl, dir)
|
||||||
|
{
|
||||||
|
Frames = new byte[dir.Count][];
|
||||||
|
ImageInfo = base_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] GetFrame(int index)
|
||||||
|
{
|
||||||
|
if (index >= Frames.Length)
|
||||||
|
throw new ArgumentException("index");
|
||||||
|
if (null != Frames[index])
|
||||||
|
return Frames[index];
|
||||||
|
|
||||||
|
var entry = Dir.ElementAt(index);
|
||||||
|
byte[] pixels;
|
||||||
|
using (var stream = OpenEntry(entry))
|
||||||
|
{
|
||||||
|
pixels = new byte[stream.Length];
|
||||||
|
stream.Read(pixels, 0, pixels.Length);
|
||||||
|
}
|
||||||
|
if (index > 0)
|
||||||
|
{
|
||||||
|
var prev_frame = GetFrame(index - 1);
|
||||||
|
for (int i = 0; i < pixels.Length; ++i)
|
||||||
|
pixels[i] += prev_frame[i];
|
||||||
|
}
|
||||||
|
Frames[index] = pixels;
|
||||||
|
return pixels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -56,6 +56,7 @@ namespace GameRes.Formats.KiriKiri
|
|||||||
public ICrypt Cipher { get; set; }
|
public ICrypt Cipher { get; set; }
|
||||||
public List<Xp3Segment> Segments { get { return m_segments; } }
|
public List<Xp3Segment> Segments { get { return m_segments; } }
|
||||||
public uint Hash { get; set; }
|
public uint Hash { get; set; }
|
||||||
|
public object Extra { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Xp3Options : ResourceOptions
|
public class Xp3Options : ResourceOptions
|
||||||
@@ -145,6 +146,7 @@ namespace GameRes.Formats.KiriKiri
|
|||||||
using (var header = new BinaryReader (header_stream, Encoding.Unicode))
|
using (var header = new BinaryReader (header_stream, Encoding.Unicode))
|
||||||
using (var filename_map = new FilenameMap())
|
using (var filename_map = new FilenameMap())
|
||||||
{
|
{
|
||||||
|
Dictionary<string, HxEntry> hx_entry_info = null;
|
||||||
while (-1 != header.PeekChar())
|
while (-1 != header.PeekChar())
|
||||||
{
|
{
|
||||||
uint entry_signature = header.ReadUInt32();
|
uint entry_signature = header.ReadUInt32();
|
||||||
@@ -208,7 +210,6 @@ namespace GameRes.Formats.KiriKiri
|
|||||||
goto NextEntry;
|
goto NextEntry;
|
||||||
}
|
}
|
||||||
entry.Name = name;
|
entry.Name = name;
|
||||||
entry.Type = FormatCatalog.Instance.GetTypeFromName (name, ContainedFormats);
|
|
||||||
entry.IsEncrypted = !(entry.Cipher is NoCrypt)
|
entry.IsEncrypted = !(entry.Cipher is NoCrypt)
|
||||||
&& !(entry.Cipher.StartupTjsNotEncrypted && "startup.tjs" == name);
|
&& !(entry.Cipher.StartupTjsNotEncrypted && "startup.tjs" == name);
|
||||||
break;
|
break;
|
||||||
@@ -253,6 +254,34 @@ namespace GameRes.Formats.KiriKiri
|
|||||||
{
|
{
|
||||||
DeobfuscateEntry (entry);
|
DeobfuscateEntry (entry);
|
||||||
}
|
}
|
||||||
|
if (null != hx_entry_info)
|
||||||
|
{
|
||||||
|
if (hx_entry_info.TryGetValue (entry.Name, out HxEntry info))
|
||||||
|
{
|
||||||
|
entry.Extra = info;
|
||||||
|
|
||||||
|
var sb = new StringBuilder ();
|
||||||
|
if (!string.IsNullOrEmpty (info.Path))
|
||||||
|
{
|
||||||
|
sb.Append (info.Path);
|
||||||
|
if (!info.Path.EndsWith ("/") && !info.Path.EndsWith ("\\"))
|
||||||
|
sb.Append ('/');
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty (info.Name))
|
||||||
|
{
|
||||||
|
sb.Append (info.Name);
|
||||||
|
if (sb.Length > 0)
|
||||||
|
entry.Name = sb.ToString ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.Append (entry.Name);
|
||||||
|
if (sb.Length > 0)
|
||||||
|
entry.Name = sb.ToString ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entry.Type = FormatCatalog.Instance.GetTypeFromName(entry.Name, ContainedFormats);
|
||||||
dir.Add (entry);
|
dir.Add (entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,6 +300,22 @@ namespace GameRes.Formats.KiriKiri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (0x34767848 == entry_signature) // "Hxv4"
|
||||||
|
{
|
||||||
|
if (crypt_algorithm.Value is HxCrypt)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var offset = header.ReadInt64 () + base_offset;
|
||||||
|
var size = header.ReadUInt32 ();
|
||||||
|
var flags = header.ReadUInt16 ();
|
||||||
|
var hx = file.View.ReadBytes (offset, size);
|
||||||
|
var crypt = crypt_algorithm.Value as HxCrypt;
|
||||||
|
hx_entry_info = crypt.ReadIndex (Path.GetFileName (file.Name), hx);
|
||||||
|
}
|
||||||
|
catch (Exception) { /* ignore parse error */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (entry_size > 7)
|
else if (entry_size > 7)
|
||||||
{
|
{
|
||||||
// 0x6E666E68 == entry_signature // "hnfn"
|
// 0x6E666E68 == entry_signature // "hnfn"
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ namespace GameRes.Formats.KiriKiri
|
|||||||
var header = new byte[5];
|
var header = new byte[5];
|
||||||
input.Read (header, 0, 5);
|
input.Read (header, 0, 5);
|
||||||
uint signature = header.ToUInt32 (0);
|
uint signature = header.ToUInt32 (0);
|
||||||
|
GuessEntryTypeBySignature (entry, signature);
|
||||||
if (0x184D2204 == signature) // LZ4 magic
|
if (0x184D2204 == signature) // LZ4 magic
|
||||||
{
|
{
|
||||||
// assume no scripts are compressed using LZ4, return decompressed stream right away
|
// assume no scripts are compressed using LZ4, return decompressed stream right away
|
||||||
@@ -197,6 +198,25 @@ namespace GameRes.Formats.KiriKiri
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static readonly Dictionary<uint, string> FileTypesMap = new Dictionary<uint, string>
|
||||||
|
{
|
||||||
|
{ 0x5367674f, "audio" }, // OGG
|
||||||
|
{ 0x46464952, "audio" }, // WAV
|
||||||
|
{ 0x474e5089, "image" }, // PNG
|
||||||
|
{ 0xe0ffd8ff, "image" }, // JPG
|
||||||
|
{ 0x30474c54, "image" }, // TLG
|
||||||
|
{ 0x35474c54, "image" }, // TLG
|
||||||
|
{ 0x36474c54, "image" }, // TLG
|
||||||
|
{ 0x35474cab, "image" }, // TLG
|
||||||
|
{ 0x584d4b4a, "image" }, // TLG
|
||||||
|
};
|
||||||
|
|
||||||
|
internal void GuessEntryTypeBySignature(Entry entry, uint signature)
|
||||||
|
{
|
||||||
|
if (FileTypesMap.TryGetValue (signature, out var type))
|
||||||
|
entry.Type = type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@@ -1406,4 +1426,91 @@ namespace GameRes.Formats.KiriKiri
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class NinkiSeiyuuCrypt : ICrypt
|
||||||
|
{
|
||||||
|
ulong m_key1;
|
||||||
|
ulong m_key2;
|
||||||
|
ulong m_key3;
|
||||||
|
|
||||||
|
byte[] m_tbl2;
|
||||||
|
byte[] m_tbl3;
|
||||||
|
|
||||||
|
public NinkiSeiyuuCrypt(ulong key1, ulong key2, ulong key3)
|
||||||
|
{
|
||||||
|
m_key1 = key1;
|
||||||
|
m_key2 = key2;
|
||||||
|
m_key3 = key3;
|
||||||
|
|
||||||
|
m_tbl2 = GetTable2(3080);
|
||||||
|
m_tbl3 = GetTable3(3080, m_key1, m_key2, m_key3);
|
||||||
|
}
|
||||||
|
|
||||||
|
static byte[] GetTable1(uint seed)
|
||||||
|
{
|
||||||
|
var key = new byte[32];
|
||||||
|
|
||||||
|
uint v48 = seed & 0x7FFFFFFF;
|
||||||
|
|
||||||
|
for (var i = 0; i < 31; i++)
|
||||||
|
{
|
||||||
|
key[i] = (byte)v48;
|
||||||
|
v48 = (v48 >> 8) | (uint)((byte)v48 << 23);
|
||||||
|
}
|
||||||
|
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static byte[] GetTable2(uint seed)
|
||||||
|
{
|
||||||
|
var key = new byte[64];
|
||||||
|
|
||||||
|
uint v51 = seed & 0xFFF;
|
||||||
|
ulong v52 = (ulong)(v51 | (v51 << 13)) | ((ulong)(v51 >> 19) << 32);
|
||||||
|
uint v53 = v51 | ((uint)v52 << 13);
|
||||||
|
uint v54 = (uint)((ulong)(((uint)v52 << 7) & 0x1FFFFFFF) | (v52 >> 19));
|
||||||
|
|
||||||
|
for (int i = 0; i < 61; i++)
|
||||||
|
{
|
||||||
|
var v56 = (byte)v53;
|
||||||
|
key[i] = (byte)v53;
|
||||||
|
v53 = (uint)((((ulong)v54 << 32) | v53) >> 8);
|
||||||
|
v54 = (v54 >> 8) | (uint)(v56 << 21);
|
||||||
|
}
|
||||||
|
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static byte[] GetTable3(uint seed, ulong key1, ulong key2, ulong key3)
|
||||||
|
{
|
||||||
|
var key = new byte[64];
|
||||||
|
|
||||||
|
uint v88 = seed & 0xFFF;
|
||||||
|
ulong v89 = (ulong)(v88 | (v88 << 13)) | ((ulong)(v88 >> 19) << 32);
|
||||||
|
uint v90 = (uint)((key1 + key2) ^ (ulong)(v88 | ((uint)v89 << 13)));
|
||||||
|
uint v91 = (uint)((ulong)(((key1 + ((key3 & 0xFFFFFFFF00000000) | (key2 & 0xFFFFFFFF))) >> 32) & 0x1FFFFFFF) ^ ((ulong)(((uint)v89 << 7) & 0x1FFFFFFF) | (v89 >> 19)));
|
||||||
|
|
||||||
|
for (int i = 0; i < 61; i++)
|
||||||
|
{
|
||||||
|
var v93 = (byte)v90;
|
||||||
|
key[i] = (byte)v90;
|
||||||
|
v90 = (uint)((((ulong)v91 << 32) | v90) >> 8);
|
||||||
|
v91 = (v91 >> 8) | (uint)(v93 << 21);
|
||||||
|
}
|
||||||
|
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Decrypt(Xp3Entry entry, long offset, byte[] buffer, int pos, int count)
|
||||||
|
{
|
||||||
|
var tbl1 = GetTable1(entry.Hash);
|
||||||
|
|
||||||
|
for (var i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
buffer[pos + i] ^= tbl1[(offset + i) % 0x1F];
|
||||||
|
buffer[pos + i] += (byte)(m_tbl2[(offset + i) % 0x3D] ^ m_tbl3[(offset + i) % 0x3D]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1006
ArcFormats/KiriKiri/HxCrypt.cs
Normal file
1006
ArcFormats/KiriKiri/HxCrypt.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -55,8 +55,8 @@ namespace GameRes.Formats.KiriKiri
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class CxEncryption : ICrypt
|
public class CxEncryption : ICrypt
|
||||||
{
|
{
|
||||||
private uint m_mask;
|
protected uint m_mask;
|
||||||
private uint m_offset;
|
protected uint m_offset;
|
||||||
|
|
||||||
protected byte[] PrologOrder;
|
protected byte[] PrologOrder;
|
||||||
protected byte[] OddBranchOrder;
|
protected byte[] OddBranchOrder;
|
||||||
@@ -207,7 +207,7 @@ namespace GameRes.Formats.KiriKiri
|
|||||||
Decrypt (entry, offset, values, pos, count);
|
Decrypt (entry, offset, values, pos, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tuple<uint, uint> ExecuteXCode (uint hash)
|
protected Tuple<uint, uint> ExecuteXCode (uint hash)
|
||||||
{
|
{
|
||||||
uint seed = hash & 0x7f;
|
uint seed = hash & 0x7f;
|
||||||
if (null == m_program_list[seed])
|
if (null == m_program_list[seed])
|
||||||
|
|||||||
Binary file not shown.
@@ -7,7 +7,7 @@
|
|||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
|
|||||||
@@ -45,8 +45,8 @@
|
|||||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
<package id="System.Buffers" version="4.5.1" targetFramework="net461" />
|
<package id="System.Buffers" version="4.5.1" targetFramework="net461" />
|
||||||
<package id="System.Memory" version="4.5.4" targetFramework="net461" />
|
<package id="System.Memory" version="4.5.4" targetFramework="net461" />
|
||||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" />
|
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" />
|
||||||
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net461" />
|
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
||||||
Reference in New Issue
Block a user