(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;
var dir = new List<Entry> (count); int version = file.View.ReadByte (3) - '0';
for (int i = 0; i < count; ++i) int name_length = version > 0 ? 4 : 2;
using (var index = file.CreateStream (index_offset, index_size))
{ {
var name = file.View.ReadString (index_offset, 4); var dir = new List<Entry> (count);
if (0 == name.Length) for (int i = 0; i < count; ++i)
return null; {
uint n1 = file.View.ReadUInt16 (index_offset+4); var name = index.ReadCString (name_length);
uint n2 = file.View.ReadUInt16 (index_offset+6); if (0 == name.Length)
uint n3 = file.View.ReadUInt32 (index_offset+8); return null;
name = string.Format ("{0}_{1:D2}_{2}_{3:D3}.wav", name, n1, n2, n3); uint n1 = index.ReadUInt16();
var entry = FormatCatalog.Instance.Create<Entry> (name); if (version > 0)
entry.Offset = file.View.ReadUInt32 (index_offset+0x0C); {
entry.Size = file.View.ReadUInt32 (index_offset+0x10); uint n2 = index.ReadUInt16();
if (!entry.CheckPlacement (file.MaxOffset)) uint n3 = index.ReadUInt32();
return null; name = string.Format ("{0}_{1:D2}_{2}_{3:D3}.wav", name, n1, n2, n3);
dir.Add (entry); }
index_offset += 0x14; else
{
uint n2 = index.ReadUInt32();
name = string.Format ("{0}_{1:D2}_{2:D3}.wav", name, n1, n2);
}
var entry = FormatCatalog.Instance.Create<Entry> (name);
entry.Offset = index.ReadUInt32();
entry.Size = index.ReadUInt32();
if (!entry.CheckPlacement (file.MaxOffset))
return null;
dir.Add (entry);
}
return new ArcFile (file, this, dir);
} }
return new ArcFile (file, this, dir);
} }
} }
} }