Merge pull request #12 from scientificworld/master

Support for several games
This commit is contained in:
ななみ
2026-01-07 18:30:17 +08:00
committed by GitHub
10 changed files with 511 additions and 8 deletions

137
ArcFormats/AdvRun/ArcARD.cs Normal file
View File

@@ -0,0 +1,137 @@
//! \file ArcARD.cs
//! \date 2025-12-24
//! \brief ADVRUN resource archive.
//
// 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.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using GameRes.Utility;
using GameRes.Compression;
namespace GameRes.Formats.AdvRun {
internal class ArdArchive : ArcFile {
private string m_key;
public string Key { get { return m_key; } }
public ArdArchive (ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, string key)
: base (arc, impl, dir)
{
m_key = key;
}
}
[Export(typeof(ArchiveFormat))]
public class ArdOpener : ArchiveFormat {
public override string Tag { get { return "ARD"; } }
public override string Description { get { return "ADVRUN resource archive"; } }
public override uint Signature { get { return 0; } }
public override bool IsHierarchic { get { return false; } }
public override bool CanWrite { get { return false; } }
public ArdOpener() {
Extensions = new string[] { "ard" };
}
public override ArcFile TryOpen(ArcView file) {
if (!file.View.AsciiEqual(4, "ARD0"))
return null;
var inf_name = VFS.ChangeFileName(file.Name, "Game.Inf");
if (!VFS.FileExists(inf_name))
return null;
using (var inf = VFS.OpenView(inf_name)) {
var key = FindKey(inf);
if (key == null)
return null;
int count = file.View.ReadInt32(8);
if (!IsSaneCount(count))
return null;
var dir = new List<Entry>(count);
uint index_offset = 0x100;
for (int i = 0; i < count; i++) {
var name = file.View.ReadString(index_offset + 0xc, 0x21, Encodings.cp932);
var entry = new PackedEntry {
Name = name,
Offset = file.View.ReadUInt32(index_offset),
Size = Math.Min(
file.View.ReadUInt32(index_offset + 4),
file.View.ReadUInt32(index_offset + 8)),
};
name = name.ToLower();
if (name.EndsWith(".snf")) entry.Type = "script";
else if (name.EndsWith(".piz")) entry.Type = "image";
else entry.Type = FormatCatalog.Instance.GetTypeFromName(name);
if (!entry.CheckPlacement(file.MaxOffset))
return null;
index_offset += 0x2d;
dir.Add(entry);
}
return new ArdArchive(file, this, dir, key);
}
}
public override Stream OpenEntry(ArcFile arc, Entry entry) {
var ard = arc as ArdArchive;
var data = ard.File.View.ReadBytes (entry.Offset, entry.Size);
if (entry.Name.ToLower().EndsWith(".snf")) {
XorDecrypt(data, ard.Key);
var input = new MemoryStream(data, 4, (int)(entry.Size - 4));
return new ZLibStream(input, CompressionMode.Decompress);
}
return new BinMemoryStream(data);
}
string FindKey(ArcView file) {
var data = file.View.ReadBytes(0, (uint)file.MaxOffset);
XorDecrypt(data, "1#jk@oih%6");
using (var input = new MemoryStream(data, 4, data.Length - 4))
using (var unpacked = new ZLibStream(input, CompressionMode.Decompress))
using (var output = new MemoryStream()) {
unpacked.CopyTo(output);
var conf = Binary.GetCString(output.ToArray(), 0);
var match = Regex.Match(conf, "^@gcode\\(\"(.*).\"\\)", RegexOptions.Multiline);
if (match.Success)
return match.Groups[1].Value;
else
return null;
}
}
void XorDecrypt(byte[] buffer, string key) {
var k = Encodings.cp932.GetBytes(key);
for (int i = 0; i < buffer.Length; i++)
buffer[i] ^= k[i % k.Length];
}
}
}

View File

@@ -0,0 +1,73 @@
//! \file ImagePIZ.cs
//! \date 2025-12-24
//! \brief ADVRUN compressed bitmap.
//
// 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;
using System.ComponentModel.Composition;
using System.IO;
using GameRes.Compression;
namespace GameRes.Formats.AdvRun
{
[Export(typeof(ImageFormat))]
public class PizFormat : ImageFormat
{
public override string Tag { get { return "PIZ"; } }
public override string Description { get { return "ADVRUN compressed bitmap"; } }
public override uint Signature { get { return 0; } }
public override bool CanWrite { get { return false; } }
public PizFormat ()
{
Extensions = new string[] { "piz" };
}
public override ImageMetaData ReadMetaData (IBinaryStream stream)
{
if (stream.Signature + 4 != stream.Length)
return null;
stream.Position = 4;
using (var lz = new ZLibStream (stream.AsStream, CompressionMode.Decompress))
{
using (var bmp = new BinaryStream (lz, stream.Name))
return Bmp.ReadMetaData (bmp);
}
}
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
{
stream.Position = 4;
using (var lz = new ZLibStream (stream.AsStream, CompressionMode.Decompress))
{
using (var bmp = new BinaryStream (lz, stream.Name))
return Bmp.Read (bmp, info);
}
}
public override void Write (Stream file, ImageData image)
{
throw new NotImplementedException ("PizFormat.Write not implemented");
}
}
}

