bsp

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2018 License: Unlicense Imports: 8 Imported by: 22

README

GoDoc Go report card

Bsp

Go library for manipulating Source Engine .bsp map files.

Features:
  • Read support for (most) non-xbox360 bsps.
  • Freely modify and resize any Lump data.
  • Limited write support
Not all lumps are current supported, but can be freely read and modified, as they are treated as []byte

The following lumps currently have a full implementation for v20 bsp's (tested against CS:S & CS:GO):

0: Entdata
1: Planes
2: Texdata
3: Vertexes
4: Visibility
5: Nodes
6: Texinfo
7: Faces
8: Lighting
9: Occlusion
10: Leafs
11: FaceId
12: Edges
13: Surfedges
14: Models
15: WorldLight
16: Leaffaces
17: LeafBrushes
18: Brushes
19: Brushsides
20: Areas
21: AreaPortals
26: DispInfo
27: OriginalFaces
28: PhysDisp
30: VertNormals
31: VertNormalIndices
33: DispVerts
34: DispLightmapSamplePosition
35: Game lump (partial: sprp only)
36: LeafWaterData
37: Primitives
38: PrimVerts
39: PrimIndices
40: Pakfile
41: ClipPortalVerts
42: Cubemaps
43: Texdatastringdata
44: Texdatastringtable
45: Overlays
46: LeafMinDistToWater
47: FaceMacroTextureInfo
48: DispTris
51: LeafAmbientIndexHDR
52: LeafAmbientIndex
54: WorldLightHDR
55: LeafAmbientLightingHDR
56: LeafAmbientLighting
58: FacesHDR
59: MapFlags
60: OverlayFades
This library may reorganise lump order during the first export. This is intentional to handle lump resizing, but will change your checksum if you export without changes.

Usage

Minimal example of obtaining entdata from a BSP. The following will print the entdata lump (entdata is a single json-like string) of a specified .bsp to console.

package main

import (
	"github.com/galaco/bsp"
	"log"
	"os"
)

func main() {
	f,_ := os.Open("de_dust2.bsp")

	// Create a new bsp reader
	reader := bsp.NewReader(f)
	
	// Read buffer
	file,err := reader.Read()
	if err != nil {
		log.Fatal(err)
	}
	f.Close()
    
	lump := file.GetLump(bsp.LUMP_ENTITIES).(*lump.Entities)
	log.Println(lump.GetData())
}

Real World examples

Contributing

All contributions welcome. Known unsupported games/maps are especially useful.

Documentation

Index

Constants

View Source
const LUMP_AREAPORTALS = 21
View Source
const LUMP_AREAS = 20
View Source
const LUMP_BRUSHES = 18
View Source
const LUMP_BRUSHSIDES = 19
View Source
const LUMP_CLIPPORTALVERTS = 41
View Source
const LUMP_CLUSTERPORTALS = 25
View Source
const LUMP_CLUSTERS = 23
View Source
const LUMP_CUBEMAPS = 42
View Source
const LUMP_DISPINFO = 26
View Source
const LUMP_DISP_LIGHTMAP_ALPHAS = 32 // contents is normally stripped out
View Source
const LUMP_DISP_LIGHTMAP_SAMPLE_POSITIONS = 34
View Source
const LUMP_DISP_MULTIBLEND = 63
View Source
const LUMP_DISP_TRIS = 48
View Source
const LUMP_DISP_VERTS = 33
View Source
const LUMP_EDGES = 12 // face edges. v1->v2, vertex order may be reversed
View Source
const LUMP_ENTITIES = 0 // Entity keyvalue data stored as string
View Source
const LUMP_FACEIDS = 11 // contents is normally stripped out by compiler
View Source
const LUMP_FACES = 7 // bsp faces
View Source
const LUMP_FACES_HDR = 58
View Source
const LUMP_FACE_MACRO_TEXTURE_INFO = 47
View Source
const LUMP_GAME_LUMP = 35 // game specific data. includes staticprop data
View Source
const LUMP_LEAFBRUSHES = 17 // brushes that define a leaf volume
View Source
const LUMP_LEAFFACES = 16 // faces that separate leaves.
View Source
const LUMP_LEAFMINDISTTOWATER = 46
View Source
const LUMP_LEAFS = 10
View Source
const LUMP_LEAFWATERDATA = 36
View Source
const LUMP_LEAF_AMBIENT_INDEX = 52
View Source
const LUMP_LEAF_AMBIENT_INDEX_HDR = 51
View Source
const LUMP_LEAF_AMBIENT_LIGHTING = 56
View Source
const LUMP_LEAF_AMBIENT_LIGHTING_HDR = 55
View Source
const LUMP_LIGHTING = 8
View Source
const LUMP_LIGHTING_HDR = 53
View Source
const LUMP_LIGHTMAPPAGES = 51
View Source
const LUMP_LIGHTMAPPAGESINFOS = 52
View Source
const LUMP_MAP_FLAGS = 59
View Source
const LUMP_MODELS = 14 // models are root bsp nodes. m[0] = worldspawn. m[0+n] are brush entity data
View Source
const LUMP_NODES = 5 // bsp node tree entries
View Source
const LUMP_OCCLUSION = 9
View Source
const LUMP_ORIGINALFACES = 27
View Source
const LUMP_OVERLAYS = 45
View Source
const LUMP_OVERLAY_FADES = 60
View Source
const LUMP_OVERLAY_SYSTEM_LEVELS = 61
View Source
const LUMP_PAKFILE = 40 // uncompressed zip of packed custom content
View Source
const LUMP_PHYSCOLLIDE = 29
View Source
const LUMP_PHYSCOLLIDESURFACE = 49 // deprecated
View Source
const LUMP_PHYSDISP = 28
View Source
const LUMP_PHYSLEVEL = 62
View Source
const LUMP_PLANES = 1 // bsp planes
View Source
const LUMP_PORTALS = 22
View Source
const LUMP_PORTALVERTS = 24
View Source
const LUMP_PRIMINDICES = 39
View Source
const LUMP_PRIMITIVES = 37
View Source
const LUMP_PRIMVERTS = 38
View Source
const LUMP_PROPCOLLISION = 22
View Source
const LUMP_PROPHULLS = 23
View Source
const LUMP_PROPHULLVERTS = 24
View Source
const LUMP_PROPTRIS = 25
View Source
const LUMP_PROP_BLOB = 49
View Source
const LUMP_SURFEDGES = 13 //
View Source
const LUMP_TEXDATA = 2 // texture data used by bsp faces
View Source
const LUMP_TEXDATA_STRING_DATA = 43 // raw string data of material paths
View Source
const LUMP_TEXDATA_STRING_TABLE = 44 // references entries in the string data lump
View Source
const LUMP_TEXINFO = 6 // face texture information
View Source
const LUMP_UNUSED0 = 22
View Source
const LUMP_UNUSED1 = 23
View Source
const LUMP_UNUSED2 = 24
View Source
const LUMP_UNUSED3 = 25
View Source
const LUMP_VERTEXES = 3 // vertex data
View Source
const LUMP_VERTNORMALINDICES = 31
View Source
const LUMP_VERTNORMALS = 30
View Source
const LUMP_VISIBILITY = 4 // vvis calculated visibility pvs & pas information
View Source
const LUMP_WATEROVERLAYS = 50
View Source
const LUMP_WORLDLIGHTS = 15
View Source
const LUMP_WORLDLIGHTS_HDR = 54
View Source
const LUMP_XZIPPAKFILE = 57 // deprecated, and xbox specific

