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:
@@ -31,7 +31,7 @@ using System.IO;
|
||||
namespace GameRes.Formats.KApp
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class AsdOpener : ArchiveFormat
|
||||
public class AsdKToolOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "ASD/KTOOL"; } }
|
||||
public override string Description { get { return "KApp engine resource archive"; } }
|
||||
@@ -122,4 +122,82 @@ namespace GameRes.Formats.KApp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class AsdArchive : ArcFile
|
||||
{
|
||||
public byte Format;
|
||||
|
||||
public AsdArchive (ArcView arc, ArchiveFormat impl, ICollection<Entry> dir) : base (arc, impl, dir)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class AsdAudioOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "ASD/SPIEL"; } }
|
||||
public override string Description { get { return "Spiel audio 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 (".asd"))
|
||||
return null;
|
||||
byte format = file.View.ReadByte (0);
|
||||
if (format != 1 && format != 2)
|
||||
return null;
|
||||
var base_name = Path.GetFileNameWithoutExtension (file.Name);
|
||||
uint index_pos = 0x10;
|
||||
uint next_offset = file.View.ReadUInt32 (index_pos);
|
||||
var dir = new List<Entry>();
|
||||
while (next_offset != 0xFFFFFFFF)
|
||||
{
|
||||
index_pos += 4;
|
||||
var entry = new Entry {
|
||||
Name = string.Format ("{0}#{1:D4}", base_name, dir.Count),
|
||||
Type = "audio",
|
||||
Offset = next_offset,
|
||||
};
|
||||
next_offset = file.View.ReadUInt32 (index_pos);
|
||||
if (next_offset != 0xFFFFFFFF)
|
||||
entry.Size = (uint)(next_offset - entry.Offset);
|
||||
else
|
||||
entry.Size = (uint)(file.MaxOffset - entry.Offset);
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
}
|
||||
if (0 == dir.Count)
|
||||
return null;
|
||||
return new AsdArchive (file, this, dir) { Format = format };
|
||||
}
|
||||
|
||||
public override Stream OpenEntry (ArcFile a, Entry entry)
|
||||
{
|
||||
var arc = (AsdArchive)a;
|
||||
var view = arc.File.View;
|
||||
uint data_size = view.ReadUInt32 (entry.Offset);
|
||||
if (2 == arc.Format) // MP3
|
||||
return arc.File.CreateStream (entry.Offset+0x10, data_size);
|
||||
|
||||
var format = new WaveFormat {
|
||||
FormatTag = view.ReadUInt16 (entry.Offset+8),
|
||||
Channels = view.ReadUInt16 (entry.Offset+0xA),
|
||||
SamplesPerSecond = view.ReadUInt32 (entry.Offset+0xC),
|
||||
AverageBytesPerSecond = view.ReadUInt32 (entry.Offset+0x10),
|
||||
BlockAlign = view.ReadUInt16 (entry.Offset+0x14),
|
||||
BitsPerSample = view.ReadUInt16 (entry.Offset+0x16),
|
||||
};
|
||||
byte[] header;
|
||||
using (var riff = new MemoryStream())
|
||||
{
|
||||
WaveAudio.WriteRiffHeader (riff, format, data_size);
|
||||
header = riff.ToArray();
|
||||
}
|
||||
var input = arc.File.CreateStream (entry.Offset+0x20, entry.Size-0x20);
|
||||
return new PrefixStream (header, input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
94
Legacy/KApp/ArcCGD.cs
Normal file
94
Legacy/KApp/ArcCGD.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
//! \file ArcCGF.cs
|
||||
//! \date 2022 May 06
|
||||
//! \brief Spiel image collection.
|
||||
//
|
||||
// Copyright (C) 2022 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;
|
||||
|
||||
// [001006][spiel] Koimusubi
|
||||
|
||||
namespace GameRes.Formats.KApp
|
||||
{
|
||||
internal class CgdEntry : Entry
|
||||
{
|
||||
public CgdMetaData Info;
|
||||
}
|
||||
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class CgdOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "CGD/SPIEL"; } }
|
||||
public override string Description { get { return "Spiel image collection"; } }
|
||||
public override uint Signature { get { return 0x65697073; } } // 'spiel100'
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
if (!file.View.AsciiEqual (0, "spiel100"))
|
||||
return null;
|
||||
int count = file.View.ReadInt32 (8);
|
||||
if (!IsSaneCount (count))
|
||||
return null;
|
||||
|
||||
var base_name = Path.GetFileNameWithoutExtension (file.Name);
|
||||
uint index_pos = 0x10;
|
||||
var dir = new List<Entry> (count);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
var entry = new CgdEntry {
|
||||
Name = string.Format ("{0}#{1:D4}", base_name, i),
|
||||
Type = "image",
|
||||
Offset = file.View.ReadUInt32 (index_pos),
|
||||
Size = file.View.ReadUInt32 (index_pos+4),
|
||||
};
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
var info = entry.Info = new CgdMetaData {
|
||||
Width = file.View.ReadUInt16 (index_pos+8),
|
||||
Height = file.View.ReadUInt16 (index_pos+0xA),
|
||||
BPP = file.View.ReadByte (index_pos+0xE),
|
||||
DataOffset = 0,
|
||||
Compression = file.View.ReadByte (index_pos+0xF),
|
||||
RgbOrder = false,
|
||||
};
|
||||
info.UnpackedSize = info.iWidth * info.iHeight * info.BPP / 8;
|
||||
dir.Add (entry);
|
||||
index_pos += 0x10;
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
public override IImageDecoder OpenImage (ArcFile arc, Entry entry)
|
||||
{
|
||||
var cgent = entry as CgdEntry;
|
||||
var input = arc.File.CreateStream (entry.Offset, entry.Size);
|
||||
if (null == cgent)
|
||||
return ImageFormatDecoder.Create (input);
|
||||
return new CgdDecoder (input, cgent.Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,27 +29,23 @@ using System.IO;
|
||||
using System.Windows.Media;
|
||||
|
||||
// [030228][spiel] The Black Box
|
||||
// [001006][spiel] Koimusubi
|
||||
|
||||
namespace GameRes.Formats.KApp
|
||||
{
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class CgdFormat : ImageFormat
|
||||
public class CgdKToolFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "CGD/KTOOL"; } }
|
||||
public override string Description { get { return "KApp compressed image format"; } }
|
||||
public override uint Signature { get { return 0x6F6F746B; } } // 'ktool210'
|
||||
|
||||
public CgdFormat ()
|
||||
{
|
||||
Signatures = new uint[] { 0x6F6F746B, 0x65697073 };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
var header = file.ReadHeader (0x18);
|
||||
if (header.ToInt32 (8) != 1)
|
||||
return null;
|
||||
if (!header.AsciiEqual ("ktool210") && !header.AsciiEqual ("spiel100"))
|
||||
if (!header.AsciiEqual ("ktool210"))
|
||||
return null;
|
||||
uint offset = header.ToUInt32 (0x10) & 0x7FFFFFFF;
|
||||
return CgdMetaData.FromStream (file, offset);
|
||||
@@ -67,11 +63,50 @@ namespace GameRes.Formats.KApp
|
||||
}
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class CgdSpielFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "CGD/SPIEL"; } }
|
||||
public override string Description { get { return "Spiel compressed image format"; } }
|
||||
public override uint Signature { get { return 0x65697073; } } // 'spiel100'
|
||||
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
var header = file.ReadHeader (0x20);
|
||||
if (header.ToInt32 (8) != 1)
|
||||
return null;
|
||||
if (!header.AsciiEqual ("spiel100"))
|
||||
return null;
|
||||
var info = new CgdMetaData {
|
||||
Width = header.ToUInt16 (0x18),
|
||||
Height = header.ToUInt16 (0x1A),
|
||||
BPP = header[0x1E],
|
||||
DataOffset = header.ToUInt32 (0x10),
|
||||
Compression = header[0x1F],
|
||||
RgbOrder = false,
|
||||
};
|
||||
info.UnpackedSize = info.iWidth * info.iHeight * info.BPP / 8;
|
||||
return info;
|
||||
}
|
||||
|
||||
public override ImageData Read (IBinaryStream file, ImageMetaData info)
|
||||
{
|
||||
var reader = new CgdDecoder (file, (CgdMetaData)info);
|
||||
return reader.Image;
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new System.NotImplementedException ("CgdFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
internal class CgdMetaData : ImageMetaData
|
||||
{
|
||||
public uint DataOffset;
|
||||
public int UnpackedSize;
|
||||
public byte Compression;
|
||||
public bool RgbOrder;
|
||||
|
||||
internal static CgdMetaData FromStream (IBinaryStream file, uint offset)
|
||||
{
|
||||
@@ -93,6 +128,7 @@ namespace GameRes.Formats.KApp
|
||||
DataOffset = offset + 0x10 + header_size,
|
||||
UnpackedSize = unpacked_size,
|
||||
Compression = compression,
|
||||
RgbOrder = bpp == 24,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -261,7 +297,9 @@ namespace GameRes.Formats.KApp
|
||||
m_input.Position = meta.DataOffset;
|
||||
var pixels = new byte[meta.UnpackedSize];
|
||||
KTool.Unpack (m_input, pixels, meta.Compression);
|
||||
PixelFormat format = 24 == meta.BPP ? PixelFormats.Rgb24 : PixelFormats.Bgra32;
|
||||
PixelFormat format = 32 == meta.BPP ? PixelFormats.Bgra32
|
||||
: meta.RgbOrder ? PixelFormats.Rgb24
|
||||
: PixelFormats.Bgr24;
|
||||
return ImageData.Create (meta, format, null, pixels);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user