Skip to content

feat(bsp): add CheckBSP to validate version 30 brush files before an engine parses them - #3

Merged
hzqst merged 1 commit into
mainfrom
feat/check-bsp
Nov 19, 2026
Merged

hzqst merged 1 commit into
mainfrom
feat/check-bsp

Conversation

@hzqst

@hzqst hzqst commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds CheckBSP(buf, bufSize, layout, result), appended to UtilAssetsIntegrityAPI_001 after CheckStudioSequenceGroup(); the existing vtable slots and result layouts are unchanged. It validates a version 30 brush file before an engine parses it (requested by HLND2T/HLND2T-DiligentGraphics#533).

  • UtilAssetsIntegrityBSPLayout (GoldSrc / Blue Shift) is passed by the caller, as engines pick it by game.
  • UtilAssetsIntegrityCheckResult_BSP::MaxLeafs bounds the leaf count with the caller's PVS capacity (zero enforced, null result skips it, as with the BMP limits).
  • src/BSPValidation.h reads records at fixed offsets and fields as the GoldSrc engine reads them. It checks:
    • lump ranges and record sizes;
    • every cross-reference;
    • embedded miptex data, including the 256-color palette GL_LoadTexture reads;
    • face extents as CalcSurfaceExtents computes them;
    • the light samples RecursiveLightPoint/R_BuildLightMap read;
    • visibility rows decoded as CM_DecompressPVS decodes them;
    • acyclic node and clipnode graphs at most 1024 levels deep, with the drawing tree below node 0 unshared.
  • Rules and limits are documented in docs/bsp-validation.md.

Stock map scan

Scanned 496 installed brush files (valve, bshift, gearbox, cstrike, czero, czeror, dod and several mods) with the smoke runner's directory argument, which now also scans .bsp.

  • All files pass except two !Src.bsp files whose surface extents exceed 512; the engine's CalcSurfaceExtents refuses those too.
  • The first scan rejected stock files, and those failures produced these relaxed rules:
    • a clipping head equal to the clipnode count (an empty hull, e.g. c2a2a, de_inferno_cz, dod_jagd);
    • visibility runs past the engine row, up to the longer compiled row: rows padded to 64 leaves, or covering every leaf as in Opposing Force and many Counter-Strike maps;
    • light/visibility offset 0 without the lump (cz_worldmap, sphere256.bsp);
    • unterminated entities (CZ:DS).

Tests

  • tests/BSPTests.h builds a complete one-face world lump by lump. It checks it through the real DLL, then breaks each rule one field at a time, for both layouts.
  • Mutation check: disabling the mark surface rule and the depth limit made the corresponding cases fail.

Verification

  • scripts/build-UtilAssetsIntegrity-x86-Release.bat and scripts/build-UtilAssetsIntegrity-x86-Debug.bat both exit 0. CTest passes 1/1 and the installed-DLL smoke test passes in each configuration.
  • format-check: 8 files, 0 with differences.
  • The validator also builds x64 / C++17 inside HLND2T-DiligentGraphics with no warnings. The test header was built only in this repository's x86 / C++20 configurations.
  • GitHub Actions results not awaited.

🤖 Generated with Claude Code

…engine parses them

Appends CheckBSP to UtilAssetsIntegrityAPI_001 with the lump layout (GoldSrc or Blue Shift) and the caller's leaf capacity. It checks lump ranges and record sizes, every cross-reference as the GoldSrc engine reads it, embedded miptex data, the light samples and visibility rows the engine reads, and acyclic, bounded node and clipnode graphs. A scan of 496 installed brush files shaped the rules: clipping heads at the clipnode count, visibility runs past the engine row, offset 0 without lighting or visibility, and unterminated entities are accepted, as stock maps need them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@hzqst
hzqst merged commit 1fffff8 into main Nov 19, 2026
3 checks passed
@hzqst
hzqst deleted the feat/check-bsp branch November 19, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant