implemented GD images and VMD audio.

This commit is contained in:
morkt 2017-01-20 10:58:56 +04:00
parent bb7e6e96b2
commit 915daf1067
4 changed files with 293 additions and 0 deletions

View File

@ -94,6 +94,8 @@
<Compile Include="Artemis\ArcPFS.cs" />
<Compile Include="AudioWMA.cs" />
<Compile Include="BlackRainbow\ArcDX.cs" />
<Compile Include="C4\AudioVMD.cs" />
<Compile Include="C4\ImageGD.cs" />
<Compile Include="Cadath\ArcKAR.cs" />
<Compile Include="Cadath\ImageKGF.cs" />
<Compile Include="Cmvs\ArcCPZ2.cs" />

52
ArcFormats/C4/AudioVMD.cs Normal file
View File

@ -0,0 +1,52 @@
//! \file AudioVMD.cs
//! \date Fri Jan 20 08:35:26 2017
//! \brief C4 engine obfuscated MP3 audio.
//
// Copyright (C) 2017 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.ComponentModel.Composition;
using System.IO;
namespace GameRes.Formats.C4
{
[Export(typeof(AudioFormat))]
public class VmdAudio : AudioFormat
{
public override string Tag { get { return "VMD"; } }
public override string Description { get { return "C4 engine MP3 audio"; } }
public override uint Signature { get { return 0; } }
public override bool CanWrite { get { return false; } }
const byte Key = 0xE5;
public override SoundInput TryOpen (IBinaryStream file)
{
var header = file.ReadHeader (3);
if (0xFF != (header[0] ^ Key) || 0xE2 != ((header[1] ^ Key) & 0xE6) ||
0xF0 == ((header[2] ^ Key) & 0xF0))
return null;
file.Position = 0;
var input = new XoredStream (file.AsStream, Key);
return new Mp3Input (input);
}
}
}

231
ArcFormats/C4/ImageGD.cs Normal file
View File

@ -0,0 +1,231 @@
//! \file ImageGD.cs
//! \date Fri Jan 20 07:07:47 2017
//! \brief C4 engine image format.
//
// Copyright (C) 2017 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;
namespace GameRes.Formats.C4
{
internal class GdMetaData : ImageMetaData
{
public uint DataOffset;
public int Compression;
}
[Export(typeof(ImageFormat))]
public class GdFormat : ImageFormat
{
public override string Tag { get { return "GD/C4"; } }
public override string Description { get { return "C4 engine image format"; } }
public override uint Signature { get { return 0x1A324447; } } // 'GD2\x1A'
public GdFormat ()
{
Signatures = new uint[] { 0x1A324447, 0x1A334447 };
}
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
var header = file.ReadHeader (4);
if (!header.AsciiEqual (0, "GD"))
return null;
int version = header[2] - '0';
GdMetaData info;
if (2 == version)
info = new GdMetaData { Width = 640, Height = 480, BPP = 24 };
else if (3 == version)
info = new GdMetaData { Width = 800, Height = 600, BPP = 24 };
else
return null;
file.Position = 4 + 3 * (info.Width / 10) * (info.Height / 10 - 1);
int compression = file.ReadByte();
if (compression != 'b' && compression != 'l' && compression != 'p')
return null;
info.Compression = compression;
info.DataOffset = (uint)file.Position + 1;
return info;
}
public override ImageData Read (IBinaryStream file, ImageMetaData info)
{
var reader = new GdReader (file, (GdMetaData)info);
var pixels = reader.Unpack();
int stride = 3 * (int)info.Width;
return ImageData.CreateFlipped (info, PixelFormats.Bgr24, null, pixels, stride);
}
public override void Write (Stream file, ImageData image)
{
throw new NotImplementedException ("GdFormat.Write not implemented");
}
}
internal sealed class GdReader
{
IBinaryStream m_input;
GdMetaData m_info;
byte[] m_output;
public GdReader (IBinaryStream input, GdMetaData info)
{
m_input = input;
m_info = info;
m_output = new byte[m_info.Width * m_info.Height * 3];
}
public byte[] Unpack ()
{
m_input.Position = m_info.DataOffset;
if ('b' == m_info.Compression)
{
m_input.Read (m_output, 0, m_output.Length);
}
else
{
using (var bits = new MsbBitStream (m_input.AsStream, true))
{
if ('l' == m_info.Compression)
UnpackL (bits);
else if ('p' == m_info.Compression)
UnpackP (bits);
else
throw new InvalidFormatException();
}
}
return m_output;
}
void UnpackL (IBitStream input)
{
int dst = 0;
var frame = new byte[0x10000];
int frame_pos = 1;
while (dst < m_output.Length)
{
int bit = input.GetNextBit();
if (-1 == bit)
break;
if (0 != bit)
{
byte v = (byte)input.GetBits (8);
m_output[dst++] = v;
frame[frame_pos++ & 0xFFFF] = v;
}
else
{
int offset = input.GetBits (16);
int count = input.GetBits (4);
if (-1 == offset || -1 == count)
break;
count += 3;
while (count --> 0)
{
byte v = frame[offset++ & 0xFFFF];
m_output[dst++] = v;
frame[frame_pos++ & 0xFFFF] = v;
}
}
}
}
void UnpackP (IBitStream input)
{
int dst = 0;
for (int i = 0; i < m_output.Length; ++i)
m_output[i] = 0xFF;
int width = (int)m_info.Width;
while (dst < m_output.Length)
{
int count = input.GetBits (2);
if (-1 == count)
break;
if (2 == count)
{
count = input.GetBits (2) + 2;
}
else if (3 == count)
{
int n = 3;
while (input.GetNextBit() > 0)
++n;
if (n >= 24)
break;
count = (1 << n | input.GetBits (n)) - 2;
}
dst += 3 * count;
m_output [dst ] = (byte)input.GetBits (8);
m_output [dst+1] = (byte)input.GetBits (8);
m_output [dst+2] = (byte)input.GetBits (8);
if (input.GetNextBit() > 0)
{
int copy_dst = dst;
for (;;)
{
int ctl = input.GetBits (2);
if (0 == ctl)
{
if (input.GetNextBit() <= 0)
break;
if (input.GetNextBit() > 0)
copy_dst += (width + 2) * 3;
else
copy_dst += (width - 2) * 3;
}
else if (1 == ctl)
copy_dst += (width - 1) * 3;
else if (2 == ctl)
copy_dst += width * 3;
else if (3 == ctl)
copy_dst += (width + 1) * 3;
else if (-1 == ctl)
break;
m_output[copy_dst] = m_output[dst];
m_output[copy_dst+1] = m_output[dst+1];
m_output[copy_dst+2] = m_output[dst+2];
}
}
dst += 3;
}
byte b = 0, g = 0, r = 0;
for (dst = 0; dst < m_output.Length; dst += 3)
{
if (0xFF == m_output[dst] && 0xFF == m_output[dst+1] && 0xFF == m_output[dst+2])
{
m_output[dst ] = b;
m_output[dst+1] = g;
m_output[dst+2] = r;
}
else
{
b = m_output[dst ];
g = m_output[dst+1];
r = m_output[dst+2];
}
}
}
}
}

