Half Life 2 & Source Engine Tweak Guide

[Page 7] Advanced Tweaking



In any Source Engine game, you can change more than just the handful of settings available under the in-game options. The Source Engine is highly customizable: there are many different Command Variables (cvars or convars for short) which can be used to alter everything from the way the game looks, the way it allocates memory to providing additional game information, to recording demos and running custom benchmarks. This gives us an excellent opportunity to tweak the game to its fullest potential, making it look and act exactly the way we want it. This section provides details of how to undertake advanced tweaking properly in the Source Engine. On the following pages you'll find a list of the more useful command variables and what they do, but first read the information below on how to correctly implement the tweaks.



Click to enlarge

Usage


There are four main ways in which you can implement command variables in Source Engine games: In the game's Command Console; through Config (.cfg) files; in the Steam Launch Options box for that particular game; or in the game's desktop icon Target box. These various methods usually result in the same outcome for each command, however they provide flexibility in the ways in which you can test, add, edit and remove cvars for the game. The way to access and use each method is covered below. Make sure you read through this information carefully otherwise the tweaks in the Advanced Tweaking section will not function correctly if at all.



Command Console


To enable the command console, you will first need to go into the in-game options, and under the Keyboard tab, click the Advanced button and tick the 'Enable developer console' option (see the In-Game Settings section). Now you can open and close the console at any time by pressing the '~' key (the key under ESC). The Command Console is a window into the game's Source Engine. It allows you to see a range of information about the game and you can use it to change the way the engine behaves in real-time, which is very useful for experimentation.



Config Files


Source games hold many of the settings you select in the in-game options - along with a range of other custom variables - in a file called config.cfg, which can typically be found in your \Program Files\Steam\SteamApps\[username]\[game name]\[game name]\cfg\ directory. For example for Team Fortress 2 the directory path is: \Program Files\Steam\SteamApps\[username]\team fortress 2\tf\cfg\, while for Portal the path is \Program Files\Steam\SteamApps\[username]\portal\portal\cfg. The config.cfg file can be opened and edited using any text editor, such as the Windows Wordpad. This file is very important, so you should first create a backup of it before you consider altering it in any way, or even just to backup your configuration before reformatting your hard drive for example.


While you can add, edit and remove commands directly in config.cfg, it is recommended that instead you create an entirely new file for adding custom commands. To do this, in the same directory as config.cfg, right-click in an empty area and select New>Text Document. Rename this new text document to autoexec.cfg (not autoexec.cfg.txt), and you can now insert all your custom commands into this config file. By default the Source Engine looks for autoexec.cfg at startup, and if it finds it, it will automatically load and execute all the valid commands in it along with those in config.cfg while starting up your game.


Additionally, you can create any other .cfg files you need, name them as you wish (as long as they end in .cfg), such as mytweaks.cfg, place them in the same directory as config.cfg, and then execute all the commands they contain from the command console (or from within autoexec.cfg) by using the exec command. For example typing the command: exec mytweaks.cfg in the console will execute all the command variables contained in the mytweaks.cfg file. They will not run automatically at startup however - only autoexec.cfg and config.cfg can do that.



Steam Launch Options


You can add various command line variables and cvars into the launch options for your Steam games, ensuring that they are activated each time that game is launched. To do this, launch Steam, then open the My Games tab and right-click on the relevant game and select Properties. In the Properties box which opens, click the 'Set Launch Options' button. You can now enter commands in this box and they will be executed whenever you start that game from Steam or your desktop icon.



Icon Properties


Similar to the way you can add command variables to the Steam Launch Options, you can also add commands to your desktop icon for a game, so that whenever you launch it they're executed at startup. If you don't have a desktop icon for your Steam-based game, open to Steam and under the My Games tab right-click on the relevant game, and select 'Create desktop shortcut'. Right-click on this new desktop icon and select Properties. Under the properties, you can enter command variables in the Target box. For example for the Portal game:


"C:\Program Files\Steam\Steam.exe" -applaunch 400 -heapsize 524288 -novid


The above command line will launch Portal (-applaunch 400) with a memory heap size of 512MB (-heapsize 524288), and the game will start without the introductory Valve video (-novid). You can add as many variables as will fit in the Target box, simply make sure you put a single space between each command. Note that unlike entering the commands in the Steam Launch Options box, if you enter them in the desktop icon's Target box they will not apply when you run that game via Steam; they only execute when you use the particular desktop icon. On the other hand the Steam Launch Option variables will apply to the game even if you launch it from a desktop icon.



Command Line Commands


There are some commands which can only be used in the Target box of your HL2 icon, or in the 'Set Launch Options' box of Steam. They cannot be used in the game's console or in your autoexec.cfg file. These are referred to as 'Command Line' commands, and the most useful of these commands are provided below:


-novid: Prevents the Valve startup movie from playing when loading up the game, speeding up startup time.


-noborder: When a game is run in Windowed mode, using this command will remove the borders around the game window.