View File

@@ -48,7 +48,7 @@ namespace GameRes.Formats.Chromium
{
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 uint Signature { get { return 0x00000004; } }
public override bool IsHierarchic { get { return true; } }
public override bool CanWrite { get { return false; } }
@@ -59,6 +59,8 @@ namespace GameRes.Formats.Chromium
public override ArcFile TryOpen (ArcView file)
{
if (file.View.ReadUInt32 (4) != file.View.ReadUInt32 (8) + 4)
return null;
uint index_size = file.View.ReadUInt32 (0x0C);
string json = file.View.ReadString (0x10, index_size, Encoding.UTF8);
var dict = JsonConvert.DeserializeObject<AsarNode> (json);

View File

@@ -132,6 +132,8 @@
<Compile Include="Adobe\ArcAIR.cs" />
<Compile Include="Ads\ArcPAC.cs" />
<Compile Include="AdvDx\ArcPKD.cs" />
<Compile Include="AdvRun\ArcARD.cs" />
<Compile Include="AdvRun\ImagePIZ.cs" />
<Compile Include="AdvScripter\ArcPAK.cs" />
<Compile Include="AdvSys\ArcAdvSys3.cs" />
<Compile Include="AdvSys\ImageGWD.cs" />
@@ -278,6 +280,7 @@
<Compile Include="elf\ImageRMT.cs" />
<Compile Include="EmbeddedResource.cs" />
<Compile Include="Emote\ImageDREF.cs" />
<Compile Include="Enigma\ArcEVB.cs" />
<Compile Include="Eternity\ArcGLNK.cs" />
<Compile Include="Eternity\ImageSGF.cs" />
<Compile Include="Ethornell\ImageCBG.cs" />

110
ArcFormats/Enigma/ArcEVB.cs Normal file
View File

@@ -0,0 +1,110 @@
//! \file ArcEVB.cs
//! \date 2025-12-27
//! \brief Enigma Virtual Box resource archive.
//
// Copyright (C) 2026 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 System.Linq;
using System.Text;
using GameRes.Utility;
namespace GameRes.Formats.Enigma {
public enum NodeTypes {
AbsoluteDrive = 1,
File = 2,
Folder = 3,
}
[Export(typeof(ArchiveFormat))]
public class EvbPackOpener : ArchiveFormat {
public override string Tag { get { return "EVB"; } }
public override string Description { get { return "Enigma Virtual Box resource archive"; } }
public override uint Signature { get { return 0x425645; } } // 'EVB'
public override bool IsHierarchic { get { return true; } }
public override bool CanWrite { get { return false; } }
public override ArcFile TryOpen(ArcView file) {
uint index_size = file.View.ReadUInt32(0x40) + 68;
uint index_offset = 0x4F;
uint file_offset = index_size;
var dir = new List<Entry>();
var name_buffer = new StringBuilder();
var counts = new List<uint> { file.View.ReadUInt32(0x4C) };
var names = new List<string> { "" };
while (index_offset < index_size - 4) {
uint item_count = file.View.ReadUInt32(index_offset + 12);
index_offset += 16;
name_buffer.Clear();
while (true) {
char c = (char)file.View.ReadUInt16(index_offset);
index_offset += 2;
if (c == 0)
break;
name_buffer.Append(c);
}
if (name_buffer.Length == 0)
return null;
var name = name_buffer.ToString();
var type = (NodeTypes)file.View.ReadByte(index_offset);
index_offset++;
counts[counts.Count - 1]--;
if (type == NodeTypes.File) {
var entry = Create<Entry>(Path.Combine(names.Concat(new[] { name }).ToArray()));
uint unpacked_size = file.View.ReadUInt32(index_offset + 2);
uint size = file.View.ReadUInt32(index_offset + 49);
if (unpacked_size != size)
return null; // packed entry not implemented
entry.Offset = file_offset;
entry.Size = size;
file_offset += size;
if (!entry.CheckPlacement(file.MaxOffset))
return null;
dir.Add(entry);
index_offset += 53;
}
else if (type == NodeTypes.Folder) {
counts.Add(item_count);
names.Add(name);
index_offset += 25;
}
else if (type == NodeTypes.AbsoluteDrive) {
counts.Add(item_count);
names.Add(name[0].ToString());
index_offset -= 4;
}
else
return null;
while (counts.Count > 0 && counts[counts.Count - 1] == 0) {
counts.RemoveAt(counts.Count - 1);
names.RemoveAt(names.Count - 1);
}
}
return new ArcFile(file, this, dir);
}
}
}

View File

@@ -150,7 +150,7 @@ namespace GameRes.Formats.Malie
var header = new byte[0x10];
foreach (var scheme in KnownSchemes.Values)
{
var decryptor = scheme.CreateDecryptor();
var decryptor = file.View.AsciiEqual (0, "LIB") ? new NoOpDecryptor() : scheme.CreateDecryptor();
ReadEncrypted (file.View, decryptor, 0, header, 0, 0x10);
ILibIndexReader reader;
if (Binary.AsciiEqual (header, 0, "LIBP"))

View File

@@ -35,6 +35,13 @@ namespace GameRes.Formats.Malie
void DecryptBlock (long block_offset, byte[] buffer, int index);
}
public class NoOpDecryptor : IMalieDecryptor
{
public void DecryptBlock (long block_offset, byte[] buffer, int index)
{
}
}
public class CamelliaDecryptor : IMalieDecryptor
{
Camellia m_enc;

View File

@@ -1,6 +1,6 @@
//! \file ArcNexas.cs
//! \date Sat Mar 14 18:03:04 2015
//! \brief NeXAS enginge resource archives implementation.
//! \brief NeXAS engine resource archives implementation.
//
// Copyright (C) 2015 by morkt
//
@@ -45,6 +45,14 @@ namespace GameRes.Formats.NeXAS
None2,
Zstd,
ZstdOrNone,
NeedDecryptionOnly = 0xFDFD, // internal magic number
}
internal interface INexasIndexReader
{
Compression PackType { get; }
List<Entry> Read ();
}
public class PacArchive : ArcFile
@@ -79,17 +87,30 @@ namespace GameRes.Formats.NeXAS
{
if (!file.View.AsciiEqual (0, "PAC") || 'K' == file.View.ReadByte (3))
return null;
var reader = new IndexReader (file, PacEncoding.Get<Encoding>());
var dir = reader.Read();
List<Entry> dir = null;
INexasIndexReader reader = new IndexReader (file, PacEncoding.Get<Encoding>());
try
{
dir = reader.Read();
}
catch {}
if (null == dir)
return null;
{
reader = new OldIndexReader (file);
dir = reader.Read();
if (null == dir)
return null;
}
if (Compression.None == reader.PackType)
return new ArcFile (file, this, dir);
return new PacArchive (file, this, dir, reader.PackType);
}
internal sealed class IndexReader
internal sealed class IndexReader : INexasIndexReader
{
ArcView m_file;
int m_count;
@@ -191,13 +212,71 @@ namespace GameRes.Formats.NeXAS
}
}
internal sealed class OldIndexReader : INexasIndexReader
{
ArcView m_file;
uint m_header_size;
public Compression PackType { get { return Compression.NeedDecryptionOnly; } }
public OldIndexReader (ArcView file)
{
m_file = file;
m_header_size = file.View.ReadUInt32 (3);
}
List<Entry> m_dir;
public List<Entry> Read ()
{
m_dir = new List<Entry> ();
using (var input = m_file.CreateStream())
{
input.Position = 7;
while (input.Position < m_header_size)
{
byte c;
List<byte> name_buffer = new List<byte>();
while (true)
{
c = (byte)input.ReadByte();
if (c == 0) break;
name_buffer.Add ((byte)~c);
}
var name = Binary.GetCString (name_buffer.ToArray(), 0);
if (string.IsNullOrWhiteSpace (name))
return null;
var entry = FormatCatalog.Instance.Create<Entry> (name);
entry.Offset = input.ReadUInt32() + m_header_size;
entry.Size = input.ReadUInt32();
if (!entry.CheckPlacement (m_file.MaxOffset))
return null;
m_dir.Add (entry);
}
}
return m_dir;
}
}
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
var input = arc.File.CreateStream (entry.Offset, entry.Size);
var pac = arc as PacArchive;
var pent = entry as PackedEntry;
if (null == pac || null == pent || !pent.IsPacked)
if (null == pac)
return input;
if (Compression.NeedDecryptionOnly == pac.PackType)
{
var data = new byte[entry.Size];
input.Read (data, 0, data.Length);
for (int i = 0; i < Math.Min (3, data.Length); i++)
data[i] = (byte)~data[i];
return new BinMemoryStream (data, entry.Name);
}
if (null == pent || !pent.IsPacked)
return input;
switch (pac.PackType)
{
case Compression.Lzss: