(Legacy): updated bunch of formats.

This commit is contained in:
morkt
2020-03-30 17:25:15 +04:00
parent 8ad1c652c6
commit 1dfa1482b9
16 changed files with 1130 additions and 25 deletions

70
Legacy/Artel/ArcPFD.cs Normal file
View File

@@ -0,0 +1,70 @@
//! \file ArcPFD.cs
//! \date 2019 May 22
//! \brief ADVG Script Interpreter System resource archive.
//
// Copyright (C) 2019 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;
// [060127][Artel] Horizont
namespace GameRes.Formats.Artel
{
[Export(typeof(ArchiveFormat))]
public class PfdOpener : ArchiveFormat
{
public override string Tag { get { return "PFD"; } }
public override string Description { get { return "Artel ADVG engine 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)
{
int count = file.View.ReadInt32 (0);
if (!IsSaneCount (count))
return null;
int index_offset = 4;
int data_offset = index_offset + count * 0x20;
var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i)
{
var name = file.View.ReadString (index_offset, 0x15);
if (string.IsNullOrEmpty (name))
return null;
var ext = file.View.ReadString (index_offset+0x15, 3);
if (!string.IsNullOrEmpty (ext))
name = Path.ChangeExtension (name, ext);
var entry = Create<Entry> (name);
entry.Offset = file.View.ReadUInt32 (index_offset+0x18);
entry.Size = file.View.ReadUInt32 (index_offset+0x1C);
if (entry.Offset < data_offset || !entry.CheckPlacement (file.MaxOffset))
return null;
dir.Add (entry);
index_offset += 0x20;
}
return new ArcFile (file, this, dir);
}
}
}

60
Legacy/Artel/AudioMUW.cs Normal file
View File

@@ -0,0 +1,60 @@
//! \file AudioMUW.cs
//! \date 2019 May 22
//! \brief ADVG Script Interpreter System audio file.
//
// Copyright (C) 2019 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;
namespace GameRes.Formats.Artel
{
[Export(typeof(AudioFormat))]
public class MuwAudio : AudioFormat
{
public override string Tag { get { return "MUW"; } }
public override string Description { get { return "Artel ADVG engine audio file"; } }
public override uint Signature { get { return 0x46464952; } } // 'RIFF'
public override bool CanWrite { get { return false; } }
public override SoundInput TryOpen (IBinaryStream file)
{
var header = file.ReadHeader (0x24);
if (!header.AsciiEqual (0, "RIFF") || !header.AsciiEqual (8, "PCMWFMT "))
return null;
uint data_pos = header.ToUInt32 (0x10) + 0x14;
file.Position = data_pos;
if (file.ReadUInt32() != 0x61746164) // 'data'
return null;
uint data_size = file.ReadUInt32();
var format = new WaveFormat {
FormatTag = header.ToUInt16 (0x14),
Channels = header.ToUInt16 (0x16),
SamplesPerSecond = header.ToUInt32 (0x18),
AverageBytesPerSecond = header.ToUInt32 (0x1C),
BlockAlign = header.ToUInt16 (0x20),
BitsPerSample = header.ToUInt16 (0x22),
};
var pcm = new StreamRegion (file.AsStream, data_pos+8, data_size);
return new RawPcmInput (pcm, format);
}
}
}

165
Legacy/Artel/ImageMRL.cs Normal file
View File

@@ -0,0 +1,165 @@
//! \file ImageMRL.cs
//! \date 2019 May 22
//! \brief ADVG Script Interpreter System image format.
//
// Copyright (C) 2019 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;
namespace GameRes.Formats.Artel
{
internal class MrlMetaData : ImageMetaData
{
public bool HasAlpha;
}
[Export(typeof(ImageFormat))]
public class MrlFormat : ImageFormat
{
public override string Tag { get { return "MRL"; } }
public override string Description { get { return "Artel ADVG engine image format"; } }
public override uint Signature { get { return 0x524D754D; } } // 'MuMRL'
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
var header = file.ReadHeader (0x18);
if (header[4] != 'L')
return null;
int bpp = header.ToUInt16 (0xC) * 8;
bool has_alpha = (header[8] & 8) != 0;
if (24 == bpp && has_alpha)
bpp = 32;
return new MrlMetaData {
Width = header.ToUInt32 (0x10),
Height = header.ToUInt32 (0x14),
BPP = bpp,
HasAlpha = has_alpha,
};
}
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
var meta = (MrlMetaData)info;
BitmapPalette palette = null;
file.Position = 0x18;
if (8 == info.BPP)
palette = ReadPalette (file.AsStream);
int stride = info.iWidth * (info.BPP / 8);
int channel_size = info.iWidth * info.iHeight;
var pixels = new byte[stride * info.iHeight];
var input_length = (int)(file.Length - file.Position);
var input = file.ReadBytes (input_length);
DecryptInput (input, 8);
MrlDecompress (input, pixels);
RestoreOutput (pixels);
byte[] image;
if (8 == info.BPP)
{
if (!meta.HasAlpha)
return ImageData.CreateFlipped (info, PixelFormats.Indexed8, palette, pixels, stride);
stride = info.iWidth * 4;
image = new byte[stride * info.iHeight];
int src = 0;
int asrc = channel_size;
var colors = palette.Colors;
for (int dst = 0; dst < image.Length; dst += 4)
{
byte c = pixels[src++];
image[dst ] = colors[c].B;
image[dst+1] = colors[c].G;
image[dst+2] = colors[c].R;
image[dst+3] = pixels[asrc++];
}
}
else
{
image = new byte[pixels.Length];
int channels = info.BPP / 8;
int src = 0;
for (int c = 0; c < channels; ++c)
{
int dst = c;
for (int i = 0; i < channel_size; ++i)
{
image[dst] = pixels[src++];
dst += channels;
}
}
}
PixelFormat format = meta.HasAlpha ? PixelFormats.Bgra32 : PixelFormats.Bgr24;
return ImageData.CreateFlipped (info, format, palette, image, stride);
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("MrlFormat.Write not implemented");
}
internal static void DecryptInput (byte[] data, byte key)
{
for (int i = 0; i < data.Length; ++i)
{
data[i] ^= key++;
}
}
internal static void MrlDecompress (byte[] input, byte[] output)
{
int src = 0;
int dst = 0;
while (src < input.Length && dst < output.Length)
{
byte p = input[src++];
if (p != 0)
{
output[dst++] = p;
}
else
{
int count = 1;
do
{
p = input[src++];
count += p;
}
while (0xFF == p);
dst += count;
}
}
}
internal static void RestoreOutput (byte[] data)
{
byte key = data[0];
for (int i = 1; i < data.Length; ++i)
{
data[i] ^= key;
key = data[i];
}
}
}
}