Vpk.exe

From Valve Developer Community
Revision as of 09:32, 16 September 2012 by Artfunkel (talk | contribs)
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

<dirname>
Creates a VPK containing the contents of the given directory. 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.
x <vpkfile> <filename1> <filename2> ...
Extract file(s).
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 <filename>
Add files references in a keyvalues 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 ?]
l <vpkfile>
L <vpkfile>
List contents of VPK. Uppercase 'L' means more detail.
-v
Verbose output.
-M
Produce a multi-chunk VPK.
  • 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.

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