Skip to content

Instantly share code, notes, and snippets.

@kice
Created April 7, 2019 16:04
Show Gist options
  • Save kice/1d7e4da2faa2ae6d22e65a91af41600b to your computer and use it in GitHub Desktop.
Save kice/1d7e4da2faa2ae6d22e65a91af41600b to your computer and use it in GitHub Desktop.
import os
import argparse
import json
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--format', default='', type=str)
parser.add_argument('-a', '--all', default=False, action='store_true')
args = parser.parse_args()
is_bsp_file = lambda fn: any(fn.endswith(ext) for ext in ['.bsp'])
filenames = [os.path.join('.', x) for x in os.listdir('.') if is_bsp_file(x)]
if args.format == 'csv':
print('map,lighting')
for bsp in filenames:
with open(bsp, 'rb') as f:
try:
ident = str(f.read(4), encoding='utf8')
if ident != 'VBSP':
print(f'{bsp} is not a Source BSP map. Identifier: "VBSP" vs "{ident}"')
continue
f.seek(936) # seek to LUMP_FACES_HDR
lump_t = [int.from_bytes(f.read(4), 'little'), int.from_bytes(f.read(4), 'little')]
map_name = os.path.splitext(os.path.basename(bsp))[0]
hdr = lump_t[0] > 0 and lump_t[1] > 0
if not hdr:
if args.format == 'csv':
print(f'{map_name},LDR')
else:
print(f'{map_name} LDR')
elif args.all:
if args.format == 'csv':
print(f'{map_name},HDR')
else:
print(f'{map_name} HDR')
except Exception as e:
print(f"Error during reading {bsp}: {str(e)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment