reorganized project directory structure.

This commit is contained in:
morkt
2015-08-19 21:40:32 +04:00
parent dd2c19c8c1
commit b05c253e8b
178 changed files with 6029 additions and 6016 deletions

View File

@@ -0,0 +1,85 @@
//! \file ArcIFL.cs
//! \date Sun Apr 12 20:47:04 2015
//! \brief IFLS archive 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.Compression;
using GameRes.Utility;
namespace GameRes.Formats.Silky
{
[Export(typeof(ArchiveFormat))]
public class IflOpener : ArchiveFormat
{
public override string Tag { get { return "IFL"; } }
public override string Description { get { return "Silky's engine resource archive"; } }
public override uint Signature { get { return 0x534c4649; } } // 'IFLS'
public override bool IsHierarchic { get { return false; } }
public override bool CanCreate { get { return false; } }
public override ArcFile TryOpen (ArcView file)
{
uint data_offset = file.View.ReadUInt32 (4);
int count = file.View.ReadInt32 (8);
if (data_offset <= 12 || data_offset >= file.MaxOffset
|| count <= 0 || count > 0xfffff)
return null;
var dir = new List<Entry> (count);
long index_offset = 12;
for (int i = 0; i < count; ++i)
{
string name = file.View.ReadString (index_offset, 0x10);
if (0 == name.Length)
return null;
var entry = FormatCatalog.Instance.CreateEntry (name);
entry.Offset = file.View.ReadUInt32 (index_offset+0x10);
entry.Size = file.View.ReadUInt32 (index_offset+0x14);
if (!entry.CheckPlacement (file.MaxOffset))
return null;
dir.Add (entry);
index_offset += 0x18;
}
return new ArcFile (file, this, dir);
}
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
if (entry.Size <= 8
|| !entry.Name.EndsWith (".snc", StringComparison.InvariantCultureIgnoreCase)
|| !arc.File.View.AsciiEqual (entry.Offset, "CMP_"))
return arc.File.CreateStream (entry.Offset, entry.Size);
int unpacked_size = arc.File.View.ReadInt32 (entry.Offset+4);
using (var input = arc.File.CreateStream (entry.Offset+8, entry.Size-8))
using (var lzss = new LzssReader (input, (int)(entry.Size - 8), unpacked_size))
{
lzss.FrameFill = 0x20;
lzss.Unpack();
return new MemoryStream (lzss.Data);
}
}
}
}

View File

@@ -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<Entry> (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);
}
}
}

View File

