Setting up a Sourcemod for the First time using the template. (Source 2013)

NOTE: The template is only compatible with the singleplayer branch of the Source 2013 engine.

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.
  • Compiling.

Setting up.

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 git@github.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.

"Configs"{ "Games" { "Template" { "GameDir" "C:\Program Files (x86)\Steam\steamapps\sourcemods\template" "Hammer" { "GameData0" "C:\Program Files (x86)\Steam\steamapps\sourcemods\template\fgds\template.fgd" "TextureFormat" "5" "MapFormat" "4" "DefaultTextureScale" "0.250000" "DefaultLightmapScale" "16" "GameExe" "C:\Program Files (x86)\Steam\steamapps\common\Source SDK Base 2013 Singleplayer\hl2.exe" "DefaultSolidEntity" "func_detail" "DefaultPointEntity" "info_player_start" "BSP" "C:\Program Files (x86)\Steam\steamapps\common\Source SDK Base 2013 Singleplayer\bin\vbsp.exe" "Vis" "C:\Program Files (x86)\Steam\steamapps\common\Source SDK Base 2013 Singleplayer\bin\vvis.exe" "Light" "C:\Program Files (x86)\Steam\steamapps\common\Source SDK Base 2013 Singleplayer\bin\vrad.exe" "GameExeDir" "C:\Program Files (x86)\Steam\steamapps\common\Source SDK Base 2013 Singleplayer" "MapDir" "C:\Program Files (x86)\Steam\steamapps\sourcemods\template\sdk_content\mapsrc" "BSPDir" "C:\Program Files (x86)\Steam\steamapps\sourcemods\template\maps" "CordonTexture" "tools\toolsskybox" "MaterialExcludeCount" "0" } } } "SDKVersion" "5"}

This will look a lot cleaner in your notepad editor, In this file, you must change all the paths so that they are valid. this in most cases can be easy as changing the drive letter. If any of these paths are incorrect, Hammer will let you know.

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.

@echo offecho Configuring Source SDK environment variables. :: Set local environment variable that will only persist in processes:: created by the current command processor shell. We use this CD:: trick so that we can set the variable to the canonical, absolute:: name, without any ..'s in it.PUSHD . :: Set CD to the path of your game or mod.
:: Example: C:\Program Files (x86)\Steam\steamapps\common\Half-Life 2\hl2 or:: C:\Program Files (x86)\Steam\steamapps\sourcemods\mymod:: Sadly, we can only use this for launcher tools.
CD "C:\Program Files (x86)\Steam\steamapps\sourcemods\template"SET VPROJECT=%CD% :: NOTE: FOR VTEX, STUDIOMDL AND MAPCOMPILE, VPROJECT DOES NOT CALL CORRECTLY:: YOU NEED TO REDEFINE THE GAMEDIR/VPROJECT IN THE RESPECTED BAT FILES!
:: Here we set the path of the SDK tools. Here we find Hammer, Faceposer, etc...set SDKDIR=C:\Program Files (x86)\Steam\steamapps\common\Source SDK Base 2013 Singleplayer\bin\ POPD :: Comment this out if you want to set it permanently as a system variable,:: too:: echo Attempting to set VPROJECT in system environment:: SETX VPROJECT %VPROJECT%:: echo.echo VPROJECT=%VPROJECT%
  • 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.
Once that's all done, close out of the command prompt and open the new sln file Game_Template_20##.sln With Visual Studio.

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.


Last Step...

Whew, now the last step and that will be to reboot Steam. After it has rebooted, you'll see a new game in your library called "SDK Template". Double click on it or hit the play button to run the mod. From here you can edit your video settings, and such. There is also a map already there and can be launched from "New Game." 

No comments:

Post a Comment