Mention: It also can work for the Alien Swarm Branch with an SWARM_DLL preprocessor, but it will not be mentioned here.
Setting up the source engine for modding is tricky at first, but once you've done it the 100's of times I've done, it becomes second nature. This tutorial will be covering:
- Setting up to compile Source Code.
- Getting the latest clone of the code.
- Getting and installing the template.
- A few merging of files.
Before you start anything, you're gonna need two things. These things are the Source SDK Base 2013 Singleplayer from Steam. You can get it by clicking that link or going in the Steam client under tools. It will automatically try to download when we install the base sourcemod too.
The next thing you're gonna need is Visual Studio Express 2010, 2012, or 2013. If you don't have any currently, I suggest you head over here and install Visual Studio Express 2013. Make sure you get the one for Windows Desktop.
Once that is installed, try running it to make sure it installed correctly!
Getting the Source code from Valve
Valve uploaded the source code for the engine on their GitHub. You can use the GitHub client and shell, or you can download it as a zip. To clone it using the shell type in
git clone email@example.com:ValveSoftware/source-sdk-2013.git
and it will start to download to your machine. Note that the default path will be under Documents/Github. (C:\Users\USERNAME\Documents\Github)
You can put the file (source-sdk-2013) anywhere you wish! I put mine under G:\Source and renamed the folder as SDK2013. For the rest of this article, I'm gonna refer the main folder (default source-sdk-2013) as "ROOT".
Getting and installing the template
You can install the template here. Once that downloads open it up to see the contents inside!
You'll see four folders and a Read.txt file. Here's a quick summary of what is in all of them.
- sdk_content - Where all your raw maps, textures, and models will go. It also has batches to launch tools.
- Source SDK Base 2013 Singleplayer - To be merged with the file of the same name under Steamapps/common.
- src - to be merged with the src folder under ROOT/sp
- template - the sourcemod folder.
Installing the Sourcemod folder.
Simply drag the folder 'template' into your $SteamDir\steamapps\sourcemods folder.
Installing the template code.
Merge the folder 'src' with the src folder under ROOT/sp. When it asks to replace any files, do so.
Overrides in the Source SDK Base 2013 Singleplayer app folder.
Go to $SteamDir\steamapps\common and locate the Source SDK Base 2013 Singleplayer app folder.
Copy the folder of the same name of the 7z file and place it in the common folder. This will once again bring up a prompt asking to merge/override/replace anything. Allow it to do so. It will replace a file called GameConfig.txt and vbsp.exe. The new vbsp will make life easier later on.
We lastly have the sdk_content folder to extract. While this can go anywhere, I recommend you put it in a file location without any spaces in the path. For example C:\users\USERNAME\Desktop will work but C:\users\USERNAME\Desktop\my mod files will not. This will prevent a bug in some of the compile batches.
Making sure all file paths are correct.The default path I set for most things are C:\Program Files (x86)\Steam\steamapps.... If your Steam folder is also in this folder, you can skip to the next step!
If not there are a few things you need to fix. First head over to $SteamDir\steamapps\common\Source SDK Base 2013 Singleplayer\bin and open the GameConfig.txt folder you had before.
Next navigate to your sdk_content folder and here you're gonna be editing the batches. Right click on them, and then hit "Edit". First, lets do set_vproject.bat. This batch makes sure the tools are configured for the right project.
- CD is the path where your sourcemod is.
- SDKDIR is where all the tools are.
Double check on all the batches minus the run_*.bat ones. When all set, lets compile our project!
First time compiling
Head over to your ROOT/sp/src folder and you'll find more batches.
There are three batches here; one for each version of Visual Studio. If you have Visual Studio Express 2013, you would click create_template_project_2013.bat. Since I have the 2010 version, I'll be using create_template_project_2010.bat instead. Double click on it to build the sln file.
|A Successful build.|
|An example of what the sln will look like.|
Welcome to Visual Studio! There is a lot here, but for now just follow along.
Once in VS, You first need to edit one cpp first. This is due to us not using the HL2_DLL preprocessor.
Go to the soultion explorer and Under Server->Source files you need to look for a file called vehicle_choreo_generic.cpp.
Double click to open it. The file should appear similar to this.
When loaded, you'll see that #include "hl2_player.h" is underlined in red like a misspelled word in a word processor. When anything is underlined in red, this means you have an error and the compiler will spit out an error. Make your vehicle_choreo_generic.cpp look like this:
What we've done here, is said "Ok, if we had defined are a HL2 game (Which is defined in the preprocessor), include this file, if not, ignore it". Since the template is not HL2, you should see it fade. Congrats on your first code edit, Best part is, it will still work if you choose to compile HL2 or EP2!
Now that mess is done, go to the top bar where you see debug. Click on it to make a drop down window and set it to "Release".
Then lastly, Go up to "Debug" and press "Build Solution". You can also press F7, or CTRL+ALT+F7 for a clean rebuild of the solution.
The compiling process will take some time depending on your hardware. Once it's all done, you should this in the output window.
Congrats! You're sourcemod compiled and it's ready to be edited. If you experience any problems with compiling the source code, I suggest looking at the wiki or the Github issue page.
Where are the new dlls?
By default, the dlls don't copy over to your sourcemod folder, but instead the ROOT/sp/game/template/bin. This is the default setting by Valve as the actual game project is in-house located under ROOT/sp/game. From there, you can copy the dlls to your $SteamDir/steamapps/sourcemods/template/bin folder.