------------------------------------------------------------------------------------
I changed the version to 099 (i figured this was ok since it wouldn't run before ;-)
------------------------------------------------------------------------------------

Title    : unqcc
Filename : unqcc99.zip
Version  : 0.99 (working beta)
Date     : 1:16 AM 7/25/97
Author(s): Christian Knauer , David Lenk (did not actually change any major stuff but made it run)
Email    : cnknauer@cip.informatik.uni-erlangen.de
Credits  : id Software for creating Quake and
           all the QuakeC gurus out there for improving it


Type of Modification
--------------------
Modification to id's QuakeC compiler (qcc)  

Deathmatch    : -
Single Player : -

Quake C       : - 
Sound         : -
MDL           : -

Description of the Modification
-------------------------------
This patch lets you decompile a progs.dat file back to native QuakeC.
It's similar to Armin Rigo's deacc, but it creates ''pure'' QuakeC code,
so you can immediatly recompile the source with qcc.
(well - at least in theory, see below)

The command ''qcc -dec'' will decompile the progs.dat file from the
current directory. Alternatively you can specify a file to decompile,
e.g. ''qcc -dec ../myprogs.dat''.

WARNING: The decompilation process will APPEND it's output to existing
qc files. So you should decompile in an empty directory.

Most of the time you will be able to compile the created source immediately.
(e.g. with id's original V1.06 source)
Unfortunately unqcc has some shortcomings, so that you sometimes will have
to modify the source by hand before it compiles cleanly (this happens e.g.
with Steven Polge's ReaperBot 0.81).

Decompilation currently does not include type synthesis, so the decompiler
uses a very cheap trick to determine the return type of a function. Sometimes
this may fail. In that case the default type ''float'' is used (which is
the right choice for most of the time) and the function as well as all of its
prototypes is marked with a comment of the form
        ''/* ERROR: Could not determine return type */''.
Use your brain to determine the correct return type and fix it by hand.

The same remark applies to entity function fields. unqcc always uses the type
.void() for them, so you probably will have to fix it (e.g. ReaperBot's
.th_weight field). (The .th_pain field is the exception to the rule here.)


Global variables are only initialized if their name starts with uppercase
letters. Otherwise their (potential) initial value is enclosed in a comment.
This works for all vital system constant such as TRUE, FL_xx, etc.
but e.g. the chase cam mod uses some lowercase constants. Again: check the
source and fix by hand.

By the way: The ''error'' in line 153 of misc.qc that you'll get during
recompilation is NOT caused by a unqcc bug. Check the origial 1.06 source
and you will see, who messed things up...   (check out end of text for example) // added by dave

Other comments of the form 
        ''/* ERROR: ... */''
may show up in the generated source and can usually be ignored. Don't ask
me where they come from. (I suspect that they are caused by qcc bugs, but
who knows ...)

If you found a progs.dat that can not be decompiled, please drop me an
email. (Tell me where it can be found, which compiler you used, etc.
Please do NOT send the progs.dat file!)

How to Install the Modification
-------------------------------
First, get the source code to id's QuakeC compiler qcc, e.g. from
ftp.cdrom.com. (I've not tested this with modified compilers, like
fastqcc from Jonathan Roy - mail me if you succeed ...)

Create a subdirectory and install the qcc source in it. Next, unzip
the file unqcc099.zip to this directory. This will replace the original //edited by dave
files ''makefile'' and ''qcc.c'' with new versions and add the file
''unqcc.c''. Now compile by issuing a ''make'' command.

This procedure has been tested under Linux and under MSDOS with DJGPPv2.
Please do not bomb me with emails like ''What is a make command?'',
''What is DJGPP?'' and the like. If you don't know what i'm talking about
then wait until some brave soul will provide a precompiled binary.
(That won't be me!)

Technical Details
-----------------
Most of the code is derived from id Software's source code to the qcc
compiler. The decompilation is just a form of symbolic evaluation of
Quake's assembler code. Check the source code for details.
Since the return type is not always exactly known and since qcc always
uses a vector store opcode to initialize function parameters i had to
use some ''dirty tricks'' in some places. Check the source (and laugh
yourself to death ...).

Famous last words: Don't expect too much! This is a terrible weekend-hack.
and it defintely has some bugs and flaws. Nevertheless, I hope it will be 
useful for you ..

The files in this archive are:

                makefile
                qcc.c
                unqcc.c

Author Information
------------------
CS Student - check
        http://wwwcip.informatik.uni-erlangen.de/~cnknauer
for details.

Distribution Permission
-----------------------
Do whatever you like with it. If you add a major improvement (like
correct type synthesis and the like), please drop me an email.

Availability
------------
This modification is available from the following places:
        ftp.cdrom.com

Version Information
-------------------
        0.99     First Release - probably the last one, too. I'm
                 currently working on my master's thesis, so time
                 is precious right now.

Disclaimer and Trademarks
-------------------------
The author takes no responsiblity for misuse of	this program. 
He is not responsible for any damage caused by it.

Quake TM (c)1996 id Software, Inc.  All Rights Reserved.
All trademarks are the property of their respective companies.

---------------------------------------

<-- This section added by ~SamWise~ (Dave) -->

---------------------------------------

---------------
Compiling UNQCC
---------------

I represent alot of confused people whom after downloading Unqcc098 were dissapointed when it 

presented us with gobs of errors.  it seems that the creator did not bother to include the 

needed files (cmdlib.c, pr_lex.c, pr_comp.h, and pr_comp.c)  he left it up to us to get them.  

Finding the files was not hard but when We recieved the source kit, the files were incompatible..

Finnaly I decided to read through the qcc.c file provided and extract the decompiling code, 

(i don't even know C).  when the code was inserted into a qcc.c file that already compiled 

perfectly the code worked great.  (ie.. thats how I am uploading this now).  PLEASE DO NOT 

GET ME WRONG, I am not trying to put down Christian Knauer (the author) I am mearly stating 

that probably on a whim he uploaded the wrong source files (sorry Christian).


-------------------------
Problems with decompiling
-------------------------

The error with line 153 of misc.qc,

ID's original Code (works great: no visible errors in code)

{
	
	precache_model ("progs/lavaball.mdl");
	self.classname = "fireball";
	self.nextthink = time + (random() * 5);
	self.think = fire_fly;
	if (!self.speed)
		self.speed == 1000;
};

unqcc's generated code (doesn't work:  this error is not ID's fault)

{
   precache_model ("progs/lavaball.mdl"); // no errors
   self.classname = "fireball"; // no errors
   self.nextthink = (time + (random () * MOVETYPE_FLY));  // MOVETYPE_FLY this name changes randomly durring decompilation it was TE_LIGHTNING twice before it turned into this.
   self.think = fire_fly; // no errors here
   if ( !self.speed ) {  // whoa where did the next line go (well that solve this problem) 
}

I will provide a bianary or qcc.exe (32bit DOS), I do not take any responsability for any 
damage caused by the use of this executable, I give no express or implied warantees about 
this program.  I can only assure you that this program works great on my p166 win95 system.

Also included in the ZIP file will be all files needed to compile this program.  (you need your
own Compiler)  I use djgpp v2 it works great for me, you can get it at ftp.simtel.net/pub/gnu/djgpp
or visit www.delorie.com for more info.


 