mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 20:04:13 +08:00
implemented CMP archives, BGD and CGD images.
This commit is contained in:
parent
cf1ce3c889
commit
a95fca5d68
@ -102,6 +102,9 @@
|
||||
<Compile Include="Cmvs\ImagePB2.cs" />
|
||||
<Compile Include="Ellefin\ArcEPK.cs" />
|
||||
<Compile Include="Entis\ArcPAC.cs" />
|
||||
<Compile Include="GameSystem\ArcCMP.cs" />
|
||||
<Compile Include="GameSystem\ImageBGD.cs" />
|
||||
<Compile Include="GameSystem\ImageCGD.cs" />
|
||||
<Compile Include="Lz4Stream.cs" />
|
||||
<Compile Include="Majiro\ImageRC8.cs" />
|
||||
<Compile Include="Mixwill\ArcARC0.cs" />
|
||||
|
120
ArcFormats/GameSystem/ArcCMP.cs
Normal file
120
ArcFormats/GameSystem/ArcCMP.cs
Normal file
@ -0,0 +1,120 @@
|
||||
//! \file ArcCMP.cs
|
||||
//! \date Sun Jan 15 15:44:39 2017
|
||||
//! \brief 'Game System' engine resource archive.
|
||||
//
|
||||
// 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.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.GameSystem
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class CmpOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "CMP"; } }
|
||||
public override string Description { get { return "'GameSystem' engine resource archive"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
public override bool IsHierarchic { get { return true; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
if (file.MaxOffset <= 8 || !file.View.AsciiEqual (file.MaxOffset-8, "PACK"))
|
||||
return null;
|
||||
uint index_offset = file.View.ReadUInt32 (file.MaxOffset-4);
|
||||
if (index_offset >= file.MaxOffset)
|
||||
return null;
|
||||
int index_size = file.View.ReadInt32 (index_offset);
|
||||
var index = new byte[index_size];
|
||||
using (var input = file.CreateStream (index_offset+4))
|
||||
LzUnpack (input, index);
|
||||
var dir = new List<Entry>();
|
||||
int index_pos = 0;
|
||||
uint offset = LittleEndian.ToUInt32 (index, index_pos);
|
||||
while (index_pos < index.Length)
|
||||
{
|
||||
index_pos += 4;
|
||||
int name_length = index[index_pos];
|
||||
if (0 == name_length)
|
||||
break;
|
||||
bool is_packed = index[index_pos+1] != 0;
|
||||
index_pos += 6;
|
||||
name_length *= 2;
|
||||
var name = Encoding.Unicode.GetString (index, index_pos, name_length);
|
||||
index_pos += name_length;
|
||||
uint next_offset = LittleEndian.ToUInt32 (index, index_pos);
|
||||
var entry = FormatCatalog.Instance.Create<PackedEntry> (name);
|
||||
entry.Offset = offset;
|
||||
entry.Size = next_offset - offset;
|
||||
entry.IsPacked = is_packed;
|
||||
if (!entry.CheckPlacement (index_offset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
offset = next_offset;
|
||||
}
|
||||
if (0 == dir.Count)
|
||||
return null;
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
void LzUnpack (IBinaryStream input, byte[] output)
|
||||
{
|
||||
int dst = 0;
|
||||
while (dst < output.Length)
|
||||
{
|
||||
byte ctl = input.ReadUInt8();
|
||||
if (0 != (ctl & 0x80))
|
||||
{
|
||||
int num = input.ReadUInt8() + (ctl << 8);
|
||||
int offset = num & 0x7FF;
|
||||
int count = Math.Min (((num >> 10) & 0x1E) + 2, output.Length - dst);
|
||||
Binary.CopyOverlapped (output, dst-offset-1, dst, count);
|
||||
dst += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = Math.Min (ctl + 1, output.Length - dst);
|
||||
input.Read (output, dst, count);
|
||||
dst += count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||
{
|
||||
var pent = entry as PackedEntry;
|
||||
if (null == pent || !pent.IsPacked)
|
||||
return base.OpenEntry (arc, entry);
|
||||
if (0 == pent.UnpackedSize)
|
||||
pent.UnpackedSize = arc.File.View.ReadUInt32 (entry.Offset);
|
||||
var data = new byte[pent.UnpackedSize];
|
||||
using (var input = arc.File.CreateStream (entry.Offset+4, entry.Size-4))
|
||||
LzUnpack (input, data);
|
||||
return new BinMemoryStream (data, entry.Name);
|
||||
}
|
||||
}
|
||||
}
|
114
ArcFormats/GameSystem/ImageBGD.cs
Normal file
114
ArcFormats/GameSystem/ImageBGD.cs
Normal file
@ -0,0 +1,114 @@
|
||||
//! \file ImageBGD.cs
|
||||
//! \date Mon Jan 16 06:43:56 2017
|
||||
//! \brief 'Game System' background 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.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace GameRes.Formats.GameSystem
|
||||
{
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class BgdFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "BGD"; } }
|
||||
public override string Description { get { return "'GameSystem' background image format"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
if (file.Signature+0x10 != file.Length)
|
||||
return null;
|
||||
var header = file.ReadHeader (0x10);
|
||||
uint width = header.ToUInt32 (4);
|
||||
uint height = header.ToUInt32 (8);
|
||||
if (0 == width || width > 0x8000 || 0 == height || height > 0x8000)
|
||||
return null;
|
||||
return new ImageMetaData
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
BPP = 24,
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (IBinaryStream file, ImageMetaData info)
|
||||
{
|
||||
int total_pixels = (int)info.Width * (int)info.Height;
|
||||
var pixels = new byte[total_pixels * 3];
|
||||
int count = total_pixels >> 1;
|
||||
int dst = 0;
|
||||
int s1 = 1, s2 = 1, s3 = 1;
|
||||
int r = 0, g = 0, b = 0;
|
||||
file.Position = 0x10;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
byte c = file.ReadUInt8();
|
||||
s1 = s1 << 4 | c & 0xF;
|
||||
s2 = s2 << 4 | (c >> 4) & 0xF;
|
||||
b += RgbShift[s1];
|
||||
g += RgbShift[s2];
|
||||
c = file.ReadUInt8();
|
||||
s3 = s3 << 4 | c & 0xF;
|
||||
r += RgbShift[s3];
|
||||
pixels[dst++] = (byte)b;
|
||||
pixels[dst++] = (byte)g;
|
||||
pixels[dst++] = (byte)r;
|
||||
s3 = ShiftTable[s3] << 4 | (c >> 4) & 0xF;
|
||||
c = file.ReadUInt8();
|
||||
s1 = ShiftTable[s1] << 4 | c & 0xF;
|
||||
s2 = ShiftTable[s2] << 4 | (c >> 4) & 0xF;
|
||||
b += RgbShift[s1];
|
||||
g += RgbShift[s2];
|
||||
r += RgbShift[s3];
|
||||
s1 = ShiftTable[s1];
|
||||
s2 = ShiftTable[s2];
|
||||
s3 = ShiftTable[s3];
|
||||
pixels[dst++] = (byte)b;
|
||||
pixels[dst++] = (byte)g;
|
||||
pixels[dst++] = (byte)r;
|
||||
}
|
||||
return ImageData.CreateFlipped (info, PixelFormats.Bgr24, null, pixels, (int)info.Width*3);
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new System.NotImplementedException ("BgdFormat.Write not implemented");
|
||||
}
|
||||
|
||||
static readonly byte[] ShiftTable = {
|
||||
0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1,
|
||||
0, 0, 1, 1, 2, 2, 1, 1, 0, 0, 1, 1, 2, 2, 1, 1,
|
||||
1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1,
|
||||
};
|
||||
static readonly short[] RgbShift = {
|
||||
1, 2, 4, 8, 0x10, 0x26, 0x50, 0xAA,
|
||||
-1, -2, -4, -8, -0x10, -0x26, -0x50, -0xAA,
|
||||
2, 4, 6, 0x0C, 0x18, 0x30, 0x60, 0xC0,
|
||||
-2, -4, -6, -0x0C, -0x18, -0x30, -0x60, -0xC0,
|
||||
5, 0x0A, 0x14, 0x1E, 0x32, 0x50, 0x82, 0xD2,
|
||||
-5, -0x0A, -0x14, -0x1E, -0x32, -0x50, -0x82, -0xD2,
|
||||
};
|
||||
}
|
||||
}
|
157
ArcFormats/GameSystem/ImageCGD.cs
Normal file
157
ArcFormats/GameSystem/ImageCGD.cs
Normal file
@ -0,0 +1,157 @@
|
||||
//! \file ImageCGD.cs
|
||||
//! \date Mon Jan 16 05:22:43 2017
|
||||
//! \brief 'Game System' CG 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.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace GameRes.Formats.GameSystem
|
||||
{
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class CgdFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "CGD"; } }
|
||||
public override string Description { get { return "'GameSystem' CG image format"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
if (file.Signature != file.Length)
|
||||
return null;
|
||||
var header = file.ReadHeader (0x10);
|
||||
uint width = header.ToUInt32 (4);
|
||||
uint height = header.ToUInt32 (8);
|
||||
if (0 == width || width > 0x8000 || 0 == height || height > 0x8000)
|
||||
return null;
|
||||
return new ImageMetaData
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
BPP = 24,
|
||||
};
|
||||
}
|
||||
|
||||
public override ImageData Read (IBinaryStream file, ImageMetaData info)
|
||||
{
|
||||
var reader = new CgdReader (file, info);
|
||||
var pixels = reader.Unpack();
|
||||
return ImageData.CreateFlipped (info, reader.Format, null, pixels, reader.Stride);
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new System.NotImplementedException ("CgdFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CgdReader
|
||||
{
|
||||
IBinaryStream m_input;
|
||||
int m_width;
|
||||
int m_height;
|
||||
byte[] m_output;
|
||||
|
||||
public int Stride { get; private set; }
|
||||
public PixelFormat Format { get { return PixelFormats.Bgr24; } }
|
||||
public byte[] Data { get { return m_output; } }
|
||||
|
||||
public CgdReader (IBinaryStream input, ImageMetaData info)
|
||||
{
|
||||
m_input = input;
|
||||
m_width = (int)info.Width;
|
||||
m_height = (int)info.Height;
|
||||
Stride = 3 * m_width;
|
||||
m_output = new byte[Stride * m_height];
|
||||
}
|
||||
|
||||
public byte[] Unpack ()
|
||||
{
|
||||
m_input.Position = 0x10;
|
||||
int dst = 0;
|
||||
byte r = 0, g = 0, b = 0;
|
||||
while (dst < m_output.Length)
|
||||
{
|
||||
int ctl = m_input.ReadUInt8();
|
||||
if (ctl < 0x80)
|
||||
{
|
||||
int src = m_input.ReadUInt8() | ctl << 8;
|
||||
b += ColorTable[src,0];
|
||||
g += ColorTable[src,1];
|
||||
r += ColorTable[src,2];
|
||||
m_output[dst++] = b;
|
||||
m_output[dst++] = g;
|
||||
m_output[dst++] = r;
|
||||
}
|
||||
else if (ctl < 0xC0)
|
||||
{
|
||||
int count = ctl - 0x7F;
|
||||
while (count --> 0)
|
||||
{
|
||||
m_output[dst++] = b;
|
||||
m_output[dst++] = g;
|
||||
m_output[dst++] = r;
|
||||
}
|
||||
}
|
||||
else if (0xFF == ctl)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = (ctl - 0xBF) * 3;
|
||||
m_input.Read (m_output, dst, count);
|
||||
dst += count;
|
||||
b = m_output[dst-3];
|
||||
g = m_output[dst-2];
|
||||
r = m_output[dst-1];
|
||||
}
|
||||
}
|
||||
return m_output;
|
||||
}
|
||||
|
||||
static readonly byte[,] ColorTable = InitColorTable();
|
||||
|
||||
private static byte[,] InitColorTable ()
|
||||
{
|
||||
var table = new byte[0x8000,3];
|
||||
for (int i = 0; i < 0x8000; ++i)
|
||||
{
|
||||
int r = (i >> 10) & 0x1F;
|
||||
int g = (i >> 5) & 0x1F;
|
||||
int b = i & 0x1F;
|
||||
if (r > 15)
|
||||
r -= 32;
|
||||
if (g > 15)
|
||||
g -= 32;
|
||||
if ( b > 15 )
|
||||
b -= 32;
|
||||
table[i,0] = (byte)b;
|
||||
table[i,1] = (byte)g;
|
||||
table[i,2] = (byte)r;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
}
|
||||
}
|
@ -1160,6 +1160,7 @@ Onna Kyoushi Suzune<br/>
|
||||
Ore Maou! ~Kudake Chitta Tamashii<br/>
|
||||
Oshioki ~Gakuen Reijou Kousei Keikaku~<br/>
|
||||
Ouma no Shoku ~Sei ni Tsukaeshi Yami no Guuzou~<br/>
|
||||
Sarai no Me<br/>
|
||||
Shukubo no Uzuki ~Hitozuma Miboujin no Nareta Karada to Amai Toiki~<br/>
|
||||
Shukubo no Uzuki 2 ~Nareta Hitozuma kara Tadayou "Onna" no Iroka~<br/>
|
||||
Volley Coaching!<br/>
|
||||
@ -1268,6 +1269,7 @@ Tsumi no Hikari Rendezvous<br/>
|
||||
</td></tr>
|
||||
<tr class="odd"><td>arc.dat</td><td>-</td><td>No</td><td rowspan="2">AdvSys3</td><td rowspan="2">
|
||||
Jii Tousaku<br/>
|
||||
Joku Dorei Tsuma<br/>
|
||||
Okami Tsuma ~Ryokan Baito de no Himitsu~<br/>
|
||||
Tain Shoukougun<br/>
|
||||
</td></tr>
|
||||
@ -1325,6 +1327,10 @@ Teri ☆ Mix<br/>
|
||||
Onepapa ~Onegai PaPa!~<br/>
|
||||
</td></tr>
|
||||
<tr class="odd last"><td>*.pb</td><td><tt>PB00</tt></td><td>No</td></tr>
|
||||
<tr><td>*.cmp</td><td>-</td><td>No</td><td rowspan="2">0verflow</td><td rowspan="2">
|
||||
Summer Radish Vacation!!<br/>
|
||||
</td></tr>
|
||||
<tr><td>*.cgd<br/>*.bgd</td><td>-</td><td>No</td></tr>
|
||||
</table>
|
||||
<p><a name="note-1" class="footnote">1</a> Non-encrypted only</p>
|
||||
</body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user