Direct modification of BSP files

Discussion for Level editing, modeling, programming, or any of the other technical aspects of Quake
Post Reply
V1979
Posts: 58
Joined: Tue Dec 23, 2014 7:00 am

Direct modification of BSP files

Post by V1979 »

I want to share my experience of direct modification of *.bsp files. If there is no need in such articles, let admins delete this topic.

This method has some limitations, but anyway it works.
Once, I was asked to modify a custom map. The purpose of modification is to substitute custom textures with original Q3 textures from \baseq3\pak0.pk3. This allows to reduce volume of a map pack on a server and time of downloading a map from a server.
Also, this method can be applied when there is a map with a good construct, but with ugly textures or simply with textures of low quality (resolution), and you want a new modified map to look correctly everywhere (to avoid collision of textures).

1. Open a chosen map in a hex editor (for example Hex Editor Neo).
2. Substitute an old texture by yours. Attention! Both (old and new) textures must have the same lenght of names and resolution (or such a new texture should be properly scaled in a shader). For example:
FIND
textures/base_wall/alpha01
REPLACE BY
textures/base_wall/beta002
3. Repeat the step 2 for all the textures that you want to replace and save the map.
4. Write shaders for your new textures, if you have complex textures or if you want to redirect (link) these new textures to the textures which already exist in your pak0.pk3.
Or make your *.jpg and (or) *.tga files or rename and use (if you're authorized) other custom textures, if you just want to re-colorize the map.
m4xpower
Posts: 32
Joined: Wed May 20, 2015 8:40 pm

Re: Direct modification of BSP files

Post by m4xpower »

V1979 wrote: [...] 1. Open a chosen map in a hex editor (for example Hex Editor Neo). [...]
...or you can just use GSAR for huge amounts of patching (search/replace) or batch processing.

DOWNLOAD LINK: http://gnuwin32.sourceforge.net/packages/gsar.htm

Command:

Code: Select all

gsar <filename.bsp> -stextures/example/shader-or-texture:000 -rcustomtx/example/shader-or-texture:000 -o
...works on text files too (e.g.: *.shader)

You might be able to use a shorter new texture name/path, if you just append the corrent amount of 0x00 to the new name.
p.s.: there's probably a unix/linux binary of gsar somewhere - or just compile it from the source.
Last edited by m4xpower on Fri May 29, 2015 3:00 pm, edited 1 time in total.
V1979
Posts: 58
Joined: Tue Dec 23, 2014 7:00 am

Re: Direct modification of BSP files

Post by V1979 »

m4xpower wrote:***
There is no need in batching, because each texture is named in a *.bsp file for just the only time.
m4xpower
Posts: 32
Joined: Wed May 20, 2015 8:40 pm

Re: Direct modification of BSP files

Post by m4xpower »

V1979 wrote:There is no need in batching, because each texture is named in a *.bsp file for just the only time.
There usually is - unless you enjoy tedious, mind-numbing work.
Just a quick example:

Code: Select all

#!/bin/bash
for BSP in *.bsp; do
    gsar ${BSP}  -stextures/example/shader-or-texture-01:000 -rcustomtx/example/shader-or-texture-01:000 -o
    # texture 0..n
    gsar ${BSP}  -stextures/example/shader-or-texture-99:000 -rcustomtx/example/shader-or-texture-99:000 -o
done
Even if you are just modifying one map, it's by far easier and faster to use a command-line tool.
User avatar
CZghost
Posts: 1943
Joined: Wed Jun 22, 2011 1:45 pm
Location: Czechia
Contact:

Re: Direct modification of BSP files

Post by CZghost »

Only for Linux users! How will use command line ordinary Windows users when Windows CMD is based off completely different scheme?
[ Linktree | Twitch | YouTube | Instagram | Websites ]
When you feel the worst, turn to the sun and all the shadows will fall behind you.” - John Lennon
V1979
Posts: 58
Joined: Tue Dec 23, 2014 7:00 am

Re: Direct modification of BSP files

Post by V1979 »

As for me, I don't understand what's to do with your code. And I won't be able to repeat it by myself, whilst with Hex Editor and its GUI, I successfully modify not only *.bsp files, but *.md3 and any others too.
Let practice will be our judge.
m4xpower
Posts: 32
Joined: Wed May 20, 2015 8:40 pm

Re: Direct modification of BSP files

Post by m4xpower »

CZghost wrote:Only for Linux users! How will use command line ordinary Windows users when Windows CMD is based off completely different scheme?

Code: Select all

@echo off

for /f %%a IN ('dir /b /On *.bsp') do (
    gsar %%a  -stextures/example/shader-or-texture-01:000 -rcustomtx/example/shader-or-texture-01:000 -o
    REM # texture 0..n
    gsar %%a  -stextures/example/shader-or-texture-99:000 -rcustomtx/example/shader-or-texture-99:000 -o
)
...that should do the trick.
User avatar
CZghost
Posts: 1943
Joined: Wed Jun 22, 2011 1:45 pm
Location: Czechia
Contact:

Re: Direct modification of BSP files

Post by CZghost »

Okay, but I do not remember Windows CMD ever had gsar command. I think it is in basic installation of Linux. I think Windows user has to download it somewhere if possible, if not, they are just over...
[ Linktree | Twitch | YouTube | Instagram | Websites ]
When you feel the worst, turn to the sun and all the shadows will fall behind you.” - John Lennon
m4xpower
Posts: 32
Joined: Wed May 20, 2015 8:40 pm

Re: Direct modification of BSP files

Post by m4xpower »

V1979 wrote:As for me, I don't understand [...]
Maybe you should read up on GSAR. And on batch processing in general.
V1979 wrote: [...]whilst with Hex Editor and its GUI, I successfully modify not only *.bsp files, but *.md3 and any others too.
Manual Hex Editing is simply a waste of time. GSAR works on any file. Be it binary or text. This includes bsp, md3, jpg, tga, shader or any other file type.
V1979 wrote: Let practice will be our judge.
Tru dat! Been working with GSAR and various other tools for a very long time. Take it from a pro: GUI hex editors are merely a shiny toy.
You won't get far, if you lower your bar.
m4xpower
Posts: 32
Joined: Wed May 20, 2015 8:40 pm

Re: Direct modification of BSP files

Post by m4xpower »

CZghost wrote:Okay, but I do not remember Windows CMD ever had gsar command. I think it is in basic installation of Linux. I think Windows user has to download it somewhere if possible, if not, they are just over...
Download link was in the 2nd post of this thread. But apparently nobody really reads anymore :rolleyes:.

http://gnuwin32.sourceforge.net/packages/gsar.htm
User avatar
CZghost
Posts: 1943
Joined: Wed Jun 22, 2011 1:45 pm
Location: Czechia
Contact:

Re: Direct modification of BSP files

Post by CZghost »

Okay, you got me :olo: :up:
[ Linktree | Twitch | YouTube | Instagram | Websites ]
When you feel the worst, turn to the sun and all the shadows will fall behind you.” - John Lennon
V1979
Posts: 58
Joined: Tue Dec 23, 2014 7:00 am

Re: Direct modification of BSP files

Post by V1979 »

m4xpower,

Useless dispute. I just give some comparison. My instructions can be compared to a manual how to drive a car, and it doesn't matter if such a car is good or bad, it exists, it works and it's enough. While you say, that a better car could be made, and suggest learning how to create such a car.
Post Reply