mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
bunch of stuff.
This commit is contained in:
73
Legacy/Herb/ArcPAK.cs
Normal file
73
Legacy/Herb/ArcPAK.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
//! \file ArcPAK.cs
|
||||
//! \date 2023 Aug 16
|
||||
//! \brief Herb Soft resource archive.
|
||||
//
|
||||
// Copyright (C) 2023 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.Herb
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class PakOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "PAK/HERB"; } }
|
||||
public override string Description { get { return "Herb Soft resource archive"; } }
|
||||
public override uint Signature { get { return 0x2E; } }
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public PakOpener ()
|
||||
{
|
||||
ContainedFormats = new[] { "GRP/HERB", "WAV", "TXT" };
|
||||
}
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
long base_offset = 0x20000;
|
||||
if (file.MaxOffset <= base_offset || !file.View.AsciiEqual (0x40, "..\0"))
|
||||
return null;
|
||||
long index_pos = 0x80;
|
||||
var dir = new List<Entry>();
|
||||
while (index_pos < base_offset && file.View.ReadByte (index_pos) != 0)
|
||||
{
|
||||
var name = file.View.ReadString (index_pos, 0x30);
|
||||
var entry = Create<Entry> (name);
|
||||
entry.Offset = file.View.ReadUInt32 (index_pos + 0x30) + base_offset;
|
||||
entry.Size = file.View.ReadUInt32 (index_pos + 0x38);
|
||||
if (entry.Size != 0)
|
||||
{
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
}
|
||||
index_pos += 0x40;
|
||||
}
|
||||
if (dir.Count == 0)
|
||||
return null;
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
91
Legacy/Herb/ImageGRP.cs
Normal file
91
Legacy/Herb/ImageGRP.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
//! \file ImageGRP.cs
|
||||
//! \date 2023 Aug 16
|
||||
//! \brief Herb Soft compressed image format.
|
||||
//
|
||||
// Copyright (C) 2023 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 GameRes.Compression;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace GameRes.Formats.Herb
|
||||
{
|
||||
internal class GrpMetaData : ImageMetaData
|
||||
{
|
||||
public int Stride;
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class GrpFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "GRP/HERB"; } }
|
||||
public override string Description { get { return "Herb Soft image format"; } }
|
||||
public override uint Signature { get { return 0x08; } }
|
||||
|
||||
public GrpFormat ()
|
||||
{
|
||||
Signatures = new[] { 0x20u, 0x18u, 0x08u };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
var header = file.ReadHeader (0x28);
|
||||
if (header.ToInt32 (4) != 0 || header.ToInt32 (8) != 1)
|
||||
return null;
|
||||
return new GrpMetaData {
|
||||
Width = header.ToUInt32 (0x20),
|
||||
Height = header.ToUInt32 (0x24),
|
||||
BPP = header[0] == 0x08 ? 8 : header[0] == 0x18 ? 16 : 24,
|
||||
Stride = header.ToInt32 (0x0C),
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (IBinaryStream file, ImageMetaData info)
|
||||
{
|
||||
var meta = (GrpMetaData)info;
|
||||
BitmapPalette palette = null;
|
||||
PixelFormat format = 8 == info.BPP ? PixelFormats.Indexed8
|
||||
: 16 == info.BPP ? PixelFormats.Bgr555
|
||||
: PixelFormats.Bgr24;
|
||||
if (8 == info.BPP)
|
||||
{
|
||||
file.Position = 0x28;
|
||||
palette = ReadPalette (file.AsStream, 0x100, PaletteFormat.RgbX);
|
||||
}
|
||||
int stride = meta.Stride;
|
||||
var pixels = new byte[stride * info.iHeight];
|
||||
file.Position = 0x428;
|
||||
using (var input = new ZLibStream (file.AsStream, CompressionMode.Decompress, true))
|
||||
{
|
||||
input.Read (pixels, 0, pixels.Length);
|
||||
}
|
||||
return ImageData.Create (info, format, palette, pixels, stride);
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new System.NotImplementedException ("GrpFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user