mirror of
https://github.com/crskycode/GARbro.git
synced 2026-06-13 17:28:55 +08:00
Compare commits
31 Commits
GARbro-Mod
...
GARbro-Mod
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7a1f910ea | ||
|
|
a0b9084978 | ||
|
|
4159c888c9 | ||
|
|
99cc04c3a6 | ||
|
|
66e4e40bff | ||
|
|
5893179d92 | ||
|
|
e5ffd784c5 | ||
|
|
4bc4ecb909 | ||
|
|
1bdeddbab0 | ||
|
|
181dd3a724 | ||
|
|
d162a02e59 | ||
|
|
214f09befb | ||
|
|
fce112d99b | ||
|
|
2dd7052e02 | ||
|
|
31a1a4f42f | ||
|
|
9647b68729 | ||
|
|
ed1b39efdd | ||
|
|
ede00c430f | ||
|
|
85c6ccfea9 | ||
|
|
53395b5453 | ||
|
|
54023174b6 | ||
|
|
2e89ad5832 | ||
|
|
dba750ba39 | ||
|
|
c1bef5d0b2 | ||
|
|
c77112e586 | ||
|
|
57a5e2a79c | ||
|
|
7c47c64083 | ||
|
|
718f255b25 | ||
|
|
8c2746084b | ||
|
|
87195d8673 | ||
|
|
3f5795a5e0 |
@@ -139,6 +139,9 @@
|
||||
<Compile Include="AdvSys\ImageGWD.cs" />
|
||||
<Compile Include="Ail\ArcLNK2.cs" />
|
||||
<Compile Include="AIRNovel\ArcAIR.cs" />
|
||||
<Compile Include="aNCHOR\ArcFPD.cs" />
|
||||
<Compile Include="aNCHOR\AudioFCD.cs" />
|
||||
<Compile Include="FrontierWorks\ArcPCARC.cs" />
|
||||
<Compile Include="Artemis\ImageNekoPNG.cs" />
|
||||
<Compile Include="CsWare\AudioWAV.cs" />
|
||||
<Compile Include="CsWare\ImageGDT.cs" />
|
||||
@@ -154,13 +157,18 @@
|
||||
<Compile Include="DxLib\WidgetDXA.xaml.cs">
|
||||
<DependentUpon>WidgetDXA.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Edoire\ArcARC.cs" />
|
||||
<Compile Include="FC01\ArcBDT.cs" />
|
||||
<Compile Include="FC01\ArcSCXA.cs" />
|
||||
<Compile Include="FC01\BdtTables.cs" />
|
||||
<Compile Include="Fog\ArcDAT.cs" />
|
||||
<Compile Include="FrontierWorks\ImageEXT.cs" />
|
||||
<Compile Include="GScripter\ArcDATA.cs" />
|
||||
<Compile Include="Guyzware\ArcDat.cs" />
|
||||
<Compile Include="Ism\ImagePNG.cs" />
|
||||
<Compile Include="Kid\ArcDATRAW.cs" />
|
||||
<Compile Include="Kid\ArcKLZ.cs" />
|
||||
<Compile Include="Kid\ArcP2T.cs" />
|
||||
<Compile Include="Kid\ImageBIP.cs" />
|
||||
<Compile Include="Kid\ImageBIParc.cs" />
|
||||
<Compile Include="Kid\ImageKLZ.cs" />
|
||||
@@ -177,6 +185,7 @@
|
||||
<Compile Include="Illusion\ArcPP.cs" />
|
||||
<Compile Include="Interheart\ImageBMP.cs" />
|
||||
<Compile Include="Interheart\ImageHMP.cs" />
|
||||
<Compile Include="CatSystem\ArcZT.cs" />
|
||||
<Compile Include="JamCreation\ArcDAT.cs" />
|
||||
<Compile Include="JamCreation\ImageDPO.cs" />
|
||||
<Compile Include="AliceSoft\ArcAAR.cs" />
|
||||
@@ -201,6 +210,7 @@
|
||||
<Compile Include="ArcARCX.cs" />
|
||||
<Compile Include="ArcASAR.cs" />
|
||||
<Compile Include="Artemis\ArcMJA.cs" />
|
||||
<Compile Include="Leaf\LeafVideo.cs" />
|
||||
<Compile Include="Macintosh\ImagePICT.cs" />
|
||||
<Compile Include="Macromedia\ArcDXR.cs" />
|
||||
<Compile Include="Macromedia\AudioSND.cs" />
|
||||
@@ -214,10 +224,13 @@
|
||||
<Compile Include="MAGES\ImageBIN.cs" />
|
||||
<Compile Include="Mugi\ArcBIN.cs" />
|
||||
<Compile Include="Musica\ArcPAK.cs" />
|
||||
<Compile Include="NEKOWORKs\ArcPACK.cs" />
|
||||
<Compile Include="NipponIchi\ArcCASN.cs" />
|
||||
<Compile Include="NipponIchi\ArcPSFS.cs" />
|
||||
<Compile Include="NipponIchi\ImageNMT.cs" />
|
||||
<Compile Include="NScripter\Script.cs" />
|
||||
<Compile Include="Ps1\ImageTIM.cs" />
|
||||
<Compile Include="Psp\ArcGim.cs" />
|
||||
<Compile Include="Psp\ArcQPK.cs" />
|
||||
<Compile Include="ScrPlayer\ImageIMG.cs" />
|
||||
<Compile Include="SingleFileArchive.cs" />
|
||||
@@ -1091,6 +1104,7 @@
|
||||
<Compile Include="KiriKiri\KiriKiriCx.cs" />
|
||||
<Compile Include="KogadoCocotte.cs" />
|
||||
<Compile Include="AudioOGG.cs" />
|
||||
<Compile Include="aPLibStream.cs" />
|
||||
<Compile Include="LzssStream.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
|
||||
120
ArcFormats/CatSystem/ArcZT.cs
Normal file
120
ArcFormats/CatSystem/ArcZT.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
//! \file ArcZT.cs
|
||||
//! \date 2021 May 25
|
||||
//! \brief CatSystem2 pack file.
|
||||
//
|
||||
// Copyright (C) 2021 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 GameRes.Compression;
|
||||
|
||||
namespace GameRes.Formats.CatSystem
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class ZtOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "ZT/PACK"; } }
|
||||
public override string Description { get { return "CatSystem2 pack file"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public ZtOpener ()
|
||||
{
|
||||
Extensions = new string[] { "zt" };
|
||||
}
|
||||
|
||||
struct ZtSubdirectory
|
||||
{
|
||||
public string Name;
|
||||
public long Offset;
|
||||
}
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
if (file.MaxOffset < 0x11C)
|
||||
return null;
|
||||
if (0x110 > file.View.ReadUInt32 (8) || 1 < file.View.ReadUInt32 (0xC))
|
||||
return null; // First entry is too small, or not a file or folder
|
||||
var dir = new List<Entry> ();
|
||||
var subdirs = new Queue<ZtSubdirectory> ();
|
||||
const string sep = "\\";
|
||||
string parent_name = "";
|
||||
long offset = 0;
|
||||
uint offset_next;
|
||||
do
|
||||
{
|
||||
offset_next = file.View.ReadUInt32 (offset);
|
||||
uint entry_size = file.View.ReadUInt32 (offset+8);
|
||||
if (0 != offset_next && 0xC + entry_size > offset_next)
|
||||
return null;
|
||||
uint attributes = file.View.ReadUInt32 (offset+0xC);
|
||||
string name = file.View.ReadString (offset+0x10, 0x104);
|
||||
if (1 < attributes || 0 == name.Length)
|
||||
return null;
|
||||
|
||||
if (0 == attributes)
|
||||
{
|
||||
var entry = FormatCatalog.Instance.Create<PackedEntry> (parent_name + name);
|
||||
uint packed_size = file.View.ReadUInt32 (offset+0x114);
|
||||
if (0x110 + packed_size != entry_size)
|
||||
return null;
|
||||
entry.Offset = offset + 0x11C;
|
||||
entry.Size = packed_size;
|
||||
entry.UnpackedSize = file.View.ReadUInt32 (offset+0x118);
|
||||
entry.IsPacked = true;
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
}
|
||||
else if (0 != file.View.ReadUInt32 (offset+4))
|
||||
{
|
||||
subdirs.Enqueue (new ZtSubdirectory { Name = parent_name + name + sep, Offset = offset });
|
||||
}
|
||||
|
||||
if (0 == offset_next && 0 != subdirs.Count)
|
||||
{ // No more entries in current directory, go to next subdirectory
|
||||
var subdir = subdirs.Dequeue ();
|
||||
parent_name = subdir.Name;
|
||||
offset = subdir.Offset;
|
||||
offset_next = file.View.ReadUInt32 (offset+4); // offset_child
|
||||
if (0xC + file.View.ReadUInt32 (offset+8) > offset_next)
|
||||
return null;
|
||||
}
|
||||
offset += offset_next;
|
||||
}
|
||||
while (0 != offset_next);
|
||||
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||
{
|
||||
var pentry = (PackedEntry)entry;
|
||||
if (0 == pentry.UnpackedSize)
|
||||
return Stream.Null;
|
||||
var input = arc.File.CreateStream (entry.Offset, entry.Size);
|
||||
return new ZLibStream (input, CompressionMode.Decompress);
|
||||
}
|
||||
}
|
||||
}
|
||||
87
ArcFormats/Edoire/ArcARC.cs
Normal file
87
ArcFormats/Edoire/ArcARC.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
//! \file ArcARC.cs
|
||||
//! \date 2026 Feb 02
|
||||
//! \brief Edoire's 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.Text;
|
||||
|
||||
namespace GameRes.Formats.Edoire
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class ArcOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "ARC"; } }
|
||||
public override string Description { get { return "Edoire's resource archive"; } }
|
||||
public override uint Signature { get { return 0x43524140; } } // "@ARCH000"
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public ArcOpener ()
|
||||
{
|
||||
Extensions = new string[] { "arc" };
|
||||
}
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
if (!file.View.AsciiEqual (0, "@ARCH000"))
|
||||
return null;
|
||||
var index_offset = file.View.ReadInt64 (file.MaxOffset-8);
|
||||
if (index_offset <= 0 || index_offset >= file.MaxOffset-12)
|
||||
return null;
|
||||
var count = file.View.ReadInt32 (index_offset);
|
||||
if (!IsSaneCount (count))
|
||||
return null;
|
||||
index_offset += 4;
|
||||
var dir = new List<Entry> (count);
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var len = file.View.ReadByte (index_offset);
|
||||
index_offset += 1;
|
||||
var name = file.View.ReadString (index_offset, len, Encoding.UTF8);
|
||||
index_offset += len;
|
||||
var offset = file.View.ReadInt64 (index_offset);
|
||||
index_offset += 8;
|
||||
var size = file.View.ReadInt64 (index_offset);
|
||||
index_offset += 9;
|
||||
len = file.View.ReadByte (index_offset);
|
||||
index_offset += 1;
|
||||
var path = file.View.ReadString (index_offset, len, Encoding.UTF8);
|
||||
index_offset += len;
|
||||
if (path.StartsWith ("/"))
|
||||
path = path.Substring (1);
|
||||
if (!string.IsNullOrEmpty (path) && !path.EndsWith ("/"))
|
||||
path += "/";
|
||||
var entry = Create<Entry> (path+name);
|
||||
entry.Offset = offset;
|
||||
entry.Size = Convert.ToUInt32 (size);
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GameRes.Utility;
|
||||
using GameRes.Compression;
|
||||
|
||||
namespace GameRes.Formats.Enigma {
|
||||
public enum NodeTypes {
|
||||
@@ -45,14 +46,34 @@ namespace GameRes.Formats.Enigma {
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public EvbPackOpener() {
|
||||
Signatures = new uint[] { 0x425645, 0x905a4d, 0 };
|
||||
Extensions = new[] { "exe" };
|
||||
}
|
||||
|
||||
public override ArcFile TryOpen(ArcView file) {
|
||||
uint index_size = file.View.ReadUInt32(0x40) + 68;
|
||||
uint index_offset = 0x4F;
|
||||
uint base_offset = 0;
|
||||
if (file.View.AsciiEqual(0, "MZ")) {
|
||||
var exe = new ExeFile(file);
|
||||
var sig = new byte[] { 0x45, 0x56, 0x42, 0x00 };
|
||||
if (exe.ContainsSection(".enigma1")) {
|
||||
var ofs = exe.FindString(exe.Sections[".enigma1"], sig);
|
||||
if (ofs != -1)
|
||||
base_offset = (uint)ofs;
|
||||
}
|
||||
if (base_offset == 0)
|
||||
return null;
|
||||
}
|
||||
else if (!file.View.AsciiEqual(0, "EVB"))
|
||||
return null;
|
||||
|
||||
uint index_size = file.View.ReadUInt32(base_offset + 0x40) + base_offset + 68;
|
||||
uint index_offset = base_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 counts = new List<uint> { file.View.ReadUInt32(base_offset + 0x4C) };
|
||||
var names = new List<string> { "" };
|
||||
|
||||
while (index_offset < index_size - 4) {
|
||||
@@ -73,12 +94,12 @@ namespace GameRes.Formats.Enigma {
|
||||
index_offset++;
|
||||
counts[counts.Count - 1]--;
|
||||
if (type == NodeTypes.File) {
|
||||
var entry = Create<Entry>(Path.Combine(names.Concat(new[] { name }).ToArray()));
|
||||
var entry = Create<PackedEntry>(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.IsPacked = unpacked_size != size;
|
||||
entry.Offset = file_offset;
|
||||
entry.UnpackedSize = unpacked_size;
|
||||
entry.Size = size;
|
||||
file_offset += size;
|
||||
if (!entry.CheckPlacement(file.MaxOffset))
|
||||
@@ -106,5 +127,30 @@ namespace GameRes.Formats.Enigma {
|
||||
|
||||
return new ArcFile(file, this, dir);
|
||||
}
|
||||
|
||||
public override Stream OpenEntry(ArcFile arc, Entry entry) {
|
||||
var pent = entry as PackedEntry;
|
||||
if (pent.IsPacked) {
|
||||
uint header_size = arc.File.View.ReadUInt32(pent.Offset);
|
||||
uint offset = header_size;
|
||||
Stream input = null;
|
||||
|
||||
for (uint i = 8; i < header_size; i += 12) {
|
||||
uint chunk_size = arc.File.View.ReadUInt32(pent.Offset + i);
|
||||
var chunk = new aPLibStream(
|
||||
arc.File.CreateStream(pent.Offset + offset, chunk_size)
|
||||
);
|
||||
if (input != null)
|
||||
input = new ConcatStream(input, chunk);
|
||||
else
|
||||
input = chunk;
|
||||
offset += chunk_size;
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
else
|
||||
return arc.File.CreateStream(pent.Offset, pent.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,12 @@ namespace GameRes.Formats.FVP
|
||||
if (null == image_info)
|
||||
return null;
|
||||
}
|
||||
// This is a atlas image, all clips are placed into a single TLG image
|
||||
if (file.View.AsciiEqual (0x2C, "TLG"))
|
||||
return null;
|
||||
// This is a diff image
|
||||
if (0x64 == file.View.ReadByte (0x2C))
|
||||
return null;
|
||||
int count = file.View.ReadInt32 (0x20);
|
||||
if (0 == count)
|
||||
count = 1;
|
||||
|
||||
@@ -28,6 +28,8 @@ using GameRes.Utility;
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
@@ -66,14 +68,112 @@ namespace GameRes.Formats.FVP
|
||||
};
|
||||
}
|
||||
|
||||
private static ImageFormat s_TlgFormat = null;
|
||||
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
stream.Position = 0x2C;
|
||||
PixelFormat format = PixelFormats.Bgra32;
|
||||
WriteableBitmap bitmap = null;
|
||||
if (0x64 == stream.PeekByte ())
|
||||
{
|
||||
// This is a diff image, try to read base image
|
||||
stream.Position += 1;
|
||||
var name = stream.ReadCString (Encoding.UTF8);
|
||||
if (!string.IsNullOrEmpty (name))
|
||||
{
|
||||
var entry = VFS.FindFile (Path.ChangeExtension (name, "hzc"));
|
||||
if (null != entry)
|
||||
{
|
||||
var decoder = VFS.OpenImage (entry);
|
||||
var image = decoder.Image;
|
||||
decoder.Dispose();
|
||||
if (null == image)
|
||||
throw new InvalidFormatException ("Failed to decode base image.");
|
||||
var converted = image.Bitmap;
|
||||
if (converted.Format != format)
|
||||
converted = new FormatConvertedBitmap (converted, format, null, 0);
|
||||
var stride = converted.PixelWidth * 4;
|
||||
var size = stride * converted.PixelHeight;
|
||||
var pixels = new byte[size];
|
||||
converted.CopyPixels (pixels, stride, 0);
|
||||
bitmap = new WriteableBitmap (converted.PixelWidth, converted.PixelHeight,
|
||||
ImageData.DefaultDpiX, ImageData.DefaultDpiY, format, null);
|
||||
var rect = new Int32Rect (0, 0, converted.PixelWidth, converted.PixelHeight);
|
||||
bitmap.WritePixels (rect, pixels, stride, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stream.ReadBytes (3).AsciiEqual ("TLG"))
|
||||
{
|
||||
// Read the TLG image
|
||||
var tlg_stream = new BinaryStream (new StreamRegion (stream.AsStream, stream.Position-3, true), stream.Name);
|
||||
if (null == s_TlgFormat)
|
||||
s_TlgFormat = FindByTag ("TLG");
|
||||
var tlg_info = s_TlgFormat.ReadMetaData (tlg_stream);
|
||||
var image = s_TlgFormat.Read (tlg_stream, tlg_info);
|
||||
// No base image
|
||||
if (null == bitmap)
|
||||
return image;
|
||||
// Size should be the same as the base image
|
||||
if (image.Width != bitmap.PixelWidth || image.Height != bitmap.PixelHeight)
|
||||
return image;
|
||||
// Blend two images
|
||||
var converted = image.Bitmap;
|
||||
if (converted.Format != format)
|
||||
converted = new FormatConvertedBitmap (converted, format, null, 0);
|
||||
var rect = new Int32Rect (0, 0, converted.PixelWidth, converted.PixelHeight);
|
||||
BlendBitmap (converted, rect, bitmap, 0, 0);
|
||||
bitmap.Freeze ();
|
||||
return new ImageData (bitmap, tlg_info);
|
||||
}
|
||||
var meta = (HzcMetaData)info;
|
||||
stream.Position = 12 + meta.HeaderSize;
|
||||
using (var decoder = new HzcDecoder (stream, meta, true))
|
||||
return decoder.Image;
|
||||
}
|
||||
|
||||
void BlendBitmap (BitmapSource bitmap, Int32Rect source, WriteableBitmap output, int x, int y)
|
||||
{
|
||||
int src_stride = source.Width * 4;
|
||||
var pixels = new byte[src_stride * source.Height];
|
||||
bitmap.CopyPixels (source, pixels, src_stride, 0);
|
||||
unsafe
|
||||
{
|
||||
int dst_stride = output.BackBufferStride;
|
||||
int offset = y * dst_stride + x * 4;
|
||||
byte* buffer = (byte*)(output.BackBuffer + offset);
|
||||
int src = 0;
|
||||
for (int h = 0; h < source.Height; ++h)
|
||||
{
|
||||
int dst = 0;
|
||||
for (int w = 0; w < source.Width; ++w)
|
||||
{
|
||||
byte src_alpha = pixels[src+3];
|
||||
if (src_alpha > 0)
|
||||
{
|
||||
if (0xFF == src_alpha || 0 == buffer[dst+3])
|
||||
{
|
||||
buffer[dst ] = pixels[src];
|
||||
buffer[dst+1] = pixels[src+1];
|
||||
buffer[dst+2] = pixels[src+2];
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[dst+0] = (byte)((pixels[src+0] * src_alpha + buffer[dst+0] * (0xFF - src_alpha)) / 0xFF);
|
||||
buffer[dst+1] = (byte)((pixels[src+1] * src_alpha + buffer[dst+1] * (0xFF - src_alpha)) / 0xFF);
|
||||
buffer[dst+2] = (byte)((pixels[src+2] * src_alpha + buffer[dst+2] * (0xFF - src_alpha)) / 0xFF);
|
||||
}
|
||||
buffer[dst+3] = src_alpha;
|
||||
}
|
||||
dst += 4;
|
||||
src += 4;
|
||||
}
|
||||
buffer += dst_stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new System.NotImplementedException ("HzcFormat.Write not implemented");
|
||||
|
||||
93
ArcFormats/Fog/ArcDAT.cs
Normal file
93
ArcFormats/Fog/ArcDAT.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
//! \file ArcDAT.cs
|
||||
//! \date 2026-01-24
|
||||
//! \brief FOG resource archive format.
|
||||
//
|
||||
// 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 GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Fog {
|
||||
internal class DatEntry : Entry {
|
||||
public string FileName;
|
||||
}
|
||||
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class DatOpener : ArchiveFormat {
|
||||
public override string Tag { get { return "DAT/FOG"; } }
|
||||
public override string Description { get { return "FOG resource archive"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public override ArcFile TryOpen(ArcView file) {
|
||||
var base_name = Path.GetFileNameWithoutExtension(file.Name);
|
||||
bool multipart = base_name.Contains("_");
|
||||
if (multipart)
|
||||
base_name = base_name.Split('_')[0];
|
||||
var index_file_name = base_name + "File.dat";
|
||||
if (!File.Exists(index_file_name))
|
||||
return null;
|
||||
|
||||
var index = File.ReadAllBytes(index_file_name);
|
||||
var transformer = new NotTransform();
|
||||
transformer.TransformBlock(index, 0, index.Length, index, 0);
|
||||
|
||||
using (var mem = new MemoryStream(index))
|
||||
using (var reader = new BinaryReader(mem)) {
|
||||
var dir = new List<Entry>();
|
||||
|
||||
while (mem.Position < mem.Length) {
|
||||
uint name_length = Binary.BigEndian(reader.ReadUInt32());
|
||||
string name = Binary.GetCString(reader.ReadBytes((int)name_length), 0);
|
||||
var entry = Create<DatEntry>(name);
|
||||
if (multipart) {
|
||||
uint part = Binary.BigEndian(reader.ReadUInt32());
|
||||
entry.FileName = string.Format("{0}_{1:00}.dat", base_name, part);
|
||||
if (!File.Exists(entry.FileName))
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
entry.FileName = file.Name;
|
||||
}
|
||||
reader.ReadUInt32();
|
||||
entry.Offset = Binary.BigEndian(reader.ReadUInt32());
|
||||
reader.ReadUInt32();
|
||||
entry.Size = Binary.BigEndian(reader.ReadUInt32());
|
||||
dir.Add(entry);
|
||||
}
|
||||
|
||||
return new ArcFile(file, this, dir);
|
||||
}
|
||||
}
|
||||
|
||||
public override Stream OpenEntry(ArcFile arc, Entry entry) {
|
||||
var dent = entry as DatEntry;
|
||||
using (var data_file = new ArcView(dent.FileName)) {
|
||||
var input = data_file.CreateStream(dent.Offset, dent.Size);
|
||||
return new XoredStream(input, 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
117
ArcFormats/FrontierWorks/ArcPCARC.cs
Normal file
117
ArcFormats/FrontierWorks/ArcPCARC.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
//! \file ArcPCARC.cs
|
||||
//! \date Tue Feb 10 2026 07:56:13
|
||||
//! \brief Frontier Works engine resource archive.
|
||||
//
|
||||
// Copyright (C) 2015 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 System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GameRes.Formats.FrontierWorks
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class PcArcOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "PCARC"; } }
|
||||
public override string Description { get { return "Frontier Works engine resource archive"; } }
|
||||
public override uint Signature { get { return 0x30303130; } } // "0100"
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public PcArcOpener()
|
||||
{
|
||||
Extensions = new string[] { "pcarc" };
|
||||
}
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
if (!file.View.AsciiEqual (0, "0100"))
|
||||
return null;
|
||||
var dir_count = file.View.ReadInt32 (4);
|
||||
if (dir_count <= 0 || dir_count > 32)
|
||||
return null;
|
||||
var data_offset = file.View.ReadInt64 (8);
|
||||
if (data_offset < 0x190)
|
||||
return null;
|
||||
var offset = 0x10;
|
||||
var dir = new List<Entry> ();
|
||||
for (var i = 0; i < dir_count; i++)
|
||||
{
|
||||
var dir_offset = file.View.ReadInt64 (offset);
|
||||
offset += 8;
|
||||
if (dir_offset < 0x190)
|
||||
break;
|
||||
var path = file.View.ReadString (dir_offset, 0x40);
|
||||
var entry_count = file.View.ReadInt32 (dir_offset+0x40);
|
||||
dir_offset += 0x50;
|
||||
if (!string.IsNullOrEmpty (path) && !path.EndsWith ("/"))
|
||||
path += "/";
|
||||
for (var j = 0; j < entry_count; j++)
|
||||
{
|
||||
var entry = new Entry ();
|
||||
entry.Name = path+file.View.ReadString (dir_offset, 0x40);
|
||||
entry.Offset = data_offset+file.View.ReadInt64 (dir_offset+0x40);
|
||||
entry.Size = file.View.ReadUInt32 (dir_offset+0x48);
|
||||
dir.Add (entry);
|
||||
dir_offset += 0x50;
|
||||
}
|
||||
}
|
||||
DetectFileTypes (dir);
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||
{
|
||||
if (entry.Name.HasExtension (".gz"))
|
||||
{
|
||||
using (var input = arc.File.CreateStream (entry.Offset, entry.Size))
|
||||
using (var gzs = new GZipStream (input, CompressionMode.Decompress))
|
||||
{
|
||||
var output = new MemoryStream ();
|
||||
gzs.CopyTo (output);
|
||||
return new BinMemoryStream (output, entry.Name.Substring (0, entry.Name.Length-3));
|
||||
}
|
||||
}
|
||||
return base.OpenEntry (arc, entry);
|
||||
}
|
||||
|
||||
static void DetectFileTypes (List<Entry> dir)
|
||||
{
|
||||
foreach (var entry in dir)
|
||||
{
|
||||
var name = entry.Name;
|
||||
if (name.HasExtension (".gz"))
|
||||
name = name.Substring (0, name.Length-3);
|
||||
if (name.HasExtension (".oggl"))
|
||||
entry.Type = "audio";
|
||||
if (string.IsNullOrEmpty (entry.Type))
|
||||
entry.Type = FormatCatalog.Instance.GetTypeFromName (name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
82
ArcFormats/FrontierWorks/ImageEXT.cs
Normal file
82
ArcFormats/FrontierWorks/ImageEXT.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
//! \file ImageEXT.cs
|
||||
//! \date Tue Feb 10 2026 08:21:40
|
||||
//! \brief Frontier Works engine image format.
|
||||
//
|
||||
// Copyright (C) 2015 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 System.Windows.Media;
|
||||
|
||||
namespace GameRes.Formats.FrontierWorks
|
||||
{
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class ExtFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "EXT"; } }
|
||||
public override string Description { get { return "Frontier Works engine image format"; } }
|
||||
public override uint Signature { get { return 0x30545845; } } // 'EXT0'
|
||||
|
||||
public ExtFormat ()
|
||||
{
|
||||
Extensions = new string[] { "ext" };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream stream)
|
||||
{
|
||||
stream.Position = 0;
|
||||
var signature = stream.ReadInt32 ();
|
||||
if (0x30545845 != signature)
|
||||
return null;
|
||||
stream.Position = 0xC;
|
||||
var width = stream.ReadUInt32 ();
|
||||
var height = stream.ReadUInt32 ();
|
||||
if (width > 0x1000 || height > 0x1000)
|
||||
return null;
|
||||
stream.Position = 0x24;
|
||||
var bpp = stream.ReadByte ();
|
||||
if (32 != bpp)
|
||||
return null;
|
||||
return new ImageMetaData
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
BPP = bpp,
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||
{
|
||||
stream.Position = 0x100;
|
||||
var pixels = new byte[info.Width*info.Height*4];
|
||||
if (pixels.Length != stream.Read (pixels, 0, pixels.Length))
|
||||
throw new EndOfStreamException ();
|
||||
return ImageData.Create (info, PixelFormats.Bgra32, null, pixels);
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new NotImplementedException ("ExtFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
93
ArcFormats/Guyzware/ArcDat.cs
Normal file
93
ArcFormats/Guyzware/ArcDat.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Guyzware
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class GdpOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag => "DAT/GDP";
|
||||
public override string Description => "Guyzware engine";
|
||||
public override uint Signature => 0;
|
||||
public override bool IsHierarchic => false;
|
||||
public override bool CanWrite => false;
|
||||
|
||||
public override ArcFile TryOpen(ArcView file)
|
||||
{
|
||||
int count = file.View.ReadInt32(0);
|
||||
if (!IsSaneCount(count))
|
||||
return null;
|
||||
|
||||
var dir = new List<Entry>(count);
|
||||
long index_offset = 4;
|
||||
|
||||
// heuristic: small first byte = variable
|
||||
byte checkByte = file.View.ReadByte(index_offset);
|
||||
bool isVariableLength = checkByte < 64;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (index_offset >= file.MaxOffset)
|
||||
break;
|
||||
|
||||
string name;
|
||||
uint offset, size;
|
||||
|
||||
if (isVariableLength)
|
||||
{
|
||||
// Variable length:
|
||||
// [1 byte length (ignored)] [Shift-JIS string] [00]
|
||||
|
||||
index_offset++; // skip length byte
|
||||
|
||||
var nameBytes = new List<byte>();
|
||||
|
||||
while (index_offset < file.MaxOffset)
|
||||
{
|
||||
byte b = file.View.ReadByte(index_offset++);
|
||||
if (b == 0)
|
||||
break;
|
||||
|
||||
nameBytes.Add(b);
|
||||
}
|
||||
|
||||
name = Encodings.cp932.GetString(nameBytes.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fixed 32 bytes
|
||||
|
||||
name = file.View.ReadString(index_offset, 32, Encodings.cp932);
|
||||
name = name.TrimEnd('\0', ' ');
|
||||
index_offset += 32;
|
||||
}
|
||||
|
||||
offset = file.View.ReadUInt32(index_offset);
|
||||
size = file.View.ReadUInt32(index_offset + 4);
|
||||
index_offset += 8;
|
||||
|
||||
var entry = new Entry
|
||||
{
|
||||
Name = name,
|
||||
Offset = offset,
|
||||
Size = size,
|
||||
};
|
||||
|
||||
if (!entry.CheckPlacement(file.MaxOffset))
|
||||
return null;
|
||||
|
||||
dir.Add(entry);
|
||||
}
|
||||
|
||||
return new ArcFile(file, this, dir);
|
||||
}
|
||||
|
||||
public override Stream OpenEntry(ArcFile arc, Entry entry)
|
||||
{
|
||||
return arc.File.CreateStream(entry.Offset, entry.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,14 @@
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
using GameRes.Utility.Serialization;
|
||||
|
||||
namespace GameRes.Formats.Leaf
|
||||
@@ -38,7 +42,7 @@ namespace GameRes.Formats.Leaf
|
||||
public override string Description { get { return "Leaf resource archive"; } }
|
||||
public override uint Signature { get { return 0x5041434B; } } // 'KCAP'
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
public override bool CanWrite { get { return true; } }
|
||||
|
||||
public KcapOpener ()
|
||||
{
|
||||
@@ -160,6 +164,87 @@ namespace GameRes.Formats.Leaf
|
||||
input.Position = 0;
|
||||
return ImageFormatDecoder.Create (input);
|
||||
}
|
||||
|
||||
// --- REPACK IMPLEMENTATION ---
|
||||
|
||||
public override void Create (Stream output, IEnumerable<Entry> entries, ResourceOptions options, EntryCallback callback)
|
||||
{
|
||||
int count = entries.Count();
|
||||
using (var writer = new BinaryWriter (output, Encoding.ASCII, true))
|
||||
{
|
||||
// 1. Write Header (KCAP v2)
|
||||
writer.Write (0x5041434B); // "KCAP"
|
||||
writer.Write (0xFFFFFFFF);
|
||||
writer.Write (0x0000FFFF);
|
||||
writer.Write (count);
|
||||
|
||||
long tableOffset = 16;
|
||||
long dataOffset = tableOffset + (count * 44);
|
||||
|
||||
writer.BaseStream.Position = dataOffset;
|
||||
|
||||
var entryInfos = new List<EntryInfo>();
|
||||
int i = 0;
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
if (callback != null)
|
||||
callback (i + 1, entry, null);
|
||||
|
||||
long currentOffset = writer.BaseStream.Position;
|
||||
|
||||
using (var input = File.OpenRead(entry.Name))
|
||||
{
|
||||
byte[] rawData = new byte[input.Length];
|
||||
input.Read (rawData, 0, (int)input.Length);
|
||||
|
||||
// Compress
|
||||
byte[] compressedData = LeafLzss.Compress (rawData);
|
||||
|
||||
// Write Data (Prefix + LZSS)
|
||||
writer.Write ((uint)compressedData.Length);
|
||||
writer.Write ((uint)rawData.Length);
|
||||
writer.Write (compressedData);
|
||||
|
||||
uint totalSize = (uint)(compressedData.Length + 8);
|
||||
|
||||
entryInfos.Add (new EntryInfo
|
||||
{
|
||||
Name = Path.GetFileName (entry.Name),
|
||||
UnpackedSize = (uint)rawData.Length,
|
||||
Offset = (uint)currentOffset,
|
||||
PackedSize = totalSize
|
||||
});
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
// Write File Table
|
||||
writer.BaseStream.Position = tableOffset;
|
||||
foreach (var info in entryInfos)
|
||||
{
|
||||
writer.Write (1); // Type
|
||||
|
||||
byte[] nameBytes = Encodings.cp932.GetBytes (info.Name);
|
||||
if (nameBytes.Length > 23) Array.Resize (ref nameBytes, 23);
|
||||
writer.Write (nameBytes);
|
||||
for (int k = nameBytes.Length; k < 24; k++) writer.Write ((byte)0);
|
||||
|
||||
writer.Write (0xFFFFFFFF); // CRC
|
||||
writer.Write (info.UnpackedSize);
|
||||
writer.Write (info.Offset);
|
||||
writer.Write (info.PackedSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct EntryInfo
|
||||
{
|
||||
public string Name;
|
||||
public uint UnpackedSize;
|
||||
public uint Offset;
|
||||
public uint PackedSize;
|
||||
}
|
||||
}
|
||||
|
||||
[Export(typeof(ScriptFormat))]
|
||||
@@ -228,4 +313,168 @@ namespace GameRes.Formats.Leaf
|
||||
public bool IsPacked { get { return _is_packed != 0; } }
|
||||
}
|
||||
#pragma warning restore 649,169
|
||||
}
|
||||
|
||||
// --- LEAF LZSS COMPRESSION ---
|
||||
internal static class LeafLzss
|
||||
{
|
||||
const int N = 4096;
|
||||
const int F = 18;
|
||||
const int THR = 2;
|
||||
const int NIL = N;
|
||||
|
||||
public static byte[] Compress (byte[] input)
|
||||
{
|
||||
if (input.Length == 0) return new byte[0];
|
||||
|
||||
using (var outStream = new MemoryStream (input.Length))
|
||||
{
|
||||
// Arrays size = N + 257 to handle Root Nodes (N+1..N+256) safely
|
||||
int[] lson = new int[N + 257];
|
||||
int[] rson = new int[N + 257];
|
||||
int[] dad = new int[N + 257];
|
||||
byte[] text_buf = new byte[N + F - 1];
|
||||
|
||||
for (int j = N + 1; j <= N + 256; j++) rson[j] = NIL;
|
||||
for (int j = 0; j < N; j++) dad[j] = NIL;
|
||||
|
||||
int match_position = 0, match_length = 0;
|
||||
|
||||
void InsertNode (int r_node)
|
||||
{
|
||||
int i, p, cmp;
|
||||
int key_pos = r_node;
|
||||
|
||||
// Root for this character
|
||||
p = N + 1 + text_buf[key_pos];
|
||||
|
||||
rson[r_node] = lson[r_node] = NIL;
|
||||
match_length = 0;
|
||||
|
||||
cmp = 1; // Initial state
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
if (cmp >= 0)
|
||||
{
|
||||
if (rson[p] != NIL) p = rson[p];
|
||||
else { rson[p] = r_node; dad[r_node] = p; return; }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lson[p] != NIL) p = lson[p];
|
||||
else { lson[p] = r_node; dad[r_node] = p; return; }
|
||||
}
|
||||
|
||||
// Compare bytes only after finding a valid child node 'p' (buffer index)
|
||||
for (i = 1; i < F; i++)
|
||||
if ((cmp = text_buf[key_pos + i] - text_buf[p + i]) != 0) break;
|
||||
|
||||
if (i > match_length)
|
||||
{
|
||||
match_position = p;
|
||||
match_length = i;
|
||||
if (match_length >= F) break;
|
||||
}
|
||||
}
|
||||
|
||||
// Replace node logic
|
||||
dad[r_node] = dad[p]; lson[r_node] = lson[p]; rson[r_node] = rson[p];
|
||||
dad[lson[p]] = r_node; dad[rson[p]] = r_node;
|
||||
if (rson[dad[p]] == p) rson[dad[p]] = r_node;
|
||||
else lson[dad[p]] = r_node;
|
||||
dad[p] = NIL;
|
||||
}
|
||||
|
||||
void DeleteNode (int p)
|
||||
{
|
||||
int q;
|
||||
if (dad[p] == NIL) return;
|
||||
if (rson[p] == NIL) q = lson[p];
|
||||
else if (lson[p] == NIL) q = rson[p];
|
||||
else
|
||||
{
|
||||
q = lson[p];
|
||||
if (rson[q] != NIL)
|
||||
{
|
||||
do { q = rson[q]; } while (rson[q] != NIL);
|
||||
rson[dad[q]] = lson[q]; dad[lson[q]] = dad[q];
|
||||
lson[q] = lson[p]; dad[lson[p]] = q;
|
||||
}
|
||||
rson[q] = rson[p]; dad[rson[p]] = q;
|
||||
}
|
||||
dad[q] = dad[p];
|
||||
if (rson[dad[p]] == p) rson[dad[p]] = q;
|
||||
else lson[dad[p]] = q;
|
||||
dad[p] = NIL;
|
||||
}
|
||||
|
||||
int code_buf_ptr = 1;
|
||||
byte[] code_buf = new byte[17];
|
||||
byte mask = 1;
|
||||
int s = 0, r = N - F;
|
||||
int len = 0;
|
||||
|
||||
for (int j = 0; j < r; j++) text_buf[j] = 0x20;
|
||||
|
||||
int bytes_read = 0;
|
||||
for (len = 0; len < F && bytes_read < input.Length; len++)
|
||||
text_buf[r + len] = input[bytes_read++];
|
||||
|
||||
if (len == 0) return new byte[0];
|
||||
|
||||
for (int j = 1; j <= F; j++) InsertNode (r - j);
|
||||
InsertNode (r);
|
||||
|
||||
do
|
||||
{
|
||||
if (match_length > len) match_length = len;
|
||||
if (match_length <= THR)
|
||||
{
|
||||
match_length = 1;
|
||||
code_buf[0] |= mask;
|
||||
code_buf[code_buf_ptr++] = text_buf[r];
|
||||
}
|
||||
else
|
||||
{
|
||||
code_buf[code_buf_ptr++] = (byte)(match_position & 0xFF);
|
||||
code_buf[code_buf_ptr++] = (byte)(((match_position >> 4) & 0xF0) | (match_length - (THR + 1)));
|
||||
}
|
||||
|
||||
if ((mask <<= 1) == 0)
|
||||
{
|
||||
outStream.Write (code_buf, 0, code_buf_ptr);
|
||||
code_buf[0] = 0; code_buf_ptr = 1; mask = 1;
|
||||
}
|
||||
|
||||
int last_match_length = match_length;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < last_match_length && bytes_read < input.Length; i++)
|
||||
{
|
||||
DeleteNode (s);
|
||||
byte c = input[bytes_read++];
|
||||
text_buf[s] = c;
|
||||
if (s < F - 1) text_buf[s + N] = c;
|
||||
s = (s + 1) & (N - 1);
|
||||
r = (r + 1) & (N - 1);
|
||||
InsertNode (r);
|
||||
}
|
||||
|
||||
while (bytes_read == input.Length && i++ < last_match_length)
|
||||
{
|
||||
DeleteNode (s);
|
||||
s = (s + 1) & (N - 1);
|
||||
r = (r + 1) & (N - 1);
|
||||
if (--len != 0) InsertNode (r);
|
||||
}
|
||||
|
||||
} while (len > 0);
|
||||
|
||||
if (code_buf_ptr > 1)
|
||||
outStream.Write (code_buf, 0, code_buf_ptr);
|
||||
|
||||
return outStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
68
ArcFormats/Leaf/LeafVideo.cs
Normal file
68
ArcFormats/Leaf/LeafVideo.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Leaf
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class VideoOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "VIDEO/LEAF"; } }
|
||||
public override string Description { get { return "Leaf/Aquaplus Video Container"; } }
|
||||
public override uint Signature { get { return 0; } } // Dynamic verification
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public override ArcFile TryOpen(ArcView file)
|
||||
{
|
||||
// Read the first 16 bytes to check the signature
|
||||
if (file.MaxOffset < 16)
|
||||
return null;
|
||||
|
||||
string ext = null;
|
||||
uint head = file.View.ReadUInt32(0);
|
||||
|
||||
// 1. Check if it is WMV/ASF (Leaf standard)
|
||||
// GUID: 30 26 B2 75 8E 66 CF 11 ...
|
||||
// In Little Endian UInt64: 0x11CF668E75B22630
|
||||
if (head == 0x75B22630)
|
||||
{
|
||||
ulong asfGuid = file.View.ReadUInt64(0);
|
||||
if (asfGuid == 0x11CF668E75B22630)
|
||||
{
|
||||
ext = ".wmv";
|
||||
}
|
||||
}
|
||||
// 2. Check if it is AVI (RIFF ... AVI )
|
||||
else if (head == 0x46464952) // "RIFF"
|
||||
{
|
||||
// Check if the type at offset 8 is "AVI "
|
||||
if (file.View.ReadUInt32(8) == 0x20495641)
|
||||
{
|
||||
ext = ".avi";
|
||||
}
|
||||
}
|
||||
// 3. Check if it is MPEG (Reusing logic, in case an old game uses it)
|
||||
else if (head == 0xBA010000)
|
||||
{
|
||||
ext = ".mpg";
|
||||
}
|
||||
|
||||
if (ext == null)
|
||||
return null;
|
||||
|
||||
// Create the virtual entry with the correct extension
|
||||
var entry = new Entry
|
||||
{
|
||||
Name = Path.GetFileNameWithoutExtension(file.Name) + ext,
|
||||
Type = "video",
|
||||
Offset = 0,
|
||||
Size = (uint)file.MaxOffset
|
||||
};
|
||||
|
||||
return new ArcFile(file, this, new List<Entry> { entry });
|
||||
}
|
||||
}
|
||||
}
|
||||
99
ArcFormats/NEKOWORKs/ArcPACK.cs
Normal file
99
ArcFormats/NEKOWORKs/ArcPACK.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
//! \file ArcPACK.cs
|
||||
//! \date 2026 Feb 01
|
||||
//! \brief NEKO WORKs Unity PACK 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;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using GameRes.Formats;
|
||||
|
||||
namespace GameRes.Formats.NEKOWORKs
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class NekoWorksPackOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "PACK/EXFS"; } }
|
||||
public override string Description { get { return "NEKO WORKs resource archive"; } }
|
||||
public override uint Signature { get { return 0x53465845; } } // 'EXFS'
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public override ArcFile TryOpen(ArcView file)
|
||||
{
|
||||
if (!file.View.AsciiEqual(0, "EXFS"))
|
||||
return null;
|
||||
|
||||
int fileCount = file.View.ReadInt32(0x0C);
|
||||
uint infoOffset = file.View.ReadUInt32(0x10);
|
||||
uint infoSize = file.View.ReadUInt32(0x18);
|
||||
uint nameBlockSize = file.View.ReadUInt32(0x20);
|
||||
uint baseDataOffset = file.View.ReadUInt32(0x28);
|
||||
|
||||
if (!IsSaneCount(fileCount))
|
||||
return null;
|
||||
|
||||
long namesOffset = infoOffset + infoSize;
|
||||
if (namesOffset + nameBlockSize > file.MaxOffset)
|
||||
return null;
|
||||
|
||||
byte[] nameData = file.View.ReadBytes(namesOffset, nameBlockSize);
|
||||
var nameList = new List<string>(fileCount);
|
||||
int start = 0;
|
||||
for (int i = 0; i < nameData.Length; ++i)
|
||||
{
|
||||
if (nameData[i] == (byte)'\n')
|
||||
{
|
||||
if (i > start)
|
||||
nameList.Add(System.Text.Encoding.UTF8.GetString(nameData, start, i - start));
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (nameList.Count < fileCount)
|
||||
return null;
|
||||
|
||||
var dir = new List<Entry>(fileCount);
|
||||
long indexOffset = infoOffset;
|
||||
|
||||
for (int i = 0; i < fileCount; ++i)
|
||||
{
|
||||
long entryPos = indexOffset + i * 0x20;
|
||||
|
||||
uint dataOffset = file.View.ReadUInt32(entryPos + 0x10);
|
||||
uint dataSize = file.View.ReadUInt32(entryPos + 0x18);
|
||||
|
||||
var entry = Create<Entry>(nameList[i]);
|
||||
entry.Offset = baseDataOffset + dataOffset;
|
||||
entry.Size = dataSize;
|
||||
|
||||
if (!entry.CheckPlacement(file.MaxOffset))
|
||||
return null;
|
||||
|
||||
dir.Add(entry);
|
||||
}
|
||||
|
||||
return new ArcFile(file, this, dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
374
ArcFormats/Psp/ArcGim.cs
Normal file
374
ArcFormats/Psp/ArcGim.cs
Normal file
@@ -0,0 +1,374 @@
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Psp
|
||||
{
|
||||
internal class GimMetaData : ImageMetaData
|
||||
{
|
||||
public int ImageInfoOffset;
|
||||
public int PaletteInfoOffset;
|
||||
public int PaletteBlockEnd;
|
||||
public bool IsLittleEndian;
|
||||
public int Format;
|
||||
public int Order; // 0=Linear, 1=Swizzled
|
||||
public int ImgDataRelOffset;
|
||||
public int PalDataRelOffset;
|
||||
public int BufferWidth; // Aligned width
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class GimFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "GIM"; } }
|
||||
public override string Description { get { return "Sony GIM Image"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
|
||||
public override ImageMetaData ReadMetaData(IBinaryStream file)
|
||||
{
|
||||
var header = file.ReadBytes(16);
|
||||
if (header.Length < 16) return null;
|
||||
|
||||
// Header check for Endianness detection
|
||||
bool littleEndian = true;
|
||||
if (header[0] == 'M' && header[1] == 'I' && header[2] == 'G') littleEndian = true;
|
||||
else if (header[0] == 'G' && header[1] == 'I' && header[2] == 'M') littleEndian = false;
|
||||
else return null;
|
||||
|
||||
// Read the entire stream into an array to facilitate navigation
|
||||
// GIMs are small, so this is safe and fast.
|
||||
byte[] data = new byte[file.Length];
|
||||
file.Position = 0;
|
||||
file.Read(data, 0, (int)file.Length);
|
||||
|
||||
int imageInfoOffset = -1;
|
||||
int paletteInfoOffset = -1;
|
||||
int paletteBlockEnd = -1;
|
||||
int offset = 0x10;
|
||||
int loop = 0;
|
||||
|
||||
// Block scanning loop (Verviewer style)
|
||||
while (offset + 0x10 <= data.Length && loop < 128)
|
||||
{
|
||||
ushort id = ReadUInt16(data, offset, littleEndian);
|
||||
// 0x02=EndFile, 0x03=EndImage (Skip), 0x04=Image, 0x05=Palette, 0xFF=FileInfo
|
||||
if (id == 0xFF) break;
|
||||
|
||||
uint size = ReadUInt32(data, offset + 4, littleEndian);
|
||||
uint next = ReadUInt32(data, offset + 8, littleEndian);
|
||||
uint headerSize = ReadUInt32(data, offset + 0xC, littleEndian);
|
||||
|
||||
if (size < headerSize || headerSize == 0) break; // Invalid data
|
||||
|
||||
// "Next" logic: If 0, usually the next block is sequential (size)
|
||||
int nextOffset = (next != 0) ? (int)next : (int)size;
|
||||
|
||||
int blockStart = offset;
|
||||
int blockEnd = blockStart + (int)size;
|
||||
int subHeader = blockStart + (int)headerSize;
|
||||
|
||||
if (blockEnd > data.Length) break;
|
||||
|
||||
if (id == 4) // Image Section
|
||||
{
|
||||
if (imageInfoOffset < 0) imageInfoOffset = subHeader;
|
||||
}
|
||||
else if (id == 5) // Palette Section
|
||||
{
|
||||
if (paletteInfoOffset < 0)
|
||||
{
|
||||
paletteInfoOffset = subHeader;
|
||||
paletteBlockEnd = blockEnd;
|
||||
}
|
||||
}
|
||||
|
||||
offset = blockStart + nextOffset;
|
||||
loop++;
|
||||
}
|
||||
|
||||
if (imageInfoOffset < 0) return null;
|
||||
|
||||
ushort imgFormat = ReadUInt16(data, imageInfoOffset + 4, littleEndian);
|
||||
ushort pixelOrder = ReadUInt16(data, imageInfoOffset + 6, littleEndian);
|
||||
ushort width = ReadUInt16(data, imageInfoOffset + 8, littleEndian);
|
||||
ushort height = ReadUInt16(data, imageInfoOffset + 0xA, littleEndian);
|
||||
ushort bpp = ReadUInt16(data, imageInfoOffset + 0xC, littleEndian);
|
||||
uint imgRel = ReadUInt32(data, imageInfoOffset + 0x1C, littleEndian);
|
||||
uint palRel = 0;
|
||||
|
||||
if (paletteInfoOffset > 0)
|
||||
palRel = ReadUInt32(data, paletteInfoOffset + 0x1C, littleEndian);
|
||||
|
||||
// Texture Alignment (Buffer Width)
|
||||
// PSP aligns in blocks of 16 bytes (128 bits)
|
||||
int align = 16;
|
||||
int pixelsPerBlock = (align * 8) / Math.Max(1, (int)bpp);
|
||||
int bufferWidth = (width + pixelsPerBlock - 1) & ~(pixelsPerBlock - 1);
|
||||
|
||||
return new GimMetaData
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
BPP = bpp,
|
||||
Format = imgFormat,
|
||||
Order = pixelOrder,
|
||||
BufferWidth = bufferWidth,
|
||||
ImageInfoOffset = imageInfoOffset,
|
||||
PaletteInfoOffset = paletteInfoOffset,
|
||||
PaletteBlockEnd = paletteBlockEnd,
|
||||
ImgDataRelOffset = (int)imgRel,
|
||||
PalDataRelOffset = (int)palRel,
|
||||
IsLittleEndian = littleEndian
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read(IBinaryStream file, ImageMetaData info)
|
||||
{
|
||||
var meta = (GimMetaData)info;
|
||||
|
||||
byte[] data = new byte[file.Length];
|
||||
file.Position = 0;
|
||||
file.Read(data, 0, (int)file.Length);
|
||||
|
||||
int imgDataOffset = meta.ImageInfoOffset + meta.ImgDataRelOffset;
|
||||
|
||||
// Safe pixel buffer reading
|
||||
int width = (int)meta.Width;
|
||||
int height = (int)meta.Height;
|
||||
int bpp = meta.BPP;
|
||||
int bufferWidth = meta.BufferWidth;
|
||||
|
||||
// Internal PSP Stride (can be larger than image width)
|
||||
int bufferStride = (bufferWidth * bpp) / 8;
|
||||
int totalBytes = bufferStride * height;
|
||||
|
||||
if (imgDataOffset + totalBytes > data.Length)
|
||||
totalBytes = Math.Max(0, data.Length - imgDataOffset);
|
||||
|
||||
byte[] pixels = new byte[totalBytes];
|
||||
Buffer.BlockCopy(data, imgDataOffset, pixels, 0, totalBytes);
|
||||
|
||||
// --- UNSWIZZLE ---
|
||||
if (meta.Order == 1)
|
||||
{
|
||||
pixels = UnswizzlePSP(pixels, width, height, bufferWidth, bpp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If linear but with lateral padding, remove it
|
||||
if (bufferWidth != width)
|
||||
pixels = RemovePadding(pixels, width, height, bufferWidth, bpp);
|
||||
|
||||
// If 4bpp Linear, we still need to fix Nibbles
|
||||
if (bpp == 4)
|
||||
SwapNibbles(pixels);
|
||||
}
|
||||
|
||||
// --- PALETTE ---
|
||||
BitmapPalette palette = null;
|
||||
if (meta.Format == 0x04 || meta.Format == 0x05)
|
||||
{
|
||||
if (meta.PaletteInfoOffset > 0 && meta.PaletteBlockEnd > 0)
|
||||
{
|
||||
int palDataOffset = meta.PaletteInfoOffset + meta.PalDataRelOffset;
|
||||
ushort palFmt = ReadUInt16(data, meta.PaletteInfoOffset + 4, meta.IsLittleEndian);
|
||||
int entrySize = (palFmt == 3) ? 4 : 2;
|
||||
|
||||
int palBytes = meta.PaletteBlockEnd - palDataOffset;
|
||||
int colorCount = palBytes / entrySize;
|
||||
|
||||
// Limit colors by BPP
|
||||
if (meta.Format == 0x04) colorCount = Math.Min(colorCount, 16);
|
||||
else if (meta.Format == 0x05) colorCount = Math.Min(colorCount, 256);
|
||||
|
||||
if (palDataOffset + (colorCount * entrySize) <= data.Length)
|
||||
{
|
||||
Color[] colors = new Color[colorCount];
|
||||
for(int i=0; i<colorCount; i++)
|
||||
{
|
||||
int pOff = palDataOffset + (i * entrySize);
|
||||
if (entrySize == 4) // RGBA8888
|
||||
{
|
||||
byte r = data[pOff];
|
||||
byte g = data[pOff+1];
|
||||
byte b = data[pOff+2];
|
||||
byte a = data[pOff+3];
|
||||
// IMPORTANT: Swap R and B to fix "blue face"
|
||||
colors[i] = Color.FromArgb(a, r, g, b);
|
||||
}
|
||||
else // 16 bit
|
||||
{
|
||||
ushort p = ReadUInt16(data, pOff, meta.IsLittleEndian);
|
||||
colors[i] = DecodePspColor(p, palFmt);
|
||||
}
|
||||
}
|
||||
palette = new BitmapPalette(colors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PixelFormat format = PixelFormats.Bgra32;
|
||||
int outputStride = (width * bpp + 7) / 8;
|
||||
byte[] outputPixels = pixels;
|
||||
|
||||
if (bpp == 8) format = PixelFormats.Indexed8;
|
||||
else if (bpp == 4) format = PixelFormats.Indexed4;
|
||||
else if (bpp == 16)
|
||||
{
|
||||
format = PixelFormats.Bgra32;
|
||||
outputPixels = Convert16to32(pixels, width, height, meta.Format, meta.IsLittleEndian);
|
||||
outputStride = width * 4;
|
||||
}
|
||||
else if (bpp == 32) format = PixelFormats.Bgra32;
|
||||
|
||||
return ImageData.Create(info, format, palette, outputPixels, outputStride);
|
||||
}
|
||||
|
||||
public override void Write(Stream file, ImageData image)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// --- HELPERS ---
|
||||
|
||||
static ushort ReadUInt16(byte[] data, int offset, bool littleEndian)
|
||||
{
|
||||
if (offset + 1 >= data.Length) return 0;
|
||||
return littleEndian
|
||||
? (ushort)(data[offset] | (data[offset + 1] << 8))
|
||||
: (ushort)((data[offset] << 8) | data[offset + 1]);
|
||||
}
|
||||
|
||||
static uint ReadUInt32(byte[] data, int offset, bool littleEndian)
|
||||
{
|
||||
if (offset + 3 >= data.Length) return 0;
|
||||
return littleEndian
|
||||
? (uint)(data[offset] | (data[offset + 1] << 8) | (data[offset + 2] << 16) | (data[offset + 3] << 24))
|
||||
: (uint)((data[offset] << 24) | (data[offset + 1] << 16) | (data[offset + 2] << 8) | data[offset + 3]);
|
||||
}
|
||||
|
||||
static byte[] UnswizzlePSP(byte[] src, int width, int height, int bufferWidth, int bpp)
|
||||
{
|
||||
// 4BPP TRICK: Treat 4BPP as 8BPP with half width for coordinate calculation.
|
||||
// This moves bytes correctly. THEN we swap nibbles.
|
||||
int procBpp = bpp;
|
||||
int procWidth = width;
|
||||
int procBufferWidth = bufferWidth;
|
||||
|
||||
if (bpp == 4)
|
||||
{
|
||||
procBpp = 8;
|
||||
procWidth = width / 2;
|
||||
procBufferWidth = bufferWidth / 2;
|
||||
}
|
||||
|
||||
int blockWidth = 16;
|
||||
int blockHeight = 8;
|
||||
|
||||
if (procBpp == 16) { blockWidth = 16; blockHeight = 4; }
|
||||
else if (procBpp == 32) { blockWidth = 8; blockHeight = 4; }
|
||||
|
||||
int dstStride = (procWidth * procBpp) / 8;
|
||||
byte[] dst = new byte[dstStride * height];
|
||||
int bppByte = procBpp / 8;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < procWidth; x++)
|
||||
{
|
||||
int bx = x / blockWidth;
|
||||
int by = y / blockHeight;
|
||||
int mx = x % blockWidth;
|
||||
int my = y % blockHeight;
|
||||
|
||||
int blocksPerRow = procBufferWidth / blockWidth;
|
||||
int blockSize = blockWidth * blockHeight * bppByte;
|
||||
int blockIdx = (by * blocksPerRow) + bx;
|
||||
int srcOffset = (blockIdx * blockSize) + ((my * blockWidth + mx) * bppByte);
|
||||
int dstOffset = (y * dstStride) + (x * bppByte);
|
||||
|
||||
if (srcOffset + bppByte <= src.Length && dstOffset + bppByte <= dst.Length)
|
||||
{
|
||||
// For 4bpp, bppByte is 1 (because we simulate 8bpp).
|
||||
byte val = src[srcOffset];
|
||||
|
||||
// 4BPP LINES FIX:
|
||||
// Unswizzle moved the correct Byte to the correct place.
|
||||
// Now we need to invert nibbles (High/Low) because WPF reads differently from PSP.
|
||||
if (bpp == 4)
|
||||
{
|
||||
val = (byte)(((val & 0x0F) << 4) | ((val & 0xF0) >> 4));
|
||||
}
|
||||
|
||||
dst[dstOffset] = val;
|
||||
|
||||
// For other formats (>8bpp), normal copy
|
||||
if (bpp > 8)
|
||||
{
|
||||
for(int k=1; k<bppByte; k++) dst[dstOffset+k] = src[srcOffset+k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
static byte[] RemovePadding(byte[] src, int width, int height, int bufferWidth, int bpp)
|
||||
{
|
||||
int srcStride = (bufferWidth * bpp + 7) / 8;
|
||||
int dstStride = (width * bpp + 7) / 8;
|
||||
byte[] dst = new byte[dstStride * height];
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
int copyLen = Math.Min(srcStride, dstStride);
|
||||
int sOff = y * srcStride;
|
||||
int dOff = y * dstStride;
|
||||
if (sOff + copyLen <= src.Length)
|
||||
Array.Copy(src, sOff, dst, dOff, copyLen);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
static void SwapNibbles(byte[] data)
|
||||
{
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
byte b = data[i];
|
||||
data[i] = (byte)(((b & 0x0F) << 4) | ((b & 0xF0) >> 4));
|
||||
}
|
||||
}
|
||||
|
||||
Color DecodePspColor(ushort v, int fmt)
|
||||
{
|
||||
int r=0, g=0, b=0, a=255;
|
||||
if (fmt == 0) { // 5650
|
||||
r=(v&0x1F)<<3; g=((v>>5)&0x3F)<<2; b=((v>>11)&0x1F)<<3;
|
||||
} else if (fmt == 1) { // 5551
|
||||
r=(v&0x1F)<<3; g=((v>>5)&0x1F)<<3; b=((v>>10)&0x1F)<<3; a=(v>>15)!=0?255:0;
|
||||
} else if (fmt == 2) { // 4444
|
||||
r=(v&0xF)<<4; g=((v>>4)&0xF)<<4; b=((v>>8)&0xF)<<4; a=((v>>12)&0xF)<<4;
|
||||
}
|
||||
// Swap R and B to fix inverted colors
|
||||
return Color.FromArgb((byte)a, (byte)b, (byte)g, (byte)r);
|
||||
}
|
||||
|
||||
byte[] Convert16to32(byte[] inp, int w, int h, int fmt, bool le)
|
||||
{
|
||||
byte[] outp = new byte[w * h * 4];
|
||||
for(int i=0; i<w*h; i++) {
|
||||
if(i*2+1>=inp.Length) break;
|
||||
ushort v = le
|
||||
? (ushort)(inp[i*2] | (inp[i*2+1] << 8))
|
||||
: (ushort)((inp[i*2] << 8) | inp[i*2+1]);
|
||||
Color c = DecodePspColor(v, fmt);
|
||||
int o = i*4;
|
||||
outp[o]=c.B; outp[o+1]=c.G; outp[o+2]=c.R; outp[o+3]=c.A;
|
||||
}
|
||||
return outp;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
134
ArcFormats/aNCHOR/ArcFPD.cs
Normal file
134
ArcFormats/aNCHOR/ArcFPD.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
//! \file ArcFPD.cs
|
||||
//! \date 2026-01-19
|
||||
//! \brief AGES Mk2 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;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Anchor {
|
||||
internal class FpdArchive : ArcFile {
|
||||
public readonly byte[] Key;
|
||||
|
||||
public FpdArchive(ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, byte[] key) : base (arc, impl, dir) {
|
||||
Key = key;
|
||||
}
|
||||
}
|
||||
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class FpdOpener : ArchiveFormat {
|
||||
public override string Tag { get { return "FPD"; } }
|
||||
public override string Description { get { return "AGES Mk2 resource archive"; } }
|
||||
public override uint Signature { get { return 0x00445046; } } // 'FPD\x00'
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public override ArcFile TryOpen(ArcView file) {
|
||||
int version = Binary.BigEndian(file.View.ReadInt32(4));
|
||||
if (version != 2)
|
||||
return null;
|
||||
|
||||
int count = (int)Binary.BigEndian(file.View.ReadInt64(8));
|
||||
if (!IsSaneCount(count))
|
||||
return null;
|
||||
|
||||
long data_start = Binary.BigEndian(file.View.ReadInt64(0x10));
|
||||
long offset = 0x38;
|
||||
if (data_start < count * 32 + offset)
|
||||
return null;
|
||||
uint index_size = (uint)(data_start - offset);
|
||||
|
||||
var key = QueryKey();
|
||||
var dir = new List<Entry>(count);
|
||||
|
||||
using (var input = file.CreateStream(offset, (uint)(data_start - offset)))
|
||||
using (var decrypted = new ByteStringEncryptedStream(input, key))
|
||||
using (var reader = new BinaryReader(decrypted)) {
|
||||
var name_offsets = new List<long>(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
long name_offset = Binary.BigEndian(reader.ReadInt64());
|
||||
long data_offset = Binary.BigEndian(reader.ReadInt64());
|
||||
long size = Binary.BigEndian(reader.ReadInt64());
|
||||
long unpacked_size = Binary.BigEndian(reader.ReadInt64());
|
||||
|
||||
var entry = new PackedEntry {
|
||||
Offset = data_start + data_offset,
|
||||
Size = (uint)size,
|
||||
UnpackedSize = (uint)unpacked_size,
|
||||
IsPacked = unpacked_size != 0
|
||||
};
|
||||
if (!entry.CheckPlacement(file.MaxOffset))
|
||||
return null;
|
||||
dir.Add(entry);
|
||||
name_offsets.Add(name_offset);
|
||||
}
|
||||
var name_block = reader.ReadBytes((int)(data_start - offset - count * 32));
|
||||
using (var mem = new MemoryStream(name_block))
|
||||
using (var stream = new ZLibStream(mem, CompressionMode.Decompress))
|
||||
using (var output = new MemoryStream()) {
|
||||
stream.CopyTo(output);
|
||||
var names = output.ToArray();
|
||||
for (int i = 0; i < count; i++) {
|
||||
dir[i].Name = Binary.GetCString(names, (int)name_offsets[i], Encoding.UTF8);
|
||||
dir[i].Type = FormatCatalog.Instance.GetTypeFromName(dir[i].Name);
|
||||
}
|
||||
}
|
||||
return new FpdArchive(file, this, dir, key);
|
||||
}
|
||||
}
|
||||
|
||||
public override Stream OpenEntry(ArcFile arc, Entry entry) {
|
||||
var farc = arc as FpdArchive;
|
||||
var pent = entry as PackedEntry;
|
||||
var input = farc.File.CreateStream(entry.Offset, entry.Size);
|
||||
var decrypted = new ByteStringEncryptedStream(input, farc.Key);
|
||||
if (pent.IsPacked)
|
||||
return new ZLibStream(decrypted, CompressionMode.Decompress);
|
||||
else
|
||||
return decrypted;
|
||||
// TODO: epk decryption
|
||||
}
|
||||
|
||||
byte[] QueryKey() {
|
||||
return DefaultScheme.ArchiveKey;
|
||||
}
|
||||
|
||||
FpdScheme DefaultScheme = new FpdScheme();
|
||||
|
||||
public override ResourceScheme Scheme {
|
||||
get { return DefaultScheme; }
|
||||
set { DefaultScheme = (FpdScheme)value; }
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class FpdScheme : ResourceScheme {
|
||||
public byte[] ArchiveKey;
|
||||
public byte[] EpkKey;
|
||||
}
|
||||
}
|
||||
55
ArcFormats/aNCHOR/AudioFCD.cs
Normal file
55
ArcFormats/aNCHOR/AudioFCD.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
//! \file AudioFCD.cs
|
||||
//! \date 2026-01-19
|
||||
//! \brief AGES Mk2 audio format.
|
||||
//
|
||||
// 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;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace GameRes.Formats.Anchor
|
||||
{
|
||||
[Export(typeof(AudioFormat))]
|
||||
public class FcdAudio : AudioFormat
|
||||
{
|
||||
public override string Tag { get { return "FCD"; } }
|
||||
public override string Description { get { return "AGES Mk2 audio format"; } }
|
||||
public override uint Signature { get { return 0x00444346; } } // 'FCD\x00'
|
||||
|
||||
public FcdAudio ()
|
||||
{
|
||||
Extensions = new string[] { "fcd" };
|
||||
}
|
||||
|
||||
public override SoundInput TryOpen (IBinaryStream file)
|
||||
{
|
||||
file.Position = 4;
|
||||
// guess: big endian, version=2, type=0 (ogg), offset=0xC
|
||||
byte[] data = { 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x4F, 0x67, 0x67, 0x53 };
|
||||
if (!file.ReadBytes (0x0C).SequenceEqual (data))
|
||||
throw new NotSupportedException();
|
||||
return new OggInput (new StreamRegion (file.AsStream, 0x0C));
|
||||
}
|
||||
}
|
||||
}
|
||||
188
ArcFormats/aPLibStream.cs
Normal file
188
ArcFormats/aPLibStream.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
//! \file aPLibStream.cs
|
||||
//! \date 2026-01-09
|
||||
|
||||
/*
|
||||
* aPLib compression library - the smaller the better :)
|
||||
*
|
||||
* C depacker
|
||||
*
|
||||
* Copyright (c) 1998-2014 Joergen Ibsen
|
||||
* All Rights Reserved
|
||||
*
|
||||
* http://www.ibsensoftware.com/
|
||||
*/
|
||||
|
||||
// C# port by scientificworld
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace GameRes.Compression {
|
||||
public sealed class aPLibCoroutine : Decompressor {
|
||||
Stream m_input;
|
||||
uint m_tag;
|
||||
uint m_bitcount;
|
||||
|
||||
public override void Initialize (Stream input) {
|
||||
m_input = input;
|
||||
}
|
||||
|
||||
protected override IEnumerator<int> Unpack () {
|
||||
uint offs, len, R0, LWM;
|
||||
|
||||
var hist = new List<byte>();
|
||||
|
||||
m_bitcount = 0;
|
||||
R0 = uint.MaxValue; // (uint) -1
|
||||
LWM = 0;
|
||||
|
||||
m_buffer[m_pos] = ReadByte();
|
||||
hist.Add(m_buffer[m_pos++]);
|
||||
if (--m_length == 0)
|
||||
yield return m_pos;
|
||||
|
||||
while (true) {
|
||||
if (GetBit() != 0) {
|
||||
if (GetBit() != 0) {
|
||||
if (GetBit() != 0) {
|
||||
offs = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
offs = (offs << 1) + GetBit();
|
||||
}
|
||||
|
||||
if (offs != 0) {
|
||||
m_buffer[m_pos] = hist[(int)(hist.Count - offs)];
|
||||
}
|
||||
else {
|
||||
m_buffer[m_pos] = 0x00;
|
||||
}
|
||||
hist.Add(m_buffer[m_pos++]);
|
||||
|
||||
LWM = 0;
|
||||
if (--m_length == 0)
|
||||
yield return m_pos;
|
||||
}
|
||||
else {
|
||||
offs = (uint)ReadByte();
|
||||
|
||||
len = 2 + (offs & 0x0001);
|
||||
|
||||
offs >>= 1;
|
||||
|
||||
if (offs != 0) {
|
||||
for (; len != 0; len--) {
|
||||
m_buffer[m_pos] = hist[(int)(hist.Count - offs)];
|
||||
hist.Add(m_buffer[m_pos++]);
|
||||
if (--m_length == 0)
|
||||
yield return m_pos;
|
||||
}
|
||||
}
|
||||
else {
|
||||
yield break;
|
||||
}
|
||||
|
||||
R0 = offs;
|
||||
LWM = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
offs = GetGamma();
|
||||
|
||||
if ((LWM == 0) && (offs == 2)) {
|
||||
offs = R0;
|
||||
|
||||
len = GetGamma();
|
||||
|
||||
for (; len != 0; len--) {
|
||||
m_buffer[m_pos] = hist[(int)(hist.Count - offs)];
|
||||
hist.Add(m_buffer[m_pos++]);
|
||||
if (--m_length == 0)
|
||||
yield return m_pos;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (LWM == 0) {
|
||||
offs -= 3;
|
||||
}
|
||||
else {
|
||||
offs -= 2;
|
||||
}
|
||||
|
||||
offs <<= 8;
|
||||
offs += (uint)ReadByte();
|
||||
|
||||
len = GetGamma();
|
||||
|
||||
if (offs >= 32000) {
|
||||
len++;
|
||||
}
|
||||
if (offs >= 1280) {
|
||||
len++;
|
||||
}
|
||||
if (offs < 128) {
|
||||
len += 2;
|
||||
}
|
||||
|
||||
for (; len != 0; len--) {
|
||||
m_buffer[m_pos] = hist[(int)(hist.Count - offs)];
|
||||
hist.Add(m_buffer[m_pos++]);
|
||||
if (--m_length == 0)
|
||||
yield return m_pos;
|
||||
}
|
||||
|
||||
R0 = offs;
|
||||
}
|
||||
|
||||
LWM = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_buffer[m_pos] = ReadByte();
|
||||
hist.Add(m_buffer[m_pos++]);
|
||||
LWM = 0;
|
||||
if (--m_length == 0)
|
||||
yield return m_pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint GetBit () {
|
||||
uint bit;
|
||||
|
||||
if (m_bitcount-- == 0) {
|
||||
m_tag = (uint)ReadByte();
|
||||
m_bitcount = 7;
|
||||
}
|
||||
bit = (m_tag >> 7) & 0x01;
|
||||
m_tag <<= 1;
|
||||
|
||||
return bit;
|
||||
}
|
||||
|
||||
uint GetGamma () {
|
||||
uint result = 1;
|
||||
|
||||
do {
|
||||
result = (result << 1) + GetBit();
|
||||
} while (GetBit() != 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
byte ReadByte () {
|
||||
int b = m_input.ReadByte();
|
||||
if (b == -1)
|
||||
throw new EndOfStreamException();
|
||||
return (byte)b;
|
||||
}
|
||||
}
|
||||
|
||||
public class aPLibStream : PackedStream<aPLibCoroutine> {
|
||||
public aPLibStream (Stream input, CompressionMode mode = CompressionMode.Decompress, bool leave_open = false) : base (input, leave_open) {
|
||||
if (mode != CompressionMode.Decompress)
|
||||
throw new NotImplementedException ("aPLibStream compression not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
102
Experimental/CatSystem/ArcIRIS.cs
Normal file
102
Experimental/CatSystem/ArcIRIS.cs
Normal file
@@ -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<Entry>();
|
||||
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<Entry>(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<Entry>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,6 +149,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Artemis\ImageIPT.cs" />
|
||||
<Compile Include="Cabinet\ArcCAB.cs" />
|
||||
<Compile Include="CatSystem\ArcIRIS.cs" />
|
||||
<Compile Include="CellWorks\ArcDB.cs" />
|
||||
<Compile Include="Artemis\GplexBuffers.cs" />
|
||||
<Compile Include="Microsoft\ArcEXE.cs" />
|
||||
|
||||
@@ -113,6 +113,11 @@ namespace GameRes.Utility
|
||||
return GetCString (data, index, length_limit, Encodings.cp932);
|
||||
}
|
||||
|
||||
public static string GetCString (byte[] data, int index, Encoding enc)
|
||||
{
|
||||
return GetCString (data, index, data.Length - index, enc);
|
||||
}
|
||||
|
||||
public static string GetCString (byte[] data, int index)
|
||||
{
|
||||
return GetCString (data, index, data.Length - index, Encodings.cp932);
|
||||
|
||||
144
Legacy/Broccoli/BroccoliGrp.cs
Normal file
144
Legacy/Broccoli/BroccoliGrp.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq; // Added for list operations if necessary
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Broccoli
|
||||
{
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class GrpFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "GRP/BROCCOLI"; } }
|
||||
public override string Description { get { return "Broccoli engine image"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
// We need to decompress to know the real size
|
||||
using (var data = DecompressData(file))
|
||||
{
|
||||
if (data == null) return null;
|
||||
|
||||
var size = data.Length;
|
||||
uint width = 0, height = 0;
|
||||
int bpp = 32;
|
||||
|
||||
// Same resolution logic as your Python script
|
||||
if (size == 1920000) { width = 800; height = 600; }
|
||||
else if (size == 1228800) { width = 640; height = 480; }
|
||||
else if (size == 1536000) { width = 800; height = 480; }
|
||||
else if (size == 768000) { width = 640; height = 400; }
|
||||
else if (size == 307200) { width = 640; height = 480; bpp = 8; }
|
||||
else if (size == 96000) { width = 200; height = 120; }
|
||||
else
|
||||
{
|
||||
// Fallback: Try to read 4-byte header (Width/Height)
|
||||
if (size > 4)
|
||||
{
|
||||
data.Position = 0;
|
||||
var reader = new BinaryReader(data);
|
||||
ushort w = reader.ReadUInt16();
|
||||
ushort h = reader.ReadUInt16();
|
||||
if (w * h * 4 == size - 4)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (width == 0) return null;
|
||||
|
||||
return new ImageMetaData
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
BPP = bpp,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override ImageData Read (IBinaryStream file, ImageMetaData info)
|
||||
{
|
||||
using (var stream = DecompressData(file))
|
||||
{
|
||||
if (stream == null) throw new InvalidFormatException();
|
||||
|
||||
// Skip 4-byte header if fallback logic was used
|
||||
int headerSkip = 0;
|
||||
if (stream.Length != info.Width * info.Height * (info.BPP / 8))
|
||||
{
|
||||
if (stream.Length == (info.Width * info.Height * 4) + 4)
|
||||
headerSkip = 4;
|
||||
}
|
||||
|
||||
stream.Position = headerSkip;
|
||||
|
||||
// Case 1: Isolated Mask (Grayscale)
|
||||
if (info.BPP == 8)
|
||||
{
|
||||
var gray = new byte[info.Width * info.Height];
|
||||
stream.Read(gray, 0, gray.Length);
|
||||
return ImageData.Create(info, PixelFormats.Gray8, null, gray);
|
||||
}
|
||||
|
||||
// Case 2: Colored Image (BGRX)
|
||||
// Due to API limitations, we won't load the mask (_m) here.
|
||||
// GARbro will show the image with a black/solid background.
|
||||
// Use your Python script to combine with the mask later.
|
||||
|
||||
var pixels = new byte[info.Width * info.Height * 4];
|
||||
stream.Read(pixels, 0, pixels.Length);
|
||||
|
||||
// The format is usually Bgr32 (the 4th byte is garbage/padding, not real alpha)
|
||||
return ImageData.Create(info, PixelFormats.Bgr32, null, pixels);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new System.NotImplementedException("Use repack.py");
|
||||
}
|
||||
|
||||
private MemoryStream DecompressData(IBinaryStream input)
|
||||
{
|
||||
input.Position = 0;
|
||||
byte[] buffer = input.ReadBytes(2048);
|
||||
int zlibOffset = -1;
|
||||
|
||||
// Search for ZLIB signature (78 9C, etc)
|
||||
for (int i = 0; i < buffer.Length - 1; i++)
|
||||
{
|
||||
if (buffer[i] == 0x78 &&
|
||||
(buffer[i+1] == 0x9C || buffer[i+1] == 0xDA || buffer[i+1] == 0x01))
|
||||
{
|
||||
zlibOffset = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (zlibOffset == -1) return null;
|
||||
|
||||
try
|
||||
{
|
||||
// Skip ZLIB header (2 bytes) to use standard DeflateStream
|
||||
input.Position = zlibOffset + 2;
|
||||
|
||||
using (var zStream = new System.IO.Compression.DeflateStream(input.AsStream, System.IO.Compression.CompressionMode.Decompress, true))
|
||||
{
|
||||
var output = new MemoryStream();
|
||||
zStream.CopyTo(output);
|
||||
output.Position = 0;
|
||||
return output;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Legacy/Broccoli/BroccoliMpeg.cs
Normal file
35
Legacy/Broccoli/BroccoliMpeg.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Broccoli
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class MpegVideoOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "MPEG/BROCCOLI"; } }
|
||||
public override string Description { get { return "Generic MPEG Video"; } }
|
||||
public override uint Signature { get { return 0xBA010000; } }
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public override ArcFile TryOpen(ArcView file)
|
||||
{
|
||||
if (file.View.ReadUInt32(0) != 0xBA010000)
|
||||
return null;
|
||||
|
||||
var entry = new Entry
|
||||
{
|
||||
Name = Path.GetFileNameWithoutExtension(file.Name) + ".mpg",
|
||||
Type = "video",
|
||||
Offset = 0,
|
||||
// FIX: Added (uint) cast for size conversion
|
||||
Size = (uint)file.MaxOffset
|
||||
};
|
||||
|
||||
return new ArcFile(file, this, new List<Entry> { entry });
|
||||
}
|
||||
}
|
||||
}
|
||||
119
Legacy/Broccoli/BroccoliPak.cs
Normal file
119
Legacy/Broccoli/BroccoliPak.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Broccoli
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class PakOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "PAK/BROCCOLI"; } }
|
||||
public override string Description { get { return "Broccoli"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
private static readonly byte[] FirstFileSignature = {
|
||||
0x73, 0x65, 0x5F, 0x63, 0x31, 0x31, 0x2E, 0x77, 0x61, 0x76
|
||||
};
|
||||
|
||||
public override ArcFile TryOpen(ArcView file)
|
||||
{
|
||||
int bufferSize = 2048;
|
||||
if (file.MaxOffset < bufferSize)
|
||||
bufferSize = (int)file.MaxOffset;
|
||||
|
||||
var buffer = file.View.ReadBytes(0, (uint)bufferSize);
|
||||
|
||||
int signaturePos = FindSignature(buffer, FirstFileSignature);
|
||||
|
||||
if (signaturePos == -1)
|
||||
return null;
|
||||
|
||||
if (signaturePos < 8)
|
||||
return null;
|
||||
|
||||
long countOffset = signaturePos - 8;
|
||||
int count = file.View.ReadInt32(countOffset);
|
||||
|
||||
if (!IsSaneCount(count))
|
||||
return null;
|
||||
|
||||
long tableStart = signaturePos;
|
||||
long entrySize = 64;
|
||||
long tableByteSize = count * entrySize;
|
||||
|
||||
long dataBlobStart = tableStart + tableByteSize;
|
||||
|
||||
if (dataBlobStart > file.MaxOffset)
|
||||
return null;
|
||||
|
||||
var dir = new List<Entry>(count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
long entryPos = tableStart + (i * entrySize);
|
||||
|
||||
var nameBytes = file.View.ReadBytes(entryPos, 48);
|
||||
|
||||
// --- FIX APPLIED HERE ---
|
||||
// Replaced Binary.Ascii with System.Text.Encoding.ASCII
|
||||
if (nameBytes.Length >= 4 &&
|
||||
(System.Text.Encoding.ASCII.GetString(nameBytes, 0, 4) == "RIFF" ||
|
||||
System.Text.Encoding.ASCII.GetString(nameBytes, 0, 4) == "OggS"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
// ------------------------
|
||||
|
||||
string name = Binary.GetCString(nameBytes, 0, nameBytes.Length, Encodings.cp932);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
continue;
|
||||
|
||||
name = name.TrimEnd('\0');
|
||||
|
||||
uint offset = file.View.ReadUInt32(entryPos + 48);
|
||||
uint size = file.View.ReadUInt32(entryPos + 56);
|
||||
|
||||
if (size == 0)
|
||||
continue;
|
||||
|
||||
var entry = FormatCatalog.Instance.Create<Entry>(name);
|
||||
|
||||
entry.Offset = dataBlobStart + offset;
|
||||
entry.Size = size;
|
||||
|
||||
if (!entry.CheckPlacement(file.MaxOffset))
|
||||
return null;
|
||||
|
||||
dir.Add(entry);
|
||||
}
|
||||
|
||||
return new ArcFile(file, this, dir);
|
||||
}
|
||||
|
||||
private int FindSignature(byte[] buffer, byte[] signature)
|
||||
{
|
||||
if (buffer.Length < signature.Length) return -1;
|
||||
|
||||
for (int i = 0; i <= buffer.Length - signature.Length; i++)
|
||||
{
|
||||
bool found = true;
|
||||
for (int j = 0; j < signature.Length; j++)
|
||||
{
|
||||
if (buffer[i + j] != signature[j])
|
||||
{
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,9 @@
|
||||
<Compile Include="Blucky\Aliases.cs" />
|
||||
<Compile Include="Bom\ImageGRP.cs" />
|
||||
<Compile Include="Broccoli\ArcP00.cs" />
|
||||
<Compile Include="Broccoli\BroccoliGrp.cs" />
|
||||
<Compile Include="Broccoli\BroccoliMpeg.cs" />
|
||||
<Compile Include="Broccoli\BroccoliPak.cs" />
|
||||
<Compile Include="CottonClub\ImageLMG.cs" />
|
||||
<Compile Include="Desire\ArcDSV.cs" />
|
||||
<Compile Include="Desire\ImageDES.cs" />
|
||||
|
||||
Reference in New Issue
Block a user