Greg Dolley’s Weblog

A Blog about Graphics Programming, Game Programming, Tips and Tricks

How to Make a Quake 3 Arena Mod

Posted by gregd1024 on January 24, 2008

Now that the Quake III port is done, I can write about creating a mod instead of just installing one. Let’s get started…

Introduction

You’ll need to be at least somewhat familiar with C programming in order to make a mod. Quake III doesn’t do what is typically done by other games these days – which is wrap all game modding into some form of scripting language (such as Lua) or abstract things to the point where you don’t need to be a game programmer or familiar with the entire codebase in order to make simple behavioral changes.

The Two Types of Mods

The first thing you’ll need to know is that there are two types of Quake III mods:

  1. QVM mods
  2. DLL mods

It doesn’t matter which type of mod you make. A QVM mod will have the same effect in the game as a DLL mod. The only difference is how these mods are executed at runtime.

QVM mods are created by compiling your source into a QVM file. These files are very similar to Java bytecode – they contain instructions that the Quake III engine interprets at runtime.

DLL mods are created by compiling your source into a Windows DLL. These DLL’s are no different from any other Win32 DLL – the operating system executes these DLL’s as native machine code whenever the Quake III engine needs to call a function contained within them.

Due to the extreme difficulty I experienced trying to load a QVM mod (as explained in a previous Quake III mod post), I’m going to focus on the creation of DLL mods for this post. In my opinion this method is the easier of the two anyway.

Get the Source Code

The first thing you’ll need to do is get the source code for Quake III Arena. You can download it from one of the following links:

You can use either of the two codebase’s. The second link is Id Software’s original C codebase, while the first link is my .NET MC++ port of their C code. Both contain a Visual Studio solution for compiling everything in one shot, but Id Software admits they didn’t do extensive testing after the VS conversion. If you only have Visual Studio 2003 then I would try their C version anyway. For those who have Visual Studio 2005, you can try the C version and just upgrade the project, but why go through the work when VS 2008 Express is free?

If you must use the original native codebase for some special reason, but only have Visual Studio 2008, send me an email through my Contact page and I’ll send you my upgrade checklist – a list of steps I did to convert the original VS 2003 project to VS 2008 while keeping the native C settings intact (once you know what the steps are, it actually only takes about 20 minutes to convert). I’m really glad Microsoft still supports ANSI C in the compiler.

You will need a retail copy of Quake 3 Arena to run mods, it will not work with the shareware demo version.

I know what you’re thinking – “but I have the source code, why can’t I circumvent the license check?!” The license check isn’t the problem. The problem is that there are a few big differences between the structure of a demo PK3 data file and a retail PK3 data file (specifically related to the UI interpreted bytecode instructions). The public source only includes code for reading a retail version’s PK3 data. If you try and force the code to read a demo data file (and believe me, I’ve tried), the game crashes half the time; the other half of the time it will run but with no menu options.

Besides, it’s not worth getting around the license – these days you can buy all three Quake games (Quake I, II, and Quake III Arena) for $20 bucks in the Ultimate Quake collection. I got mine at Fry’s Electronics for $19.95; I’d recommend you get it from a discount electronics store too since buying it from Id Software’s site will cost a little more ($30 bucks at the time of this writing).

Game Project Structure

There are eight project files included in the source. You’ll only need to focus on three of them:

  1. The cgame project.
  2. The game project.
  3. The quake3 project.

These projects build as Win32 DLL’s. However, you must change where the compiler saves them. Open their project settings and set the output directory to the “baseq3” folder of your Quake III installation (i.e. on my computer it is “c:\quake3\baseq3”).

Modify the Code

We’re going to change one line of code that will make the rocket launcher repeat-fire at a faster rate. Open the source file, bg_pmove.c, under the game project and look for a function called PM_Weapon. Once in this function scroll close to the bottom of it where you should see a switch statement that looks like:

