Installing and Debugging the Source Code
This article will explain the basic steps for installing and debugging the source code.
Step By Step
Run the Create a Mod wizard
- Run the Source SDK from Steam and choose the Create a Mod link.
- You can normally choose any type of mod here, but for the purposes of this tutorial, choose the Modify Half-Life 2 Single Player option and click Next.
- In the top edit control of the next dialog, enter a directory where you would like to create a mod. This tutorial will assume you entered C:\MyMod.
- In the bottom edit control, enter any name for your mod. This will become a subdirectory under your SteamInstallPath\SteamApps\SourceMods folder. This example will assume you entered MyMod here.
- Click the Next button and the source code will be installed on your hard drive.
- Wait for the mod wizard to finish.
Compile the Source Code
For general considerations about compilation go here: Compiler Choices
For more specific:
Currently the code is better compiling on VS2005. You can download it at http://www.microsoft.com/express/2005/
Setup debugging parameters
- In the Solution Explorer window, right-click on the current project (the one in bold) and choose Properties.
- In the Property Pages dialog that appears, choose the Debugging item on the left-hand side.
- On the right-hand side, in the text control next to Command, enter
C:\Steam\SteamApps\Username\source sdk base 2007\hl2.exe(adjusting the folder names given here to reflect your own Steam installation).
- Next to Command Arguments, enter
-dev -sw -game "C:\Steam\SteamApps\SourceMods\MyMod"(where MyMod is the name of your mod you entered in the Create a Mod dialog).
- Next to Working Directory, enter
C:\Steam\SteamApps\Username\source sdk base 2007(adjusting the folder names given here to reflect your own Steam installation).
- Click the OK button.
C:\Steam\SteamApps\Username\team fortress 2\hl2.exeand
C:\Steam\SteamApps\Username\team fortress 2
"C:\Steam\SteamApps\Username\team fortress 2\hl2.exe"etc. It MIGHT work without them, but if you are having trouble with debugging, this is something else to try.
fatal error LNK1169: one or more multiply defined symbols foundor
error LNK2005: __malloc_dbg already defined in memoverride.obj, these can be fixed by adding "/FORCE:MULTIPLE" (without the quotes) into the project properties/configuration properties/linker/command line/additional options. This will most likely have to be added to both the server and client project within the solution.
Run in the debugger
- Important: after an SDK update, you must make sure to run whatever game you're editing through Steam once (only one time is necessary) before running in the debugger. If you don't, you may get Steam errors when running through the debugger.
- Right-click on the same project you were editing the properties for, and choose Debug->Start New Instance.
- If you get a warning that
hl2.exehas no debugging information, ignore it.
- It should now launch Half-Life 2 and run your code. You can make modifications to the code now, rebuild, and rerun the game with your changes!
Alternative: run-time attachment
- Start the mod using Steam
- Inside Visual Studio, Main Menu > Debug > Attach to Process...
- Select the hl2.exe process with the title of your mod
A good next step after mastering this document is to look at the Your First Entity document, in which you will make changes to some of the source code.
If you plan to integrate code updates from Valve, and if you want code backups and revision history, take a look at the Using Source Control with the Source SDK document.