@@ -0,0 +1,176 @@
//! \file ImageGRD.cs
//! \date Sun Apr 12 21:05:44 2015
//! \brief Silky's GRD image format.
//
// 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.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GameRes.Utility;
namespace GameRes.Formats.Silky
{
internal class GrdMetaData : ImageMetaData
{
public int DataSize;
}
[Export(typeof(ImageFormat))]
public class GrdFormat : ImageFormat
{
public override string Tag { get { return "GRD"; } }
public override string Description { get { return "Silky's RGB image format"; } }
public override uint Signature { get { return 0x5f504d43u; } } // 'CMP_'
public override void Write (Stream file, ImageData image)
{
throw new NotImplementedException ("GrdFormat.Write not implemented");
}
public override ImageMetaData ReadMetaData (Stream stream)
{
stream.Seek (4, SeekOrigin.Current);
int data_size = stream.ReadByte() | stream.ReadByte() << 8 | stream.ReadByte() << 16 | stream.ReadByte() << 24;
stream.Seek (4, SeekOrigin.Current);
using (var reader = new Reader (stream, 0x22)) // BMP header
{
reader.Unpack();
var bmp = reader.Data;
if (bmp[0] != 'B' || bmp[1] != 'M')
return null;
int width = LittleEndian.ToInt32 (bmp, 0x12);
int height = LittleEndian.ToInt32 (bmp, 0x16);
int bpp = LittleEndian.ToInt16 (bmp, 0x1c);
return new GrdMetaData
{
Width = (uint)width,
Height = (uint)height,
BPP = bpp,
DataSize = data_size,
};
}
}
public override ImageData Read (Stream stream, ImageMetaData info)
{
var meta = info as GrdMetaData;
if (null == meta)
throw new ArgumentException ("GrdFormat.Read should be supplied with GrdMetaData", "info");
stream.Position = 12;
using (var reader = new Reader (stream, meta.DataSize))
{
reader.Unpack();
byte[] pixels = reader.Data;
using (var bmp = new MemoryStream (reader.Data, false))
{
var decoder = new BmpBitmapDecoder (bmp,
BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
BitmapSource frame = decoder.Frames[0];
frame.Freeze();
return new ImageData (frame, info);
}
}
}
}
// custom LZSS reader
//
internal class Reader : IDisposable
{
Stream m_input;
byte[] m_output;
public byte[] Data { get { return m_output; } }
public Reader (Stream file, int dst_size)
{
m_input = file;
m_output = new byte[dst_size];
}
public void Unpack ()
{
var frame = new byte[0x1000];
int frame_pos = 0xfee;
for (int i = 0; i < frame_pos; ++i)
frame[i] = 32;
int ctl = 0;
int dst = 0;
while (dst < m_output.Length)
{
ctl >>= 1;
if (0 == (ctl & 0x100))
{
int b = m_input.ReadByte();
if (-1 == b)
break;
ctl = b | 0xff00;
}
if (0 != (ctl & 1))
{
int b = m_input.ReadByte();
if (-1 == b)
break;
m_output[dst++] = (byte)b;
frame[frame_pos++] = (byte)b;
frame_pos &= 0xfff;
}
else
{
int lo = m_input.ReadByte();
if (-1 == lo)
break;
int hi = m_input.ReadByte();
if (-1 == hi)
break;
int offset = (hi & 0xF0) << 4 | lo;
int count = (hi & 0xF) + 3;
for (int i = 0; i < count && dst < m_output.Length; ++i)
{
byte b = frame[(offset + i) & 0xfff];
m_output[dst++] = b;
frame[frame_pos++] = b;
frame_pos &= 0xfff;
}
}
}
}
#region IDisposable Members
public void Dispose ()
{
if (null != m_input)
{
m_input = null;
}
GC.SuppressFinalize (this);
}
#endregion
}
}

View File

@@ -0,0 +1,115 @@
//! \file ImageIGF.cs
//! \date Sun Jun 28 00:13:01 2015
//! \brief Silky's compressed image format.
//
// 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.ComponentModel.Composition;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GameRes.Compression;
using GameRes.Utility;
namespace GameRes.Formats.Silky
{
internal class IgfMetaData : ImageMetaData
{
public int UnpackedSize;
public bool IsPacked;
}
[Export(typeof(ImageFormat))]
public class IgfFormat : ImageFormat
{
public override string Tag { get { return "IGF"; } }
public override string Description { get { return "Silky's image format"; } }
public override uint Signature { get { return 0x5355455Au; } } // 'ZEUS'
public override ImageMetaData ReadMetaData (Stream stream)
{
var header = new byte[0x14];
if (header.Length != stream.Read (header, 0, header.Length))
return null;
uint width = LittleEndian.ToUInt32 (header, 4);
uint height = LittleEndian.ToUInt32 (header, 8);
int unpacked_size = LittleEndian.ToInt32 (header, 0xC);
int flags = LittleEndian.ToInt32 (header, 0x10);
int bpp = flags & 0xff;
if (0 == bpp)
bpp = 32;
return new IgfMetaData
{
Width = width,
Height = height,
BPP = bpp,
UnpackedSize = unpacked_size,
IsPacked = 0 != (flags & 0x80000000),
};
}
public override ImageData Read (Stream stream, ImageMetaData info)
{
var meta = info as IgfMetaData;
if (null == meta)
throw new ArgumentException ("IgfFormat.Read should be supplied with IgfMetaData", "info");
int stride = (int)info.Width*info.BPP/8;
stream.Position = 0x14;
byte[] pixels;
if (meta.IsPacked)
{
int in_size = (int)(stream.Length - 0x14);
using (var lzss = new LzssReader (stream, in_size, meta.UnpackedSize))
{
lzss.FrameFill = 0x20;
lzss.Unpack();
pixels = lzss.Data;
}
}
else
{
pixels = new byte[info.Height*stride];
if (pixels.Length != stream.Read (pixels, 0, pixels.Length))
throw new InvalidFormatException ("Unexpected end of file");
}
PixelFormat format;
if (24 == info.BPP)
format = PixelFormats.Bgr24;
else if (32 == info.BPP)
format = PixelFormats.Bgra32;
else
format = PixelFormats.Gray8;
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height,
ImageData.DefaultDpiX, ImageData.DefaultDpiY, format, null, pixels, stride);
var flipped = new TransformedBitmap (bitmap, new ScaleTransform { ScaleY = -1 });
flipped.Freeze();
return new ImageData (flipped, info);
}
public override void Write (Stream file, ImageData image)
{
throw new NotImplementedException ("IgfFormat.Write not implemented");
}
}
}

View File

@@ -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);
}
}
}