Half-Life 2

Half-Life 2

Not enough ratings
[Linux & macOS] Play Half-Life 2 Mods with native engine
By Mono
Some community-made mods have only a Windows port, but they can actually play on Linux natively without Proton.
   
Award
Favorite
Favorited
Unfavorite
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:
6 Comments
SourceStick 3 Aug, 2024 @ 4:14am 
Seems like this trick didn't work :E
Half-Life 2 or Source SDK 2013 Singleplayer [Upcoming] just launch like normal even with the added code.
SourceStick 2 Aug, 2024 @ 12:16pm 
The biggest problem I have with running Half-Life 2 mods is either missing gameinfo.txt or library client not found errors! >:(
I'll probably give this a try, but I'm curious if you have any info on this? I really wanna go spread the advice around as I see so many posts about these problems with no answers (including my own)!

I'm currently trying to launch TWHL:Source: Without using Proton for anything, I get library client error. If I put Source SDK 2013 Singleplayer [Upcoming] to run through Proton, I get the gameinfo.txt error. It doesn't matter if I've set the mod it self run through Proton in either care (Honestly I don't even know if this does anything :P).
Mono  [author] 22 Oct, 2020 @ 2:42am 
I currently have no GoldSrc game installed on my PC, so I am not sure. If you make it work, please let me know, thanks.
Mono  [author] 18 Oct, 2020 @ 3:47pm 
Maybe it's no different playing with Proton, but in our way we can save more disk spaces(in this case, Year Long Alarm requires 7 GB originally but we can cut it down to 200+ MB). Also, for some low-spec computers playing natively will be more enjoyable.
unemployed virgin 17 Oct, 2020 @ 6:41am 
that's really interesting to know how it works under the hood, thanks for the guide.
what are the benefits of not using proton ? in my experience, source engine games work like a charm with Proton, maybe a few crashes here and then
Mono  [author] 15 Oct, 2020 @ 9:43am 
The macos and linux seemed sharing the same startup script, so I think it should also work on mac