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,99 @@
//! \file ArcBlackPackage.cs
//! \date Wed Apr 15 14:58:52 2015
//! \brief Black Package archive 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 GameRes.Compression;
using GameRes.Utility;
namespace GameRes.Formats.Ffa
{
[Export(typeof(ArchiveFormat))]
public class DatOpener : ArchiveFormat
{
public override string Tag { get { return "FFA/DAT"; } }
public override string Description { get { return "FFA System resource archive"; } }
public override uint Signature { get { return 0; } }
public override bool IsHierarchic { get { return false; } }
public override bool CanCreate { get { return false; } }
public DatOpener ()
{
Extensions = new string[] { "dat" };
}
public override ArcFile TryOpen (ArcView file)
{
string lst_name = Path.ChangeExtension (file.Name, ".lst");
if (lst_name == file.Name)
return null;
var lst_info = new FileInfo (lst_name);
if (!lst_info.Exists)
return null;
int count = (int)(lst_info.Length/0x16);
if (count > 0xffff || count*0x16 != lst_info.Length)
return null;
using (var lst = new ArcView (lst_name))
{
var dir = new List<Entry> (count);
uint index_offset = 0;
for (int i = 0; i < count; ++i)
{
string name = lst.View.ReadString (index_offset, 14);
var entry = FormatCatalog.Instance.CreateEntry (name);
entry.Offset = lst.View.ReadUInt32 (index_offset+14);
entry.Size = lst.View.ReadUInt32 (index_offset+18);
if (!entry.CheckPlacement (file.MaxOffset))
return null;
dir.Add (entry);
index_offset += 0x16;
}
return new ArcFile (file, this, dir);
}
}
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
var input = arc.File.CreateStream (entry.Offset, entry.Size);
if (entry.Size <= 8 || !entry.Name.EndsWith (".so4", StringComparison.InvariantCultureIgnoreCase))
return input;
using (var header = new ArcView.Reader (input))
{
int packed = header.ReadInt32();
int unpacked = header.ReadInt32();
if (packed+8 != entry.Size || packed <= 0 || unpacked <= 0)
return input;
using (input)
using (var reader = new LzssReader (input, packed, unpacked))
{
reader.Unpack();
return new MemoryStream (reader.Data);
}
}
}
}
}

84
ArcFormats/Ffa/ArcFFA.cs Normal file
View File

@@ -0,0 +1,84 @@
//! \file ArcFFA.cs
//! \date Wed May 13 11:22:07 2015
//! \brief FFA System archives.
//
// 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.Ffa
{
[Export(typeof(ArchiveFormat))]
public class ArcOpener : ArchiveFormat
{
public override string Tag { get { return "FFA/ARC"; } }
public override string Description { get { return "FFA System resource archive"; } }
public override uint Signature { get { return 0x5954324d; } }
public override bool IsHierarchic { get { return false; } }
public override bool CanCreate { get { return false; } }
public ArcOpener ()
{
Extensions = new string[] { "arc" };
Signatures = new uint[] { 0x5954324d, 0x5f54324d };
}
public override ArcFile TryOpen (ArcView file)
{
#pragma warning disable 219
string type;
if (file.View.AsciiEqual (0, "M2TYPE_WAV"))
type = "wave";
else if (file.View.AsciiEqual (0, "M2T_BMP"))
type = "bmp_";
else if (file.View.AsciiEqual (0, "M2T_WORD"))
type = "word";
else
return null;
#pragma warning restore 219
uint index_size = file.View.ReadUInt32 (file.MaxOffset-12);
long index_offset = file.MaxOffset-0x14-index_size;
int count = file.View.ReadInt32 (file.MaxOffset-8);
if (index_offset <= 0 || count <= 0 || count > 0xfffff)
return null;
file.View.Reserve (index_offset, index_size);
var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i)
{
var name = file.View.ReadString (index_offset, 0x10);
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);
}
}
}

416
ArcFormats/Ffa/AudioWA1.cs Normal file
View File

