mirror of
https://github.com/crskycode/GARbro.git
synced 2025-01-11 20:39:29 +08:00
(Cyberworks): another archives naming scheme.
This commit is contained in:
parent
bfed66e077
commit
6a8b51b0af
@ -62,46 +62,52 @@ namespace GameRes.Formats.Cyberworks
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Regex s_arcname_re = new Regex (@"^.+0(?<id>(?<num>\d)(?<idx>[a-z])?)(?:|\..*)$", RegexOptions.IgnoreCase);
|
static Regex s_arcname_re = new Regex (@"^.+0(?<id>(?<num>\d)(?<idx>[a-z])?)(?:|\..*)$", RegexOptions.IgnoreCase);
|
||||||
|
static Regex s_datname_re = new Regex (@"^(?<name>d[a-z]+?)(?<idx>[ah])?\.dat$", RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
public override ArcFile TryOpen (ArcView file)
|
public override ArcFile TryOpen (ArcView file)
|
||||||
{
|
{
|
||||||
var arc_name = Path.GetFileName (file.Name);
|
var arc_name = Path.GetFileName (file.Name);
|
||||||
var match = s_arcname_re.Match (arc_name);
|
|
||||||
if (!match.Success)
|
|
||||||
return null;
|
|
||||||
char num = match.Groups["num"].Value[0];
|
|
||||||
if (num < '4' || num > '6')
|
|
||||||
return null;
|
|
||||||
int arc_idx = 0;
|
int arc_idx = 0;
|
||||||
if (match.Groups["idx"].Success)
|
StringBuilder toc_name_builder;
|
||||||
arc_idx = char.ToUpper (match.Groups["idx"].Value[0]) - '@';
|
var match = s_arcname_re.Match (arc_name);
|
||||||
|
if (match.Success)
|
||||||
var toc_name_builder = new StringBuilder (arc_name);
|
|
||||||
var num_pos = match.Groups["id"].Index;
|
|
||||||
toc_name_builder.Remove (num_pos, match.Groups["id"].Length);
|
|
||||||
toc_name_builder.Insert (num_pos, num-'3');
|
|
||||||
var toc_name = toc_name_builder.ToString();
|
|
||||||
|
|
||||||
toc_name = VFS.CombinePath (VFS.GetDirectoryName (file.Name), toc_name);
|
|
||||||
byte[] toc;
|
|
||||||
using (var toc_view = VFS.OpenView (toc_name))
|
|
||||||
{
|
{
|
||||||
if (toc_view.MaxOffset <= 0x10)
|
char num = match.Groups["num"].Value[0];
|
||||||
|
if (num < '4' || num > '6')
|
||||||
return null;
|
return null;
|
||||||
uint unpacked_size = DecodeDecimal (toc_view, 0);
|
if (match.Groups["idx"].Success)
|
||||||
if (unpacked_size <= 4 || unpacked_size > 0x1000000)
|
arc_idx = char.ToUpper (match.Groups["idx"].Value[0]) - '@';
|
||||||
return null;
|
|
||||||
uint packed_size = DecodeDecimal (toc_view, 8);
|
toc_name_builder = new StringBuilder (arc_name);
|
||||||
if (packed_size > toc_view.MaxOffset)
|
toc_name_builder.Append (arc_name);
|
||||||
return null;
|
var num_pos = match.Groups["id"].Index;
|
||||||
toc = new byte[unpacked_size];
|
toc_name_builder.Remove (num_pos, match.Groups["id"].Length);
|
||||||
using (var toc_s = toc_view.CreateStream (0x10, packed_size))
|
toc_name_builder.Insert (num_pos, num-'3');
|
||||||
using (var lzss = new LzssStream (toc_s))
|
|
||||||
{
|
|
||||||
if (toc.Length != lzss.Read (toc, 0, toc.Length))
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if ((match = s_datname_re.Match (arc_name)).Success)
|
||||||
|
{
|
||||||
|
toc_name_builder = new StringBuilder (match.Groups["name"].Value);
|
||||||
|
if (match.Groups["idx"].Success)
|
||||||
|
{
|
||||||
|
if ('a' == match.Groups["idx"].Value[0])
|
||||||
|
{
|
||||||
|
arc_idx = 1;
|
||||||
|
toc_name_builder.Append ('h');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
toc_name_builder.Append ('h');
|
||||||
|
toc_name_builder.Append (".dat");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var toc_name = toc_name_builder.ToString();
|
||||||
|
toc_name = VFS.CombinePath (VFS.GetDirectoryName (file.Name), toc_name);
|
||||||
|
var toc = ReadToc (toc_name);
|
||||||
|
if (null == toc)
|
||||||
|
return null;
|
||||||
|
|
||||||
int entry_size = LittleEndian.ToInt32 (toc, 0) + 4;
|
int entry_size = LittleEndian.ToInt32 (toc, 0) + 4;
|
||||||
if (entry_size < 0x16)
|
if (entry_size < 0x16)
|
||||||
return null;
|
return null;
|
||||||
@ -165,6 +171,29 @@ namespace GameRes.Formats.Cyberworks
|
|||||||
return new BellArchive (file, this, dir, options.Scheme);
|
return new BellArchive (file, this, dir, options.Scheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte[] ReadToc (string toc_name)
|
||||||
|
{
|
||||||
|
using (var toc_view = VFS.OpenView (toc_name))
|
||||||
|
{
|
||||||
|
if (toc_view.MaxOffset <= 0x10)
|
||||||
|
return null;
|
||||||
|
uint unpacked_size = DecodeDecimal (toc_view, 0);
|
||||||
|
if (unpacked_size <= 4 || unpacked_size > 0x1000000)
|
||||||
|
return null;
|
||||||
|
uint packed_size = DecodeDecimal (toc_view, 8);
|
||||||
|
if (packed_size > toc_view.MaxOffset - 0x10)
|
||||||
|
return null;
|
||||||
|
using (var toc_s = toc_view.CreateStream (0x10, packed_size))
|
||||||
|
using (var lzss = new LzssStream (toc_s))
|
||||||
|
{
|
||||||
|
var toc = new byte[unpacked_size];
|
||||||
|
if (toc.Length != lzss.Read (toc, 0, toc.Length))
|
||||||
|
return null;
|
||||||
|
return toc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||||
{
|
{
|
||||||
uint entry_size = entry.Size;
|
uint entry_size = entry.Size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user