mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-03 18:35:36 +08:00
(Legacy): DZP images and PAQ archives.
This commit is contained in:
parent
7278a18538
commit
447511a340
67
Legacy/Force/ArcPAQ.cs
Normal file
67
Legacy/Force/ArcPAQ.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
//! \file ArcPAQ.cs
|
||||||
|
//! \date 2018 Jul 31
|
||||||
|
//! \brief Force 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.IO;
|
||||||
|
|
||||||
|
namespace GameRes.Formats.Force
|
||||||
|
{
|
||||||
|
[Export(typeof(ArchiveFormat))]
|
||||||
|
public class PaqOpener : ArchiveFormat
|
||||||
|
{
|
||||||
|
public override string Tag { get { return "PAQ/FORCE"; } }
|
||||||
|
public override string Description { get { return "Force resource archive"; } }
|
||||||
|
public override uint Signature { get { return 0; } }
|
||||||
|
public override bool IsHierarchic { get { return false; } }
|
||||||
|
public override bool CanWrite { get { return false; } }
|
||||||
|
|
||||||
|
public override ArcFile TryOpen (ArcView file)
|
||||||
|
{
|
||||||
|
if (!file.Name.HasExtension (".paq"))
|
||||||
|
return null;
|
||||||
|
int count = file.View.ReadInt32 (0);
|
||||||
|
if (!IsSaneCount (count))
|
||||||
|
return null;
|
||||||
|
var base_name = Path.GetFileNameWithoutExtension (file.Name);
|
||||||
|
uint index_offset = 8;
|
||||||
|
uint data_offset = 4 + (uint)count * 8;
|
||||||
|
var dir = new List<Entry> (count);
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
var name = string.Format ("{0}#{1:D4}", base_name, i);
|
||||||
|
var entry = AutoEntry.Create (file, data_offset, name);
|
||||||
|
entry.Size = file.View.ReadUInt32 (index_offset);
|
||||||
|
if (!entry.CheckPlacement (file.MaxOffset))
|
||||||
|
return null;
|
||||||
|
dir.Add (entry);
|
||||||
|
index_offset += 8;
|
||||||
|
data_offset += entry.Size;
|
||||||
|
}
|
||||||
|
return new ArcFile (file, this, dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
118
Legacy/Force/ImageDZP.cs
Normal file
118
Legacy/Force/ImageDZP.cs
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
//! \file ImageDZP.cs
|
||||||
|
//! \date 2018 Jul 31
|
||||||
|
//! \brief Force image format.
|
||||||
|
//
|
||||||
|
// 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.ComponentModel.Composition;
|
||||||
|
using System.IO;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using GameRes.Utility;
|
||||||
|
|
||||||
|
// [990807][Force] Hajimete no Otsukai ~first adventure of little witch~
|
||||||
|
|
||||||
|
namespace GameRes.Formats.Force
|
||||||
|
{
|
||||||
|
[Export(typeof(ImageFormat))]
|
||||||
|
public class DzpFormat : ImageFormat
|
||||||
|
{
|
||||||
|
public override string Tag { get { return "DZP"; } }
|
||||||
|
public override string Description { get { return "Force image format"; } }
|
||||||
|
public override uint Signature { get { return 0; } }
|
||||||
|
|
||||||
|
public DzpFormat ()
|
||||||
|
{
|
||||||
|
Signatures = new uint[] { 24, 8 };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||||
|
{
|
||||||
|
if (!file.Name.HasExtension (".dzp"))
|
||||||
|
return null;
|
||||||
|
var header = file.ReadHeader (12);
|
||||||
|
int bpp = header.ToInt32 (0);
|
||||||
|
uint width = header.ToUInt32 (4);
|
||||||
|
uint height = header.ToUInt32 (8);
|
||||||
|
if (0 == width || width > 0x1000 || 0 == height || height > 0x1000)
|
||||||
|
return null;
|
||||||
|
return new ImageMetaData { Width = width * 4, Height = height * 4, BPP = bpp };
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ImageData Read (IBinaryStream file, ImageMetaData info)
|
||||||
|
{
|
||||||
|
file.Position = 12;
|
||||||
|
BitmapPalette palette = null;
|
||||||
|
if (8 == info.BPP)
|
||||||
|
palette = ReadPalette (file.AsStream);
|
||||||
|
int stride = (int)info.Width * (info.BPP / 8);
|
||||||
|
var pixels = new byte[stride * (int)info.Height];
|
||||||
|
PixelFormat format;
|
||||||
|
if (8 == info.BPP)
|
||||||
|
{
|
||||||
|
Unpack8BPP (file, pixels);
|
||||||
|
format = PixelFormats.Indexed8;
|
||||||
|
}
|
||||||
|
else if (24 == info.BPP)
|
||||||
|
{
|
||||||
|
Unpack24BPP (file, pixels);
|
||||||
|
format = PixelFormats.Bgr24;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new InvalidFormatException();
|
||||||
|
return ImageData.Create (info, format, palette, pixels, stride);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unpack8BPP (IBinaryStream input, byte[] output)
|
||||||
|
{
|
||||||
|
int dst = 0;
|
||||||
|
while (dst < output.Length && input.PeekByte() != -1)
|
||||||
|
{
|
||||||
|
byte v = input.ReadUInt8();
|
||||||
|
int count = input.ReadByte();
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
|
output[dst++] = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unpack24BPP (IBinaryStream input, byte[] output)
|
||||||
|
{
|
||||||
|
int dst = 0;
|
||||||
|
while (dst < output.Length && input.PeekByte() != -1)
|
||||||
|
{
|
||||||
|
input.Read (output, dst, 3);
|
||||||
|
int count = input.ReadByte();
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
count *= 3;
|
||||||
|
Binary.CopyOverlapped (output, dst, dst+3, count-3);
|
||||||
|
dst += count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write (Stream file, ImageData image)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException ("DzpFormat.Write not implemented");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user