Skip to content

Instantly share code, notes, and snippets.

@grant-h

grant-h/HL1-BSP.bt

Last active Sep 5, 2017
Embed
What would you like to do?
An 010 Editor Binary Template (BT) for HL1 BSP files
//--------------------------------------
//--- 010 Editor v8.0 Binary Template
//
// Author: grant-h
// Purpose: 010 Editor Binary Template for HL1 BSP files
// Based from https://gist.github.com/rhulha/b7bd3d43104bf80b619ae454a8b9e439
// And from http://hlbsp.sourceforge.net/index.php?content=bspdef#texinfo
//--------------------------------------
LittleEndian();
uint32 version;
local int i;
typedef struct {
float x,y,z;
} VEC3D <read=ReadVEC3D>;
typedef struct {
uint32 offset;
uint32 length;
} lump;
struct {
lump entities;
lump planes;
lump textures;
lump vertices;
lump visibility;
lump nodes;
lump texinfo;
lump faces;
lump lighting;
lump clipnodes;
lump leaves;
lump marksurfaces;
lump edges;
lump surfedges;
lump models;
} lumps;
/////// LUMP_ENTITIES
FSeek(lumps.entities.offset);
char ents[lumps.entities.length];
/////// LUMP_PLANES
typedef struct {
float normal[3];
float dist;
int nType;
} Plane;
FSeek( lumps.planes.offset);
Plane planes[lumps.planes.length / sizeof(Plane)];
/////// LUMP_TEXTURES
typedef struct {
char name[16];
int width, height;
int offsets[4];
} MipTex <read=ReadMipTex>;
FSeek( lumps.textures.offset);
int nMipTextures;
int textureOffsets[nMipTextures];
for(i = 0; i < nMipTextures; i++) {
FSeek(lumps.textures.offset + textureOffsets[i]);
MipTex texture;
}
/////// LUMP_VERTICES
FSeek( lumps.vertices.offset);
VEC3D vertices[lumps.vertices.length / sizeof(VEC3D)];
/////// LUMP_VISIBILITY
FSeek( lumps.visibility.offset);
/////// LUMP_NODES
typedef struct {
int plane;
short children[2]; // Children indices. Negative numbers are leaf indices: -(leaf+1).
short mins[3];// Integer bounding box min coord.
short maxs[3];
short firstFace, nFaces;
} Node;
FSeek( lumps.nodes.offset);
Node nodes[lumps.nodes.length / sizeof(Node)];
/////// LUMP_TEXINFO
typedef struct {
VEC3D vS;
float fSShift;
VEC3D vT;
float fTShift;
int iMiptex;
int nFlags;
} TextureInfo;
FSeek( lumps.texinfo.offset);
TextureInfo texinfo[lumps.texinfo.length / sizeof(TextureInfo)];
/////// LUMP_FACES
typedef struct {
short plane;
short planeSide;
int firstEdge;
short edges;
short textureInfo;
char styles[4];
int lightmapOffset;
} Face;
FSeek( lumps.faces.offset);
Face faces[lumps.faces.length / sizeof(Face)];
/////// LUMP_LIGHTING
typedef struct {
char r, g, b;
} RGB;
FSeek( lumps.lighting.offset);
RGB lighting[lumps.lighting.length / sizeof(RGB)];
/////// LUMP_CLIPNODES
typedef struct {
int plane;
short children[2];
} ClipNode;
FSeek( lumps.clipnodes.offset);
ClipNode clipnodes[lumps.clipnodes.length / sizeof(ClipNode)];
/////// LUMP_LEAVES
typedef struct {
int nContents; // Visdata cluster index.
int nVisOffset; // Areaportal area.
int mins[3]; // Integer bounding box min coord.
int maxs[3]; // Integer bounding box max coord.
int firstMarkSurface; // First leafface for leaf.
int nMarkSurfaces; // Number of leaffaces for leaf.
char ambientLevels[4];
} Leaf;
FSeek( lumps.leaves.offset);
Leaf leaves[lumps.leaves.length / sizeof(Leaf)];
/////// LUMP_MARKSURFACES
FSeek( lumps.marksurfaces.offset);
short marksurfaces[lumps.marksurfaces.length / sizeof(short)];
/////// LUMP_EDGES
typedef struct {
short vIndex[2];
} Edge;
FSeek( lumps.edges.offset);
Edge edges[lumps.edges.length / sizeof(Edge)];
/////// LUMP_SURFEDGES
FSeek( lumps.surfedges.offset);
int surfedges[lumps.texinfo.length / sizeof(int)];
/////// LUMP_MODELS
typedef struct {
float mins[3];
float maxs[3];
VEC3D origin;
int iHeadnodes[4];
int visLeafs;
int firstFace, nFaces;
} Model;
FSeek( lumps.models.offset);
Model models[lumps.models.length / sizeof(Model)];
//////////////////////////////////////////
string ReadVEC3D( VEC3D &entry )
{
string s;
SPrintf( s, "<%.2f, %.2f, %.2f>", entry.x, entry.y, entry.z );
return s;
}
string ReadMipTex( MipTex &entry )
{
string s;
string wad = "";
if(entry.offsets[0] == 0 && entry.offsets[1] == 0 && entry.offsets[2] == 0 && entry.offsets[3] == 0) {
wad = "(WAD)";
} else {
wad = "";
}
SPrintf( s, "%s %dx%d", entry.name, entry.width, entry.height );
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment