Vpk.exe

From Valve Developer Community
Revision as of 21:56, 25 April 2013 by DontWannaName (talk | contribs) (→‎Commands: Updated with latest commands and formats)
Jump to navigation Jump to search

VPK ("Valve Pak") files are uncompressed archives used to package game content. Valve's post-GCF games store materials, models, particles, and choreography scenes in VPK files. VPK is also used to distribute mods via the the addoninstaller tool that ships with some games.

Creation

VPKs can be created with the command line tool vpk.exe.

Commands

Usage:

vpk [options] <command> <command arguments ...>
vpk [options] <directory>
vpk [options] <vpkfile>

Create VPK/Add Files

vpk <dirname>
Creates a pack file named <dirname>.vpk. Must be an existing location. The VPK will appear next to the directory.
Tip.pngTip:Drag a folder onto the tool in Explorer to trigger this command.
vpk a <vpkfile> <filename1> <filename2> ...
Add file(s).
a <vpkfile> @<filename>
Adds the files referenced in a "response file" (not response rules). Note the @ symbol.
k vpkfile <keyvalues_filename>
Add files references in a keyvalues control file.
Icon-Bug.pngBug:They will appear inside the VPK with their full path (C:\etc\) intact - is there a way to avoid this?  [todo tested in ?]
vpk <directory>
Create VPK from directory structure.
Note.pngNote:This is invoked when a directory is dragged onto the VPK tool.

Extract Files

vpk x <vpkfile> <filename1> <filename2> ...
Extract file(s).
vpk <vpkfile>
Extract all files from VPK.
Note.pngNote:This is invoked when a .VPK file is dragged onto the VPK tool.

Display VPK Info

vpk l <vpkfile>
List contents of VPK.
vpk L <vpkfile>
List Detailed contents of VPK.

VPK Integrity/Security

vpk checksig <vpkfile>
Verify signature of specified VPK file. Requires -k to specify key file to use.

Misc

vpk generate_keypair <keybasename>
Generate public/private key file. Output files will be named <keybasemame>.publickey.vdf and <keybasemame>.privatekey.vdf
Note.pngNote:Remember: your private key should be kept private.

Options

Tip.pngTip:Please note the case of these options. A capital letter is different than a lowercase letter.
-v
Verbose output.
-M
Produce a multi-chunk VPK.
Note.pngNote:Required if creating a VPK with key values.
  • Each chunk is a file limited to around 200MB.
  • To reduce patch sizes, chunks are never overwritten. New/modified files are instead written to a brand new chunk every time you run the tool.
    Note.pngNote:Multi-chunk generations only works when creating a VPK from a response file.
    Tip.pngTip:To inspect a multi-chunk VPK open the '_dir' file.
-P
Use SteamPipe-friendly incremental build algorithm. Use with 'k' command. For optimal incremental build performance, the control file used for the previous build should exist and be named the same as theinput control file, with '.bak' appended, and each file entryshould have an 'md5' value. The 'md5' field need not be theactual MD5 of the file contents, it is just a unique identifierthat will be compared to determine if the file contents has changedbetween builds.
-c <size>
Use specified chunk size (in MB). Default is 200.
-a
Align files within chunk on n-byte boundary. Default is 1.
-K
With commands 'a' or 'k': Sign VPK with specified private key.
-k
  • With commands 'a' or 'k': Public key that will be distributed and used by third parties to verify signatures.
  • With command 'checksig': Check signature using specified key file.

Response file

A "response file" contains a list of files to be added to a VPK. Paths are relative to the current directory of the vpk tool.

Below is a Python script which generates a response file and then builds a multi-chunk VPK. Put it in your mod folder. You will need to edit the three variables at the top.

# User settings (don't use the \ character)
target_folders = [ "materials", "models", "particles", "scenes" ]
file_types = [ "vmt", "vtf", "mdl", "phy", "vtx", "vvd", "pcf", "vcd" ]
vpk_path = "C:/Program Files (x86)/Steam/steamapps/common/SourceFilmmaker/game/bin/vpk.exe"

# Script begins
import os,subprocess
from os.path import join
response_path = join(os.getcwd(),"vpk_list.txt")

out = open(response_path,'w')
len_cd = len(os.getcwd()) + 1

for user_folder in target_folders:
	for root, dirs, files in os.walk(join(os.getcwd(),user_folder)):
		for file in files:
			if len(file_types) and file.rsplit(".")[-1] in file_types:
				out.write(os.path.join(root[len_cd:].replace("/","\\"),file) + "\n")

out.close()

subprocess.call([vpk_path, "-M", "a", "pak01", "@" + response_path])

Excluded files

Executable and archive files are discarded by the VPK tool:

.zip .reg .rar .msi .exe .dll .com .cmd .bat

See also