Skip to main content

Overview

The BspFile class provides low-level access to BSP files, handling file I/O, header parsing, and lump management. It supports various Source engine game formats including special handling for Titanfall, Left 4 Dead 2, Dark Messiah, and other variants. Package: info.ata4.bspsrc.lib Source: BspFile.java:46

Constructor

BspFile

public BspFile()
Creates a new empty BspFile instance. Source: BspFile.java:84

Public Methods

load

public void load(Path file, boolean memMapping) throws BspException, IOException
Opens the BSP file and loads its headers and lumps.
file
Path
required
BSP file path to open.
memMapping
boolean
required
If true, the file will be memory-mapped for faster access. If false, the entire file is loaded into memory. Memory-mapping is faster but prevents saving to the same file due to JVM restrictions.
Throws:
  • BspException - if the file format is invalid or unsupported
  • IOException - if the file cannot be opened or read
Source: BspFile.java:97
public void load(Path file) throws BspException, IOException
Opens the BSP file with memory-mapping enabled by default.
file
Path
required
BSP file path to open.
Source: BspFile.java:164

save

public void save(Path file) throws IOException
Saves the BSP file with updated headers and lumps.
file
Path
required
Destination file path to save to.
Throws:
  • IOException - if the file cannot be written
Source: BspFile.java:168

loadLumpFiles

public void loadLumpFiles()
Loads external lump files (e.g., mapname_l_0.lmp) and overrides internal lumps with their content. Source: BspFile.java:392

getLumps

public List<Lump> getLumps()
Returns an unmodifiable list of all currently loaded lumps. Returns: Unmodifiable list of lumps Source: BspFile.java:728

getLump

public Lump getLump(LumpType type)
Returns the lump for the given lump type.
type
LumpType
required
The lump type to retrieve.
Returns: The lump for the specified type Source: BspFile.java:736

getGameLumps

public List<GameLump> getGameLumps()
Returns an unmodifiable list of all game lumps. Returns: Unmodifiable list of game lumps Source: BspFile.java:745

getGameLump

public GameLump getGameLump(String sid)
Returns the game lump matching the specified fourCC string ID.
sid
String
required
FourCC string identifier (e.g., “sprp” for static props).
Returns: Game lump if found, otherwise null Source: BspFile.java:755

compress

public void compress()
Compresses all lumps using LZMA compression, except for the pakfile lump. Source: BspFile.java:768

uncompress

public void uncompress()
Uncompresses all compressed lumps. Source: BspFile.java:808

hasCompressedLumps

public boolean hasCompressedLumps()
Checks if the map contains any compressed lumps. Returns: True if there’s at least one compressed lump Source: BspFile.java:826

getPakFile

public PakFile getPakFile()
Returns the PakFile object for accessing the embedded pakfile lump (embedded resources like materials and models). Returns: PakFile instance for this BSP Source: BspFile.java:837

canReadLump

public boolean canReadLump(LumpType type)
Checks if a lump type is compatible with this BSP version.
type
LumpType
required
The lump type to check.
Returns: True if the lump type is available for this BSP version Source: BspFile.java:847

getNextLumpFile

public Path getNextLumpFile()
Generates the file path for the next available lump file based on the naming pattern mapname_l_N.lmp. Returns: Path for new lump file, or null if maximum number reached Source: BspFile.java:857

getName

public String getName()
Returns the name of this file (filename without .bsp extension). Returns: BSP name Source: BspFile.java:874

setName

public void setName(String name)
Manually sets a new name for this file. This doesn’t rename the actual file but affects the result of getNextLumpFile().
name
String
required
New BSP name.
Source: BspFile.java:884

getFile

public Path getFile()
Returns the file path on the file system for this BSP file. Returns: File path Source: BspFile.java:893

getVersion

public int getVersion()
Returns the BSP format version number. Returns: BSP version Source: BspFile.java:902

setVersion

public void setVersion(int version) throws BspException
Sets a new BSP version. Note: This doesn’t convert lump structures for compatibility.
version
int
required
New BSP version number.
Source: BspFile.java:913

getRevision

public int getRevision()
Returns the map revision number, usually matching the “mapversion” keyvalue in the world spawn entity. Returns: Map revision Source: BspFile.java:923

setRevision

public void setRevision(int mapRev)
Sets a new map revision number.
mapRev
int
required
New map revision.
Source: BspFile.java:932

getByteOrder

public ByteOrder getByteOrder()
Returns the endianness of the BSP file, detected from the ident value in the header. Returns: Byte order of the BSP (BIG_ENDIAN or LITTLE_ENDIAN) Source: BspFile.java:942

getAppId

public int getAppId()
Returns the detected Source engine application ID for this file. Returns: Source engine application ID (see SourceAppId constants) Source: BspFile.java:951

setAppId

public void setAppId(int appId)
Manually sets the Source engine application ID for file handling.
appId
int
required
New Source engine application ID.
Source: BspFile.java:959

getReader

public BspFileReader getReader()
Returns a BspFileReader instance for reading structured data from this BSP file. Returns: BspFileReader for this file Source: BspFile.java:967

Public Constants

BSP_ID

public static final int BSP_ID
Big-endian Valve BSP identifier (“VBSP”). Source: BspFile.java:52

BSP_ID_TF

public static final int BSP_ID_TF
Big-endian Titanfall BSP identifier (“rBSP”). Source: BspFile.java:55

HEADER_LUMPS

public static final int HEADER_LUMPS = 64
Number of lumps in standard BSP files. Source: BspFile.java:61

HEADER_LUMPS_TF

public static final int HEADER_LUMPS_TF = 128
Number of lumps in Titanfall BSP files. Source: BspFile.java:62

HEADER_SIZE

public static final int HEADER_SIZE = 1036
Size of the BSP header in bytes. Source: BspFile.java:63

MAX_LUMPFILES

public static final int MAX_LUMPFILES = 128
Maximum number of external lump files. Source: BspFile.java:64

Usage Example

import info.ata4.bspsrc.lib.BspFile;
import info.ata4.bspsrc.lib.lump.LumpType;
import java.nio.file.Path;

// Load a BSP file
BspFile bsp = new BspFile();
bsp.load(Path.of("maps/dm_example.bsp"));

// Get basic information
System.out.println("BSP Version: " + bsp.getVersion());
System.out.println("Map Name: " + bsp.getName());
System.out.println("App ID: " + bsp.getAppId());

// Access lumps
Lump entityLump = bsp.getLump(LumpType.LUMP_ENTITIES);
System.out.println("Entity lump size: " + entityLump.getLength());

// Access game lumps
GameLump staticProps = bsp.getGameLump("sprp");
if (staticProps != null) {
    System.out.println("Static props found");
}

// Extract embedded files
bsp.getPakFile().unpack(Path.of("output/embedded"));

// Decompress if needed
if (bsp.hasCompressedLumps()) {
    bsp.uncompress();
}

See Also

Build docs developers (and LLMs) love