Half Life 2 Tweak Guide
[Page 7] Advanced Tweaking
You can change more than just the handful of settings available under the in-game options in Half Life 2. The Source Engine by Valve is highly customizable: there are over 1800 Command Variables (cvars) which can be used to alter everything from the way the game allocates memory to providing additional game information to recording demos and running custom benchmarks. This gives us an excellent opportunity to tweak Half Life 2 to its fullest potential. This section provides details of how to tweak Half Life 2 correctly using the command variables, and the next few pages provide a list of the more useful command variables and what they do.
There are four main ways in which you can implement command variables in Half Life 2: In the game's Console; through Config (.cfg) files; in the Steam Launch Options box; or in your game icon's 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. If this section looks familiar to you, that's because you may have seen something just like it in my Doom 3 Tweak Guide. There are a lot of similarities between tweaking Doom 3 and Half Life 2. This is no coincidence - although Half Life 2 has a completely different engine from Doom 3, it is the sign of an advanced and highly modifiable engine that you can access a large range of command variables in a variety of ways.
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:
Half Life 2 Console
To enable the Half Life 2 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 mode (console)' option (see the Keyboard option under the In-Game Settings section above). Now you can open and close the console at any time by pressing the '~' key (the key under ESC). The Half Life 2 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.
Half Life 2 Config Files
Half Life 2 holds 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 be found in your \Program Files\Valve\Steam\SteamApps\[username]\half-life 2\hl2\cfg\ directory. This file can be opened and edited using any text editor, such as the Windows Wordpad. The config.cfg file is very important, so you should first create a backup of it before you edit it in any way.
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 Half Life 2 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 Half Life 2.
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 run the commands they contain from the Half Life 2 console (or from autoexec.cfg) by using the "exec" command. For example typing the command: exec mytweaks.cfg in the console will execute 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 variables into the launch options for Half Life 2, ensuring that they are activated each time Half Life 2 is launched. To do this, right-click on your Steam icon and select 'Play Games'. Right-click on the Half Life 2 entry under 'My Games' and select Properties. In the Properties box which opens, click the 'Launch Options' button. You can now enter command variables in this box and they will be executed whenever you start Half Life 2 from Steam or your desktop icon.
Half Life 2 Icon Properties
Similar to the way you can add command variables to the Steam Launch Options, you can also add them to the Half Life 2 startup by editing the desktop icon used to launch the game. If you don't have a desktop icon for Half Life 2, go to Steam>Play Games and right-click on Half Life 2 under 'My Games', then select 'Create desktop shortcut'. Right-click on the desktop icon for Half Life 2 and select Properties. Under the properties, you can enter command variables in the Target box. For example:
"C:\Program Files\Valve\Steam\Steam.exe" -applaunch 220 -heapsize 512000 +map_background none
The above command line will launch Half Life 2 (-applaunch 220) with a memory allocation of around 500MB (-heapsize 512000), and Half Life 2 will start without a 3D background on the main menu (+map_background none). 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 Half Life 2 from Steam, whereas the Steam Launch Option variables will apply to Half Life 2 even when 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 '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:
-heapsize [Kilobytes]: This command tells Half Life 2 to allocate more RAM to the game system heap, where it can be accessed by the game to improve performance by storing more game information in RAM and hence reducing loading pauses. The default heapsize is 64MB, however you can safely allocate around 128MB (i.e. -heapsize 128000) for most systems. You can use higher values if you have more RAM, but I don't recommend exceeding half your physical RAM (e.g. for 1GB RAM, set heapsize of 512000).
-console: Speeds up the loading of Half Life 2 at startup by not loading up the background 3D graphics on the main menu and instead loading up a blurry background picture and the Half Life 2 console open. Note you can close this console using the '~' key.
-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 HL2 with 640x480 resolution). Make sure you choose a resolution supported by your monitor and with the correct ratio of width to height (usually 4:3).
-dxlevel [version]: Using this command allows you to force Half Life 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 reduction in image quality but an increase in performance. Other values include -dxlevel 80 -dxlevel 81 and -dxlevel90. 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.
-rate [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. -rate 85). Make absolutely certain that the rate you are trying to apply does not exceed your monitor's capabilities otherwise you may damage your monitor - especially if you change resolutions and forget to change this option.
Notice that all of the command line commands above have a '-' in front of them. This only applies to these specific few 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 Half Life 2 the DirectX Hardware support is reduced to DirectX7.0, and the contents of the file 'mytweaks.cfg' will be executed.
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.
Using Command Variable Tweaks ? The Best Method
In general, the majority of the command variables you will be using will be inserted into a config file after 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, help and revert commands to search for and learn more about specific commands (See Common Commands under the Command Variables list on the next page for details of these commands).
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 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.
A sample autoexec.cfg file content is provided below as an example of what it should look like:
bindtoggle z cl_showfps 2
mat_dxlevel 81
sv_autosave 0
jpeg_quality 60
snd_mixahead 0.7
cl_forcepreload 1
sv_forcepreload 1
cl_smooth 0
cl_ragdoll_collide 1
r_fastzreject 1
muzzleflash_light 0
r_decals 1000
r_maxmodeldecal 25
dsp_enhance_stereo 1
mat_bloom 0
The settings above suit a medium level system without lowering image quality or realism noticeably, however do not just cut and paste this file into your own autoexec.cfg without referring to what each of these commands does, as it may not suit some people and/or may conflict with your system hardware. This is not the most optimal autoexec.cfg file to use for everyone. In fact the major reason why I don't provide generic 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. I strongly urge you to take the time to test and compile your own list of command variables, otherwise you may run into a bunch of troubles with incorrect/incompatible settings.
Troubleshooting Command Variable Issues
If you do run into any problems with cvar changes you have made, you should note that many changes you make in the console or in your autoexec.cfg file (or any other config file) may also be recorded in the config.cfg file by the game engine and hence become "permanent", even if you delete or alter other config files. You can either search through config.cfg and alter or delete the cvar there, or you can restore your backed-up version of config.cfg to undo all your changes.
If on the other hand you don't think a command you've included in a config file is being implemented at all, firstly read through the above instructions thoroughly. If the instructions are followed in detail, command variables will work, simply because I have tested them and I know these methods are sound. However on the off chance that it still doesn't resolve your dilemma, enter the command in the console with your chosen value, then just type the cvar name again (with no value). It should show the new value against the cvar - if not, then the command is either not being used properly, the value you want to apply is invalid, or you may not be able to change it due to your hardware capabilities. Also note that cheat commands (denoted by (cheat) next to them on the list in the following pages) can only be enabled if the sv_cheats 1 command is first used.
In the case of the commands which can only be used in an icon's Target box, or from Steam's 'Launch Options', such as heapsize, you can open the console immediately after HL2 has started up and you should see some indications of their implementation. With Heapsize for example, once you open the console after Half Life 2 has just loaded you will see the amount of memory allocated to the game at the top of the console text.
That covers how to apply tweaks in Half Life 2. The next few pages go into the actual command variables which can be used to tweak Half Life 2.
