mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-27 07:34:00 +08:00
implemented Will co. engine resources.
This commit is contained in:
parent
6736819db1
commit
56d2a45d94
@ -67,6 +67,7 @@
|
||||
<Compile Include="ArcPD.cs" />
|
||||
<Compile Include="ArcRPA.cs" />
|
||||
<Compile Include="ArcSteinsGate.cs" />
|
||||
<Compile Include="ArcWILL.cs" />
|
||||
<Compile Include="ArcXFL.cs" />
|
||||
<Compile Include="ArcXP3.cs" />
|
||||
<Compile Include="ArcYPF.cs" />
|
||||
@ -103,6 +104,7 @@
|
||||
<Compile Include="ImageRCT.cs" />
|
||||
<Compile Include="ImageTLG.cs" />
|
||||
<Compile Include="ImageWCG.cs" />
|
||||
<Compile Include="ImageWIP.cs" />
|
||||
<Compile Include="KiriKiriCx.cs" />
|
||||
<Compile Include="KogadoCocotte.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@ -215,6 +217,9 @@
|
||||
<EmbeddedResource Include="Strings\arcStrings.ru-RU.resx" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>perl "$(SolutionDir)inc-revision.pl" "$(ProjectPath)" $(ConfigurationName)</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
96
ArcFormats/ArcWILL.cs
Normal file
96
ArcFormats/ArcWILL.cs
Normal file
@ -0,0 +1,96 @@
|
||||
//! \file ArcWILL.cs
|
||||
//! \date Fri Oct 31 13:37:11 2014
|
||||
//! \brief ARC archive format implementation.
|
||||
//
|
||||
// Copyright (C) 2014 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;
|
||||
|
||||
namespace GameRes.Formats.Will
|
||||
{
|
||||
internal class ExtRecord
|
||||
{
|
||||
public string Extension;
|
||||
public int FileCount;
|
||||
public uint DirOffset;
|
||||
}
|
||||
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class ArcOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "ARC"; } }
|
||||
public override string Description { get { return "Will Co. game engine resource archive"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanCreate { get { return false; } }
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
int ext_count = file.View.ReadInt32 (0);
|
||||
if (ext_count <= 0 || ext_count > 0xff)
|
||||
return null;
|
||||
|
||||
uint dir_offset = 4;
|
||||
var ext_list = new List<ExtRecord> (ext_count);
|
||||
int file_count = 0;
|
||||
for (int i = 0; i < ext_count; ++i)
|
||||
{
|
||||
string ext = file.View.ReadString (dir_offset, 4).ToLowerInvariant();
|
||||
int count = file.View.ReadInt32 (dir_offset+4);
|
||||
uint offset = file.View.ReadUInt32 (dir_offset+8);
|
||||
if (count <= 0 || count > 0xffff || offset <= dir_offset)
|
||||
return null;
|
||||
ext_list.Add (new ExtRecord { Extension = ext, FileCount = count, DirOffset = offset });
|
||||
file_count += count;
|
||||
dir_offset += 12;
|
||||
}
|
||||
var dir = ReadFileList (file, ext_list, 9);
|
||||
if (null == dir)
|
||||
dir = ReadFileList (file, ext_list, 13);
|
||||
if (null == dir)
|
||||
return null;
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
List<Entry> ReadFileList (ArcView file, IEnumerable<ExtRecord> ext_list, uint name_size)
|
||||
{
|
||||
var dir = new List<Entry>();
|
||||
foreach (var ext in ext_list)
|
||||
{
|
||||
uint dir_offset = ext.DirOffset;
|
||||
for (int i = 0; i < ext.FileCount; ++i)
|
||||
{
|
||||
string name = file.View.ReadString (dir_offset, name_size).ToLowerInvariant()+'.'+ext.Extension;
|
||||
var entry = FormatCatalog.Instance.CreateEntry (name);
|
||||
entry.Size = file.View.ReadUInt32 (dir_offset+name_size);
|
||||
entry.Offset = file.View.ReadUInt32 (dir_offset+name_size+4);
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
dir_offset += name_size+8;
|
||||
}
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
}
|
230
ArcFormats/ImageWIP.cs
Normal file
230
ArcFormats/ImageWIP.cs
Normal file
@ -0,0 +1,230 @@
|
||||
//! \file ImageWIP.cs
|
||||
//! \date Fri Oct 31 14:52:49 2014
|
||||
//! \brief Will image format implementation.
|
||||
//
|
||||
// Copyright (C) 2014 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.IO;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace GameRes.Formats.Will
|
||||
{
|
||||
internal class WipMetaData : ImageMetaData
|
||||
{
|
||||
public int FrameCount;
|
||||
public uint FrameSize;
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class WipFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "WIP"; } }
|
||||
public override string Description { get { return "Will Co. image format"; } }
|
||||
public override uint Signature { get { return 0x46504957u; } } // 'WIPF'
|
||||
|
||||
public WipFormat ()
|
||||
{
|
||||
Extensions = new string[] { "wip", "msk" };
|
||||
}
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
{
|
||||
using (var file = new BinaryReader (stream, Encoding.ASCII, true))
|
||||
{
|
||||
if (Signature != file.ReadUInt32())
|
||||
return null;
|
||||
int frames = file.ReadUInt16();
|
||||
int bpp = file.ReadUInt16();
|
||||
uint width = file.ReadUInt32();
|
||||
uint height = file.ReadUInt32();
|
||||
int x = file.ReadInt32();
|
||||
int y = file.ReadInt32();
|
||||
file.ReadUInt32(); // 0
|
||||
uint frame_size = file.ReadUInt32();
|
||||
if (24 != bpp && 8 != bpp)
|
||||
{
|
||||
Trace.WriteLine ("unsupported bpp", "WipFormat");
|
||||
return null;
|
||||
}
|
||||
if (frames > 1)
|
||||
Trace.WriteLine ("Extra frames ignored", "WipFormat");
|
||||
return new WipMetaData
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
OffsetX = x,
|
||||
OffsetY = y,
|
||||
BPP = bpp,
|
||||
FrameCount = frames,
|
||||
FrameSize = frame_size,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new NotImplementedException ("WipFormat.Write not implemented");
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream file, ImageMetaData info)
|
||||
{
|
||||
var meta = info as WipMetaData;
|
||||
if (null == meta)
|
||||
throw new ArgumentException ("WipFormat.Read should be supplied with WipMetaData", "info");
|
||||
file.Position = 8 + 24 * meta.FrameCount;
|
||||
Color[] palette = null;
|
||||
if (8 == meta.BPP)
|
||||
{
|
||||
var palette_data = new byte[0x400];
|
||||
if (palette_data.Length != file.Read (palette_data, 0, palette_data.Length))
|
||||
throw new InvalidFormatException();
|
||||
palette = new Color[0x100];
|
||||
for (int i = 0; i < 0x100; ++i)
|
||||
{
|
||||
palette[i] = Color.FromRgb (palette_data[i*4], palette_data[i*4+1], palette_data[i*4+2]);
|
||||
}
|
||||
}
|
||||
using (var reader = new Reader (file, meta))
|
||||
{
|
||||
reader.Unpack();
|
||||
BitmapSource bitmap;
|
||||
if (24 == meta.BPP)
|
||||
{
|
||||
byte[] raw = reader.Data;
|
||||
int size = (int)meta.Width * (int)meta.Height;
|
||||
byte[] pixels = new byte[size*3];
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
pixels[i*3] = raw[i];
|
||||
pixels[i*3+1] = raw[i+size];
|
||||
pixels[i*3+2] = raw[i+size*2];
|
||||
}
|
||||
bitmap = BitmapSource.Create ((int)meta.Width, (int)meta.Height, 96, 96,
|
||||
PixelFormats.Bgr24, null, pixels, (int)meta.Width*3);
|
||||
}
|
||||
else if (8 == meta.BPP)
|
||||
{
|
||||
byte[] pixels = reader.Data;
|
||||
bitmap = BitmapSource.Create ((int)meta.Width, (int)meta.Height, 96, 96,
|
||||
PixelFormats.Indexed8, new BitmapPalette (palette), pixels, (int)meta.Width);
|
||||
}
|
||||
else
|
||||
throw new InvalidFormatException();
|
||||
bitmap.Freeze();
|
||||
return new ImageData (bitmap, meta);
|
||||
}
|
||||
}
|
||||
|
||||
internal class Reader : IDisposable
|
||||
{
|
||||
private BinaryReader m_input;
|
||||
private uint m_length;
|
||||
private byte[] m_data;
|
||||
|
||||
public byte[] Data { get { return m_data; } }
|
||||
|
||||
public Reader (Stream file, WipMetaData info)
|
||||
{
|
||||
m_length = info.FrameSize;
|
||||
// int stride = (int)info.Width*((info.BPP+7)/8);
|
||||
int stride = (int)info.Width*4;
|
||||
m_data = new byte[stride * (int)info.Height];
|
||||
m_input = new BinaryReader (file, Encoding.ASCII, true);
|
||||
}
|
||||
|
||||
private byte[] m_window = new byte[0x1000];
|
||||
|
||||
public void Unpack ()
|
||||
{
|
||||
int current = 0;
|
||||
int window_index = 1;
|
||||
int control = 0;
|
||||
byte input = 0;
|
||||
for (uint length = m_length; length > 0; )
|
||||
{
|
||||
control >>= 1;
|
||||
if (0 == (control & 0x100))
|
||||
{
|
||||
input = m_input.ReadByte();
|
||||
--length;
|
||||
control = input | 0xff00;
|
||||
}
|
||||
if (0 != (control & 1))
|
||||
{
|
||||
if (length < 1)
|
||||
throw new InvalidFormatException();
|
||||
input = m_input.ReadByte();
|
||||
--length;
|
||||
m_data[current++] = input;
|
||||
m_window[window_index++] = input;
|
||||
window_index &= 0xfff;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (length < 2)
|
||||
throw new InvalidFormatException();
|
||||
int di = m_input.ReadByte();
|
||||
input = m_input.ReadByte();
|
||||
length -= 2;
|
||||
int offset = ((di << 8) | input) >> 4;
|
||||
int count = (input & 0xf) + 2;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
int src = (i + offset) & 0xfff;
|
||||
input = m_window[src];
|
||||
m_data[current++] = input;
|
||||
m_window[window_index++] = input;
|
||||
window_index &= 0xfff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
bool disposed = false;
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
Dispose (true);
|
||||
GC.SuppressFinalize (this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose (bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if (disposing)
|
||||
m_input.Dispose();
|
||||
m_input = null;
|
||||
m_data = null;
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user