Update VPK models

This commit is contained in:
Matt Nadareski
2024-11-18 02:13:52 -05:00
parent b4a5154da8
commit f862e018fb
7 changed files with 114 additions and 9 deletions

View File

@@ -0,0 +1,27 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.VPK
{
/// <see href="https://developer.valvesoftware.com/wiki/VPK_(file_format)"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class ArchiveMD5SectionEntry
{
public uint ArchiveIndex;
/// <summary>
/// Where to start reading bytes
/// </summary>
public uint StartingOffset;
/// <summary>
/// How many bytes to check
/// </summary>
public uint Count;
/// <summary>
/// Expected checksum
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[]? MD5Checksum = new byte[16];
}
}

View File

@@ -3,17 +3,37 @@ using System.Runtime.InteropServices;
namespace SabreTools.Models.VPK
{
/// <see href="https://github.com/RavuAlHemio/hllib/blob/master/HLLib/VPKFile.h"/>
/// <see href="https://developer.valvesoftware.com/wiki/VPK_(file_format)"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class DirectoryEntry
{
/// <summary>
/// A 32bit CRC of the file's data.
/// </summary>
public uint CRC;
/// <summary>
/// The number of bytes contained in the index file.
/// </summary>
public ushort PreloadBytes;
/// <summary>
/// A zero based index of the archive this file's data is contained in.
/// If 0x7fff, the data follows the directory.
/// </summary>
public ushort ArchiveIndex;
/// <summary>
/// If ArchiveIndex is 0x7fff, the offset of the file data relative to the
/// end of the directory (see the header for more details).
/// Otherwise, the offset of the data from the start of the specified archive.
/// </summary>
public uint EntryOffset;
/// <summary>
/// If zero, the entire file is stored in the preload data.
/// Otherwise, the number of bytes stored starting at EntryOffset.
/// </summary>
public uint EntryLength;
/// <summary>

View File

@@ -1,6 +1,7 @@
namespace SabreTools.Models.VPK
{
/// <see href="https://github.com/RavuAlHemio/hllib/blob/master/HLLib/VPKFile.h"/>
/// <see href="https://developer.valvesoftware.com/wiki/VPK_(file_format)"/>
public sealed class DirectoryItem
{
public string? Extension { get; set; }

View File

@@ -6,27 +6,33 @@ namespace SabreTools.Models.VPK
/// Added in version 2.
/// </summary>
/// <see href="https://github.com/RavuAlHemio/hllib/blob/master/HLLib/VPKFile.h"/>
/// <see href="https://developer.valvesoftware.com/wiki/VPK_(file_format)"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class ExtendedHeader
{
/// <summary>
/// Reserved
/// How many bytes of file content are stored in this
/// VPK file (0 in CSGO)
/// </summary>
public uint Dummy0;
public uint FileDataSectionSize;
/// <summary>
/// Archive hash length
/// The size, in bytes, of the section containing MD5
/// checksums for external archive content
/// </summary>
public uint ArchiveHashLength;
public uint ArchiveMD5SectionSize;
/// <summary>
/// Looks like some more MD5 hashes.
/// The size, in bytes, of the section containing MD5
/// checksums for content in this file (should always be 48)
/// </summary>
public uint ExtraLength;
public uint OtherMD5SectionSize;
/// <summary>
/// Reserved
/// The size, in bytes, of the section containing the public
/// key and signature. This is either 0 (CSGO & The Ship) or
/// 296 (HL2, HL2:DM, HL2:EP1, HL2:EP2, HL2:LC, TF2, DOD:S & CS:S)
/// </summary>
public uint Dummy1;
public uint SignatureSectionSize;
}
}

View File

@@ -3,6 +3,7 @@ using System.Runtime.InteropServices;
namespace SabreTools.Models.VPK
{
/// <see href="https://github.com/RavuAlHemio/hllib/blob/master/HLLib/VPKFile.h"/>
/// <see href="https://developer.valvesoftware.com/wiki/VPK_(file_format)"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class Header
{
@@ -13,6 +14,9 @@ namespace SabreTools.Models.VPK
public uint Version;
public uint DirectoryLength;
/// <summary>
/// The size, in bytes, of the directory tree
/// </summary>
public uint TreeSize;
}
}

View File

@@ -0,0 +1,18 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.VPK
{
/// <see href="https://developer.valvesoftware.com/wiki/VPK_(file_format)"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class OtherMD5Section
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[]? TreeChecksum = new byte[16];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[]? ArchiveMD5SectionChecksum = new byte[16];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[]? WholeFileChecksum = new byte[16];
}
}

View File

@@ -0,0 +1,29 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.VPK
{
/// <see href="https://developer.valvesoftware.com/wiki/VPK_(file_format)"/>
[StructLayout(LayoutKind.Sequential)]
public sealed class SignatureSection
{
/// <summary>
/// Always seen as 160 (0xA0) bytes
/// </summary>
public uint PublicKeySize;
/// <summary>
/// <see cref="PublicKeySize"/>
/// </summary>
public byte[]? PublicKey;
/// <summary>
/// Always seen as 128 (0x80) bytes
/// </summary>
public uint SignatureSize;
/// <summary>
/// <see cref="SignatureSize"/>
/// </summary>
public byte[]? Signature;
}
}