@@ -0,0 +1,416 @@
//! \file AudioWA1.cs
//! \date Thu Apr 16 11:49:16 2015
//! \brief FFA System compressed WAV 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.Text;
using GameRes.Compression;
using GameRes.Utility;
namespace GameRes.Formats.Ffa
{
[Export(typeof(AudioFormat))]
public class Wa1Audio : AudioFormat
{
public override string Tag { get { return "WA1"; } }
public override string Description { get { return "FFA System wave audio format"; } }
public override uint Signature { get { return 0; } }
private static int ReadInt32 (Stream file)
{
int dword = file.ReadByte();
dword |= file.ReadByte() << 8;
dword |= file.ReadByte() << 16;
dword |= file.ReadByte() << 24;
return dword;
}
public override SoundInput TryOpen (Stream file)
{
int packed = ReadInt32 (file);
if (packed < 0)
return null;
byte[] input;
if (packed > 9)
{
if ((packed + 8) != file.Length)
return null;
int unpacked = ReadInt32 (file);
if (unpacked <= 0)
return null;
using (var reader = new LzssReader (file, packed, unpacked))
{
reader.Unpack();
if (Binary.AsciiEqual (reader.Data, 0, "RIFF"))
{
var sound = new WaveInput (new MemoryStream (reader.Data));
file.Dispose();
return sound;
}
input = reader.Data;
}
}
else
{
if (0x46464952 != ReadInt32 (file)) // 'RIFF'
return null;
file.Position = 0;
input = new byte[file.Length];
file.Read (input, 0, input.Length);
}
var wa1 = new Wa1Reader (input);
wa1.Unpack();
var wav = new WaveInput (new MemoryStream (wa1.Data));
file.Dispose();
return wav;
}
}
internal class Wa1Reader
{
byte[] m_input;
byte[] m_output;
int m_type;
int m_data_size;
public int Type { get { return m_type; } }
public byte[] Data { get { return m_output; } }
public Wa1Reader (byte[] input)
{
m_input = input;
m_type = LittleEndian.ToInt32 (m_input, 0);
if (0 != m_type && 4 != m_type && 8 != m_type)
throw new InvalidFormatException();
if (!Binary.AsciiEqual (m_input, 4, "RIFF") || !Binary.AsciiEqual (m_input, 0x28, "data"))
throw new InvalidFormatException();
m_data_size = LittleEndian.ToInt32 (m_input, 0x2c);
m_output = new byte[m_data_size+0x2c];
Buffer.BlockCopy (m_input, 4, m_output, 0, 0x2c);
LittleEndian.Pack (m_output.Length-8, m_output, 4);
}
static ushort[] word_456CA0 = new ushort[] {
0x39, 0x39, 0x39, 0x39, 0x4D, 0x66, 0x80, 0x99,
0x39, 0x39, 0x39, 0x39, 0x4D, 0x66, 0x80, 0x99,
};
public byte[] Unpack ()
{
switch (Type)
{
case 0: UnpackV0(); break;
case 4: UnpackV4(); break;
case 8: UnpackV8(); break;
}
return m_output;
}
void UnpackV4 ()
{
int src = 0x30;
int dst = 0x2c;
uint v72 = 127;
int v73 = 0;
int v74 = 0;
int a5 = 0;
for (int v71 = m_data_size >> 1; v71 != 0; --v71)
{
int v170 = v73;
int v75 = a5;
int v76 = (ushort)a5;
int v77 = v75 >> 16;
int v81;
int v78;
int v79;
int v80;
if ((byte)v77 < 8u)
{
v78 = m_input[src++];
v79 = v78 << v77;
v77 = (v77 + 8) & 0xff;
v76 |= v79;
}
if ((v76 & 3) == 2)
{
v80 = v76 >> 2;
v77 = (v77 - 2) & 0xff;
v81 = 0;
}
else if (0 != (v76 & 3))
{
if ((v76 & 7) == 5)
{
v80 = v76 >> 3;
v77 = (v77 - 3) & 0xff;
v81 = 1;
}
else if ( (v76 & 7) == 1 )
{
v80 = v76 >> 3;
v77 = (v77 - 3) & 0xff;
v81 = 9;
}
else if ( (v76 & 0xF) == 11 )
{
v80 = v76 >> 4;
v77 = (v77 - 4) & 0xff;
v81 = 2;
}
else if ((v76 & 0xF) == 3)
{
v80 = v76 >> 4;
v77 = (v77 - 4) & 0xff;
v81 = 10;
}
else if ((v76 & 0x1F) == 23)
{
v80 = v76 >> 5;
v77 = (v77 - 5) & 0xff;
v81 = 3;
}
else if ((v76 & 0x1F) == 7)
{
v80 = v76 >> 5;
v77 = (v77 - 5) & 0xff;
v81 = 11;
}
else if ((v76 & 0x3F) == 47)
{
v80 = v76 >> 6;
v77 = (v77 - 6) & 0xff;
v81 = 4;
}
else if ((v76 & 0x3F) == 15)
{
v80 = v76 >> 6;
v77 = (v77 - 6) & 0xff;
v81 = 12;
}
else if ((v76 & 0x7F) == 95)
{
v80 = v76 >> 7;
v77 = (v77 - 7) & 0xff;
v81 = 5;
}
else if ((v76 & 0x7F) == 31)
{
v80 = v76 >> 7;
v77 = (v77 - 7) & 0xff;
v81 = 13;
}
else
{
switch (v76 & 0xff)
{
case 0x7F: v81 = 6; break;
case 0xFF: v81 = 14; break;
case 0xBF: v81 = 7; break;
default: v81 = 15; break;
}
v80 = v76 >> 8;
v77 = (v77 - 8) & 0xff;
}
}
else
{
v80 = v76 >> 2;
v77 = (v77 - 2) & 0xff;
v81 = 8;
}
int v82 = (v77 << 16) | v80;
v73 = v170;
int v171 = v82;
v82 = v81;
int v83 = v81;
v82 = (2 * (v81 & 7) + 1) & 0xff;
uint v84 = (v72 * (uint)(ushort)v82) >> 3;
uint v85 = v84 & 0xffff;
if (0 != (v83 & 8))
{
int dword = v74 << 16 | (v73 & 0xffff);
dword -= (int)v85;
v73 = dword & 0xffff;
v74 = dword >> 16;
if (v74 < 0 && v73 < 0x8000u)
{
v73 = -32768;
v74 = -1;
}
}
else
{
int dword = v74 << 16 | (v73 & 0xffff);
dword += (int)v85;
v73 = dword & 0xffff;
v74 = dword >> 16;
if (v74 >= 0 && v73 >= 0x8000u)
{
v73 = 32767;
v74 = 0;
}
}
uint v88 = (uint)word_456CA0[v81] * v72;
v72 = (v88 >> 6) & 0xffff;
if (v72 < 0x7fu)
v72 = 0x7f;
else if (v72 > 0x6000u)
v72 = 0x6000;
LittleEndian.Pack ((ushort)v73, m_output, dst);
dst += 2;
a5 = v171;
}
}
void UnpackV0 ()
{
int src = 0x30;
int dst = 0x2c;
uint v12 = 127;
int v13 = 0;
int v14 = 0;
int a5 = 0;
for (int v11 = m_data_size >> 1; v11 != 0; --v11)
{
if ((a5 >> 8) == 1)
{
a5 = m_input[src++];
}
else
{
a5 = 0x100 | (m_input[src] >> 4);
}
int v15 = a5 & 0xF;
int v160 = v15;
int v16 = v15;
uint v17 = v12 * (uint)(byte)(2 * (v15 & 7) + 1) >> 3;
uint v18 = v17 & 0xffff;
if (0 != (v16 & 8))
{
int dword = v14 << 16 | (v13 & 0xffff);
dword -= (int)v18;
v13 = dword & 0xffff;
v14 = dword >> 16;
if ( v14 < 0 && v13 < 0x8000u )
{
v13 = -32768;
v14 = -1;
}
}
else
{
int dword = v14 << 16 | (v13 & 0xffff);
dword += (int)v18;
v13 = dword & 0xffff;
v14 = dword >> 16;
if ( v14 >= 0 && v13 >= 0x8000u )
{
v13 = 32767;
v14 = 0;
}
}
uint v21 = (uint)word_456CA0[v160] * v12;
v12 = (v21 >> 6) & 0xffff;
if (v12 < 0x7Fu)
v12 = 127;
else if (v12 > 0x6000u)
v12 = 0x6000;
LittleEndian.Pack ((ushort)v13, m_output, dst);
dst += 2;
}
}
void UnpackV8 ()
{
int src = 0x30;
int dst = 0x2c;
int v95 = m_data_size >> 2;
for (int i = 0; i < 2; ++i)
{
int a5 = i;
uint v96 = 127;
int v97 = 0;
int v98 = 0;
int v172 = dst;
for (int j = 0; j < v95; ++j)
{
if (1 == (a5 >> 8))
{
a5 = m_input[src++];
}
else
{
a5 = 0x100 | (m_input[src] >> 4);
}
int v99 = a5 & 0xF;
int v150 = v99;
int v100 = v99;
uint v101 = v96 * (uint)(byte)(2 * (v99 & 7) + 1) >> 3;
uint v102 = v101 & 0xffff;
if (0 != (v100 & 8))
{
int dword = v98 << 16 | (v97 & 0xffff);
dword -= (int)v102;
v97 = dword & 0xffff;
v98 = dword >> 16;
if ( v98 < 0 && v97 < 0x8000u )
{
v97 = -32768;
v98 = -1;
}
}
else
{
int dword = v98 << 16 | (v97 & 0xffff);
dword += (int)v102;
v97 = dword & 0xffff;
v98 = dword >> 16;
if ( v98 >= 0 && v97 >= 0x8000u )
{
v97 = 32767;
v98 = 0;
}
}
uint v105 = (uint)word_456CA0[v150] * v96;
v96 = (v105 >> 6) & 0xffff;
if (v96 < 0x7Fu)
v96 = 127;
else if (v96 > 0x6000u)
v96 = 0x6000;
LittleEndian.Pack ((ushort)v97, m_output, dst);
dst += 4;
}
dst = v172 + 2;
}
}
}
}

