mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-02 03:10:26 +08:00
reorganized project directory structure.
This commit is contained in:
233
ArcFormats/Dac/ArcDPK.cs
Normal file
233
ArcFormats/Dac/ArcDPK.cs
Normal file
@@ -0,0 +1,233 @@
|
||||
//! \file ArcDPK.cs
|
||||
//! \date Mon Jun 01 13:29:09 2015
|
||||
//! \brief DPK archive
|
||||
//
|
||||
// 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.Globalization;
|
||||
using System.IO;
|
||||
using GameRes.Formats.Properties;
|
||||
using GameRes.Formats.Strings;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Dac
|
||||
{
|
||||
internal class DpkOptions : ResourceOptions
|
||||
{
|
||||
public uint Key1;
|
||||
public uint Key2;
|
||||
}
|
||||
|
||||
public class DpkScheme
|
||||
{
|
||||
public uint Key1 { get; set; }
|
||||
public uint Key2 { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string OriginalTitle { get; set; }
|
||||
}
|
||||
|
||||
internal class DpkEntry : Entry
|
||||
{
|
||||
public uint Hash;
|
||||
}
|
||||
|
||||
internal class DpkArchive : ArcFile
|
||||
{
|
||||
public readonly uint Key1;
|
||||
public readonly uint Key2;
|
||||
|
||||
public DpkArchive (ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, DpkOptions opt)
|
||||
: base (arc, impl, dir)
|
||||
{
|
||||
Key1 = opt.Key1;
|
||||
Key2 = opt.Key2;
|
||||
}
|
||||
}
|
||||
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class DpkOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "DPK"; } }
|
||||
public override string Description { get { return "DAC engine resource archive"; } }
|
||||
public override uint Signature { get { return 0x004b5044; } } // 'DPK'
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanCreate { get { return false; } }
|
||||
|
||||
public static readonly DpkScheme[] KnownSchemes = new DpkScheme[]
|
||||
{
|
||||
new DpkScheme { Key1 = 0x0FF98, Name = arcStrings.ArcDefault,
|
||||
Key2 = 0x43E78A5C },
|
||||
new DpkScheme { Key1 = 0x0C3BD, Name = "Inbou no Wakusei",
|
||||
Key2 = 0x577D4861, OriginalTitle = "淫暴の惑星~破壊と欲望の衝動~" },
|
||||
new DpkScheme { Key1 = 0x04D49, Name = "Ryoshuu",
|
||||
Key2 = 0x39712FED, OriginalTitle = "虜囚 -RYOSYU-" },
|
||||
new DpkScheme { Key1 = 0x11EAF, Name = "Ryobaku ~Haitoku no Atelier~",
|
||||
Key2 = 0xB9976112, OriginalTitle = "虜縛~背徳のアトリエ~" },
|
||||
new DpkScheme { Key1 = 0x0527F, Name = "Ryoshuu ~Jogakusei Choukyou~",
|
||||
Key2 = 0x339B266F, OriginalTitle = "虜讐~女学生調教~" },
|
||||
new DpkScheme { Key1 = 0x0946E, Name = "Shirogane no Cal to Soukuu no Joou",
|
||||
Key2 = 0xB1956783, OriginalTitle = "白銀のカルと蒼空の女王" },
|
||||
new DpkScheme { Key1 = 0x0BB51, Name = "Shiromiko",
|
||||
Key2 = 0x891F52A3, OriginalTitle = "白神子 ~しろみこ~" },
|
||||
new DpkScheme { Key1 = 0x09F59, Name = "Shoujotachi no Saezuri",
|
||||
Key2 = 0x5DDE9B8D, OriginalTitle = "少女達のさえずり" },
|
||||
new DpkScheme { Key1 = 0x0583F, Name = "Yumemiru Tsuki no Lunalutia",
|
||||
Key2 = 0xB81031D7, OriginalTitle = "夢みる月のルナルティア" },
|
||||
};
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
var header = new byte[8];
|
||||
if (8 != file.View.Read (8, header, 0, 8))
|
||||
return null;
|
||||
byte last = header[7];
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
header[i] ^= (byte)(i - 8);
|
||||
}
|
||||
int data_offset = LittleEndian.ToInt32 (header, 0);
|
||||
if (data_offset <= 16 || data_offset >= file.MaxOffset)
|
||||
return null;
|
||||
int index_length = data_offset - 16;
|
||||
var index = new byte[index_length];
|
||||
if (index_length != file.View.Read (16, index, 0, (uint)index_length))
|
||||
return null;
|
||||
DecryptIndex (index, 16, index_length, last);
|
||||
int count = LittleEndian.ToInt32 (index, 0);
|
||||
if (count <= 0 || count > 0xfffff)
|
||||
return null;
|
||||
|
||||
var options = Query<DpkOptions> (arcStrings.ArcEncryptedNotice);
|
||||
var name_bytes = new byte[0x20];
|
||||
var dir = new List<Entry> (count);
|
||||
int base_offset = 4 + count * 4;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
var index_offset = base_offset + LittleEndian.ToInt32 (index, 4+i*4);
|
||||
int name_begin = index_offset+0x0c;
|
||||
int name_end = Array.IndexOf (index, (byte)0, name_begin);
|
||||
if (-1 == name_end)
|
||||
name_end = index.Length;
|
||||
if (name_end == name_begin)
|
||||
continue;
|
||||
if ('z' == index[name_end-1])
|
||||
--name_end; // strip 'z' from file extensions
|
||||
|
||||
int name_length = name_end - name_begin;
|
||||
var name = Encodings.cp932.GetString (index, name_begin, name_length);
|
||||
if (name_length > name_bytes.Length)
|
||||
name_bytes = new byte[name_length];
|
||||
// shift-jis characters sequence may contain '\\' that is not a path delimiter
|
||||
string name_base = Path.GetFileName (name);
|
||||
name_length = Encodings.cp932.GetBytes (name_base, 0, name_base.Length, name_bytes, 0);
|
||||
|
||||
uint size = LittleEndian.ToUInt32 (index, index_offset + 4);
|
||||
var entry = new DpkEntry
|
||||
{
|
||||
Name = name,
|
||||
Type = FormatCatalog.Instance.GetTypeFromName (name),
|
||||
Hash = GetNameHash (name_bytes, 0, name_length, options.Key1, options.Key2, size),
|
||||
Offset = data_offset + LittleEndian.ToUInt32 (index, index_offset),
|
||||
Size = size,
|
||||
};
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
}
|
||||
if (0 == dir.Count)
|
||||
return null;
|
||||
return new DpkArchive (file, this, dir, options);
|
||||
}
|
||||
|
||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||
{
|
||||
var parc = arc as DpkArchive;
|
||||
var pentry = entry as DpkEntry;
|
||||
if (null == parc || null == pentry)
|
||||
return arc.File.CreateStream (entry.Offset, entry.Size);
|
||||
var data = new byte[entry.Size];
|
||||
arc.File.View.Read (entry.Offset, data, 0, entry.Size);
|
||||
DecryptEntry (data, parc.Key1, parc.Key2, pentry);
|
||||
return new MemoryStream (data);
|
||||
}
|
||||
|
||||
private void DecryptIndex (byte[] buf, int base_offset, int length, byte last)
|
||||
{
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int key = base_offset + i + last;
|
||||
last = buf[i];
|
||||
buf[i] ^= (byte)key;
|
||||
}
|
||||
}
|
||||
|
||||
private void DecryptEntry (byte[] data, uint key1, uint key2, DpkEntry entry)
|
||||
{
|
||||
for (uint i = 0; i < data.Length; ++i)
|
||||
{
|
||||
data[i] ^= (byte)(key1 + (key1 >> 8));
|
||||
data[i] -= (byte)entry.Hash;
|
||||
key1 += key2;
|
||||
}
|
||||
}
|
||||
|
||||
private uint GetNameHash (byte[] name, int begin, int length, uint key1, uint key2, uint entry_size)
|
||||
{
|
||||
uint hash = 0;
|
||||
for (int i = begin+length-1; i >= begin; --i)
|
||||
{
|
||||
hash += key1 + key2 * (entry_size + name[i]);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override ResourceOptions GetDefaultOptions ()
|
||||
{
|
||||
return new DpkOptions {
|
||||
Key1 = Settings.Default.DPKKey1,
|
||||
Key2 = Settings.Default.DPKKey2,
|
||||
};
|
||||
}
|
||||
|
||||
public override ResourceOptions GetOptions (object w)
|
||||
{
|
||||
var widget = w as GUI.WidgetDPK;
|
||||
if (null != widget)
|
||||
{
|
||||
uint result_key;
|
||||
if (uint.TryParse (widget.Key1.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result_key))
|
||||
Settings.Default.DPKKey1 = result_key;
|
||||
if (uint.TryParse (widget.Key2.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result_key))
|
||||
Settings.Default.DPKKey2 = result_key;
|
||||
}
|
||||
return this.GetDefaultOptions();
|
||||
}
|
||||
|
||||
public override object GetAccessWidget ()
|
||||
{
|
||||
return new GUI.WidgetDPK();
|
||||
}
|
||||
}
|
||||
}
|
||||
504
ArcFormats/Dac/ImageDGC.cs
Normal file
504
ArcFormats/Dac/ImageDGC.cs
Normal file
@@ -0,0 +1,504 @@
|
||||
//! \file ImageDGC.cs
|
||||
//! \date Tue Jun 02 03:24:27 2015
|
||||
//! \brief DAC engine 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 GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.Dac
|
||||
{
|
||||
internal class DgcMetaData : ImageMetaData
|
||||
{
|
||||
public uint Flags;
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class DgcFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "DGC"; } }
|
||||
public override string Description { get { return "DAC engine image format"; } }
|
||||
public override uint Signature { get { return 0x00434744; } } // 'DGC'
|
||||
|
||||
public override ImageMetaData ReadMetaData (Stream stream)
|
||||
{
|
||||
using (var input = new ArcView.Reader (stream))
|
||||
{
|
||||
input.ReadInt32();
|
||||
var info = new DgcMetaData();
|
||||
info.Flags = input.ReadUInt32();
|
||||
info.Width = input.ReadUInt16();
|
||||
info.Height = input.ReadUInt16();
|
||||
if (info.Width > 0x7fff || info.Height > 0x7fff)
|
||||
return null;
|
||||
info.BPP = 0 == (info.Flags & Reader.FlagAlphaChannel) ? 24 : 32;
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
public override ImageData Read (Stream stream, ImageMetaData info)
|
||||
{
|
||||
var meta = info as DgcMetaData;
|
||||
if (null == meta)
|
||||
throw new ArgumentException ("DgcFormat.Read should be supplied with DgcMetaData", "info");
|
||||
|
||||
stream.Position = 12;
|
||||
using (var reader = new Reader (stream, meta))
|
||||
{
|
||||
reader.Unpack();
|
||||
return ImageData.Create (info, reader.Format, null, reader.Data);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new System.NotImplementedException ("DgcFormat.Write not implemented");
|
||||
}
|
||||
|
||||
internal class Reader : IDataUnpacker, IDisposable
|
||||
{
|
||||
BinaryReader m_input;
|
||||
byte[] m_output;
|
||||
readonly int m_width;
|
||||
readonly int m_height;
|
||||
readonly int m_max_dict_size;
|
||||
readonly int m_pixel_size;
|
||||
readonly int m_stride;
|
||||
readonly bool m_use_dict;
|
||||
readonly bool m_has_alpha;
|
||||
|
||||
public const int FlagAlphaChannel = 0x4000000;
|
||||
public const int FlagUseDictionary = 0x2000000;
|
||||
|
||||
public byte[] Data { get { return m_output; } }
|
||||
public PixelFormat Format { get; private set; }
|
||||
|
||||
public Reader (Stream input, DgcMetaData info)
|
||||
{
|
||||
m_width = (int)info.Width;
|
||||
m_height = (int)info.Height;
|
||||
m_input = new ArcView.Reader (input);
|
||||
m_use_dict = 0 != (info.Flags & FlagUseDictionary);
|
||||
m_has_alpha = 0 != (info.Flags & FlagAlphaChannel);
|
||||
m_max_dict_size = (int)(info.Flags & 0xffffff);
|
||||
if (m_has_alpha)
|
||||
{
|
||||
Format = PixelFormats.Bgra32;
|
||||
m_pixel_size = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
Format = PixelFormats.Bgr24;
|
||||
m_pixel_size = 3;
|
||||
}
|
||||
m_stride = m_width * m_pixel_size;
|
||||
m_output = new byte[m_stride*m_height];
|
||||
}
|
||||
|
||||
public void Unpack ()
|
||||
{
|
||||
if (!m_use_dict)
|
||||
UnpackLZ();
|
||||
else if (m_max_dict_size > 0x100)
|
||||
UnpackWithDictLarge();
|
||||
else
|
||||
UnpackWithDictSmall();
|
||||
if (m_has_alpha)
|
||||
UnpackAlphaChannel();
|
||||
}
|
||||
|
||||
void UnpackWithDictLarge ()
|
||||
{
|
||||
var dict = new byte[m_max_dict_size * 3];
|
||||
for (int y = 0; y < m_height;)
|
||||
{
|
||||
int dict_len = m_input.ReadUInt16() + 1;
|
||||
m_input.Read (dict, 0, dict_len * 3);
|
||||
|
||||
for (int y_end = m_input.ReadUInt16(); y < y_end; y++)
|
||||
{
|
||||
var dst = y * m_stride;
|
||||
short line_size = m_input.ReadInt16();
|
||||
if (line_size > 0)
|
||||
{
|
||||
if (dict_len > 256)
|
||||
UnpackLine16 (dst, line_size, dict);
|
||||
else
|
||||
UnpackLine8 (dst, line_size, dict);
|
||||
}
|
||||
else if (line_size < 0)
|
||||
{
|
||||
var src_line = (y + line_size) * m_stride;
|
||||
Buffer.BlockCopy (m_output, src_line, m_output, dst, m_stride);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int x = 0; x < m_width; x++)
|
||||
{
|
||||
int i;
|
||||
if (dict_len > 256)
|
||||
i = m_input.ReadUInt16();
|
||||
else
|
||||
i = m_input.ReadByte();
|
||||
i *= 3;
|
||||
m_output[dst] = dict[i];
|
||||
m_output[dst+1] = dict[i+1];
|
||||
m_output[dst+2] = dict[i+2];
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnpackWithDictSmall ()
|
||||
{
|
||||
var dict = new byte[m_max_dict_size * 3];
|
||||
|
||||
int dict_len = m_input.ReadByte() + 1;
|
||||
m_input.Read (dict, 0, dict_len * 3);
|
||||
|
||||
for (int y = 0; y < m_height; y++)
|
||||
{
|
||||
int dst = y * m_stride;
|
||||
int line_size = m_input.ReadInt16();
|
||||
if (line_size > 0)
|
||||
{
|
||||
UnpackLine8 (dst, line_size, dict);
|
||||
}
|
||||
else if (line_size < 0)
|
||||
{
|
||||
var src_line = (y + line_size) * m_stride;
|
||||
Buffer.BlockCopy (m_output, src_line, m_output, dst, m_stride);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int x = 0; x < m_width; x++)
|
||||
{
|
||||
int i = 3 * m_input.ReadByte();
|
||||
m_output[dst] = dict[i];
|
||||
m_output[dst+1] = dict[i+1];
|
||||
m_output[dst+2] = dict[i+2];
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnpackLZ ()
|
||||
{
|
||||
for (int y = 0; y < m_height; y++)
|
||||
{
|
||||
int dst = y * m_stride;
|
||||
short line_size = m_input.ReadInt16();
|
||||
if (line_size > 0)
|
||||
{
|
||||
UnpackLineLZ (dst, line_size);
|
||||
}
|
||||
else if (line_size < 0)
|
||||
{
|
||||
int src_line = (y + line_size) * m_stride;
|
||||
Buffer.BlockCopy (m_output, src_line, m_output, dst, m_stride);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int x = 0; x < m_width; x++)
|
||||
{
|
||||
m_input.Read (m_output, dst, 3);
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnpackAlphaChannel()
|
||||
{
|
||||
int alpha_pos = 3;
|
||||
for (int y = 0; y < m_height; y++)
|
||||
{
|
||||
int dst = alpha_pos + y * m_stride;
|
||||
|
||||
short line_size = m_input.ReadInt16();
|
||||
if (line_size > 0)
|
||||
{
|
||||
UnpackLineAlpha (dst, line_size);
|
||||
}
|
||||
else if (line_size < 0)
|
||||
{
|
||||
int src_line = alpha_pos + (y + line_size) * m_stride;
|
||||
for (int x = 0; x < m_width; x++)
|
||||
{
|
||||
m_output[dst] = m_output[src_line];
|
||||
dst += m_pixel_size;
|
||||
src_line += m_pixel_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int x = 0; x < m_width; x++)
|
||||
{
|
||||
m_output[dst] = m_input.ReadByte();
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnpackLine16 (int dst, int length, byte[] dict)
|
||||
{
|
||||
while (length > 0)
|
||||
{
|
||||
short ctl = m_input.ReadInt16();
|
||||
length -= 2;
|
||||
if (0 != (ctl & 0x8000))
|
||||
{
|
||||
int count = (ctl & 0x3F) + 2;
|
||||
int offset = ctl >> 6;
|
||||
offset *= m_pixel_size;
|
||||
count *= m_pixel_size;
|
||||
Binary.CopyOverlapped (m_output, dst+offset, dst, count);
|
||||
dst += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = ctl & 0x1FFF;
|
||||
if (0 != (ctl & 0x4000))
|
||||
{
|
||||
int index = 0;
|
||||
if (0 != (ctl & 0x2000))
|
||||
{
|
||||
index = m_input.ReadByte();
|
||||
--length;
|
||||
}
|
||||
else
|
||||
{
|
||||
index = m_input.ReadUInt16();
|
||||
length -= 2;
|
||||
}
|
||||
index *= 3;
|
||||
while (0 != count--)
|
||||
{
|
||||
m_output[dst] = dict[index];
|
||||
m_output[dst+1] = dict[index+1];
|
||||
m_output[dst+2] = dict[index+2];
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (0 != count--)
|
||||
{
|
||||
int index = 0;
|
||||
if (0 != (ctl & 0x2000))
|
||||
{
|
||||
index = m_input.ReadByte();
|
||||
--length;
|
||||
}
|
||||
else
|
||||
{
|
||||
index = m_input.ReadUInt16();
|
||||
length -= 2;
|
||||
}
|
||||
index *= 3;
|
||||
m_output[dst] = dict[index];
|
||||
m_output[dst+1] = dict[index+1];
|
||||
m_output[dst+2] = dict[index+2];
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnpackLine8 (int dst, int length, byte[] dict)
|
||||
{
|
||||
while (length > 0)
|
||||
{
|
||||
byte ctl = m_input.ReadByte();
|
||||
--length;
|
||||
if (0 != ctl)
|
||||
{
|
||||
int index = 3 * m_input.ReadByte();
|
||||
--length;
|
||||
while (0 != ctl--)
|
||||
{
|
||||
m_output[dst] = dict[index];
|
||||
m_output[dst+1] = dict[index+1];
|
||||
m_output[dst+2] = dict[index+2];
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ctl = m_input.ReadByte();
|
||||
--length;
|
||||
if (0 == (ctl & 0x80))
|
||||
{
|
||||
for (int count = ctl + 2; 0 != count; --count)
|
||||
{
|
||||
int src = 3 * m_input.ReadByte();
|
||||
--length;
|
||||
m_output[dst] = dict[src];
|
||||
m_output[dst+1] = dict[src+1];
|
||||
m_output[dst+2] = dict[src+2];
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = (short)((ctl << 8) | m_input.ReadByte());
|
||||
--length;
|
||||
int count = (offset & 0x3F) + 4;
|
||||
offset >>= 6;
|
||||
offset *= m_pixel_size;
|
||||
count *= m_pixel_size;
|
||||
Binary.CopyOverlapped (m_output, dst+offset, dst, count);
|
||||
dst += count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnpackLineAlpha (int dst, int length)
|
||||
{
|
||||
while (length > 0)
|
||||
{
|
||||
byte ctl = m_input.ReadByte();
|
||||
--length;
|
||||
if (0 != ctl)
|
||||
{
|
||||
byte alpha = m_input.ReadByte();
|
||||
--length;
|
||||
while (0 != ctl--)
|
||||
{
|
||||
m_output[dst] = alpha;
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ctl = m_input.ReadByte();
|
||||
--length;
|
||||
if (0 == (ctl & 0x80))
|
||||
{
|
||||
int count = ctl + 2;
|
||||
length -= count;
|
||||
while (0 != count--)
|
||||
{
|
||||
m_output[dst] = m_input.ReadByte();
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = (short)((ctl << 8) | m_input.ReadByte());
|
||||
--length;
|
||||
int count = (offset & 0x3F) + 4;
|
||||
offset >>= 6;
|
||||
offset *= m_pixel_size;
|
||||
while (0 != count--)
|
||||
{
|
||||
m_output[dst] = m_output[dst+offset];
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UnpackLineLZ (int dst, int length)
|
||||
{
|
||||
while (length > 0)
|
||||
{
|
||||
short ctl = m_input.ReadInt16();
|
||||
length -= 2;
|
||||
|
||||
if (0 != (ctl & 0x8000))
|
||||
{
|
||||
int count = (ctl & 0x3F) + 1;
|
||||
int offset = ctl >> 6;
|
||||
offset *= m_pixel_size;
|
||||
|
||||
while (0 != count--)
|
||||
{
|
||||
m_output[dst] = m_output[dst+offset];
|
||||
m_output[dst+1] = m_output[dst+offset+1];
|
||||
m_output[dst+2] = m_output[dst+offset+2];
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = ctl & 0x1FFF;
|
||||
if (0 != (ctl & 0x4000))
|
||||
{
|
||||
m_input.Read (m_output, dst, 3);
|
||||
length -= 3;
|
||||
dst += m_pixel_size;
|
||||
if (--count > 0)
|
||||
{
|
||||
count *= m_pixel_size;
|
||||
Binary.CopyOverlapped (m_output, dst-m_pixel_size, dst, count);
|
||||
dst += count;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (0 != count--)
|
||||
{
|
||||
m_input.Read (m_output, dst, 3);
|
||||
length -= 3;
|
||||
dst += m_pixel_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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();
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
33
ArcFormats/Dac/WidgetDPK.xaml
Normal file
33
ArcFormats/Dac/WidgetDPK.xaml
Normal file
@@ -0,0 +1,33 @@
|
||||
<Grid x:Class="GameRes.Formats.GUI.WidgetDPK"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="clr-namespace:GameRes.Formats.Strings"
|
||||
xmlns:p="clr-namespace:GameRes.Formats.Properties"
|
||||
xmlns:dac="clr-namespace:GameRes.Formats.Dac">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition MinWidth="130" Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Label Content="{x:Static s:arcStrings.LabelEncScheme}" Target="{Binding ElementName=EncScheme}"
|
||||
Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right"/>
|
||||
<ComboBox Name="EncScheme" Grid.Column="1" Grid.Row="0" Margin="0,3,0,0" Width="200"
|
||||
ItemsSource="{Binding Source={x:Static dac:DpkOpener.KnownSchemes}, Mode=OneWay}"
|
||||
DisplayMemberPath="Name" SelectedValuePath="Name"
|
||||
SelectedValue="{Binding Source={x:Static p:Settings.Default}, Path=DPKLastScheme, Mode=TwoWay}"/>
|
||||
<TextBox Name="Original" Background="Transparent" BorderThickness="0" Text="{Binding Path=OriginalTitle}"
|
||||
IsReadOnly="True" TextWrapping="NoWrap" Grid.Column="1" Grid.Row="1" Margin="0,3,0,3"
|
||||
DataContext="{Binding ElementName=EncScheme, Path=SelectedItem}"/>
|
||||
<Label Content="{x:Static s:arcStrings.DPKKeys}" Target="{Binding ElementName=Key1}"
|
||||
ToolTip="{x:Static s:arcStrings.ArcHex32Bit}"
|
||||
Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right"/>
|
||||
<TextBox Name="Key1" Grid.Column="1" Grid.Row="2" Margin="0,3,0,3" Width="100" HorizontalAlignment="Left"
|
||||
ToolTip="{x:Static s:arcStrings.ArcHex32Bit}"/>
|
||||
<TextBox Name="Key2" Grid.Column="1" Grid.Row="3" Margin="0,3,0,3" Width="100" HorizontalAlignment="Left"
|
||||
ToolTip="{x:Static s:arcStrings.ArcHex32Bit}"/>
|
||||
</Grid>
|
||||
41
ArcFormats/Dac/WidgetDPK.xaml.cs
Normal file
41
ArcFormats/Dac/WidgetDPK.xaml.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Windows.Controls;
|
||||
using GameRes.Formats.Dac;
|
||||
using GameRes.Formats.Properties;
|
||||
|
||||
namespace GameRes.Formats.GUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for WidgetDPK.xaml
|
||||
/// </summary>
|
||||
public partial class WidgetDPK : Grid
|
||||
{
|
||||
public WidgetDPK ()
|
||||
{
|
||||
InitializeComponent ();
|
||||
var last_scheme = EncScheme.SelectedItem as DpkScheme;
|
||||
if (null == last_scheme)
|
||||
last_scheme = DpkOpener.KnownSchemes[0];
|
||||
uint key1 = Settings.Default.DPKKey1;
|
||||
uint key2 = Settings.Default.DPKKey2;
|
||||
if (last_scheme.Key1 != key1 || last_scheme.Key2 != key2)
|
||||
EncScheme.SelectedIndex = -1;
|
||||
else if (null == EncScheme.SelectedItem)
|
||||
EncScheme.SelectedIndex = 0;
|
||||
Key1.Text = key1.ToString ("X");
|
||||
Key2.Text = key2.ToString ("X8");
|
||||
|
||||
EncScheme.SelectionChanged += OnSchemeChanged;
|
||||
}
|
||||
|
||||
void OnSchemeChanged (object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
var widget = sender as ComboBox;
|
||||
var scheme = widget.SelectedItem as DpkScheme;
|
||||
if (null != scheme)
|
||||
{
|
||||
Key1.Text = scheme.Key1.ToString ("X");
|
||||
Key2.Text = scheme.Key2.ToString ("X8");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user