mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
implemented Patisserie archives.
This commit is contained in:
@@ -141,6 +141,8 @@
|
||||
<Compile Include="NonColor\WidgetNCARC.xaml.cs">
|
||||
<DependentUpon>WidgetNCARC.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Patisserie\ArcBIN.cs" />
|
||||
<Compile Include="Patisserie\ArcRAW.cs" />
|
||||
<Compile Include="RealLive\ArcG00.cs" />
|
||||
<Compile Include="RealLive\ArcOVK.cs" />
|
||||
<Compile Include="RealLive\AudioNWA.cs" />
|
||||
|
||||
202
ArcFormats/Patisserie/ArcBIN.cs
Normal file
202
ArcFormats/Patisserie/ArcBIN.cs
Normal file
@@ -0,0 +1,202 @@
|
||||
//! \file ArcBIN.cs
|
||||
//! \date Thu Jul 21 21:10:31 2016
|
||||
//! \brief Patisserie resource archive.
|
||||
//
|
||||
// Copyright (C) 2016 by morkt
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameRes.Compression;
|
||||
|
||||
namespace GameRes.Formats.Patisserie
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class BinOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "BIN/OZ"; } }
|
||||
public override string Description { get { return "Patisserie resource archive"; } }
|
||||
public override uint Signature { get { return 0x01005A4F; } } // 'OZ'
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanCreate { get { return false; } }
|
||||
|
||||
public BinOpener ()
|
||||
{
|
||||
Extensions = new string[] { "bin" };
|
||||
}
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
if (!file.View.AsciiEqual (4, "OFST"))
|
||||
return null;
|
||||
int index_size = file.View.ReadInt32 (8);
|
||||
int count = index_size / 4;
|
||||
if (!IsSaneCount (count))
|
||||
return null;
|
||||
var base_name = Path.GetFileNameWithoutExtension (file.Name);
|
||||
string content_ext = "", content_type = "";
|
||||
if (base_name.EndsWith ("flac", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
content_ext = "flac";
|
||||
content_type = "audio";
|
||||
base_name = base_name.Substring (0, base_name.Length-4);
|
||||
}
|
||||
else if (base_name.EndsWith ("ogg", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
content_ext = "ogg";
|
||||
content_type = "audio";
|
||||
base_name = base_name.Substring (0, base_name.Length-3);
|
||||
}
|
||||
|
||||
var filenames = GetFileNames (VFS.GetDirectoryName (file.Name), base_name);
|
||||
if (null == filenames)
|
||||
filenames = new List<string> (count);
|
||||
for (int i = filenames.Count; i < count; ++i)
|
||||
filenames.Add (string.Format ("{0}#{1:D5}", base_name, i));
|
||||
|
||||
uint index_offset = 0xC;
|
||||
var dir = new List<Entry> (count);
|
||||
uint next_offset = file.View.ReadUInt32 (index_offset);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
index_offset += 4;
|
||||
var entry = new PackedEntry { Name = filenames[i] };
|
||||
entry.Offset = next_offset;
|
||||
next_offset = i+1 < count ? file.View.ReadUInt32 (index_offset) : (uint)file.MaxOffset;
|
||||
entry.Size = next_offset - (uint)entry.Offset;
|
||||
if (entry.Size > 0 && !entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
if (!string.IsNullOrEmpty (content_type))
|
||||
{
|
||||
entry.Type = content_type;
|
||||
entry.Name = Path.ChangeExtension (entry.Name, content_ext);
|
||||
}
|
||||
dir.Add (entry);
|
||||
}
|
||||
foreach (PackedEntry entry in dir.Where (e => e.Size > 4))
|
||||
{
|
||||
entry.IsPacked = file.View.AsciiEqual (entry.Offset, "DFLT");
|
||||
if (entry.IsPacked)
|
||||
{
|
||||
entry.Size = file.View.ReadUInt32 (entry.Offset+4);
|
||||
entry.UnpackedSize = file.View.ReadUInt32 (entry.Offset+8);
|
||||
entry.Offset += 12;
|
||||
}
|
||||
else if (file.View.AsciiEqual (entry.Offset, "DATA"))
|
||||
{
|
||||
entry.Size = file.View.ReadUInt32 (entry.Offset+4);
|
||||
entry.UnpackedSize = entry.Size;
|
||||
entry.Offset += 8;
|
||||
if (string.IsNullOrEmpty (entry.Type))
|
||||
{
|
||||
uint signature = file.View.ReadUInt32 (entry.Offset);
|
||||
if (0x43614C66 == signature) // 'fLaC'
|
||||
{
|
||||
entry.Type = "audio";
|
||||
entry.Name = Path.ChangeExtension (entry.Name, "flac");
|
||||
}
|
||||
else
|
||||
{
|
||||
var res = AutoEntry.DetectFileType (signature);
|
||||
if (null != res)
|
||||
{
|
||||
entry.Type = res.Type;
|
||||
var ext = res.Extensions.FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty (ext))
|
||||
entry.Name = Path.ChangeExtension (entry.Name, ext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||
{
|
||||
var input = arc.File.CreateStream (entry.Offset, entry.Size);
|
||||
var pent = entry as PackedEntry;
|
||||
if (null == pent || !pent.IsPacked)
|
||||
return input;
|
||||
return new ZLibStream (input, CompressionMode.Decompress);
|
||||
}
|
||||
|
||||
IList<string> GetArcNames (string lst_name)
|
||||
{
|
||||
return File.ReadAllLines (lst_name, Encodings.cp932);
|
||||
}
|
||||
|
||||
IList<string> GetFileNames (string dir_name, string base_name)
|
||||
{
|
||||
var lists_lst_name = VFS.CombinePath (dir_name, "lists.lst");
|
||||
if (!VFS.FileExists (lists_lst_name))
|
||||
return null;
|
||||
var arcs = GetArcNames (lists_lst_name);
|
||||
var arc_no = arcs.IndexOf (base_name);
|
||||
if (-1 == arc_no)
|
||||
return null;
|
||||
var lists_bin_name = VFS.CombinePath (dir_name, "lists.bin");
|
||||
using (var lists_bin = VFS.OpenView (lists_bin_name))
|
||||
return ReadFileNames (lists_bin, arc_no);
|
||||
}
|
||||
|
||||
IList<string> ReadFileNames (ArcView index, int arc_no)
|
||||
{
|
||||
if (index.View.ReadUInt32 (0) != Signature)
|
||||
return null;
|
||||
if (!index.View.AsciiEqual (4, "OFST"))
|
||||
return null;
|
||||
int index_size = index.View.ReadInt32 (8);
|
||||
int arc_count = index_size / 4;
|
||||
if (arc_no >= arc_count)
|
||||
return null;
|
||||
uint index_offset = index.View.ReadUInt32 (0xC + arc_no * 4);
|
||||
if (index_offset >= index.MaxOffset)
|
||||
return null;
|
||||
Stream input;
|
||||
if (index.View.AsciiEqual (index_offset, "DFLT"))
|
||||
{
|
||||
uint packed_size = index.View.ReadUInt32 (index_offset+4);
|
||||
input = index.CreateStream (index_offset+12, packed_size);
|
||||
input = new ZLibStream (input, CompressionMode.Decompress);
|
||||
}
|
||||
else if (index.View.AsciiEqual (index_offset, "DATA"))
|
||||
{
|
||||
uint data_size = index.View.ReadUInt32 (index_offset+4);
|
||||
input = index.CreateStream (index_offset+8, data_size);
|
||||
}
|
||||
else
|
||||
return null;
|
||||
using (input)
|
||||
using (var reader = new StreamReader (input, Encodings.cp932))
|
||||
{
|
||||
var list = new List<string>();
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
list.Add (line.Trim());
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
88
ArcFormats/Patisserie/ArcRAW.cs
Normal file
88
ArcFormats/Patisserie/ArcRAW.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
//! \file ArcRAW.cs
|
||||
//! \date Fri Jul 22 00:56:19 2016
|
||||
//! \brief Patisserie animation resource.
|
||||
//
|
||||
// Copyright (C) 2016 by morkt
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
|
||||
namespace GameRes.Formats.Patisserie
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class RawOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "ABB/RAW"; } }
|
||||
public override string Description { get { return "Patisserie animation resource"; } }
|
||||
public override uint Signature { get { return 0x04574152; } } // 'RAW\x04'
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanCreate { get { return false; } }
|
||||
|
||||
public RawOpener ()
|
||||
{
|
||||
Extensions = new string[] { "raw" };
|
||||
}
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
uint end = file.View.ReadUInt32 (4);
|
||||
if (end > file.MaxOffset - 8)
|
||||
return null;
|
||||
end += 8;
|
||||
uint current_offset = 8;
|
||||
var dir = new List<Entry>();
|
||||
int i = 0;
|
||||
while (current_offset < end)
|
||||
{
|
||||
var entry = new Entry {
|
||||
Name = string.Format (i.ToString ("D4")),
|
||||
Type = "image",
|
||||
Offset = current_offset,
|
||||
};
|
||||
uint width = file.View.ReadUInt32 (current_offset+0xC);
|
||||
uint height = file.View.ReadUInt32 (current_offset+0x10);
|
||||
entry.Size = 0x14 + 4 * width * height;
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
current_offset += entry.Size;
|
||||
++i;
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||
{
|
||||
var info = new ImageMetaData
|
||||
{
|
||||
OffsetX = arc.File.View.ReadInt32 (entry.Offset+4),
|
||||
OffsetY = arc.File.View.ReadInt32(entry.Offset+8),
|
||||
Width = arc.File.View.ReadUInt32(entry.Offset+0xC),
|
||||
Height = arc.File.View.ReadUInt32(entry.Offset+0x10),
|
||||
BPP = 32,
|
||||
};
|
||||
var pixels = arc.File.View.ReadBytes (entry.Offset+0x14, entry.Size-0x14);
|
||||
return TgaStream.Create (info, pixels);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user