634
ArcFormats/Ffa/ImagePT1.cs Normal file
View File

@@ -0,0 +1,634 @@
//! \file ImagePT1.cs
//! \date Wed Apr 15 15:17:24 2015
//! \brief FFA System 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.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GameRes.Utility;
namespace GameRes.Formats.Ffa
{
internal class Pt1MetaData : ImageMetaData
{
public int Type;
public uint PackedSize;
public uint UnpackedSize;
}
[Export(typeof(ImageFormat))]
public class Pt1Format : ImageFormat
{
public override string Tag { get { return "PT1"; } }
public override string Description { get { return "FFA System RGB image format"; } }
public override uint Signature { get { return 2u; } }
public Pt1Format ()
{
Signatures = new uint[] { 2, 1, 0 };
}
public override void Write (Stream file, ImageData image)
{
throw new NotImplementedException ("Pt1Format.Write not implemented");
}
public override ImageMetaData ReadMetaData (Stream stream)
{
using (var input = new ArcView.Reader (stream))
{
int type = input.ReadInt32();
if (type < 0 || type > 2)
return null;
if (-1 != input.ReadInt32())
return null;
int x = input.ReadInt32();
int y = input.ReadInt32();
uint width = input.ReadUInt32();
uint height = input.ReadUInt32();
uint comp_size = input.ReadUInt32();
uint uncomp_size = input.ReadUInt32();
if (uncomp_size != width*height*3u)
return null;
return new Pt1MetaData {
Width = width,
Height = height,
OffsetX = x,
OffsetY = y,
BPP = 24,
Type = type,
PackedSize = comp_size,
UnpackedSize = uncomp_size
};
}
}
public override ImageData Read (Stream stream, ImageMetaData info)
{
var meta = info as Pt1MetaData;
if (null == meta)
throw new ArgumentException ("Pt1Format.Read should be supplied with Pt1MetaData", "info");
stream.Position = 0x20;
var reader = new Reader (stream, meta);
reader.Unpack();
return ImageData.Create (meta, PixelFormats.Bgr24, null, reader.Data);
}
internal class Reader
{
byte[] m_input;
byte[] m_output;
int m_type;
int m_width;
int m_height;
int m_stride;
int m_left = 0;
public byte[] Data { get { return m_output; } }
public Reader (Stream input, Pt1MetaData info)
{
m_type = info.Type;
m_input = new byte[info.PackedSize+8];
if ((int)info.PackedSize != input.Read (m_input, 0, (int)info.PackedSize))
throw new InvalidFormatException ("Unexpected end of file");
m_width = (int)info.Width;
m_height = (int)info.Height;
m_output = new byte[info.UnpackedSize];
m_stride = m_width*3;
}
public byte[] Unpack ()
{
switch (m_type)
{
case 2: UnpackV2(); break;
case 1: UnpackV1(); break;
case 0: UnpackV0(); break;
}
return m_output;
}
uint edx;
byte ch;
int src;
void ReadNext ()
{
byte cl = (byte)(32 - ch);
edx &= 0xFFFFFFFFu >> cl;
edx += LittleEndian.ToUInt32 (m_input, src) << ch;
src += cl >> 3;
ch += (byte)(cl & 0xf8);
}
void UnpackV2 ()
{
src = 0;
int dst = 0;
Buffer.BlockCopy (m_input, src, m_output, dst, 3);
src += 3;
dst += 3;
edx = LittleEndian.ToUInt32 (m_input, src);
src += 3;
ch = 0x18;
uint _CF;
uint ebx;
sbyte ah;
byte al;
// [ebp+var_8] = i
for (int i = 1; i < m_width; ++i)
{
ReadNext();
_CF = edx & 1;
edx >>= 1;
if (0 != _CF)
{
--ch;
Buffer.BlockCopy (m_output, dst-3, m_output, dst, 3);
dst += 3;
}
else
{
ch -= 2;
_CF = edx & 1;
edx >>= 1;
if (0 != _CF)
{
ah = sub_4225EA();
al = (byte)(ah + m_output[dst-3]);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(ah + m_output[dst-3]);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(ah + m_output[dst-3]);
m_output[dst++] = al;
}
else
{
ReadNext();
LittleEndian.Pack ((ushort)edx, m_output, dst);
edx >>= 16;
m_output[dst+2] = (byte)edx;
dst += 3;
edx >>= 8;
ch -= 24;
}
}
}
for (int i = 1; i < m_height; ++i)
{
dst += m_left; // XXX add edi, [ebp+arg_8]
ReadNext();
_CF = edx & 1;
edx >>= 1;
if (0 != _CF)
{
--ch;
Buffer.BlockCopy (m_output, dst-m_stride, m_output, dst, 3);
dst += 3;
}
else // loc_42207F
{
ch -= 2;
_CF = edx & 1;
edx >>= 1;
if (0 != _CF)
{
ah = sub_4225EA();
al = (byte)(ah + m_output[dst-m_stride]);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(ah + m_output[dst-m_stride]);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(ah + m_output[dst-m_stride]);
m_output[dst++] = al;
}
else // loc_4220FC
{
ReadNext();
LittleEndian.Pack ((ushort)edx, m_output, dst);
edx >>= 16;
m_output[dst+2] = (byte)edx;
dst += 3;
edx >>= 8;
ch -= 24;
}
}
for (int j = 1; j < m_width; ++j)
{
ReadNext();
_CF = edx & 1;
edx >>= 1;
if (0 != _CF)
{
--ch;
ebx = (uint)(dst - m_stride);
ah = sub_4225EA();
al = (byte)(m_output[dst-3] - m_output[ebx-3] + m_output[ebx] + ah);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(m_output[dst-3] - m_output[ebx-2] + m_output[ebx+1] + ah);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(m_output[dst-3] - m_output[ebx-1] + m_output[ebx+2] + ah);
m_output[dst++] = al;
}
else
{
_CF = edx & 1;
edx >>= 1;
if (0 != _CF)
{
ch -= 2;
ebx = (uint)(dst - m_stride);
al = (byte)(m_output[dst-3] - m_output[ebx-3] + m_output[ebx]);
m_output[dst++] = al;
al = (byte)(m_output[dst-3] - m_output[ebx-2] + m_output[ebx+1]);
m_output[dst++] = al;
al = (byte)(m_output[dst-3] - m_output[ebx-1] + m_output[ebx+2]);
m_output[dst++] = al;
}
else
{
ebx = edx & 3;
if (3 == ebx)
{
edx >>= 2;
ch -= 4;
Buffer.BlockCopy (m_output, dst-3, m_output, dst, 3);
dst += 3;
}
else if (2 == ebx)
{
edx >>= 2;
ch -= 4;
ReadNext();
LittleEndian.Pack ((ushort)edx, m_output, dst);
edx >>= 16;
m_output[dst+2] = (byte)edx;
dst += 3;
edx >>= 8;
ch -= 24;
}
else if (1 == ebx)
{
edx >>= 2;
ch -= 4;
ah = sub_4225EA();
al = (byte)(ah + m_output[dst-3]);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(ah + m_output[dst-3]);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(ah + m_output[dst-3]);
m_output[dst++] = al;
}
else
{
ebx = edx & 0xf;
edx >>= 4;
ch -= 6;
if (0 == ebx)
{
Buffer.BlockCopy (m_output, dst - m_stride - 3, m_output, dst, 3);
dst += 3;
}
else if (8 == ebx)
{
Buffer.BlockCopy (m_output, dst - m_stride, m_output, dst, 3);
dst += 3;
}
else if (4 == ebx)
{
ah = sub_4225EA();
al = (byte)(ah + m_output[dst - m_stride - 3]);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(ah + m_output[dst - m_stride - 3]);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(ah + m_output[dst - m_stride - 3]);
m_output[dst++] = al;
}
else
{
ah = sub_4225EA();
al = (byte)(ah + m_output[dst - m_stride]);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(ah + m_output[dst - m_stride]);
m_output[dst++] = al;
ReadNext();
ah = sub_4225EA();
al = (byte)(ah + m_output[dst - m_stride]);
m_output[dst++] = al;
}
}
}
}
}
}
}
sbyte sub_4225EA ()
{
uint _CF = edx & 1;
edx >>= 1;
if (0 != _CF)
{
--ch;
return 0;
}
uint bits = edx & 3;
if (2 == bits)
{
edx >>= 2;
ch -= 3;
return -1;
}
if (1 == bits)
{
edx >>= 2;
ch -= 3;
return 1;
}
switch (edx & 7)
{
case 7:
edx >>= 3;
ch -= 4;
return -2;
case 3:
edx >>= 3;
ch -= 4;
return 2;
case 4:
edx >>= 3;
ch -= 4;
return -3;
default:
switch (edx & 0x3f)
{
case 0x38:
edx >>= 6;
ch -= 7;
return 3;
case 0x18:
edx >>= 6;
ch -= 7;
return -4;
case 0x28:
edx >>= 6;
ch -= 7;
return 4;
case 0x08:
edx >>= 6;
ch -= 7;
return -5;
case 0x30:
edx >>= 6;
ch -= 7;
return 5;
case 0x10:
edx >>= 6;
ch -= 7;
return -6;
case 0x20:
edx >>= 6;
ch -= 7;
return 6;
default:
switch (edx & 0xff)
{
case 0xc0:
edx >>= 8;
ch -= 9;
return -7;
case 0x40:
edx >>= 8;
ch -= 9;
return 7;
case 0x80:
edx >>= 8;
ch -= 9;
return -8;
default:
switch (edx & 0x3ff)
{
case 0x300:
edx >>= 10;
ch -= 11;
return 8;
case 0x100:
edx >>= 10;
ch -= 11;
return -9;
case 0x200:
edx >>= 10;
ch -= 11;
return 9;
default:
switch (edx & 0xfff)
{
case 0xc00:
edx >>= 12;
ch -= 13;
return -10;
case 0x400:
edx >>= 12;
ch -= 13;
return 10;
case 0x800:
edx >>= 12;
ch -= 13;
return -11;
default:
switch (edx & 0x3fff)
{
case 0x3000:
edx >>= 14;
ch -= 15;
return 0x0b;
case 0x1000:
edx >>= 14;
ch -= 15;
return -12;
case 0x2000:
edx >>= 14;
ch -= 15;
return 0x0c;
default:
edx >>= 14;
ch -= 15;
return -13;
}
}
}
}
}
}
}
void UnpackV1 ()
{
int src = 0; // dword_462E74
int dst = 0; // dword_462E78
byte[] frame = new byte[0x1000]; // word_461A28
PopulateLzssFrame (frame);
int ebp = 0xfee;
while (src < m_input.Length)
{
byte ah = m_input[src++];
for (int mask = 1; mask != 0x100; mask <<= 1)
{
if (0 != (ah & mask))
{
byte al = m_input[src++];
frame[ebp++] = al;
ebp &= 0xfff;
m_output[dst++] = al;
m_output[dst++] = al;
m_output[dst++] = al;
}
else
{
int offset = m_input[src++];
int count = m_input[src++];
offset |= (count & 0xf0) << 4;
count = (count & 0x0f) + 3;
for (; count != 0; --count)
{
byte al = frame[offset++];
frame[ebp++] = al;
offset &= 0xfff;
ebp &= 0xfff;
m_output[dst++] = al;
m_output[dst++] = al;
m_output[dst++] = al;
}
}
if (dst >= m_output.Length)
return;
}
}
}
void UnpackV0 ()
{
int src = 0;
int dst = 0;
byte[] frame = new byte[0x1000]; // word_461A28
PopulateLzssFrame (frame);
int ebp = 0xfee;
while (src < m_input.Length)
{
byte ah = m_input[src++];
for (int mask = 1; mask != 0x100; mask <<= 1)
{
if (0 != (ah & mask))
{
byte al = m_input[src++];
frame[ebp++] = al;
ebp &= 0xfff;
m_output[dst++] = al;
}
else
{
int offset = m_input[src++];
int count = m_input[src++];
offset |= (count & 0xf0) << 4;
count = (count & 0x0f) + 3;
for (int i = 0; i < count; ++i)
{
byte al = frame[offset++];
frame[ebp++] = al;
offset &= 0xfff;
ebp &= 0xfff;
m_output[dst++] = al;
}
}
if (dst >= m_output.Length)
return;
}
}
}
void PopulateLzssFrame (byte[] frame)
{
int fill = 0;
int ecx;
for (int al = 0; al < 0x100; ++al)
for (ecx = 0x0d; ecx > 0; --ecx)
frame[fill++] = (byte)al;
for (int al = 0; al < 0x100; ++al)
frame[fill++] = (byte)al;
for (int al = 0xff; al >= 0; --al)
frame[fill++] = (byte)al;
for (ecx = 0x80; ecx > 0; --ecx)
frame[fill++] = 0;
for (ecx = 0x6e; ecx > 0; --ecx)
frame[fill++] = 0x20;
for (ecx = 0x12; ecx > 0; --ecx)
frame[fill++] = 0;
}
}
}
}