Variables

This section is empty.

Functions

This section is empty.

Types

type Bsp

type Bsp struct {
	// contains filtered or unexported fields
}

Root .bsp filetype container. Consists of a 1036byte header and 64 lump blocks.

func ReadFromFile

func ReadFromFile(filepath string) (*Bsp, error)

Wraps ReadFromStream to control the file access as well. Use ReadFromStream if you already have a file handle

func ReadFromStream

func ReadFromStream(reader io.Reader) (*Bsp, error)

Read from any struct that implements io.Reader handy for passing in a string/bytes/other stream

func (*Bsp) GetHeader

func (bsp *Bsp) GetHeader() Header

Get the header for a bsp.

func (*Bsp) GetLump

func (bsp *Bsp) GetLump(index int) lumps.ILump

Get the lump for a given index.

func (*Bsp) GetLumpRaw

func (bsp *Bsp) GetLumpRaw(index int) *Lump

Get the lump for a given index.

func (*Bsp) SetLump

func (bsp *Bsp) SetLump(index int, lump Lump)

Set the lump data for a given index.

type Header struct {
	Id       int32
	Version  int32
	Lumps    [64]HeaderLump
	Revision int32
}

Bsp header. Contains format and lump layout data. Do not trust lump information between import and export

type HeaderLump

type HeaderLump struct {
	Offset  int32
	Length  int32
	Version int32
	Id      [4]byte
}

Layout information for a given lump, stored in the Header.

type Lump

type Lump struct {
	// contains filtered or unexported fields
}

Container for a lump. Also includes metadata about the lump. N.B. Some information mirrors the header's lump descriptor, but header information should not be trusted after import completion.

func (*Lump) GetContents

func (l *Lump) GetContents() lumps.ILump

Get the contents of a lump. NOTE: Will need to be cast to the relevant lumps

func (*Lump) GetLength

func (l *Lump) GetLength() int32

Get length of a lump in bytes.

func (*Lump) GetRawContents

func (l *Lump) GetRawContents() []byte

Get the raw []byte contents of a lump. N.B. This is the raw imported value. To get the raw value of a modified lump, use GetContents().ToBytes()

func (*Lump) SetContents

func (l *Lump) SetContents(data lumps.ILump)

Set content type of a lump.

func (*Lump) SetId

func (l *Lump) SetId(index int)

Get lump identifier Id is the lump type index (not the index for the order the lumps are stored)

func (*Lump) SetRawContents

func (l *Lump) SetRawContents(raw []byte)

Set raw []byte contents of a lump.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Bsp File reader.

func (*Reader) Read

func (r *Reader) Read() (*Bsp, error)

Reads the BSP into internal byte structure Note that parsing is somewhat lazy. Proper data structures are only generated for lumps that are requested at a later time. This generated the header, then []byte data for each lump

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Bsp export writer.

func NewWriter

func NewWriter() Writer

Return a new bsp writer instance.

func (*Writer) GetBsp

func (w *Writer) GetBsp() Bsp

Get bsp file to write.

func (*Writer) SetBsp

func (w *Writer) SetBsp(file Bsp)

Set bsp file to write.

func (*Writer) Write

func (w *Writer) Write() []byte

Write bsp to []byte.

func (*Writer) WriteLump

func (w *Writer) WriteLump(index int) []byte

Export a single lump to []byte.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL