mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-27 15:44:00 +08:00
(DatOpener): recognize archives with different filename lengths.
This commit is contained in:
parent
98ee3af701
commit
0f9c679b8c
@ -45,33 +45,50 @@ namespace GameRes.Formats.MnoViolet
|
|||||||
Extensions = new string[] { "dat" };
|
Extensions = new string[] { "dat" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static readonly uint[] NameSizes = { 100, 68, 44 };
|
||||||
|
static readonly Lazy<ImageFormat> s_GraFormat = new Lazy<ImageFormat> (() => ImageFormat.FindByTag ("GRA"));
|
||||||
|
|
||||||
public override ArcFile TryOpen (ArcView file)
|
public override ArcFile TryOpen (ArcView file)
|
||||||
{
|
{
|
||||||
int count = file.View.ReadInt32 (0);
|
int count = file.View.ReadInt32 (0);
|
||||||
if (count <= 0 || count > 0xfffff)
|
if (!IsSaneCount (count))
|
||||||
return null;
|
return null;
|
||||||
uint name_size = 100;
|
List<Entry> dir = null;
|
||||||
uint index_size = (uint)((name_size+8) * count);
|
foreach (var name_size in NameSizes)
|
||||||
uint first_offset = file.View.ReadUInt32 (4+name_size+4);
|
|
||||||
if (first_offset != (4 + index_size) || index_size > file.View.Reserve (4, index_size))
|
|
||||||
return null;
|
|
||||||
var dir = new List<Entry> (count);
|
|
||||||
long index_offset = 4;
|
|
||||||
for (int i = 0; i < count; ++i)
|
|
||||||
{
|
{
|
||||||
string name = file.View.ReadString (index_offset, name_size);
|
uint index_size = (uint)((name_size+8) * count);
|
||||||
if (0 == name.Length)
|
uint first_offset = file.View.ReadUInt32 (4+name_size+4);
|
||||||
return null;
|
if (first_offset == (4 + index_size) && first_offset < file.MaxOffset)
|
||||||
index_offset += name_size;
|
{
|
||||||
uint offset = file.View.ReadUInt32 (index_offset+4);
|
if (null == dir)
|
||||||
var entry = AutoEntry.Create (file, offset, name);
|
dir = new List<Entry> (count);
|
||||||
entry.Size = file.View.ReadUInt32 (index_offset);
|
long index_offset = 4;
|
||||||
if (offset <= index_size || !entry.CheckPlacement (file.MaxOffset))
|
for (int i = 0; i < count; ++i)
|
||||||
return null;
|
{
|
||||||
dir.Add (entry);
|
string name = file.View.ReadString (index_offset, name_size);
|
||||||
index_offset += 8;
|
if (string.IsNullOrWhiteSpace (name))
|
||||||
|
goto CheckNextLength;
|
||||||
|
index_offset += name_size;
|
||||||
|
uint offset = file.View.ReadUInt32 (index_offset+4);
|
||||||
|
var entry = new AutoEntry (name, () => {
|
||||||
|
uint signature = file.View.ReadUInt32 (offset);
|
||||||
|
if (1 == signature)
|
||||||
|
return s_GraFormat.Value;
|
||||||
|
return AutoEntry.DetectFileType (signature);
|
||||||
|
});
|
||||||
|
entry.Offset = offset;
|
||||||
|
entry.Size = file.View.ReadUInt32 (index_offset);
|
||||||
|
if (offset <= index_size || !entry.CheckPlacement (file.MaxOffset))
|
||||||
|
goto CheckNextLength;
|
||||||
|
dir.Add (entry);
|
||||||
|
index_offset += 8;
|
||||||
|
}
|
||||||
|
return new ArcFile (file, this, dir);
|
||||||
|
}
|
||||||
|
CheckNextLength:
|
||||||
|
;
|
||||||
}
|
}
|
||||||
return new ArcFile (file, this, dir);
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user