From 57a5e2a79c899bebfa13d2bc19c9558b75082b6b Mon Sep 17 00:00:00 2001 From: scientificworld Date: Sun, 25 Jan 2026 23:53:46 +0800 Subject: [PATCH] feat: support IRISPCK used by CatSystem Android It appears that red<=>blue channel swapping is needed for hg3 images contained in this type of archives. --- Experimental/CatSystem/ArcIRIS.cs | 102 ++++++++++++++++++++++++++++++ Experimental/Experimental.csproj | 1 + 2 files changed, 103 insertions(+) create mode 100644 Experimental/CatSystem/ArcIRIS.cs diff --git a/Experimental/CatSystem/ArcIRIS.cs b/Experimental/CatSystem/ArcIRIS.cs new file mode 100644 index 00000000..9adeb297 --- /dev/null +++ b/Experimental/CatSystem/ArcIRIS.cs @@ -0,0 +1,102 @@ +//! \file ArcIRIS.cs +//! \date 2026-01-25 +//! \brief CatSystem for Android 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.Text; +using GameRes.Utility; + +namespace GameRes.Formats.CatSystem { + [Export(typeof(ArchiveFormat))] + public class IrisPckOpener : ArchiveFormat { + public override string Tag { get { return "DAT/IRIS"; } } + public override string Description { get { return "CatSystem for Android resource archive"; } } + public override uint Signature { get { return 0x53495249; } } // 'IRISPCK' + 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, "PCK")) + return null; + + uint offset = 0x18; + var dir = new List(); + var name_buffer = new StringBuilder(); + + while (offset < file.MaxOffset) { + offset += 8; + uint name_length = file.View.ReadUInt32(offset); + + offset += 8; + name_buffer.Clear(); + for (int i = 0; i < name_length; i += 2) { + char c = (char)file.View.ReadUInt16(offset + i); + if (c == 0) + break; + name_buffer.Append(c); + } + var dirname = name_buffer.ToString().Replace("/", "\\"); + offset += name_length; + + offset += 4; + int count = (int)file.View.ReadUInt32(offset); + var dir_inner = new List(count); + + offset += 0xC; + uint prev = 0; + for (int i = 0; i < count; i++) { + offset += 8; + uint size = file.View.ReadUInt32(offset); + uint padded_size = file.View.ReadUInt32(offset + 4); + name_length = file.View.ReadUInt32(offset + 8); + offset += 0x18; + name_buffer.Clear(); + for (int j = 0; j < name_length; j += 2) { + char c = (char)file.View.ReadUInt16(offset + j); + if (c == 0) + break; + name_buffer.Append(c); + } + var basename = name_buffer.ToString(); + var entry = Create(Path.Combine(dirname, basename)); + entry.Offset = prev; + entry.Size = size; + prev += padded_size; + offset += name_length; + dir_inner.Add(entry); + } + + for (int i = 0; i < count; i++) { + dir_inner[i].Offset += offset; + } + offset += prev; + dir.AddRange(dir_inner); + } + + return new ArcFile(file, this, dir); + } + } +} diff --git a/Experimental/Experimental.csproj b/Experimental/Experimental.csproj index 26d81de4..b6643c32 100644 --- a/Experimental/Experimental.csproj +++ b/Experimental/Experimental.csproj @@ -149,6 +149,7 @@ +