From 7cfe2e328e9756abe4d5c9ac27e2a3792ddc30a9 Mon Sep 17 00:00:00 2001 From: scientificworld Date: Thu, 25 Dec 2025 10:25:44 +0800 Subject: [PATCH 01/10] feat: add ADVRUN archive and image formats --- ArcFormats/AdvRun/ArcARD.cs | 137 ++++++++++++++++++++++++++++++++++ ArcFormats/AdvRun/ImagePIZ.cs | 73 ++++++++++++++++++ ArcFormats/ArcFormats.csproj | 2 + 3 files changed, 212 insertions(+) create mode 100644 ArcFormats/AdvRun/ArcARD.cs create mode 100644 ArcFormats/AdvRun/ImagePIZ.cs diff --git a/ArcFormats/AdvRun/ArcARD.cs b/ArcFormats/AdvRun/ArcARD.cs new file mode 100644 index 00000000..78535b71 --- /dev/null +++ b/ArcFormats/AdvRun/ArcARD.cs @@ -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 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(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]; + } + } +} diff --git a/ArcFormats/AdvRun/ImagePIZ.cs b/ArcFormats/AdvRun/ImagePIZ.cs new file mode 100644 index 00000000..b0447dc1 --- /dev/null +++ b/ArcFormats/AdvRun/ImagePIZ.cs @@ -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"); + } + } +} diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 8df6b724..3b8ecdb6 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -132,6 +132,8 @@ + + From ec15a2ad84ac6e0549603ed06746e1febc54bb8f Mon Sep 17 00:00:00 2001 From: scientificworld Date: Thu, 25 Dec 2025 20:26:47 +0800 Subject: [PATCH 02/10] feat: add DAT/DUKE format similar to PAC/CLIO but with encryption. --- Legacy/Duke/ArcDAT.cs | 88 +++++++++++++++++++++++++++++++++++++++++++ Legacy/Legacy.csproj | 1 + 2 files changed, 89 insertions(+) create mode 100644 Legacy/Duke/ArcDAT.cs diff --git a/Legacy/Duke/ArcDAT.cs b/Legacy/Duke/ArcDAT.cs new file mode 100644 index 00000000..2a5d70d3 --- /dev/null +++ b/Legacy/Duke/ArcDAT.cs @@ -0,0 +1,88 @@ +//! \file ArcDAT.cs +//! \date 2025-12-25 +//! \brief Duke 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; +using GameRes.Utility; + +namespace GameRes.Formats.Duke +{ + [Export(typeof(ArchiveFormat))] + public class DatOpener : ArchiveFormat + { + public override string Tag { get { return "DAT/DUKE"; } } + public override string Description { get { return "Duke 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) + { + int count = (int)(file.View.ReadUInt32 (0) ^ 0xfa261efb); + if (!file.Name.HasExtension (".dat") || !IsSaneCount (count)) + return null; + + uint index_offset = 4; + uint data_offset = index_offset + (uint)count * 0x28u; + var dir = new List (count); + for (int i = 0; i < count; ++i) + { + var buffer = file.View.ReadBytes (index_offset, 0x20); + for (int counter = 0; counter < 0x20; counter++) + { + buffer[counter] = (byte)(buffer[counter] ^ counter * 5 + 172); + } + var name = Binary.GetCString (buffer, 0); + if (string.IsNullOrWhiteSpace (name)) + return null; + var entry = FormatCatalog.Instance.Create (name); + entry.Size = (uint)(file.View.ReadUInt32 (index_offset+0x20) ^ 0xfa261efb); + entry.Offset = file.View.ReadUInt32 (index_offset+0x24); + if (entry.Offset < data_offset || !entry.CheckPlacement (file.MaxOffset)) + return null; + dir.Add (entry); + index_offset += 0x28; + } + return new ArcFile (file, this, dir); + } + + public override Stream OpenEntry (ArcFile arc, Entry entry) + { + var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); + var name = Encodings.cp932.GetBytes (entry.Name); + int length = name.Length; + for (int i = 0; i < entry.Size && i < 0x2c00; i += length) + { + for (int j = 0; j < length && j < entry.Size - i; j++) + { + data[i + j] = (byte)(data[i + j] ^ name[j] + i + j); + } + } + return new BinMemoryStream (data); + } + } +} diff --git a/Legacy/Legacy.csproj b/Legacy/Legacy.csproj index 19c8f3e5..fadcf734 100644 --- a/Legacy/Legacy.csproj +++ b/Legacy/Legacy.csproj @@ -214,6 +214,7 @@ + From c94178744b9090fef1b5dfe025d6577ccf1f5a53 Mon Sep 17 00:00:00 2001 From: scientificworld Date: Sat, 27 Dec 2025 22:53:12 +0800 Subject: [PATCH 03/10] feat: add support for older NeXAS archives --- ArcFormats/Nexas/ArcPAC.cs | 84 +++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 5 deletions(-) diff --git a/ArcFormats/Nexas/ArcPAC.cs b/ArcFormats/Nexas/ArcPAC.cs index e10a0d53..5c2536f7 100644 --- a/ArcFormats/Nexas/ArcPAC.cs +++ b/ArcFormats/Nexas/ArcPAC.cs @@ -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 // @@ -32,6 +32,7 @@ using System.ComponentModel.Composition; using GameRes.Compression; using GameRes.Formats.Strings; using GameRes.Utility; +using System.Diagnostics; namespace GameRes.Formats.NeXAS { @@ -45,6 +46,7 @@ namespace GameRes.Formats.NeXAS None2, Zstd, ZstdOrNone, + NeedDecryptionOnly = 0xFDFD, // magic number, no actual meaning } public class PacArchive : ArcFile @@ -79,10 +81,23 @@ namespace GameRes.Formats.NeXAS { if (!file.View.AsciiEqual (0, "PAC") || 'K' == file.View.ReadByte (3)) return null; - var reader = new IndexReader (file, PacEncoding.Get()); - var dir = reader.Read(); + + List dir = null; + dynamic reader = new IndexReader (file, PacEncoding.Get()); + 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); @@ -191,13 +206,72 @@ namespace GameRes.Formats.NeXAS } } + internal sealed class OldIndexReader + { + 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 m_dir; + + public List Read () + { + m_dir = new List (); + using (var input = m_file.CreateStream()) + { + input.Position = 7; + while (input.Position < m_header_size) + { + byte c; + List name_buffer = new List(); + while (true) + { + c = (byte)input.ReadByte(); + if (c == 0) break; + name_buffer.Add ((byte)~c); + } + var name = Binary.GetCString (name_buffer.ToArray(), 0); + Debug.Write(name); + if (string.IsNullOrWhiteSpace (name)) + return null; + var entry = FormatCatalog.Instance.Create (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: From db28f8abd64c1634674a3e0a6ded1023ee20ef8e Mon Sep 17 00:00:00 2001 From: scientificworld Date: Sat, 27 Dec 2025 22:56:54 +0800 Subject: [PATCH 04/10] chore: remove debug code --- ArcFormats/Nexas/ArcPAC.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ArcFormats/Nexas/ArcPAC.cs b/ArcFormats/Nexas/ArcPAC.cs index 5c2536f7..c62c6977 100644 --- a/ArcFormats/Nexas/ArcPAC.cs +++ b/ArcFormats/Nexas/ArcPAC.cs @@ -32,7 +32,6 @@ using System.ComponentModel.Composition; using GameRes.Compression; using GameRes.Formats.Strings; using GameRes.Utility; -using System.Diagnostics; namespace GameRes.Formats.NeXAS { @@ -238,7 +237,6 @@ namespace GameRes.Formats.NeXAS name_buffer.Add ((byte)~c); } var name = Binary.GetCString (name_buffer.ToArray(), 0); - Debug.Write(name); if (string.IsNullOrWhiteSpace (name)) return null; var entry = FormatCatalog.Instance.Create (name); From a27a9d8a5cc85dcd2dc7ee586eb9304046870d68 Mon Sep 17 00:00:00 2001 From: scientificworld Date: Wed, 31 Dec 2025 02:42:48 +0800 Subject: [PATCH 05/10] feat: support unencrypted LIBP archive --- ArcFormats/Malie/ArcLIB.cs | 2 +- ArcFormats/Malie/MalieEncryption.cs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ArcFormats/Malie/ArcLIB.cs b/ArcFormats/Malie/ArcLIB.cs index 38e4f672..2ec9d039 100644 --- a/ArcFormats/Malie/ArcLIB.cs +++ b/ArcFormats/Malie/ArcLIB.cs @@ -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")) diff --git a/ArcFormats/Malie/MalieEncryption.cs b/ArcFormats/Malie/MalieEncryption.cs index 9e8edd55..af26c471 100644 --- a/ArcFormats/Malie/MalieEncryption.cs +++ b/ArcFormats/Malie/MalieEncryption.cs @@ -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; From 32d48b7e44929805fa950fa1b566fccacf39e9ed Mon Sep 17 00:00:00 2001 From: scientificworld Date: Sat, 3 Jan 2026 11:00:26 +0800 Subject: [PATCH 06/10] feat: add support for EVB package --- ArcFormats/Enigma/ArcEVB.cs | 104 ++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 ArcFormats/Enigma/ArcEVB.cs diff --git a/ArcFormats/Enigma/ArcEVB.cs b/ArcFormats/Enigma/ArcEVB.cs new file mode 100644 index 00000000..b6f59356 --- /dev/null +++ b/ArcFormats/Enigma/ArcEVB.cs @@ -0,0 +1,104 @@ +//! \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 { + 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(); + var name_buffer = new StringBuilder(); + var counts = new List { file.View.ReadUInt32(0x4C) }; + var names = new List { "" }; + + 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(Path.Combine(names.Append(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); + while (counts.Count > 0 && counts[counts.Count - 1] == 0) { + counts.RemoveAt(counts.Count - 1); + names.RemoveAt(names.Count - 1); + } + index_offset += 53; + } + else if (type == NodeTypes.Folder) { + counts.Add(item_count); + names.Add(name); + index_offset += 25; + } + else + return null; + } + + return new ArcFile(file, this, dir); + } + } +} From 51ed011911064707fe85eec98513f14e149130ff Mon Sep 17 00:00:00 2001 From: scientificworld Date: Sat, 3 Jan 2026 11:38:41 +0800 Subject: [PATCH 07/10] feat: improve ASAR detection method --- ArcFormats/ArcASAR.cs | 4 +++- ArcFormats/ArcFormats.csproj | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ArcFormats/ArcASAR.cs b/ArcFormats/ArcASAR.cs index 824491fe..9d677de1 100644 --- a/ArcFormats/ArcASAR.cs +++ b/ArcFormats/ArcASAR.cs @@ -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 (json); diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 3b8ecdb6..0b37488c 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -280,6 +280,7 @@ + From 8a80875b6829342650b7b3116a18f43d03a9425d Mon Sep 17 00:00:00 2001 From: scientificworld Date: Sat, 3 Jan 2026 12:07:51 +0800 Subject: [PATCH 08/10] fix: append -> concat --- ArcFormats/Enigma/ArcEVB.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArcFormats/Enigma/ArcEVB.cs b/ArcFormats/Enigma/ArcEVB.cs index b6f59356..7fd06cdc 100644 --- a/ArcFormats/Enigma/ArcEVB.cs +++ b/ArcFormats/Enigma/ArcEVB.cs @@ -72,7 +72,7 @@ namespace GameRes.Formats.Enigma { index_offset++; counts[counts.Count - 1]--; if (type == NodeTypes.File) { - var entry = Create(Path.Combine(names.Append(name).ToArray())); + var entry = Create(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) From 7909b5b64145ad5721753767446fc9c6a8f6bfe6 Mon Sep 17 00:00:00 2001 From: scientificworld Date: Sun, 4 Jan 2026 12:26:59 +0800 Subject: [PATCH 09/10] feat: EVB parsing improvement --- ArcFormats/Enigma/ArcEVB.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ArcFormats/Enigma/ArcEVB.cs b/ArcFormats/Enigma/ArcEVB.cs index 7fd06cdc..e117e293 100644 --- a/ArcFormats/Enigma/ArcEVB.cs +++ b/ArcFormats/Enigma/ArcEVB.cs @@ -32,6 +32,7 @@ using GameRes.Utility; namespace GameRes.Formats.Enigma { public enum NodeTypes { + AbsoluteDrive = 1, File = 2, Folder = 3, } @@ -83,10 +84,6 @@ namespace GameRes.Formats.Enigma { if (!entry.CheckPlacement(file.MaxOffset)) return null; dir.Add(entry); - while (counts.Count > 0 && counts[counts.Count - 1] == 0) { - counts.RemoveAt(counts.Count - 1); - names.RemoveAt(names.Count - 1); - } index_offset += 53; } else if (type == NodeTypes.Folder) { @@ -94,8 +91,17 @@ namespace GameRes.Formats.Enigma { 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); From 25f06a1c98c446e3ae4e6f0ab5bb989f77d29c83 Mon Sep 17 00:00:00 2001 From: scientificworld Date: Wed, 7 Jan 2026 12:02:14 +0800 Subject: [PATCH 10/10] chore: code enhancement --- ArcFormats/Nexas/ArcPAC.cs | 15 +++++++++++---- Legacy/Duke/ArcDAT.cs | 5 ++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ArcFormats/Nexas/ArcPAC.cs b/ArcFormats/Nexas/ArcPAC.cs index c62c6977..2aa5fded 100644 --- a/ArcFormats/Nexas/ArcPAC.cs +++ b/ArcFormats/Nexas/ArcPAC.cs @@ -45,7 +45,14 @@ namespace GameRes.Formats.NeXAS None2, Zstd, ZstdOrNone, - NeedDecryptionOnly = 0xFDFD, // magic number, no actual meaning + NeedDecryptionOnly = 0xFDFD, // internal magic number + } + + internal interface INexasIndexReader + { + Compression PackType { get; } + + List Read (); } public class PacArchive : ArcFile @@ -82,7 +89,7 @@ namespace GameRes.Formats.NeXAS return null; List dir = null; - dynamic reader = new IndexReader (file, PacEncoding.Get()); + INexasIndexReader reader = new IndexReader (file, PacEncoding.Get()); try { dir = reader.Read(); @@ -103,7 +110,7 @@ namespace GameRes.Formats.NeXAS return new PacArchive (file, this, dir, reader.PackType); } - internal sealed class IndexReader + internal sealed class IndexReader : INexasIndexReader { ArcView m_file; int m_count; @@ -205,7 +212,7 @@ namespace GameRes.Formats.NeXAS } } - internal sealed class OldIndexReader + internal sealed class OldIndexReader : INexasIndexReader { ArcView m_file; uint m_header_size; diff --git a/Legacy/Duke/ArcDAT.cs b/Legacy/Duke/ArcDAT.cs index 2a5d70d3..ffb6f9ee 100644 --- a/Legacy/Duke/ArcDAT.cs +++ b/Legacy/Duke/ArcDAT.cs @@ -42,8 +42,11 @@ namespace GameRes.Formats.Duke public override ArcFile TryOpen (ArcView file) { + if (!file.Name.HasExtension (".dat")) + return null; + int count = (int)(file.View.ReadUInt32 (0) ^ 0xfa261efb); - if (!file.Name.HasExtension (".dat") || !IsSaneCount (count)) + if (!IsSaneCount (count)) return null; uint index_offset = 4;