(VPK): added VPK0 archives implementation.

This commit is contained in:
morkt 2017-12-08 14:45:08 +04:00
parent 8fbc8d4723
commit 1860077251

View File

@ -42,6 +42,7 @@ namespace GameRes.Formats.Will
public VpkOpener () public VpkOpener ()
{ {
Extensions = new string[] { "vpk" }; Extensions = new string[] { "vpk" };
Signatures = new uint[] { 0x314B5056, 0x304B5056 };
} }
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
@ -58,25 +59,37 @@ namespace GameRes.Formats.Will
long data_offset = index_offset + index_size; long data_offset = index_offset + index_size;
if (data_offset >= file.MaxOffset || data_offset <= index_offset) if (data_offset >= file.MaxOffset || data_offset <= index_offset)
return null; return null;
int version = file.View.ReadByte (3) - '0';
int name_length = version > 0 ? 4 : 2;
using (var index = file.CreateStream (index_offset, index_size))
{
var dir = new List<Entry> (count); var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
var name = file.View.ReadString (index_offset, 4); var name = index.ReadCString (name_length);
if (0 == name.Length) if (0 == name.Length)
return null; return null;
uint n1 = file.View.ReadUInt16 (index_offset+4); uint n1 = index.ReadUInt16();
uint n2 = file.View.ReadUInt16 (index_offset+6); if (version > 0)
uint n3 = file.View.ReadUInt32 (index_offset+8); {
uint n2 = index.ReadUInt16();
uint n3 = index.ReadUInt32();
name = string.Format ("{0}_{1:D2}_{2}_{3:D3}.wav", name, n1, n2, n3); name = string.Format ("{0}_{1:D2}_{2}_{3:D3}.wav", name, n1, n2, n3);
}
else
{
uint n2 = index.ReadUInt32();
name = string.Format ("{0}_{1:D2}_{2:D3}.wav", name, n1, n2);
}
var entry = FormatCatalog.Instance.Create<Entry> (name); var entry = FormatCatalog.Instance.Create<Entry> (name);
entry.Offset = file.View.ReadUInt32 (index_offset+0x0C); entry.Offset = index.ReadUInt32();
entry.Size = file.View.ReadUInt32 (index_offset+0x10); entry.Size = index.ReadUInt32();
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset))
return null; return null;
dir.Add (entry); dir.Add (entry);
index_offset += 0x14;
} }
return new ArcFile (file, this, dir); return new ArcFile (file, this, dir);
} }
} }
}
} }