diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index a98375a3..50faea71 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -86,6 +86,7 @@ + @@ -149,6 +150,7 @@ + diff --git a/ArcFormats/ArcMFG.cs b/ArcFormats/ArcMFG.cs new file mode 100644 index 00000000..cce41920 --- /dev/null +++ b/ArcFormats/ArcMFG.cs @@ -0,0 +1,76 @@ +//! \file ArcMFG.cs +//! \date Wed Apr 29 13:22:31 2015 +//! \brief MFG resourse archives implementation. +// +// Copyright (C) 2015 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 GameRes.Utility; + +namespace GameRes.Formats.Silky +{ + [Export(typeof(ArchiveFormat))] + public class MfgOpener : ArchiveFormat + { + public override string Tag { get { return "MFG"; } } + public override string Description { get { return "Silky's engine resource archive"; } } + public override uint Signature { get { return 0x46504c41; } } // 'ALPF' + public override bool IsHierarchic { get { return false; } } + public override bool CanCreate { get { return false; } } + + public MfgOpener () + { + Extensions = new string[] { "mfg", "mfm", "mfs" }; + } + + public override ArcFile TryOpen (ArcView file) + { + int count = file.View.ReadInt32 (4); + if (count <= 0 || count > 0xfffff) + return null; + var dir = new List (count); + long index_offset = 8; + uint next_offset = file.View.ReadUInt32 (index_offset+0x10); + for (int i = 0; i < count; ++i) + { + string name = file.View.ReadString (index_offset, 0x10); + if (0 == name.Length) + return null; + uint offset = next_offset; + index_offset += 0x14; + if (i+1 != count) + next_offset = file.View.ReadUInt32 (index_offset+0x10); + else + next_offset = (uint)file.MaxOffset; + var entry = AutoEntry.Create (file, offset, name); + entry.Size = next_offset - offset; + if (!entry.CheckPlacement (file.MaxOffset)) + return null; + dir.Add (entry); + } + return new ArcFile (file, this, dir); + } + } +} diff --git a/ArcFormats/ImageMFG.cs b/ArcFormats/ImageMFG.cs new file mode 100644 index 00000000..56000c5c --- /dev/null +++ b/ArcFormats/ImageMFG.cs @@ -0,0 +1,116 @@ +//! \file ImageMFG.cs +//! \date Wed Apr 29 13:47:56 2015 +//! \brief Silky's MFG image format implementation. +// +// Copyright (C) 2015 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.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using GameRes.Utility; + +namespace GameRes.Formats.Silky +{ + internal class MfgMetaData : ImageMetaData + { + public int Type; + public int Stride; + } + + [Export (typeof (ImageFormat))] + public class MfgFormat : ImageFormat + { + public override string Tag { get { return "MFG"; } } + public override string Description { get { return "Silky's RGB image format"; } } + public override uint Signature { get { return 0x5f47464du; } } // 'MFG_' + + public MfgFormat () + { + Signatures = new uint[] { 0x5f47464d, 0x4147464d, 0x4347464d }; // 'MFG_', 'MFGA', 'MFGC' + Extensions = new string[] { "mfp" }; // made-up + } + + public override void Write (Stream file, ImageData image) + { + throw new NotImplementedException ("MfgFormat.Write not implemented"); + } + + public override ImageMetaData ReadMetaData (Stream stream) + { + using (var file = new ArcView.Reader (stream)) + { + stream.Seek (3, SeekOrigin.Current); + byte id = file.ReadByte(); + uint data_size = file.ReadUInt32(); + uint width = file.ReadUInt32(); + uint height = file.ReadUInt32(); + uint stride = file.ReadUInt32(); + if (stride < width) + throw new NotSupportedException(); + if (stride*height != data_size) + return null; + return new MfgMetaData + { + Width = width, + Height = height, + BPP = (int)(stride*8/width), + Type = id, + Stride = (int)stride, + }; + } + } + + public override ImageData Read (Stream stream, ImageMetaData info) + { + var meta = info as MfgMetaData; + if (null == meta) + throw new ArgumentException ("MfgFormat.Read should be supplied with MfgMetaData", "info"); + + stream.Position = 0x14; + if ('_' != meta.Type) + using (var file = new ArcView.Reader (stream)) + { + for (uint i = 0; i < meta.Height; ++i) + { + uint n = file.ReadUInt32(); + file.BaseStream.Seek (n*8, SeekOrigin.Current); + } + } + byte[] pixels = new byte[meta.Stride*info.Height]; + if (pixels.Length != stream.Read (pixels, 0, pixels.Length)) + throw new InvalidFormatException ("Unexpected end of file"); + PixelFormat format; + if (24 == meta.BPP) + format = PixelFormats.Bgr24; + else + format = PixelFormats.Bgra32; + var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96, + format, null, pixels, meta.Stride); + bitmap.Freeze(); + return new ImageData (bitmap, info); + } + } +} diff --git a/ArcFormats/Properties/AssemblyInfo.cs b/ArcFormats/Properties/AssemblyInfo.cs index 762fb631..28ba47e2 100644 --- a/ArcFormats/Properties/AssemblyInfo.cs +++ b/ArcFormats/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion ("1.0.4.43")] -[assembly: AssemblyFileVersion ("1.0.4.43")] +[assembly: AssemblyVersion ("1.0.4.44")] +[assembly: AssemblyFileVersion ("1.0.4.44")]