mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-23 19:34:15 +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);
|
||||
if (!ReadIndex (file, dir, count, base_offset) &&
|
||||
!ReadIndex (file, dir, count, base_offset, true))
|
||||
return null;
|
||||
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+0x108);
|
||||
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 = 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);
|
||||
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 null;
|
||||
return false;
|
||||
dir.Add (entry);
|
||||
current_offset += 0xC;
|
||||
current_offset += size_pos+8;
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user