View File

@ -442,6 +442,7 @@ Hana to Otome ni Shukufuku o <span class="footnote">ShiinaRio v2.46</span><br/>
Helter Skelter <span class="footnote">ShiinaRio v2.40</span><br/>
Hin wa Bokura no Fuku no Kami <span class="footnote">ShiinaRio v2.49</span><br/>
Hitozuma Onna Kyoushi Reika <span class="footnote">ShiinaRio v2.39</span><br/>
Idol Koukai Chijoku Sex <span class="footnote">ShiinaRio v2.46</span><br/>
Intruder <span class="footnote">ShiinaRio v2.49</span><br/>
Itsuka, Dokoka de ~Ano Ameoto no Kioku~<span class="footnote">2.36 or 2.37</span><br/>
Kichiku Nakadashi Suieibu<span class="footnote">ShiinaRio v2.41</span><br/>
@ -454,9 +455,11 @@ Najimi no Oba-chan <span class="footnote">ShiinaRio v2.47</span><br/>
Niizuma to Yuukaihan <span class="footnote">ShiinaRio v2.45</span><br/>
Otome Chibaku Yuugi <span class="footnote">ShiinaRio v2.40</span><br/>
Otome Juurin Yuugi <span class="footnote">ShiinaRio v2.37</span><br/>
Puchipuchi Idol Kouhosei <span class="footnote">ShiinaRio v2.49</span><br/>
Pure Love! <span class="footnote">ShiinaRio v2.47</span><br/>
Ran→Sem <span class="footnote">ShiinaRio v2.47</span><br/>
Rin×Sen <span class="footnote">ShiinaRio v2.47</span><br/>
Ryoumaden ~Houkago no Rakuen~ <span class="footnote">ShiinaRio v2.47</span><br/>
Sabae no Ou <span class="footnote">ShiinaRio v2.36</span><br/>
Shinigami no Testament <span class="footnote">ShiinaRio v2.49</span><br/>
Shojo Mama<span class="footnote">ShiinaRio v2.49</span><br/>
@ -664,6 +667,7 @@ Dies irae ~Amantes amentes~<br/>
Dokidoki Sister Paradise 2<br/>
Kajiri Kamui Kagura<br/>
Paradise Lost<br/>
Sacrifice ~Seifuku Gari~<br/>
Sakashiki Hito ni Miru Kokoro<br/>
Tenmon Dokei no Aria<br/>
Tsumi Koi x 2/3<br/>
@ -1341,6 +1345,10 @@ Summer Radish Vacation!! 2<br/>
<tr class="odd"><td>*.vfs</td><td><tt>VFS File</tt></td><td>No</td><td>VNSystem</td><td>
Seika no Mori<br/>
</td></tr>
<tr><td>*.gd</td><td><tt>GD2</tt><br/><tt>GD3</tt></td><td>No</td><td rowspan="2">C4</td><td rowspan="2">
Koi Suru Science<br/>
</td></tr>
<tr class="last"><td>*.vmd</td><td>-</td><td>No</td></tr>
</table>
<p><a name="note-1" class="footnote">1</a> Non-encrypted only</p>
</body>