-heapsize [Kilobytes]: This command tells the Source Engine to allocate more RAM to the system heap, where it can be accessed by the game to improve performance by caching more game information in RAM and hence reducing loading pauses. The default heapsize varies, but can be 256MB or less. If you have 2GB of RAM you may wish to increase this to 512MB (a heapsize of 524288). You can use higher values if you wish, but I don't recommend exceeding half your physical RAM (e.g. for 2GB RAM, don't set heapsize higher than 1024000). You can't force the game to load completely into RAM, that's not what this command does.


Note: More recent Source games may use the mem_max_heapsize command to determine the maximum possible heap size in MB. See the next page for more details of this command.


-console: Speeds up the loading of a game by not loading up the background 3D graphics on the main menu and instead loading up a blurry background picture and the command console is open. Note you can close this console using the '~' key or clicking the x at the top right of the box.


-dxlevel [version]: Using this command allows you to force the game into only using the specified DirectX version for shaders. For example, use -dxlevel 70 to force Hardware DirectX7.0 level support for shaders. This means a noticeable reduction in image quality but an increase in performance. Other values include -dxlevel 80 -dxlevel 81, -dxlevel90 and -dxlevel95. Note that this only works if you choose a DirectX version which is lower than the current one supported by your graphics card - see the Hardware DirectX Version option under the In-Game settings for more details. Note further that lowering the DirectX Level may also cause glitches and problems, so it should be used mainly as a last resort.


-width [pixels] -height [pixels]: Using these two commands you can set a custom resolution in Pixel Width x Pixel Height (e.g. -width 640 –height 480 starts the game with 640x480 resolution). Make sure you choose a resolution supported by your monitor and with the correct ratio of width to height.


-refresh [Hz]: Specifies the refresh rate the game will use upon loading. This is normally not required as your system should already use the optimal refresh rate at your chosen resolution. However if this is not the case you can force it to a specific refresh rate (e.g. -refresh 85). Make absolutely certain that the rate you are trying to apply does not exceed your monitor's capabilities otherwise you may get a blank screen, especially if you change resolutions and forget to change this option.


-32bit: Forces the game to start in 32-bit mode, which is the default on 32-bit systems. This command is only useful if you're running a 64-bit OS and wish to run a game in 32-bit for compatibility reasons.


-dev: Starts the game in developer mode, and usefully also results in the removal of the animated background in the main menu, speeding up startup times. However error/debug text will constantly be displayed on screen during play.


-threads: According to Mike Durand of Valve, the Source engine defaults to taking advantage of no more than three threads due to various issues. However a user can manually override this limitation by specifying -threads 4 (for quad core) on the command line. For anyone using an eight-core CPU, -threads 8 is also possible. Obviously if this causes any problems, remove this command.


Notice that all of the command line commands above have a '-' in front of them. This only applies to these specific command line commands. In general if you want to run any of the command variables listed on the next few pages in your icon's Target box, or in Launch Options, you must add a '+' sign in front of them instead of a '-' before inserting them. For example, if you want to use the exec command to execute a config file at startup, you will actually have to put the command into the Target/Launch Options box in the following way:


-dxlevel 70 +exec mytweaks.cfg


In the example above, when you start your game the DirectX Hardware support is reduced to DirectX7.0, and the contents of the file 'mytweaks.cfg' will be executed if it exists in the appropriate directory.


The simple rule for using commands in the command line is that aside from the few command line-specific commands listed further above, all other command variables, such as those listed on the following pages, require a '+' sign in front of them if used in the Target box or Steam's Launch Options. Note that you must also place a single space between each separate command, and no " " (quote) marks are required around the commands.



The Best Method


In general, the majority of the command variables you will be using will be inserted into a config file after first being tested in the console. To use a command variable in the game's console, open the console and simply type the name of the command variable. This will show you the current setting for the variable as well as its default setting. If you want to change a command variable's value, simply type the name of the variable, then a space, then the value you want to assign it. Some command variables don't require a value, and can be run simply by entering their name and pressing return. You can use the cvarlist, find, and help commands to search for and learn more about specific commands - see Common Commands under the Command Variables list on the next page for more details.


Once you've tested the effects of specific variables in the console, if you only want to change a few you can insert them directly into your game icon's Target box or Steam Launch Options box as detailed further above. However in most cases it is better to create an autoexec.cfg file and insert all your custom command variables one under the other in that file. Note that when using command variables in autoexec.cfg, you don't need to use any '-', '+' or " " signs around the command. Simply enter the command name, followed by a space, and the value you want to assign it - just as if you were entering it into the console. However if for some reason you decide to edit or insert any settings into config.cfg, you will need to use "" marks around the value assigned to any command variable. In general you should avoid editing config.cfg and use autoexec.cfg for your tweaking.


Note that one of the reasons I don't provide "pre-tweaked" autoexec.cfg files in my guides is that I have no way of knowing your image quality and performance preferences, not to mention precisely which hardware is on each system. There are very few commands which give extra performance without any visual quality impact. Therefore it requires testing and learning what the commands do on your part to create a useful autoexec.cfg for your own system. It's not a simple process, and I strongly urge you not to just copy and paste someone else's autoexec.cfg as you will likely run into a bunch of troubles or wind up with effects enabled/disable that you don't want. Understanding what you're doing is the key to tweaking.



That covers the methods used to apply advanced tweaks to the Source Engine. The next few pages go into detail on the actual command variables which can be used for tweaking.