Merge pull request #10 from scientificworld/master

Support for multiple games
This commit is contained in:
ななみ
2025-12-25 00:39:28 +08:00
committed by GitHub
10 changed files with 43255 additions and 25151 deletions

92
ArcFormats/ArcASAR.cs Normal file
View File

@@ -0,0 +1,92 @@
//! \file ArcASAR.cs
//! \date 2025-12-23
//! \brief Electron/Atom Shell resource archive format.
//
// Copyright (C) 2025 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.Text;
using Newtonsoft.Json;
namespace GameRes.Formats.Chromium
{
class AsarNode
{
[JsonProperty("files")]
public Dictionary<string, AsarNode> Files { get; set; }
[JsonProperty("size")]
public uint Size { get; set; }
[JsonProperty("offset")]
public string Offset { get; set; }
}
[Export(typeof(ArchiveFormat))]
public class AsarOpener : ArchiveFormat
{
public override string Tag { get { return "ASAR"; } }
public override string Description { get { return "Electron/Atom Shell archive format"; } }
public override uint Signature { get { return 0; } }
public override bool IsHierarchic { get { return true; } }
public override bool CanWrite { get { return false; } }
public AsarOpener ()
{
Extensions = new string[] { "asar" };
}
public override ArcFile TryOpen (ArcView file)
{
uint index_size = file.View.ReadUInt32 (0x0C);
string json = file.View.ReadString (0x10, index_size, Encoding.UTF8);
var dict = JsonConvert.DeserializeObject<AsarNode> (json);
var dir = new List<Entry> ();
ParseIndex (dir, dict, (uint)((index_size + 0x10 + 3) & ~3));
return new ArcFile (file, this, dir);
}
internal void ParseIndex (List<Entry> dir, AsarNode dict, uint pad, string cur = "") {
if (dict.Files != null)
{
foreach (var kv in dict.Files)
{
string k = kv.Key;
AsarNode v = kv.Value;
ParseIndex (dir, v, pad, cur != "" ? $"{cur}/{k}" : k);
}
}
else
{
var entry = new Entry {
Name = cur,
Size = dict.Size,
Offset = uint.Parse (dict.Offset) + pad,
Type = FormatCatalog.Instance.GetTypeFromName (cur)
};
dir.Add (entry);
}
}
}
}

View File

@@ -63,6 +63,9 @@
<Reference Include="NVorbis, Version=0.10.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NVorbis.0.10.4\lib\net45\NVorbis.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Snappy.NET, Version=1.1.1.8, Culture=neutral, processorArchitecture=MSIL">
@@ -194,6 +197,7 @@
<Compile Include="Aoi\ImageAGF.cs" />
<Compile Include="Apricot\ArcDAT.cs" />
<Compile Include="ArcARCX.cs" />
<Compile Include="ArcASAR.cs" />
<Compile Include="Artemis\ArcMJA.cs" />
<Compile Include="Macintosh\ImagePICT.cs" />
<Compile Include="Macromedia\ArcDXR.cs" />
@@ -284,8 +288,10 @@
<Compile Include="FC01\ImageTIL.cs" />
<Compile Include="FC01\ImageWM2.cs" />
<Compile Include="FC01\ImageWMK.cs" />
<Compile Include="FrontWing\ArcDAT.cs" />
<Compile Include="FrontWing\ArcFG.cs" />
<Compile Include="FrontWing\ArcFLT.cs" />
<Compile Include="FrontWing\ArcTLP.cs" />
<Compile Include="FrontWing\ArcVAV.cs" />
<Compile Include="FrontWing\ImageFG.cs" />
<Compile Include="GLib\ArcG.cs" />

View File

@@ -42,7 +42,7 @@ namespace GameRes.Formats.Artemis
public PfsOpener ()
{
Extensions = new string[] { "pfs", "000", "001", "002", "003", "004", "005", "010" };
Extensions = new string[] { "pfs", "ipd", "000", "001", "002", "003", "004", "005", "010" };
ContainedFormats = new string[] { "PNG", "JPEG", "IPT", "OGG", "TXT", "SCR" };
Settings = new[] { PfsEncoding };
}
@@ -67,6 +67,7 @@ namespace GameRes.Formats.Artemis
return OpenPf (file, version, GetAltEncoding());
}
case 2: return OpenPf2 (file);
case 0: return OpenPf0 (file); // SALA ONE .ipd format
default: return null;
}
}
@@ -129,6 +130,27 @@ namespace GameRes.Formats.Artemis
return new ArcFile (file, this, dir);
}
ArcFile OpenPf0 (ArcView file)
{
int count = file.View.ReadInt32 (3);
if (!IsSaneCount (count))
return null;
int offset = 7;
var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i)
{
var name = file.View.ReadString (offset, 0x104, Encoding.ASCII);
var entry = Create<Entry> (name);
entry.Offset = file.View.ReadUInt32 (offset + 0x104);
entry.Size = file.View.ReadUInt32 (offset + 0x108);
if (!entry.CheckPlacement (file.MaxOffset))
return null;
offset += 0x10C;
dir.Add (entry);
}
return new ArcFile (file, this, dir);
}
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
var parc = arc as PfsArchive;

