Difference between revisions of "VPK"

From Valve Developer Community
Jump to: navigation, search
(Added an actual working script for the linux version of the vpk tool.)
m (Whoops, small syntax error in last edit. all fixed up now)
Line 46: Line 46:
VPK_LINUX="$(find "${HOME}/.local/share/Steam" -type f -iname "vpk_linux32" -print | head -n 1)"
VPK_LINUX="$(find "${HOME}/.local/share/Steam" -type f -iname "vpk_linux32" -print | head -n 1)"
VALVE_LIB_DIR="$(dirname  "${VPK_LINUX}")"
VALVE_LIB_DIR="$(dirname  "${VPK_LINUX}")"

Revision as of 13:03, 17 April 2016

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.


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

The tool can be located in the following folders depending on the game. The tool is not game dependent, however it is suggested that you use the tool that corresponds to the game you are creating the vpk for. The version in one game may not be as up to date as the version in another due to game updates.

 Game  Path to VPK.exe
Alien SwarmAlien Swarm C:\Program Files (x86)\Steam\SteamApps\common\Alien Swarm\bin
Team Fortress 2Team Fortress 2 C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\bin
Left 4 DeadLeft 4 Dead C:\Program Files (x86)\Steam\SteamApps\common\Left 4 Dead\bin
Counter-Strike: SourceCounter-Strike: Source C:\Program Files (x86)\Steam\SteamApps\common\Counter-Strike Source\bin
Source Source SDK Base 2013 C:\Program Files (x86)\Steam\SteamApps\common\Source SDK Base 2013\<Singleplayer or Multiplayer>\bin
Counter-Strike: Global Offensive Counter-Strike: Global Offensive C:\Program Files (x86)\Steam\SteamApps\common\Counter-Strike Global Offensive\bin

For servers installed using SteamCMD, it is located in the server's bin\ directory. On Linux, it is named vpk_linux32 instead of vpk.exe.

Linux users

On linux clients, the vpk file can be found replacing "C:\Program Files (x86)\Steam\SteamApps\common" for "~/.steam/steam/SteamApps/common/". However, it is named vpk_linux32.

If you are running on a 64-bit system this binary will not work by default. You must tell it to use the 32-bit libraries located in the same directory. This can be done by setting the LD_LIBRARY_PATH. The following script, if created in the above listed bin directories, will create a wrapper to properly launch the 32 bit executable;

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 
exec "$DIR/vpk_linux32" "[email protected]"

Alternatively, if you're running 64-bit Linux, you can use this script to execute the vpk_linux32 binary successfully. Save this script to "/usr/local/bin/vpk" for ease of use.

VPK_LINUX="$(find "${HOME}/.local/share/Steam" -type f -iname "vpk_linux32" -print | head -n 1)"
VALVE_LIB_DIR="$(dirname  "${VPK_LINUX}")"



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.png Tip: 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.
Bug.png Bug: They will appear inside the VPK with their full path (C:\etc\) intact - is there a way to avoid this?
vpk <directory>
Create VPK from directory structure.
Note.png Note: 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.png Note: 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.


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


Tip.png Tip: Please note the case of these options. A capital letter is different than a lowercase letter.
Verbose output.
Produce a multi-chunk VPK.
Note.png Note: 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.png Note: Multi-chunk generations only works when creating a VPK from a response file.
    Tip.png Tip: To inspect a multi-chunk VPK open the '_dir' file.
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.
Align files within chunk on n-byte boundary. Default is 1.
With commands 'a' or 'k': Sign VPK with specified private key.
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.


Listed below are some examples of using the tool and what they will do.

Creating A Key Value File and VPK

1. Create a folder with the correct directory structure and files that you wish to use such as mymod/resource/ui/<file.res>
2. Use the command line in a prompt or a bat:
vpk generate_keypair <name>
vpk -M -k <name>.publickey.vdf -K <name>.privatekey.vdf "C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\bin\mymod"
3. In the folder where the vpk tool is located there will now be a public key vdf, a private key vdf, a vpk named mymod_000 and a vpk named mymod_dir.
Warning.png Warning: Never disclose or share your private key vdf or the key. Only share the public key.
  • You must distribute your mod with both the mymod_dir and mymod_000 vpks for the keyvalue to work.

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")


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