This article's documentation is for anything that uses the Source engine. Click here for more information.

BSPZIP: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Setting bug notice hidetested=1 param on page where the bug might not need tested in param specified)
 
(75 intermediate revisions by 29 users not shown)
Line 1: Line 1:
__TOC__
{{LanguageBar}}
The [[BSP]] format maps used in [[Source]] engine can have embedded custom materials and models. '''Bspzip''' is a command-line utility that allows level designers to embed, extract, and list game content in .BSP files, simplifying the distribution of custom map content.
{{src topicon}}
{{map compile pipeline|source1}}


The <code>bspzip.exe</code> application can be used in four separate modes, with the following syntax:
{{toc-right}}
'''BSPZIP''' is a [[command-line]] tool that allows arbitrary files to be embedded within a [[BSP (Source 1)|BSP]]. When the map is being loaded the files will be mounted as if they were present in the game's real content folders.
{{tip|Several [[#GUIs/Replacements|GUI utilities]] have been created that may be more convenient than using BSPZIP directly.}}
{{tip|Embedded content can be examined with archive tools that support uncompressed and {{w|LZMA}}-compressed [[ZIP]] files by opening the BSP file.<br>In some instances, it may be necessary to open via hash, as certain operations will cause additional data to be written after the "pakfile" lump in the BSP.}}
{{bug|tested={{bms}}|Custom [[VMT]] files located in the root of {{path|materials/}} folder may fail to be packed into the BSP, use subfolders for custom materials.<br>example: {{path|materials/my_custom_materials/}}}}


<pre>
While it is usually a good idea to BSPZIP content, there are times when it can cause problems and other times when it won't work at all (e.g., for [[Maplist Thumbnails]]). When this happens, a [[resource list]] can be used instead.
bspzip -dir bspfile
bspzip -addfile bspfile relativepathname fullpathname newbspfile
bspzip -addlist bspfile listfile newbspfile
bspzip -extract bspfile files.zip
</pre>


== Basic usage ==
== Usage ==
The Windows environment variable <code>"%sourcesdk%"</code> can be utilized to locate <code>bspzip.exe</code> easily in a command-line statement. This variable contains the location of the [[Source SDK]] installation directory.
BSPZIP is found at <tt>"common\<gamename>\bin\bspzip.exe"</tt>. It performs several functions:


For example, to list all of the embedded contents of a [[Half-Life 2: Deathmatch]] map called <code>"dm_lockdown.bsp"</code>, you would open a command prompt, change to the directory to <code>"half-life 2/hl2/maps"</code> and type this at the command-line:
=== Adding a List of Files ===
The most common function. There are two related commands:


<pre>
-addlist <input bsp> <file list> <output bsp>
"%sourcesdk%\bin\bspzip" -dir dm_lockdown.bsp
-addorupdatelist <input bsp> <file list> <output bsp>
</pre>


{{note|For Orange Box games the path is "%sourcesdk%\bin\orangebox\bin\bspzip" rather than "%sourcesdk%\bin\bspzip".}}
Include file extensions. The former command packs all files in the list, the latter (untested, Orange Box only) packs only those that have changed since the last operation.
{{tip|The input and output files can be the same.}}


This will generate a list of files embedded into the .BSP file, like this:
The "file list" is a <tt>.txt</tt> file containing this pattern:


<pre>
internal_path/file1
materials/maps/dm_lockdown/tile/tilewall009b_-3792_3120_72.vmt
external_path\file1
materials/maps/dm_lockdown/tile/tilewall009b_-3488_2752_80.vmt
internal_path/file2
materials/maps/dm_lockdown/tile/tilewall009b_-3488_3104_72.vmt
external_path\file2
materials/maps/dm_lockdown/tile/tilewall009b_-3192_3120_72.vmt
...
materials/maps/dm_lockdown/tile/tilewall009b_-2944_3136_72.vmt
...
</pre>


In this case, all of the cubemap materials used in <code>dm_lockdown.bsp</code> are listed.
* Internal paths (relative paths) are the location the file will take within the BSP; e.g., <tt>materials/metal/new_steel.vmt</tt>.
* External paths (absolute paths) are the location of the file to be packed, e.g., <tt>C:\Users\Public\our_maps\materials\metal\new_steel.vmt</tt>.


{{note|It is very important that you set the "Current Game"' in either the "SDK Launcher" or "VConfig" to the correct game directory before you open a command prompt to compile textures. Changing the "Current Game" will not affect any command prompt windows that are already open. This is due to how Windows uses environment variables.}}
For example:
materials/foo/bar.vtf
D:\Steam\steamapps\common\Counter-Strike Source\cstrike\custom\stuff\materials\foo\bar.vtf
materials/foo/bar.vmt
D:\Steam\steamapps\common\Counter-Strike Source\cstrike\custom\stuff\materials\foo\bar.vmt
sound/lorem/ipsum.mp3
D:\Steam\steamapps\common\Counter-Strike Source\cstrike\custom\stuff\sound\lorem\ipsum.mp3


== Embedding individual files ==
=== Adding a Single File ===
Using the <code>-addfile</code> command with Bspzip allows you to add an individual file to the .BSP. The syntax is:
The same principle as above, but without a file list.


<pre>
-addfile <input bsp> <internal path> <external path> <output bsp>
bspzip -addfile bspfile relativepathname fullpathname newbspfile
</pre>


where <code>bspfile</code> is the original map file; <code>relativepathname</code> is the file to be added, expressed as a path relative to the game directory; <code>fullpathname</code> is the same file, expressed as an absolute path; and <code>newbspfile</code> is the name of the resulting map file.
=== Viewing and Extracting Files ===
If you have an archive tool installed that is able to look inside BSPs, it's better to use that. If you don't, these are the commands you need:


For example, if you had a .VMT at <code>"/half-life 2 deathmatch/hl2mp/materials/metal/sample.vmt"</code> that you wished to embed into a map called <code>"dm_mymap.bsp"</code>, you would type this at the command-line:
-extract <bsp file> <output.zip>
-extractfiles <bsp file>
-dir <bsp file>


<pre>
=== Handling Cubemaps ===
"%sourcesdk%\bin\bspzip" -addfile dm_mymap.bsp "materials/metal/sample.vmt" "%vproject%/materials/metal/sample.vmt" dm_mymap.bsp
Should be self-evident:
</pre>


This would read the map <code>"dm_mymap.bsp"</code>, add <code>"materials/metal/sample.vmt"</code>, and output the result back into the original file <code>"dm_mymap.bsp"</code>. The environment variable <code>"%vproject%"</code> was used to locate the game directory.
-extractcubemaps <bsp file> <output folder>
-deletecubemaps <bsp file>
{{warning|<tt>-deletecubemaps</tt> actually deletes all <tt>.vtf</tt> files in the <tt>.bsp</tt>—handle with caution!}}
{{bug|tested={{src13mp}}|{{code|-deletecubemaps}} may actually delete the entire PAKFILE lump, rendering the map broken! Use {{vide|4}} or {{vpkedit|4}} instead.}}


== Embedding a list of files ==
== Testing ==
Using the <code>-addlist</code> command with Bspzip allows you to add a number of files specified in a .TXT file list:
There are situations where files won't be loaded from BSP files correctly. As time goes on, they become fewer in number, but it's always worth checking regardless. The easiest way to do so is moving all of the embedded content out of the game's folders—or even better, not storing it there in the first place.


<pre>
== Compression ==
bspzip -addlist bspfile listfile newbspfile
{{since|{{src13mp}}}} {{also|{{strata}} {{jbep3}}}}
</pre>
Repacking allows you to [[compression|compress]] your map using {{w|LZMA}} to save hard drive space and download times. To repack a map and compress it, these commands are used:


The list file uses a similar format to the <code>-addfile</code> command -- a path relative to the game directory, as well as an absolute path to the files you wish to add. The file should list the relative and absolute path for each file, like this:
-repack -compress <bsp file>


<pre>
To decompress repacked maps, run the same command but ommit the <code>-compress</code> command:
relativepath/file1
absolutepath/file1
relativepath/file2
absolutepath/file2
...
</pre>


For example, if you had several .VMT files in <code>"/half-life 2 deathmatch/hl2mp/materials/metal/"</code> that you wished to embed, you would create a list file like this in a text editor:
-repack <bsp file>


<pre>
{{warning|
materials/metal/sample.vmt
* Repacked maps won't work in {{sfm|4.1}} and will crash the program on load!
C:/Program Files/Valve/Steam/SteamApps/username/half-life 2 deathmatch/hl2mp/materials/metal/sample.vmt
* Trying to [[Cubemaps#Building cubemaps|build cubemaps]] on a already compressed map will result in the game crashing!}}
materials/metal/sample.vtf
C:/Program Files/Valve/Steam/SteamApps/username/half-life 2 deathmatch/hl2mp/materials/metal/sample.vtf
materials/metal/sample2.vmt
C:/Program Files/Valve/Steam/SteamApps/username/half-life 2 deathmatch/hl2mp/materials/metal/sample2.vmt
materials/metal/sample2.vtf
C:/Program Files/Valve/Steam/SteamApps/username/half-life 2 deathmatch/hl2mp/materials/metal/sample2.vtf
</pre>


It is important to leave a line break after the last file, or it will not be added. Save the file in the maps directory (where the .BSP is located). It can be placed anywhere, but it's most convenient to find it in this location.
{{bug|tested={{tf2}} {{css}}|Map compression may sometimes result in packed [[ADPCM]] audio files not properly caching, resulting in improper playback on subsequent loads. This does not happen if the [[soundcache|audio cache]] was created when the BSP file was uncompressed, or when using other audio formats (8-bit, 16-bit, [[MP3]], etc). This also does not seem to occur when using {{tf2|4.1|addtext='s}} workshop uploader.
Since files which are flagged as streaming ({{code|<nowiki>*</nowiki>}} [[sound character]]) are not loaded from the cache, they are unaffected by this bug. As such, it may be preferable to only use ADPCM for looping music.}}
{{bug|hidetested=1|[[ANI]] files will not load correctly from a compressed BSP.}}


If you wanted to add files in a list called <code>"addmaterials.txt"</code> to a .BSP called <code>"dm_mymap.bsp"</code>, you would type this at the console:
{{note|
* The BSPZIP included with {{csgo}} Authoring Tools doesn't support repacking.{{confirm|Does {{CSGO}} even support compressed BSPs?}}
* {{tf2}} automatically compresses BSPs when uploading to the workshop.
* {{gmod}} supports compressed BSPs, but the BSPZIP included with {{gmod}} doesn't support repacking ([https://github.com/Facepunch/garrysmod-requests/issues/2372 relevant GitHub request]). Use the BSPZIP that comes with {{tf2}} instead. }}
{{tip|The map will need to be decompressed before BSPZIP will allow new files to be packed into the BSP.
{{workaround|[https://github.com/ficool2/map_batch_updater Ficool2's Map Batch Updater] can edit the contents of compressed BSPs, including changing the compression level of the ZIP lump. although the same compression level will apply to ''all'' packed files
{{modernConfirm|Can the ZIP lump in a compressed BSP be edited in some other way (using some other tool), allowing for custom levels of compression of different contained files? Perhaps using [[Lump file format|LMPFIX]]?<br>For example, the compression method used ({{wiki|LZMA}}) significantly impacts the load latency of audio files at high compression levels compared to faster methods.}}}}
}}


<pre>
== GUIs/Replacements ==
"%sourcesdk%\bin\bspzip" -addlist dm_mymap.bsp addmaterials.txt dm_mymap.bsp
The following GUI tools are often preferred to BSPZIP directly, and they may aid you in determining which files need to be packed into your map.
</pre>
* {{compilepal|2}}
* [[Packbsp]]
* {{Map Analyst|2}}
* {{Pakrat|2}}
* {{vide|2}}
* {{vpkedit|2}}
* {{bspzipgui moltard|2}}(2020) - This app allows you to embed a folder with your files into BSP file, repack (compress and decompress) and can save different map configurations. It uses bspzip for the actual packing.
* [https://github.com/geotavros/BspZipGui BspZipGui](2016) - The app allows you to embed a folder with your files into BSP file in just a few clicks. It uses bspzip for the actual packing.
* {{autobspp|2}} - Automatically detects content that is used in the map and packs it. It has a GUI as well as a command line interface which makes it easy to add as a compile step in Hammer.
* [https://github.com/jackson-c/quickpack QuickPack] - This script quickly finds and packs all dependencies in a map. For models with different skins, it only packs used skins to save file space.
* {{teamspen|2}} - This includes a post-compiler which automatically finds and packs custom content, and adds entities to control auto-packing.


This would read the map <code>"dm_mymap.bsp"</code>, add all the files referenced in <code>"addmaterials.txt"</code> and output the result back into the original file <code>"dm_mymap.bsp"</code>. Bspzip generates the following output when this command is executed:
== See also ==
* [[Resource list]] (Alternative method to push content to users)
* [[GCFScape]] (Read-only tool for inspecting BSP contents)


<pre>
Opening bsp file: C:/Program Files/Valve/Steam/SteamApps/username/half-life 2 deathmatch/hl2mp/maps/dm_mymap.bsp
Adding file: C:/Program Files/Valve/Steam/SteamApps/username/half-life 2 deathmatch/hl2mp/materials/metal/sample.vmt
Adding file: C:/Program Files/Valve/Steam/SteamApps/username/half-life 2 deathmatch/hl2mp/materials/metal/sample.vtf
Adding file: C:/Program Files/Valve/Steam/SteamApps/username/half-life 2 deathmatch/hl2mp/materials/metal/sample2.vmt
Adding file: C:/Program Files/Valve/Steam/SteamApps/username/half-life 2 deathmatch/hl2mp/materials/metal/sample2.vtf


Writing new bsp file: C:/Program Files/Valve/Steam/SteamApps/username/half-life 2 deathmatch/hl2mp/maps/dm_mymap.bsp
[[Category:Official Source Tools]]
</pre>
 
== Extracting files ==
You can extract content embedded in a .BSP file with Bspzip using the following syntax:
 
<pre>
bspzip -extract bspfile files.zip
</pre>
 
This will create a new .ZIP format file that contains all of the embedded content in the .BSP you specify. For example:
 
<pre>
"%sourcesdk%\bin\bspzip" -extract dm_mymap.bsp dm_mymap_content.zip
</pre>
 
This would create a file called <code>"dm_mymap_content.zip"</code> that contains all of the embedded files in <code>"dm_mymap.bsp"</code>. The .ZIP file can now be opened and decompressed to examine the contents.
 
== Scripting ==
To automate the process of adding files to a map, save the following as a .BAT file:
 
"%sourcesdk%/bin/bspzip.exe" -addlist <BSP NAME> <.TXT FILE LIST> <NEW BSP NAME>
pause
 
You will need to fill in the values in brackets. Then whenever you want to update the existing zipped content in your map, run the file.
 
To view files within a map with a script, save the following as a .BAT file:
 
"%sourcesdk%/bin/bspzip.exe" -dir %1
pause
 
Drag any map over it and it's contents will be displayed.
 
== Testing and conclusion ==
{{note|You can add custom model content using the same method. Just make sure you add all of the relevant model files (.MDL, .VTX, .PHY, etc.) as well as any materials that the models have referenced.}}
 
Once you're done adding custom content to the .BSP files, it's also important to test to make sure you've added all of the necessary files. One way to do this is to move the necessary content files (models, materials) out of their proper directory into another directory temporarily. Then, launch the game and load the map. If you've done things correctly, the content should still appear in the map, since they are now loaded from inside the .BSP file instead of the materials or models directory. This is an accurate simulation of what another user loading your map would experience.
 
If some of the content does not load correctly, and you receive error messages that files are missing in the console, go back and check your process and make sure you made no mistakes when you added the files. Using the <code>bspzip -dir</code> command to list the contents of your .BSP file can be useful to find errors, such as an improper directory path.
 
Once you've tested for errors, you can restore the content back to the proper locations and you're ready to distribute your BSP file.
 
== Similar applications ==
* [[GCFScape]] - extraction only.
* [[Map Analyst]]
* [[Pakrat]]
* [[WinBSPZip]] - a GUI frontend for Bspzip.
{{note|WinBSPZip is no longer compatible with current map format (since August 2006 SDK update).}}
 
[[Category:Level Design]]
[[Category:Tutorials]]
[[Category:Tools]]

Latest revision as of 07:07, 20 May 2025

English (en)中文 (zh)Translate (Translate)

VBSPVVISVRADBSPZIP

BSPZIP is a command-line tool that allows arbitrary files to be embedded within a BSP. When the map is being loaded the files will be mounted as if they were present in the game's real content folders.

Tip.pngTip:Several GUI utilities have been created that may be more convenient than using BSPZIP directly.
Tip.pngTip:Embedded content can be examined with archive tools that support uncompressed and Wikipedia icon LZMA-compressed ZIP files by opening the BSP file.
In some instances, it may be necessary to open via hash, as certain operations will cause additional data to be written after the "pakfile" lump in the BSP.
Icon-Bug.pngBug:Custom VMT files located in the root of 🖿materials/ folder may fail to be packed into the BSP, use subfolders for custom materials.
example: 🖿materials/my_custom_materials/  (tested in: Black Mesa)

While it is usually a good idea to BSPZIP content, there are times when it can cause problems and other times when it won't work at all (e.g., for Maplist Thumbnails). When this happens, a resource list can be used instead.

Usage

BSPZIP is found at "common\<gamename>\bin\bspzip.exe". It performs several functions:

Adding a List of Files

The most common function. There are two related commands:

-addlist <input bsp> <file list> <output bsp>
-addorupdatelist <input bsp> <file list> <output bsp>

Include file extensions. The former command packs all files in the list, the latter (untested, Orange Box only) packs only those that have changed since the last operation.

Tip.pngTip:The input and output files can be the same.

The "file list" is a .txt file containing this pattern:

internal_path/file1
external_path\file1
internal_path/file2
external_path\file2
...
  • Internal paths (relative paths) are the location the file will take within the BSP; e.g., materials/metal/new_steel.vmt.
  • External paths (absolute paths) are the location of the file to be packed, e.g., C:\Users\Public\our_maps\materials\metal\new_steel.vmt.

For example:

materials/foo/bar.vtf
D:\Steam\steamapps\common\Counter-Strike Source\cstrike\custom\stuff\materials\foo\bar.vtf
materials/foo/bar.vmt
D:\Steam\steamapps\common\Counter-Strike Source\cstrike\custom\stuff\materials\foo\bar.vmt
sound/lorem/ipsum.mp3
D:\Steam\steamapps\common\Counter-Strike Source\cstrike\custom\stuff\sound\lorem\ipsum.mp3

Adding a Single File

The same principle as above, but without a file list.

-addfile <input bsp> <internal path> <external path> <output bsp>

Viewing and Extracting Files

If you have an archive tool installed that is able to look inside BSPs, it's better to use that. If you don't, these are the commands you need:

-extract <bsp file> <output.zip>
-extractfiles <bsp file>
-dir <bsp file>

Handling Cubemaps

Should be self-evident:

-extractcubemaps <bsp file> <output folder>
-deletecubemaps <bsp file>
Warning.pngWarning:-deletecubemaps actually deletes all .vtf files in the .bsp—handle with caution!
Icon-Bug.pngBug:-deletecubemaps may actually delete the entire PAKFILE lump, rendering the map broken! Use VIDE VIDE or VPKEdit VPKEdit instead.  (tested in: Source 2013 Multiplayer)

Testing

There are situations where files won't be loaded from BSP files correctly. As time goes on, they become fewer in number, but it's always worth checking regardless. The easiest way to do so is moving all of the embedded content out of the game's folders—or even better, not storing it there in the first place.

Compression

(in all games since Source 2013 Multiplayer) (also in Strata Source Jabroni Brawl: Episode 3) Repacking allows you to compress your map using Wikipedia icon LZMA to save hard drive space and download times. To repack a map and compress it, these commands are used:

-repack -compress <bsp file>

To decompress repacked maps, run the same command but ommit the -compress command:

-repack <bsp file>
Warning.pngWarning:
  • Repacked maps won't work in Source Filmmaker Source Filmmaker and will crash the program on load!
  • Trying to build cubemaps on a already compressed map will result in the game crashing!
Icon-Bug.pngBug:Map compression may sometimes result in packed ADPCM audio files not properly caching, resulting in improper playback on subsequent loads. This does not happen if the audio cache was created when the BSP file was uncompressed, or when using other audio formats (8-bit, 16-bit, MP3, etc). This also does not seem to occur when using Team Fortress 2 Team Fortress 2's workshop uploader. Since files which are flagged as streaming (* sound character) are not loaded from the cache, they are unaffected by this bug. As such, it may be preferable to only use ADPCM for looping music.  (tested in: Team Fortress 2 Counter-Strike: Source)
Icon-Bug.pngBug:ANI files will not load correctly from a compressed BSP.
Note.pngNote:
  • The BSPZIP included with Counter-Strike: Global Offensive Authoring Tools doesn't support repacking.
    Confirm:Does Counter-Strike: Global Offensive even support compressed BSPs?
  • Team Fortress 2 automatically compresses BSPs when uploading to the workshop.
  • Garry's Mod supports compressed BSPs, but the BSPZIP included with Garry's Mod doesn't support repacking (relevant GitHub request). Use the BSPZIP that comes with Team Fortress 2 instead.
Tip.pngTip:The map will need to be decompressed before BSPZIP will allow new files to be packed into the BSP.
PlacementTip.pngWorkaround:Ficool2's Map Batch Updater can edit the contents of compressed BSPs, including changing the compression level of the ZIP lump. although the same compression level will apply to all packed files
Confirm:Can the ZIP lump in a compressed BSP be edited in some other way (using some other tool), allowing for custom levels of compression of different contained files? Perhaps using LMPFIX?
For example, the compression method used (Wikipedia icon LZMA) significantly impacts the load latency of audio files at high compression levels compared to faster methods.

GUIs/Replacements

The following GUI tools are often preferred to BSPZIP directly, and they may aid you in determining which files need to be packed into your map.

  • Compile Pal Compile Pal
  • Packbsp
  • Map Analyst Map Analyst
  • Pakrat Pakrat
  • VIDE VIDE
  • VPKEdit VPKEdit
  • Moltard's BspZipGUI Moltard's BspZipGUI(2020) - This app allows you to embed a folder with your files into BSP file, repack (compress and decompress) and can save different map configurations. It uses bspzip for the actual packing.
  • BspZipGui(2016) - The app allows you to embed a folder with your files into BSP file in just a few clicks. It uses bspzip for the actual packing.
  • AutoBSPpackingTool AutoBSPpackingTool - Automatically detects content that is used in the map and packs it. It has a GUI as well as a command line interface which makes it easy to add as a compile step in Hammer.
  • QuickPack - This script quickly finds and packs all dependencies in a map. For models with different skins, it only packs used skins to save file space.
  • TeamSpen's Hammer Addons TeamSpen's Hammer Addons - This includes a post-compiler which automatically finds and packs custom content, and adds entities to control auto-packing.

See also

  • Resource list (Alternative method to push content to users)
  • GCFScape (Read-only tool for inspecting BSP contents)