View File

@@ -0,0 +1,104 @@
//! \file ArcDAT.cs
//! \date 2025-12-13
//! \brief FrontWing resource archive.
//
// Copyright (C) 2018 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 GameRes.Utility;
namespace GameRes.Formats.FrontWing
{
[Export(typeof(ArchiveFormat))]
public class DatOpener : ArchiveFormat
{
public override string Tag { get { return "DAT/TIMELEAP"; } }
public override string Description { get { return "'Time Leap' resource archive"; } }
public override uint Signature { get { return 0; } }
public override bool IsHierarchic { get { return false; } }
public override bool CanWrite { get { return false; } }
public override ArcFile TryOpen (ArcView file)
{
if (file.MaxOffset < 4)
return null;
int count = file.View.ReadInt32 (file.MaxOffset - 4);
if (!IsSaneCount (count))
return null;
int index_size = 0x50 * count;
if (file.MaxOffset < index_size + 4)
return null;
var index = file.View.ReadBytes (file.MaxOffset - 4 - index_size, (uint)index_size);
NibbleSwap (index);
int index_offset = 0;
var dir = new List<Entry> (count);
for (int i = 0; i < count; i++)
{
var name = Binary.GetCString (index, index_offset, 0x40);
var entry = Create<Entry> (name);
entry.Offset = LittleEndian.ToUInt32 (index, index_offset + 0x40);
entry.Size = LittleEndian.ToUInt32 (index, index_offset + 0x48);
if (!entry.CheckPlacement (file.MaxOffset))
return null;
index_offset += 0x50;
dir.Add (entry);
}
return new ArcFile (file, this, dir);
}
static readonly byte[] keyTable = {
0xff, 0xff, 0xff, 0x01,
0x9c, 0xaa, 0xa5, 0x00,
0x30, 0xff, 0x77, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
var data = arc.File.View.ReadBytes (entry.Offset, entry.Size);
for (int i = 1; i < data.Length; i += 4)
{
data[i] = (byte)(-data[i] & 0xff);
}
for (int i = 0; i < data.Length; i += 3)
{
data[i] ^= keyTable[i / 5 % 5 + i % 6];
}
NibbleSwap(data, 2, 6);
return new BinMemoryStream (data);
}
void NibbleSwap (byte[] buffer, int start = 0, int step = 1)
{
for (int i = start; i < buffer.Length; i += step)
{
buffer[i] = (byte)(((buffer[i] & 0xf0) >> 4) + ((buffer[i] & 0xf) << 4));
}
}
}
}

View File

