Half-Life 2 Guide

[Linux & macOS] Play Half-Life 2 Mods with native engine for Half-Life 2

[Linux & macOS] Play Half-Life 2 Mods with native engine

Overview

Some community-made mods have only a Windows port, but they can actually play on Linux natively without Proton.

Pre-knowledges

Directory Structure & Launch Options Explained

Assume the relative path from ~/.steam/steamapps/common/Half-Life 2

  • bin/: Contains the game engine itself.
  • hl2/: Half-Life 2 basic resources.
  • episodic/: Half-Life 2: Episode One specific resources.
  • ep2/: Half-Life 2: Episode Two specific resources.
  • … (some other unrelated stuff)

You may have realized that Episode One and Two are installed along with Half-Life 2 itself, thus sharing the same directory. But how the launcher know which to start? What is the difference between them when you click “Play” in Episode One and in its sequel?

The answer is: command-line arguments. When you want to play Half-Life 2, “-game hl2” is passed to launcher; for Episode One, it’s “-game episodic”. This also applies to other Source Engine games like Portal 2 etc.

Basically, a custom mod is no different from official ones, it comes with a game engine, some mod-specific resources, and optional, resources referred from hl2/, episodic/, or ep2/. What essential here is only the mod-specific resource, thus we can figure out how to use our already-exist Half-Life 2 game to launch the mod.

Step 1: Have your mod installed from Steam

(Here, I will take the Half-Life 2: Year Long Alarm for example.)

Open the mod directory, you should see the folder “yearlongalarm/“.
Soft link it to Half-Life 2 root directory:

Step 2: Modify launch script to accept custom arguments

Theoretically, you can simply start the mod by running

./hl2_linux -game yearlongalarm

However, it’s not the truth. Steam uses some tricks to prevent us from launching the game directly, maybe the Steam client will set some special environment variables. Weird enough, Portal series can be launched in this way! But for Half-Life 2, the only way is to modify the launching script.

We will pass our mod name through environment variables.
Edit “Half-Life 2/hl2.sh”

Code used here is:

if [ -z ${MODNAME+x} ]; then LAUNCH_OPTIONS=”$@” else LAUNCH_OPTIONS=$(echo “$@” | sed “s/-game w*/-game $MODNAME/”) fi

Explain:
It checks whether $MODNAME is set, if so, substitute the “-game xxx” to our “-game $MODNAME“, if not then just keep it untouched.

Step 3: Set Half-Life 2 Launch Options

Add MODNAME=yearlongalarm before your Half-Life 2 launch options.
NOTE: The launch option is for Half-Life 2, not the mod itself!

Save the settings, and start Half-Life 2(again, not the mod!), you can see Year Long Alarm is launched successfully.

Additional Notes

If your mod referred some resources from Episode One or Two(you can figure this out by checking whether the mod directory contains episodic/ or ep2/), but you have not installed the corresponding episodes, you will also need to soft link these two folders.

If you are prompted to lack some resources, try to soft link the mod’s own episodic, ep2 or hl2.
For example, Half-Life 2: Down Fall requires both downfall(mod-specific resources) and hl2 to launch. In this case, you will need to rename the original hl2:

SteamSolo.com