deqbsp3 version 0.9

Partially copryight 1998, 1999 Alexander Malmberg <alexander@malmberg.org>.
Partially based on id software code.


antidbsp version 0.9

Partially copryight 1998, 1999 Alexander Malmberg <alexander@malmberg.org>.
Partially based on id software code.


This is a semi-beta/developers release, although both programs should
be fairly stable.

Legal stuff (read, it's important!)
-----------------------------------
Use at your own risk. Neither the author of this program (Alexander
Malmberg), nor id software, shall in any way be liable for any damage caused
by these programs, nor shall they in any way be responsible for any use
of these programs, legal or illegal. If you use any of these programs, you
do so at your own risk and you are responsible for the results of your use
of the programs yourself. Note that incorrect use of these programs may
entitle others to take legal action against you, including but not limited
to suing you.

These programs may be freely distributed as long as nothing is charged for
them, and they are not distributed along with an item that is charged
for, and the programs are distributed with all files included and identical
to the ones in the .zip file distributed by me (Alexander Malmberg).

These programs may be freely used, as long as use of the programs don't
violate any other licenses.

The source code for these programs may be freely used and modified, as long
as any resulting program is NOT distributed to anyone, and all copyright
notices remain unchanged. Thus, you may modify the programs for your own use,
but you can't distribute a modified version. If you want to distribute
a modified version, contact me (Alexander Malmberg) and we'll talk about it.


deqbsp3
*******

Legal notes
-----------
This program can be used to do a lot of bad things, but please do not use
it in that way. Check with the author of the .bsp file you want to decompile
to see if it's OK to decompile it, and what you're allowed to do with the
.map file.

I've spoken with John Carmack of id software, and he said they don't mind
that people use a program like this to decompile their maps and look at how
they're constructed, but distributing their maps or using the entire or
parts of their maps in other maps is not allowed. (Note that non
of that is in writing, so legally, you have no right to decompile them,
either.)

If this program helps you with your editing/whatever (in any (legal) way),
some credit would be nice.


Usage
-----
Syntax:
   deqbsp3.exe input.bsp output.map

deqbsp3 will load input.bsp, do some processing, and write output.map.
The .map file will have floating point values in the plane definitions,
so make sure your editor can load that.


Note that I've limited the distributed binary of deqbsp3 so that it
'scrambles' texture information. Thus, the resulting .map file will be useful
to see how hint and clip brushes are used, and to see how the entities are
placed and work, but it'll be pratically useless for recompiling (try it and
you'll see why).


Algorithm/code
--------------
This is just a short description. See the code for more detail.
The code's all C. Everything but deqbsp3.c come from id's tool source
package, although I've modified some of them. deqbsp3.c handles all the
converting but relies on the other files for misc. stuff, and it's entirely
written by me (Alexander Malmberg).

First, the .bsp file is loaded. After that, I traverse the BSP tree
for every model and set values in a global structure to mark which
brushes belong to which model. Then, I loop through all the entities
and write their keys/values. If the entity is a model, I loop through
all the brushes and write the ones that belong to the entity's model.

Well, that's it. In the code, there's more code to handle special cases,
but that's the main algorithm.

I use DJGPP v2.01 and GCC 2.8.0 to compile it. If you can just get the
stuff in the common/ directory to work with your platform, you shouldn't
have any troubles porting it.

Functions:
----------
WritePlane()     Write a plane from the .bsp file in the .map format.

WriteTexinfo()   Write a texinfo from the .bsp file in .map format, converts
                 texture vectors to shift/scale/rotate format.

SetModel()       Used to set which brushes belong to which model.

main()           All the entity/brush loops, and some special case handling.


If you really want to remove the limit, you shouldn't have any problems,
but remember you can't distribute such a version.


antidbsp
********
This is the other program I'm distributing.

Syntax:
   antidbsp.exe input.bsp output.bsp

Loads input.bsp, removes texture information, writes output.bsp.

The algorithm is quite simple. First it builds a list of all unique (with
respect to texture flags) texinfos and a translate list from the normal
texinfos, then it goes over all brushes and changes their texinfo
reference to the first unique one with the same flags. I've tested this,
and haven't discovered any side effects. Running this program on a .bsp
file before releasing it won't stop people from decompiling it, but the
decompiled map files will have only one normal texture, only one light
texture, etc. Thus, as the amount of work needed to retexture the entire map
is very large (especially if the map's large), the .map file the decompiler
outputs will be practically useless if the decompiling person wants to
recompile the map or use parts of the map as prefabs.

I'll conduct further experiments to see what extra information I can remove
to further prevent decompilers from functioning as time allows. However,
this can never be a permanent solution to the problem of people decompiling
others' maps.


Final words
***********
Well, as you can see, decompiling .bsp files is not impossible, as has been
taught. Hopefully, these programs (especially deqbsp3) should be interesting
to study, and I hope you'll learn something from it.

If you have any questions, comments, suggestions, etc., e-mail me.

- Alexander Malmberg <alexander@malmberg.org>