@@ -0,0 +1,106 @@
//! \file ArcTLP.cs
//! \date 2025-12-22
//! \brief FrontWing resource archive.
//
// Copyright (C) 2018 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 GameRes.Utility;
using GameRes.Compression;
namespace GameRes.Formats.FrontWing
{
[Export(typeof(ArchiveFormat))]
public class TlpOpener : ArchiveFormat
{
public override string Tag { get { return "PAC/TLP"; } }
public override string Description { get { return "'Time Leap Paradise' resource archive"; } }
public override uint Signature { get { return 0x5f504c54; } } // 'TLP_DAT'
public override bool IsHierarchic { get { return true; } }
public override bool CanWrite { get { return false; } }
public override ArcFile TryOpen (ArcView file)
{
if (!file.View.AsciiEqual (4, "DAT"))
return null;
int count = file.View.ReadInt32 (0x10);
if (!IsSaneCount (count))
return null;
int index_size = 0x110 * count;
var index = file.View.ReadBytes (0x20, (uint)index_size);
byte type = file.View.ReadByte (0x18);
Decrypt (index, index_size, type);
var first_name = Binary.GetCString (index, 0, 0x104);
if (first_name != "data/ajfkur3h45n56d7u78a7nh9u7iI8ny0fau6i4al27we4hfuelnrg")
return null;
int index_offset = 0x110;
var dir = new List<Entry> (count - 1);
for (int i = 1; i < count; i++)
{
var name = Binary.GetCString (index, index_offset, 0x104);
var entry = Create<PackedEntry> (name);
entry.Offset = LittleEndian.ToUInt32 (index, index_offset + 0x104);
entry.UnpackedSize = LittleEndian.ToUInt32 (index, index_offset + 0x108);
entry.Size = LittleEndian.ToUInt32 (index, index_offset + 0x10C);
if (!entry.CheckPlacement (file.MaxOffset))
return null;
index_offset += 0x110;
dir.Add (entry);
}
return new ArcFile (file, this, dir);
}
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
var data = arc.File.View.ReadBytes (entry.Offset, entry.Size);
byte type = arc.File.View.ReadByte (0x18);
int len = Math.Min (arc.File.View.ReadByte (0x19) >> 1, data.Length);
Decrypt (data, len, type);
return new ZLibStream (new MemoryStream (data), CompressionMode.Decompress);
}
void Decrypt (byte[] buffer, int length, byte type = 0)
{
if (type == 0)
{
byte key = 0xcb;
for (int i = 0; i < length; i++)
{
buffer[i] = Binary.RotByteR ((byte)(buffer[i] ^ key), 1);
key = 1;
}
}
else
{
throw new System.NotImplementedException ("decryption type not implemented");
}
}
}
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -59,21 +59,14 @@ namespace GameRes.Formats.Sas5
var GetEntryName = CreateEntryNameDelegate (file.Name);
index_offset += 0x20;
int real_count = 0;
for (int i = 0; i < count; ++i)
{
int block = file.View.ReadInt32 (index_offset + i * 0x14);
real_count += Convert.ToInt32 (block != block_start);
}
var dir = new List<Entry> (real_count);
var dir = new List<Entry> ();
for (int i = 0; i < count; ++i)
{
int block = file.View.ReadInt32 (index_offset);
if (block == block_start)
continue;
var entry = new Entry {
Name = GetEntryName (i),
Name = GetEntryName (i, block - block_start - 1),
Offset = file.View.ReadUInt32 (index_offset + 4),
Size = file.View.ReadUInt32 (index_offset + 12),
};
@@ -89,17 +82,17 @@ namespace GameRes.Formats.Sas5
return new ArcFile (file, this, dir);
}
internal Func<int, string> CreateEntryNameDelegate (string arc_name)
internal Func<int, int, string> CreateEntryNameDelegate (string arc_name)
{
var index = Sec5Opener.LookupIndex (arc_name);
string base_name = Path.GetFileNameWithoutExtension (arc_name);
if (null == index)
return n => GetDefaultName (base_name, n);
return (n, m) => GetDefaultName (base_name, n);
else
return (n) => {
return (n, m) => {
Entry entry;
if (index.TryGetValue (n, out entry))
return entry.Name;
if (index.TryGetValue (m, out entry))
return entry.Name.Substring (1); // remove leading slash
return GetDefaultName (base_name, n);
};
}

View File

@@ -112,29 +112,32 @@ namespace GameRes.Formats.Sas5
}
if (0 == match.Length)
return null;
using (var sec5 = new ArcView (match[0]))
foreach (var m in match)
{
if (!sec5.View.AsciiEqual (0, "SEC5"))
return null;
uint offset = 8;
while (offset < sec5.MaxOffset)
using (var sec5 = new ArcView (m))
{
string id = sec5.View.ReadString (offset, 4, Encoding.ASCII);
if ("ENDS" == id)
break;
uint section_size = sec5.View.ReadUInt32 (offset+4);
offset += 8;
if ("RESR" == id)
if (!sec5.View.AsciiEqual (0, "SEC5"))
continue;
uint offset = 8;
while (offset < sec5.MaxOffset)
{
using (var resr = sec5.CreateStream (offset, section_size))
return ReadResrSection (resr);
string id = sec5.View.ReadString (offset, 4, Encoding.ASCII);
if ("ENDS" == id)
break;
uint section_size = sec5.View.ReadUInt32 (offset+4);
offset += 8;
if ("RESR" == id)
{
using (var resr = sec5.CreateStream (offset, section_size))
return ReadResrSection (resr);
}
if ("RES2" == id)
{
using (var res2 = sec5.CreateStream (offset, section_size))
return ReadRes2Section (res2);
}
offset += section_size;
}
if ("RES2" == id)
{
using (var res2 = sec5.CreateStream (offset, section_size))
return ReadRes2Section (res2);
}
offset += section_size;
}
}
return null;
@@ -413,10 +416,12 @@ namespace GameRes.Formats.Sas5
arc_name = ReadString();
else if ("arc-index" == param_name)
arc_index = ReadInteger();
else if ("arc-path" == param_name)
name = ReadString();
else
SkipObject();
}
if (!string.IsNullOrEmpty (arc_name) && arc_index != null)
if (!string.IsNullOrEmpty (arc_name))
{
arc_name = Path.GetFileName (arc_name);
if (!map.ContainsKey (arc_name))
@@ -426,6 +431,8 @@ namespace GameRes.Formats.Sas5
Name = name,
Type = type,
};
if (arc_index == null)
arc_index = map[arc_name].Count;
map[arc_name][arc_index.Value] = entry;
}
}

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Crc32C.NET" version="1.0.5.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net461" />
<package id="NVorbis" version="0.10.4" targetFramework="net461" />
<package id="SharpZipLib" version="1.3.3" targetFramework="net461" />
<package id="Snappy.NET" version="1.1.1.8" targetFramework="net461" />

View File

@@ -49,12 +49,12 @@ namespace GameRes.Formats.Nug
uint index_size = (uint)count * 0x40u;
if (index_size > file.View.Reserve (index_offset, index_size))
return null;
var dir = new List<Entry> (count);
var dir = new List<Entry> ();
for (int i = 0; i < count; ++i)
{
uint entry_size = file.View.ReadUInt32 (index_offset);
if (entry_size < 0x40)
return null;
break;
var name = file.View.ReadString (index_offset+0x10, 0x30);
var entry = Create<PackedEntry> (name);
entry.Offset = file.View.ReadUInt32 (index_offset+4);