Compiling with Metrowerks CodeWarrior|
I'm Too Cool for your Damn Tutorial:
Can't be bothered to do it all yourself? You can download a neat little
package I prepared and get started right away.
I have included a project (.mcp) file, some configuration type files, and the original,
unmodified source code from id that is also contained in the q2source_12_11.zip
file mentioned in the full tutorial below.
Quick Start Instructions:
1. Download my Q2 Game DLL Package (285k).
2. Unzip the file into your "CodeWarrior/Project Stationary" directory (preserving directory structure)
so that you end up with a directory and files such as:
which contains the project (.mcp) file, etc.
3. Open CodeWarrior.
4. Select New Project... from the File menu.
5. Choose the Q2 Game DLL template (the folder you just put in the Stationary folder).
6. Save the project in your Quake2 directory (avoid spaces in the file name, such as My_Game) for convenience.
7. Modify files as desired and Make the gamex86.dll file.
8. Launch Quake 2 with the neccessary additional command line parameters, such as: +set game "My_Game"
This tutorial is designed to guide you through the entire process of using
Metrowerks CodeWarrior to compile the gamex86.dll file for Quake 2.
This tutorial assumes that you are using CodeWarroir Pro 2 (the latest version
as of January 1998), but it should be very applicable to older (and newer) versions.
This same process can also be used to compile the gamex86.dll under MacOS if you should
Why does CodeWarrior kick so much ass?
This section ain't exactly neccessary for this tutorial, but I've got
this feeling that most people out there have never even heard of CodeWarrior,
and so I feel compelled to say something on its behalf. CodeWarrior is
a great Integrated Development Environment, with a slick (the slickest if you ask
me) interface, and a lot of powerful features. It is a multi-platform hosted,
multi-platform targetting, multi-lingual programming tool that can help you write
better programs faster and easier.
Some of the features that I find especially apealing when making things like Quake 2
DLL's are its multi-file searching capabilities, its organized project settings dialogue,
its convenient function popup menu at the top of source windows, and its many other
intuitive interface features. Okay, I'm done now.
Starting the Project:
To compile the Q2 DLL, you'll need to create a project file that you will
put in its own directory somewhere, along with some other special files and
the source code for the Q2 game DLL. My recommendation is to create a
nice template project the first time, put this project directory in you Stationary
folder, and then when you want to make a Quake 2 mod, you'll be able to just
choose New Project and go to it.
1. Open CodeWarrior.
2. Choose File->New Project...
3. With the "Create New Folder" option checked, select:
Win32_x86 -> C_C++ -> Win32 C DLL
4. Change the location to your CodeWarrior\Stationary folder.
5. Save the project as something like Q2_Game_DLL
6. You should end up with the project file (.mcp) in a directory such as:
Adding Files to the Project:
Now that the project is created and located where we want it, its time to
get the source code and add it to the project.
1. Download the q2source_12_11.zip
2. Unzip this file (preserving directories) and locate the "game" directory inside.
3. Create a new folder in the same directory as your project file called
4. Copy the Quake 2 source files (all 75) from the "game" directory to this directory.
5. Back in CodeWarrior, select the x86_Win32 DLL.c file in the Source group in the project window
6. Choose Project->Remove Selected Items
7. Select the Source group, then choose Project->Add Files...
8. Change to the Game Source directory you just created
9. Select all of the .c files, and click Add
10. The source files should now all be listed under the Source group in the project window.
Configuring the Project:
Since id used VC++ to compile the gamex86.dll, they included a file with all the project settings for VC++ calle
game.dsp. CodeWarrior can't interpret this file, so we will have to go through and make
changes to our project settings to create a project that behaves as much as possible like the
project id originally created.
1. Chose the Targets tab at the top of the project window
2. Open the settings window for the MSL C DLL Release target
3. Make the following changes (these settings are based on information in the game.dsp file)
||game - Win32 Release
|Enums Always Int:
4. Close the settings window, saving changes.
5. Open the MSL C DLL Debug settings window, and make the following changes:
||game - Win32 Debug
|Enums Always Int:
6. Close the settings window, saving changes
7. Create a new file by choosing File->New, and insert the following text:
8. Save the file in your project directory (where the .mcp file is) as C_ONLY.h
9. Create another new file, and insert the following text:
10. Save the file in your project directory as game_CW.def
Making Your Own Quake 2 Mod
Now that all the hard stuff is done, Making your own mod is easy.
I suggest you put your projects folders right in your Quake2 folder, so
that you won't have to move files arround after compiling. Also, to keep
things nice, if you discover that there is something wrong with your
template that you want to change for all succesive Quake 2 projects, you
can go back and open up the original project in the Stationary folder.
This way you can easily switch over to the updated source code (for example)
that id will release in the next few weeks.
Also, one good way to modify the source so that you'll know you are using
a modified gamex86.dll when you run Quake 2 is to add a line of code to the
InitGame() function, so that when the dll is loaded, you will know that
it is the DLL you created. The instructions below suggest how to do this.
Here's a good way to make your own Quake 2 mod:
1. In CodeWarrior, choose File->New Project...
2. With the Create Folder option checked, select the Q2_Game_DLL template that you created and click OK
3. Locate your Quake2 directory, and save the file as something like My_Game.mcp (avoid spaces)
4. With the Files tab selected in the project window, open source files as desired and modify them
5. To mark the DLL, open the g_save.c file and locate the InitGame() function
6. Locate the following line at the beginning of the function:
gi.dprintf ("==== InitGame ====\n");
7. After this line add something like:
gi.dprintf ("** Modified by SJG **\n");
8. You can add more .c files to the project using the Project->Add Window or Project->Add Files... commands accordingly
9. Make the gamex86.dll by choosing Project->Make
10. You are now ready to test out your work. You can leave CodeWarrior open if you want to easily make further changes and test them
11. To make it easy to launch Quake 2 with your mod, locate the shortcuts you currently use to luanch Quake 2 (try right-clicking on the Start button and choosing Explore)
12. Copy the shortcut, and rename it appropriately
13. Right-click on the shortcut to access its Properties
14. Under the Program tab, edit the Target field to add the following parameters:
+set game "My_Game"
where My_Game is the name of the directory containing you modified gamex86.dll
15. You may also want to add a simple "+" (without the quotes) at the end of this field to prevent the cinematic and demos from loading automatically
16. Close the shortcut properties and open it (double clickor locate it in the Start menu)
17. Once Quake 2 has loaded, check the messages at the console (you can scroll up using PageUp) to find the message you added after the "==== InitGame ====" message
18. Start a new game to test out your work (you can just type "map base1" at the console)
19. If you want to modify the same gamex86.dll some more, type "disconnect" at the console, make changes in CodeWarrior, make the DLL, switch back to Quake 2, and start a new game
Well, that's the full deal. Be sure to let me know if you
have any problems with this tutorial. I'd also be interested to hear from anyone curious or
knowledgeable about things like using the debugger, changing the settings for optimization,
or getting the inline assebly code to work. Thanks to Andrew Southwick, Alex Harper, and Matt Henderson
from Metrowerks for helping me get this all to work.