(ArcAI5Opener): scheme definitions moved to external project.

This commit is contained in:
morkt
2015-12-03 15:52:50 +04:00
parent 6d6b81c88f
commit af9ec6f096

View File

@@ -32,6 +32,7 @@ using GameRes.Utility;
namespace GameRes.Formats.Elf namespace GameRes.Formats.Elf
{ {
[Serializable]
public class ArcIndexScheme public class ArcIndexScheme
{ {
public int NameLength; public int NameLength;
@@ -40,6 +41,12 @@ namespace GameRes.Formats.Elf
public uint OffsetKey; public uint OffsetKey;
} }
[Serializable]
public class Ai5Scheme : ResourceScheme
{
public Dictionary<string, ArcIndexScheme> KnownSchemes;
}
[Export(typeof(ArchiveFormat))] [Export(typeof(ArchiveFormat))]
public class ArcAI5Opener : ArchiveFormat public class ArcAI5Opener : ArchiveFormat
{ {
@@ -49,20 +56,23 @@ namespace GameRes.Formats.Elf
public override bool IsHierarchic { get { return false; } } public override bool IsHierarchic { get { return false; } }
public override bool CanCreate { get { return false; } } public override bool CanCreate { get { return false; } }
public static readonly Dictionary<string, ArcIndexScheme> KnownSchemes = new Dictionary<string, ArcIndexScheme> { public static Dictionary<string, ArcIndexScheme> KnownSchemes = new Dictionary<string, ArcIndexScheme>();
{ "Dorei Kaigo", new ArcIndexScheme
{ NameLength = 0x14, NameKey = 0x06, SizeKey = 0x55303024, OffsetKey = 0x57683256 } },
{ "Jokei Kazoku ~Inbou~", new ArcIndexScheme
{ NameLength = 0x1E, NameKey = 0x73, SizeKey = 0xAF5789BC, OffsetKey = 0x59FACB45 } },
};
public ArcAI5Opener () public ArcAI5Opener ()
{ {
Extensions = new string[] { "arc" }; Extensions = new string[] { "arc" };
} }
public override ResourceScheme Scheme
{
get { return new Ai5Scheme { KnownSchemes = KnownSchemes }; }
set { KnownSchemes = ((Ai5Scheme)value).KnownSchemes; }
}
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (0 == KnownSchemes.Count)
return null;
int count = file.View.ReadInt32 (0); int count = file.View.ReadInt32 (0);
if (!IsSaneCount (count)) if (!IsSaneCount (count))
return null; return null;
@@ -106,15 +116,18 @@ namespace GameRes.Formats.Elf
for (int i = 0; i < m_count; ++i) for (int i = 0; i < m_count; ++i)
{ {
m_file.View.Read (index_offset, m_name_buf, 0, (uint)scheme.NameLength); m_file.View.Read (index_offset, m_name_buf, 0, (uint)scheme.NameLength);
for (int n = 0; n < m_name_buf.Length; ++n) int n;
for (n = 0; n < m_name_buf.Length; ++n)
{ {
m_name_buf[n] ^= scheme.NameKey; m_name_buf[n] ^= scheme.NameKey;
if (0 == m_name_buf[n]) if (0 == m_name_buf[n])
break; break;
if (m_name_buf[n] < 0x20)
return null;
} }
string name = Binary.GetCString (m_name_buf, 0, m_name_buf.Length); if (0 == n)
if (0 == name.Length)
return null; return null;
string name = Encodings.cp932.GetString (m_name_buf, 0, n);
index_offset += scheme.NameLength; index_offset += scheme.NameLength;
var entry = FormatCatalog.Instance.Create<Entry> (name); var entry = FormatCatalog.Instance.Create<Entry> (name);
entry.Size = m_file.View.ReadUInt32 (index_offset) ^ scheme.SizeKey; entry.Size = m_file.View.ReadUInt32 (index_offset) ^ scheme.SizeKey;