Vpk.exe: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(→‎Multi-chunk files: Added relative path example)
No edit summary
Line 1: Line 1:
'''VPK''' ("Valve Pak") files are uncompressed archives used to package content (never code). They are the successors to [[GCF]]s, and when passed to the <code>addoninstaller</code> tool are also used to distribute add-ons like custom campaigns.
'''VPK''' ("Valve Pak") files are uncompressed archives used to package game content. Valve's post-[[GCF]] games store [[VMT|material]]s, [[MDL|model]]s, [[particles]], and [[VCD|choreography scenes]] in VPK files. VPK is also used to distribute mods via the the <code>addoninstaller</code> tool that ships with some games.


== VPK tool ==
== Creation ==


VPKs can be created with the [[command line]] tool <code>vpk.exe</code>, found at <code><game>\bin\</code>. It is available in all newer Source engine games since [[Left 4 Dead]].
VPKs can be created with the [[command line]] tool <code>vpk.exe</code>.
 
When you create a VPK, some executable and archive files will be discarded. Files with following extensions are affected: .zip, .reg, .rar, .msi, .exe, .dll, .com, .cmd and .bat.


=== Commands ===
=== Commands ===


; <code><dirname></code>
; <code><dirname></code>
: Creates a new VPK in the directory given, containing the contents of that directory. Must be an existing location. Alternatively, drag a folder onto the tool in Explorer to trigger this command. {{bug|If the location is outside the game's folder, the file will just be called ".vpk".}}
: Creates a VPK containing the contents of the given directory. Must be an existing location. The VPK will appear next to the directory. {{tip|Drag a folder onto the tool in Explorer to trigger this command.}}
; <code>x <vpkfile> <filename1> <filename2> ...</code>
; <code>x <vpkfile> <filename1> <filename2> ...</code>
: Extract file(s).
: Extract file(s).
Line 16: Line 14:
: Add file(s).
: Add file(s).
; <code>a <vpkfile> @<filename></code>
; <code>a <vpkfile> @<filename></code>
: Adds the files referenced in a "response file" (''not'' response rules). Note the <code>@</code> symbol.
; <code>k vpkfile <filename></code>
; <code>k vpkfile <filename></code>
: Add files listed in a response file ('a' - note the @) or a keyvalues file ('k'). {{bug|They will appear inside the VPK with their full path (<code>C:\etc\</code>) intact - is there a way to avoid this?}}
: Add files references in a [[keyvalues]] file. {{bug|They will appear inside the VPK with their full path (<code>C:\etc\</code>) intact - is there a way to avoid this?}}
; <code>l <vpkfile></code>
; <code>l <vpkfile></code>
; <code>L <vpkfile></code>
; <code>L <vpkfile></code>
Line 24: Line 23:
: Verbose output.
: Verbose output.
; <code>-M</code>
; <code>-M</code>
: Produce a multi-chunk VPK that is split across several files and has an index. To inspect a multi-chunk VPK look at the '_dir' file.
: 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|Multi-chunk generations only works when creating a VPK from a response file.}}{{tip|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 <code>vpk</code> 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.
 
<source lang="python">
# 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])
</source>
 
=== Excluded files ===
 
Executable and archive files are discarded by the VPK tool:


=== Multi-chunk files ===
.zip .reg .rar .msi .exe .dll .com .cmd .bat
A multi-chunk VPK requires a list of the files to be packed:
* Create the list using Windows console, <code>dir /s /b *.<file format> >> <text file name></code>. ''For example, dir /s /b *.vmt >> responsefile''. Repeat this (manually or with a script) until every file format to be packed is added to the list.
* In a text editor, remove any absolute paths making them relative to the game. For example, "C:\Program Files\Steam\steamapps\common\portal 2\portal2\models\props\tripwire_turret.mdl" would become "models\props\tripwire_turret.mdl".
* Finally pack the file, <code>vpk -M a pak01 @<text file name></code>. ''For example, vpk -M a pak01 @responsefile''.


== See also ==
== See also ==

Revision as of 09:32, 16 September 2012

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