==============================================================================
* XCOM Collectors Edition bugfix loaders - version 0.91
==============================================================================

First: this is for the DirectDraw Windows version of xcom 1 & 2,
not the old dos versions; sorry, I wont be doing work on the dos
versions. One source for the windows version is some game magazine
cover CD, another source is the Collectors Edition. If you get a
"Couldn't ReadProcessMemory" error, you probably have the dos
version - or some windows version I don't know of - get in contact.
If you get "Couldn't CreateProcess", the filename of your xcom
executable is something I haven't thought of - get in contact.

Usage: copy files from "xcom1" or "xcom2" to your game folder;
which version to copy where should be obvious, I hope. The loader(s)
will look for "ufo defense.exe", "xcom1.exe", "ufo.exe" for xcom 1,
and "Terror From the Deep.exe", "xcom2.exe", "ufo2.exe" for xcom2.
If your executable has a different filename, you will have to
specify it on the commandline (or make a shortcut to ldr_xcom?.exe").
(Also, if the loader can't find any of these executables, it will
show a file-open dialog, where you can specify you executable. This
was added more or less as a last-minute change - I hope it hasn't
broken anything (probably it did, I'm tired. Sigh.)).

You can also add command-line arguments, which are needed to use
eg xcomutil. To do this, you *must* specify the executable filename
first. Ie, do something like "ldr_xcom1 ufo.exe 1". The loader will
wait for the game to finish before terminating, so you can use this
from batch files and such.

If the loaders for some reason don't work, tell me:

*) any error messages the loader might spit out
*) the name of your XCOM executable file
*) any other 'interesting behaviour'


==============================================================================
* Thanks and stuff
==============================================================================
Lots of thanks to cynica_l for fixes, cleanups, and extensive playi...testing.
Thanks to _Stone for some help... damn I can make stupid mistakes sometimes.
Last but *NOT* least, thanks to all the people that has shown interest in this,
sorry for not being as responsive as I ought to be, but I'm damn busy :(

Thanks to "nebiun" for reporting a bug with the executable scanning.

==============================================================================
*  Below this point is version history and technical info. Proceed at
*  your own risk ;)
==============================================================================

2001/11/27:
A few months ago I jumped out of my chair of joy when I saw the X-COM
collectors edition. Enemy Unknown, Terror from the deep, apocalypse,
interceptor, and email games. Well, I was only really interested in
the first two, but didn't hurt getting the others as well. Oh boy, soon
I was going to re-experience the joy of playing these games! When I
found out the games had been rewritten for win32, I was even happier,
as the dos-extended versions didn't want to run under win2k. I was pretty
excited. Got home with the box, installed the game, and... *BooM*. All
garbled graphics. Got me pretty depressed. Finally found that this was
fixable by turning off DDraw acceleration, but... that's a hack imho.

Since I'm a programmer and fiddle a bit with reverse engineering every
now and then, I had a suspicion what might be wrong, since I've seen
the same with my first DirectDraw code. The programmers were not taking
the "pitch" into consideration. Their graphics cards have obviously had
width equal to pitch for 320x200.

Last night I finally got in the mood for attacking this problem (slightly
bored, slightly angry that there still isn't a patch around, as it's a
VERY trivial problem to solve). After a couple of hours of programming and
Reverse Engineering, I've come up with the following solution. A loader.
Simply stick the exe in your ufo directory and run that instead of the
original exe, and it will dynamically load&patch the game executable (in
memory, your original executable is left intact). The code is patched to
query DirectDraw for the pitch, and use a correct image display routine.

The 9x loader should work on any win32 version, while the NT loader only
works on, well, NT based systems (nt?, 2k, XP). Even though the 9x loader
also works on NT systems, I decided to released both, as the NT loader is
somewhat cleaner. Source included.

I hope someone ends up finding this useful. I had a lot of fun fixing
Mythos's bugs (well, I think it's Mythos who did the win32 port), and now
I can also have fun playing the good old game :D. Haven't looked at TFTD
yet, but I believe it to have the same problem, and I will release fix
for it later.

2001/12/26:
Finally got my XCOM CD back from my friend, and took at look at "Terror
From The Deep". Took me about fifteen minutes to find the problems and
rewrite my loader code to support both versions. TFTD loader seems to work
just fine, but... there was some weird code I didn't feel like digging
through. Both tactical and combat seems to work fine, though.

Removed the NT loader, only the "unified 9x loader" is included. Source
still included.

2002/01/03:
Fixed music bug under NT based windows versions. Stupid microsoft, stupid
and lame MCI API. This code is still pretty experimental, but since I run
win2k, and the code seems to work fine under9x as well, the included exes
have the music bugfix as well. If you don't want/need the music bugfix,
simply don't copy "musfix.dll" to your game folder.

Also, the loaders now take an optional commandline parameter: the executable
to load. Yep, now you can call your exes xcom1.exe and xcom2.exe if you want.
Doesn't seem to work if you drag an XCOM executable onto the loader, but...
I can't be bothered to fix that right now ;).

Next up? Perhaps I should try fixing the animation speed.

2002/11/03:
Been too busy with other things, sorry. This version should be easier to
use (regarding x-com executable filename), and has better parameter
passing support. Loader waits for game to finish before terminating (needed
for xcomutil support?) Fixed up (this) documentation somewhat.

2002/12/05:
Updated the internal "architecture" of the loader somewhat. Now, the
loader only injects the patch DLL into the game - all patching and fixing
is done by the patch.dll. Returning errocode properly. Etc etc etc.

2003/04/30:
Shame on me. Finally got myself together. Uploaded the new version, and
sent emails back to all (I hope :-O) the people who have mailed me. Oh yes,
also added a "GetOpenFileName" thingy - hopefully everybody will be able
to use the loaders now.

2003/09/24:
Version 0.91. Duh, stupid f0dder - there was a bug in the executable
scanning code, causing the patches not to be able to auto-scan for the
executable. The error was assigning a wrong string, so even if "ufo.exe"
was found, the patch would try to load "UFO Defense.exe;xcom1.exe;ufo.exe",
which would obviously fail ;). Also, I had forgotten to include "mytypes.h"
with the source, so recompilation out-of-the-box isn't possible.

f0dder, f0dder@druk.nu, http://f0dder.has.it, http://f0dder.cjb.net, 2003/09/24.