switch( pm->ps->weapon ) {

In the switch statement look for the case of WP_ROCKET_LAUNCHER; it is 125 lines below the start of the function. In that case block the variable “addTime” is being set to 800 – change this to 100. So instead of:

case WP_ROCKET_LAUNCHER:
   addTime = 800;

   break;

Now the code should look like:

case WP_ROCKET_LAUNCHER:
   addTime = 100; // for rapid fire
   break;

Under the build configuration drop-down of Visual Studio select “Debug.” You could have selected “Release” but running in debug mode will give you better diagnostic information in the event something crashes. 

Now compile the source – select “Build->Rebuild Solution” from the menu. I recommend a full rebuild instead of a regular build just in case some stray binaries were accidentally left in the original source tree.

Installing and Running the Mod

Now it’s time to take the compiled DLL’s and have Quake III use them as a mod. By now you should have modified the three DLL projects to output their binaries to “c:\quake3\baseq3” (or whatever you chose as your Quake III installation). Open that directory in Explorer and check for the following DLL’s:

  1. cgamex86.dll
  2. qagamex86.dll
  3. uix86.dll

If those DLL’s are present, you’re ready to run your mod! Simply start Quake III with the following command line:

“quake3.exe +set sv_pure 0 +set vm_game 0 +set vm_cgame 0 +set vm_ui 0”

When the Quake III menu options load, select a single player game and run an instance without any bots (so you won’t get distracted). After you’re inside the map, press tilde (”~”) to drop down the Quake 3 console. Here you’ll see a ton a status text. Use the <Page Up> and <Page Down> keys to scroll through everything line by line. You’ll want to look for status messages saying your DLL’s were loaded OK. The status text for qagamex86 is quite a few pages up, while the status of cgamex86 and uix86 are near the bottom. These lines look like, “LoadLibrary qagamex86.dll ok.”

When you see the DLL’s were loaded successfully, you’re done! Now try picking up the rocket launcher and see how fast it fires!! A good map for getting the rocket launcher right away is q3dm1 accessible under Squirmish mode.

More Fun

Here’s something extra you can do to make the rocket launcher feel and act more like a rapid fire weapon. You see, when we changed the firing rate of the rocket launcher above, we really only changed the trigger rate (the minimum amount of time that you have to wait between rocket fires), but didn’t touch the speed at which the rockets travel. It will feel better and you’ll get more frags if the weapon has a faster muzzle velocity.

In order to do this, open up g_missile.c under the game project and search for a function called “fire_rocket.” Once there, you’ll notice that the function is very small and most of what it’s doing is setting projectile properties. You’re interested in the following line near the bottom:

VectorScale( dir, 900, bolt->s.pos.trDelta );

Change this line to:

VectorScale( dir, 1800, bolt->s.pos.trDelta );

So you’re really just changing the “900” to an “1800.” Anything less than 900 will give you a slower rocket, and anything more than 900 will give you a faster rocket. But beware! Just as you can now fire faster rockets, this also means the bots can do so as well.

Conclusion

Coming up with your own complex mods that require more than editing two lines of code will require some study of the Quake III codebase. You can learn quickly by simply playing around with the code and stepping through it with a debugger.

-Greg Dolley

*Get new posts automatically! Subscribe via RSS here. Want email updates instead? Click here.

Advertisement

26 Responses to “How to Make a Quake 3 Arena Mod”

  1. Roderick said

    First of all, I want to say thanks for porting the Q3 source to the latest Visual Studio. This helps me tremendously. Now, I followed the instructions in this blog post and got the rocket launcher to switch to rapid-fire mode, but I got a few errors while rebuilding the solution:

    Error 1 fatal error C1083: Cannot open include file: ‘dinput.h’: No such file or directory c:\downloads\quake3_arena_vc9_net_mcpp_port\quake3_arena_vc9_net_mcpp_port\code\win32\win_local.h 36
    Error 2 fatal error C1083: Cannot open include file: ‘dinput.h’: No such file or directory c:\downloads\quake3_arena_vc9_net_mcpp_port\quake3_arena_vc9_net_mcpp_port\code\win32\win_local.h 36
    Error 3 error BK1506 : cannot open file ‘.\Debug\tr_image.sbr’: No such file or directory BSCMAKE
    Error 5 fatal error C1083: Cannot open include file: ‘dinput.h’: No such file or directory c:\downloads\quake3_arena_vc9_net_mcpp_port\quake3_arena_vc9_net_mcpp_port\code\win32\win_local.h 36
    Error 6 fatal error C1083: Cannot open include file: ‘dinput.h’: No such file or directory c:\downloads\quake3_arena_vc9_net_mcpp_port\quake3_arena_vc9_net_mcpp_port\code\win32\win_local.h 36
    Error 7 fatal error C1083: Cannot open include file: ‘dinput.h’: No such file or directory c:\downloads\quake3_arena_vc9_net_mcpp_port\quake3_arena_vc9_net_mcpp_port\code\win32\win_local.h 36
    Error 8 fatal error C1083: Cannot open include file: ‘dinput.h’: No such file or directory c:\downloads\quake3_arena_vc9_net_mcpp_port\quake3_arena_vc9_net_mcpp_port\code\win32\win_local.h 36
    Error 9 fatal error C1083: Cannot open include file: ‘dinput.h’: No such file or directory c:\downloads\quake3_arena_vc9_net_mcpp_port\quake3_arena_vc9_net_mcpp_port\code\win32\win_local.h 36
    Error 10 fatal error C1083: Cannot open include file: ‘dinput.h’: No such file or directory c:\downloads\quake3_arena_vc9_net_mcpp_port\quake3_arena_vc9_net_mcpp_port\code\win32\win_local.h 36
    Error 11 fatal error C1083: Cannot open include file: ‘dinput.h’: No such file or directory c:\downloads\quake3_arena_vc9_net_mcpp_port\quake3_arena_vc9_net_mcpp_port\code\win32\win_local.h 36
    Error 13 error BK1506 : cannot open file ‘.\Debug\win_input.sbr’: No such file or directory BSCMAKE

    Any idea of what’s going on there? Also, I copied my quake 3 installation to the C:\quake3 directory, but after I rebuilt the solution, the quake3.exe was gone.

  2. gregd1024 said

    Roderick,

    Yeah, this is an easy fix.

    These errors mean you don’t have the DirectX SDK installed (dinput.h is for DirectInput). Some of the project files refer to “$(DXSDK_DIR)\Include” as an additional include path, but the one’s you modified the first time just didn’t require it. Then when you did a rebuild all, the compiler tried to look for DirectX on those projects which need the DirectX headers and couldn’t find ’em. Hence these errors.

    The only other possibility is that you do have the DirectX SDK, but it’s not installed in the path referred to by the DXSDK_DIR environment variable. For this case, just change the environment variable. (Edit: Or you could change the project settings and hardcode the path.)

    -Greg Dolley

  3. Roderick said

    I completely forgot to check back here earlier, but yeah, it compiled perfectly after installing the DirectX SDK (I thought I had already done so a while back, but that was probably for a different computer).

    I’m not sure if you would be able to help me, but I have another problem, and that is getting Quake 3 to recognize imported assets. I’ve been trying to follow this tutorial ( http://code3arena.planetquake.gamespy.com/tutorials/tutorial25.shtml ) and after rebuilding the solution, the flashlight works perfectly, but the laser sight does not appear at all. I’ve tried putting the .shader and .jpg files in all sorts of directories within my Quake 3 install directory, but to no avail.

  4. gregd1024 said

    Hi Roderick,

    Sorry for the delay. I haven’t seen that mod before so I’m not sure how much help I can be, but I’ll try. I’m going to list some places to put breakpoints, but since you’ve modified the source from my version, the line numbers I reference could be a little different than yours.

    First, put a breakpoint in the function RE_AddRefEntityToScene inside tr_scene.c (which is the function that trap_R_AddRefEntityToScene eventually calls). See if the entity for the laser is really being added to the global entity render list.

    Second, inside tr_scene.c put a breakpoint @ about line # 355: tr.refdef.entities is filled with the global entity render list, see if your laser entity is in that list.

    Third, inside tr_main.c put a breakpoint @ about line #1299, inside R_AddEntitySurfaces(), see if your shader is part of the entity list in the for() loop on that line.

    Fourth, inside tr_shade.c @ about line #999, inside the RB_IterateStagesGeneric() function, you’ll see a call to “R_DrawElements( input->numIndexes, input->indexes );” — this call will either draw a compiled vertex array or strip elements depending on which one is supported by your video card. See if the polygon vertices representing your shader surface is in the list passed into R_DrawElements(). Btw, since I haven’t studied this mod, I’m not sure whether the laser is being rendered as a polygon or whether it’s some other OpenGL primitive (such as an image blended into the existing color buffer), so this part might be irrelevant.

    Hope this helps. Sorry I couldn’t provide a more definitive answer.

    -Greg Dolley

  5. count said

    Why does the realse quake3.exe run in demo mode I have the real version the Gold version with the updated 1.32 patch, I run it from the C:\quake3\ directory and it does the deom version, I have transfered all the pak files and the cd key and cd key .dll file

  6. count said

    woops , sry I forgot to put the .dll into the Quake install directory from the C:\Quake3 directory , now it works , Thanks alot for making the conversion to VS C++ 2008

  7. gregd1024 said

    Count – sure, no problem! 🙂

    -Greg Dolley

  8. count said

    What about the botlib project how could you load up a mod with that, with the *.dll , or due you have to build the whole solution

  9. gregd1024 said

    Count – for that one you just build the whole solution. It creates botlib.lib. The other projects in the solution which depend on it are configured to automatically rebuild whenever that lib file changes. The same is true with the renderer project (renderer.lib) and splines project (splines.lib).

    -Greg Dolley

  10. JediTim said

    I have been trying to get using the .dlls to work for a while now, but whenever I use the dlls, as soon as I start up, before the main menu, it gives me a error in the console : “RE_RegisterFont: FreeType code not available” and it has a blank screen. If I put it back and it doesn’t use my dlls then the game loads fine. Has anyone else encountered this?

  11. gregd1024 said

    JediTim,

    I haven’t seen this error, but from looking at the code (specifically, RE_RegisterFont), I can tell that it will display this message if it can’t open the font file or the font file is zero length. The font dat file is stored inside the Q3 pak file, so I’m guessing that when you use the DLL’s, they are referencing a different pak file than the default. Do you have other pak files installed in your quake directory from other mods? What directory are the DLL’s installed under? (This is important!)

    -Greg Dolley

  12. Matt Lacey said

    I downloaded this earlier, I’m looking to do a mod which is going to involve http requests in the background so a .NET port seemed perfect (congrats on the port btw – excellent work!)

    However, when I use the .exe I compile with the project the rendered appears to be a bit screwed, loading text (when starting a single player game) is not correctly positioned then in game it renders certain entities such as other players + the weapon, but the world is pretty much a hall of mirrors affair (not strictly but similar in appearance). Any idea what’s going on with this?

  13. gregd1024 said

    Matt,

    If you’re running it straight from the command line, make sure you put the parameters that was discussed in the original port article. This tells Q3 to run from the DLL’s instead of the interpreted byte-code in the pak files. If you’re running it from the IDE, the parameters should already be set, but double-check the project properties and make sure.

    The mirror effect, the messed up menus, and the other weird stuff all stem from the same problem – those game DLL’s (qagamex86, cgamex86, and uix86) aren’t being loaded (or one of the three loads but the other two come from the pak file causing a mismatch). It’s typically caused by the latter – only one DLL loads. You can check whether those DLL’s are loading correctly or whether there’s an error by looking at the Q3 console after joining a level (press the “~” key to bring down the console and to scroll up). To get to where the first DLL loads you’ll have to scroll many pages up (almost to the top). The status text for DLL loading looks like: “Loading .dll. OK” After which (a couple lines under) it’ll display a date of when the DLL was compiled – obviously the year should be 2008. If there’s an error loading a DLL it’ll say so and then fall back to pak file code (in this case the date displayed is somewhere in 2001, if I remember correctly).

    If you do see an error with loading of the DLL’s (which I’m 99% sure you will), then double-check that the DLL’s are in the correct location – “c:\quake3\” for Debug builds and “c:\quake3\baseq3\” for Release builds (but I’d put them in both locations just to be safe). Make sure your project working directory is “c:\quake3\” or, if you’re launching from the command-line, that you’re launching _from_ the Q3 install directory (c:\quake3).

    For other common problems see my article about Quake 3 mod problems and solutions. Believe me, I’ve dealt with hundreds of problems like this, and it’s _always_ been caused by something simple I overlooked (causing me to bang my head against the wall later).

    Let me know how it goes.

    -Greg Dolley

  14. Yajo said

    I managed to compile it nicely. Thanks for the work.
    just wondered if you ever did manage to make qvm’s after this article ?

    further more , as i just picked up looking at code for first time and compiling i wondered. i see people making mods for older versions. what i need to do to make say one of my dll’s work for 1.16n, as sourcecode compiled is already point1.32? , i know im just a newb at this but gotta ask :p

    • gregd1024 said

      Yajo – nah, I never made the QVM’s – there’s just too much work involved and too little time. 😉 As far as DLL’s working with v1.16n – if the quake3.exe expects the same function signatures in v1.16n as in v1.32, then the same DLL’s should work. That’s the whole point of using DLL’s. 😉 However, I’ve never looked at the source for that older version, so I don’t know whether the exported DLL functions have the same parameters.

      -Greg

  15. Yajo said

    i havent looked too but probably some differences i guess. i found the 1.17 sourcecode, and by using that with my old vs c++ 6 the compiled dll worked with 116. the included lcc/q3asm in 117 source also made me make those qvm’s with already functioning batch files.as long as all paths and libraries were set.
    havent tried it with 1.32 yet though .. as im more or less only playing in 1.16 anyway.
    im pretty noob novice so i’m mostly doing this for my own curiosity, having fun i guess on my way to ..making… something…. idiotic..usuless ..stuff. :p

  16. Michel said

    Hey, just wondering if this error has anything to do with not having DirectX SDK installed:

    Error 1 error BK1506 : cannot open file ‘.\Debug\tr_image.sbr’: No such file or directory BSCMAKE renderer

    If it isn’t can you post a download link for that file so I can put it in to the Debug folder?

    • gregd1024 said

      Michel – that’s a source browser file used by the IDE when you look up definitions and functions. The fact that the compiler is looking for that file tells me something else in the compilation failed. And, yes, you need the DirectX SDK installed because Quake 3 uses DirectInput.

  17. NewbModder said

    I need help putting on a mod…
    most people say theres a mod menu but there isn’t one. I only have the demo version though so do I need to download the full version?
    and where do I download it from?

    • gregd1024 said

      Hi NewbModder – yeah, there’s a mod menu, but not in the demo version I don’t think. I don’t think there’s any full version download – you’d need to order the full version on CD from id Software.

      -Greg Dolley

  18. Newone said

    Hi! greg this page its useful. so basically anyone with knownoledge about c++ and visual basica can make their own mod? because we got a old q3 mod. but has it flaws and the mod author dissappear from every part of the internet. so my brother want to make just some fixes like allowing a certain limit of ips trying to connect the server because some q3fillers users its keeping spamming the server. so basically its just a little update that the author didnt before to dissapear. so basically i just have some questions

    we need some specific programs? because i dont think to make a q3 mod without the proper tools since the mod its on qmv format.

    mods use the same language?

    or maybe we can just do a dll to work with the mod so we just can make the dll and upload it to the server?

    i hope your answers because really we just want to get rid off frm those q3fillers users because they get mad for being banned for the use of hacks.

  19. Gavin said

    ok. I am VERY confused. When I go into the pk3 files i can edit many things. I edited all the weapons.c inside of botfiles folder in all the pk3 files and it says that the botfiles were used before opening the program. Can you help?

  20. Kcr4zY said

    i have a problem building the cg.event, i have modified it, but there’s 40 errors. (sorry 4 my english is bad). i also set it to MFC to shared dlls

  21. Prateek said

    Hey greg I have changed everything but can’t get them to work.And by the way do you happen ti know how to run a deathgun mod?If you would tell me.And I am not understanding how to output there binaries to quake 3 and how am I supposed to output their binaries to quake 3.

  22. I haven’t seen this error, but from looking at the code (specifically, RE_RegisterFont), I can tell that it will display this message if it can’t open the font file or the font file is zero length. The font dat file is stored inside the Q3 pak file, so I’m guessing that when you use the DLL’s, they are referencing a different pak file than the default. Do you have other pak files installed in your quake directory from other mods? What directory are the DLL’s installed under? (This is important!)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: