mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 05:35:34 +08:00
(PAC/LUNA): support 64-bit offsets.
This commit is contained in:
parent
e24c01ad0f
commit
5d94af9cfa
@ -45,23 +45,44 @@ namespace GameRes.Formats.LunaSoft
|
||||
if (!IsSaneCount (count))
|
||||
return null;
|
||||
long base_offset = file.View.ReadUInt32 (8);
|
||||
|
||||
uint current_offset = 0x10;
|
||||
var dir = new List<Entry> (count);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
uint name_length = file.View.ReadUInt32 (current_offset+0x108);
|
||||
var name = file.View.ReadString (current_offset, name_length);
|
||||
var entry = FormatCatalog.Instance.Create<Entry> (name);
|
||||
current_offset += 0x100;
|
||||
entry.Offset = base_offset + file.View.ReadUInt32 (current_offset);
|
||||
entry.Size = file.View.ReadUInt32 (current_offset+4);
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
if (!ReadIndex (file, dir, count, base_offset) &&
|
||||
!ReadIndex (file, dir, count, base_offset, true))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
current_offset += 0xC;
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
bool ReadIndex (ArcView file, List<Entry> dir, int count, long base_offset, bool long_offsets = false)
|
||||
{
|
||||
Func<uint, long> read_offset;
|
||||
uint size_pos;
|
||||
if (long_offsets)
|
||||
{
|
||||
read_offset = idx_off => file.View.ReadInt64 (idx_off);
|
||||
size_pos = 0x108;
|
||||
}
|
||||
else
|
||||
{
|
||||
read_offset = idx_off => file.View.ReadUInt32 (idx_off);
|
||||
size_pos = 0x104;
|
||||
}
|
||||
dir.Clear();
|
||||
uint current_offset = 0x10;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
uint name_length = file.View.ReadUInt32 (current_offset+size_pos+4);
|
||||
if (name_length > 0x100 || 0 == name_length)
|
||||
return false;
|
||||
var name = file.View.ReadString (current_offset, name_length);
|
||||
var entry = Create<Entry> (name);
|
||||
entry.Offset = base_offset + read_offset (current_offset+0x100);
|
||||
entry.Size = file.View.ReadUInt32 (current_offset+size_pos);
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return false;
|
||||
dir.Add (entry);
|
||||
current_offset += size_pos+8;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user