mirror of
https://github.com/crskycode/GARbro.git
synced 2026-06-06 13:48:57 +08:00
Compare commits
25 Commits
GARbro-Mod
...
GARbro-Mod
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
848a3a7b17 | ||
|
|
fb543fd3bc | ||
|
|
1b30bb8249 | ||
|
|
1aa985dffd | ||
|
|
ba1f807157 | ||
|
|
c8a20e0d3d | ||
|
|
c6c46ce30e | ||
|
|
dd3d706919 | ||
|
|
00490899e3 | ||
|
|
845e99f433 | ||
|
|
c6d8e7c423 | ||
|
|
1648a7a4f4 | ||
|
|
c278e48615 | ||
|
|
1ab7087fe7 | ||
|
|
99778823f1 | ||
|
|
ea84d6cc19 | ||
|
|
da25246c69 | ||
|
|
9f5f96dd64 | ||
|
|
c40996a775 | ||
|
|
7e4f35163d | ||
|
|
26129650fb | ||
|
|
7d0cc66090 | ||
|
|
9e0909ff0c | ||
|
|
73f16aff26 | ||
|
|
b06648783f |
@@ -228,6 +228,7 @@
|
||||
<Compile Include="Interheart\ArcFPK2.cs" />
|
||||
<Compile Include="Interheart\ImageCandy.cs" />
|
||||
<Compile Include="Ivory\ArcSG.cs" />
|
||||
<Compile Include="Kaguya\ArcAF.cs" />
|
||||
<Compile Include="Kaguya\ArcPL00.cs" />
|
||||
<Compile Include="Kaguya\ArcPL10.cs" />
|
||||
<Compile Include="Kaguya\ArcPLT.cs" />
|
||||
|
||||
@@ -73,10 +73,9 @@ namespace GameRes.Formats.Emote
|
||||
var match = PathRe.Match (line);
|
||||
if (!match.Success)
|
||||
return null;
|
||||
var pak_name = match.Groups[1].Value;
|
||||
var pak_name = VFS.CombinePath (dir, match.Groups[1].Value);
|
||||
if (!VFS.FileExists (pak_name))
|
||||
return null;
|
||||
pak_name = VFS.CombinePath (dir, pak_name);
|
||||
layers.Add (Tuple.Create (pak_name, match.Groups[2].Value));
|
||||
}
|
||||
if (0 == layers.Count)
|
||||
|
||||
133
ArcFormats/Kaguya/ArcAF.cs
Normal file
133
ArcFormats/Kaguya/ArcAF.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
//! \file ArcAF.cs
|
||||
//! \date Sun Apr 02 09:01:51 2017
|
||||
//! \brief Atelier Kaguya resource archive.
|
||||
//
|
||||
// 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;
|
||||
|
||||
namespace GameRes.Formats.Kaguya
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class AfOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "ARC/AF01"; } }
|
||||
public override string Description { get { return "Atelier Kaguya resource archive"; } }
|
||||
public override uint Signature { get { return 0x31304641; } } // 'AF01'
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
const int MaxFileNameLength = 0x100;
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
uint index_offset = file.View.ReadUInt32 (8);
|
||||
if (index_offset >= file.MaxOffset - 8)
|
||||
return null;
|
||||
using (var index = file.CreateStream (index_offset + 8))
|
||||
{
|
||||
long data_offset = 12;
|
||||
var name_buffer = new byte[MaxFileNameLength];
|
||||
var dir = new List<Entry>();
|
||||
while (index.PeekByte() != -1)
|
||||
{
|
||||
int name_length = index.ReadInt32();
|
||||
if (name_length <= 0 || name_length > name_buffer.Length)
|
||||
return null;
|
||||
if (name_length != index.Read (name_buffer, 0, name_length))
|
||||
return null;
|
||||
var name = DecryptString (name_buffer, name_length);
|
||||
name = name.TrimStart ('\\', '/');
|
||||
var entry = FormatCatalog.Instance.Create<PackedEntry> (name);
|
||||
int flags = index.ReadInt16();
|
||||
entry.IsPacked = 1 == flags;
|
||||
data_offset += 4 + name_length + 6;
|
||||
if (entry.IsPacked)
|
||||
data_offset += 4;
|
||||
entry.Offset = data_offset;
|
||||
entry.Size = index.ReadUInt32();
|
||||
entry.UnpackedSize = index.ReadUInt32();
|
||||
if (!entry.IsPacked)
|
||||
entry.Size = entry.UnpackedSize;
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
data_offset += entry.Size;
|
||||
}
|
||||
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 arc.File.CreateStream (entry.Offset, entry.Size);
|
||||
using (var input = arc.File.CreateStream (entry.Offset, entry.Size))
|
||||
{
|
||||
var output = new byte[pent.UnpackedSize];
|
||||
LzUnpack (input, output);
|
||||
return new BinMemoryStream (output);
|
||||
}
|
||||
}
|
||||
|
||||
string DecryptString (byte[] name, int length)
|
||||
{
|
||||
for (int i = 0; i < length; ++i)
|
||||
name[i] ^= 0xFF;
|
||||
return Encodings.cp932.GetString (name, 0, length);
|
||||
}
|
||||
|
||||
void LzUnpack (Stream input, byte[] output)
|
||||
{
|
||||
var frame = new byte[0x1000];
|
||||
int frame_pos = 1;
|
||||
int dst = 0;
|
||||
using (var bits = new MsbBitStream (input))
|
||||
{
|
||||
while (dst < output.Length)
|
||||
{
|
||||
if (0 != bits.GetNextBit ())
|
||||
{
|
||||
byte b = (byte)bits.GetBits (8);
|
||||
output[dst++] = b;
|
||||
frame[frame_pos++ & 0xFFF] = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = bits.GetBits (12);
|
||||
int count = bits.GetBits (4) + 2;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
byte b = frame[(offset + i) & 0xFFF];
|
||||
output[dst++] = b;
|
||||
frame[frame_pos++ & 0xFFF] = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1513,4 +1513,46 @@ namespace GameRes.Formats.KiriKiri
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SyangrilaSmartCrypt : ICrypt
|
||||
{
|
||||
byte[] GetKey (uint hash)
|
||||
{
|
||||
return new byte[5]
|
||||
{
|
||||
(byte)(hash >> 5),
|
||||
(byte)(hash >> 5),
|
||||
(byte)(hash >> 7),
|
||||
(byte)(hash >> 1),
|
||||
(byte)(hash >> 4),
|
||||
};
|
||||
}
|
||||
|
||||
public override byte Decrypt (Xp3Entry entry, long offset, byte value)
|
||||
{
|
||||
var key = GetKey (entry.Hash);
|
||||
if (offset <= 0x64)
|
||||
return (byte)(value ^ key[4]);
|
||||
else
|
||||
return (byte)(value ^ key[offset & 3]);
|
||||
}
|
||||
|
||||
public override void Decrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count)
|
||||
{
|
||||
var key = GetKey (entry.Hash);
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
if (offset+i <= 0x64)
|
||||
buffer[pos+i] ^= key[4];
|
||||
else
|
||||
buffer[pos+i] ^= key[(offset+i) & 3];
|
||||
}
|
||||
}
|
||||
|
||||
public override void Encrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count)
|
||||
{
|
||||
Decrypt (entry, offset, buffer, pos, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -28,17 +28,25 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace GameRes.Formats.Sakana
|
||||
{
|
||||
internal class SxEntry : PackedEntry
|
||||
{
|
||||
public int Storage;
|
||||
public ushort Flags;
|
||||
|
||||
public bool IsEncrypted { get { return 0 == (Flags & 0x10); } }
|
||||
}
|
||||
|
||||
internal class SxStorage
|
||||
{
|
||||
public uint Size;
|
||||
public ulong Timestamp;
|
||||
}
|
||||
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class SxOpener : ArchiveFormat
|
||||
{
|
||||
@@ -52,9 +60,7 @@ namespace GameRes.Formats.Sakana
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
var base_name = Path.GetFileName (file.Name);
|
||||
var sx_name = base_name.Substring (0, 4) + "(00).sx";
|
||||
sx_name = VFS.ChangeFileName (file.Name, sx_name);
|
||||
var sx_name = FindSxName (file.Name);
|
||||
if (!VFS.FileExists (sx_name) || file.Name.Equals (sx_name, StringComparison.InvariantCultureIgnoreCase))
|
||||
return null;
|
||||
byte[] index_data;
|
||||
@@ -140,6 +146,20 @@ namespace GameRes.Formats.Sakana
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static string FindSxName(string name)
|
||||
{
|
||||
var base_name = Path.GetFileName (name);
|
||||
var file_name = Path.GetFileNameWithoutExtension (base_name);
|
||||
for (var i = 1; i <= file_name.Length; i++)
|
||||
{
|
||||
var sx_name = file_name.Substring (0, i) + "(00).sx";
|
||||
sx_name = VFS.ChangeFileName (name, sx_name);
|
||||
if (VFS.FileExists (sx_name))
|
||||
return sx_name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
internal class SxIndexDeserializer
|
||||
@@ -170,36 +190,47 @@ namespace GameRes.Formats.Sakana
|
||||
m_dir = new List<Entry> (count);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
m_index.ReadUInt16();
|
||||
m_index.ReadByte();
|
||||
int storage = m_index.ReadByte();
|
||||
ushort flags = Binary.BigEndian (m_index.ReadUInt16());
|
||||
uint offset = Binary.BigEndian (m_index.ReadUInt32());
|
||||
uint size = Binary.BigEndian (m_index.ReadUInt32());
|
||||
var entry = new SxEntry {
|
||||
Storage = storage,
|
||||
Flags = flags,
|
||||
Offset = (long)offset << 4,
|
||||
Size = size,
|
||||
IsPacked = 0 != (flags & 0x03),
|
||||
};
|
||||
if (!entry.CheckPlacement (m_max_offset))
|
||||
return null;
|
||||
m_dir.Add (entry);
|
||||
}
|
||||
|
||||
count = Binary.BigEndian (m_index.ReadUInt16());
|
||||
var storages = new List<SxStorage>(count);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
m_index.ReadUInt32();
|
||||
m_index.ReadUInt32();
|
||||
m_index.ReadUInt32();
|
||||
Binary.BigEndian (m_index.ReadUInt32()); // archive body length
|
||||
m_index.ReadUInt64();
|
||||
m_index.Seek (16, SeekOrigin.Current); // MD5 sum
|
||||
var storage = new SxStorage {
|
||||
Size = Binary.BigEndian (m_index.ReadUInt32()) << 4,
|
||||
Timestamp = Binary.BigEndian (m_index.ReadUInt64()),
|
||||
};
|
||||
storages.Add (storage);
|
||||
m_index.Seek (16, SeekOrigin.Current); // MD5
|
||||
}
|
||||
|
||||
count = Binary.BigEndian (m_index.ReadUInt16());
|
||||
if (count > 0)
|
||||
m_index.Seek (count * 24, SeekOrigin.Current);
|
||||
DeserializeTree();
|
||||
// Remove entries in other archives
|
||||
// Note using file size as archive identification can be problematic, but faster than MD5
|
||||
var current_storage = storages.FindIndex (s => m_max_offset == s.Size);
|
||||
if (-1 != current_storage)
|
||||
{
|
||||
m_dir = m_dir.Where (e => e.CheckPlacement (m_max_offset) && (e as SxEntry).Storage == current_storage).ToList();
|
||||
}
|
||||
return m_dir;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="4.0.4.1" newVersion="6.0.0.0"/>
|
||||
<bindingRedirect oldVersion="4.0.4.1" newVersion="4.0.5.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<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">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
<package id="System.Buffers" version="4.5.1" 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.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net461" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user